• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_CAMERA_DPS_SESSION_COORDINATOR_H
17 #define OHOS_CAMERA_DPS_SESSION_COORDINATOR_H
18 
19 #include <cstdint>
20 
21 #include "enable_shared_create.h"
22 #include "ideferred_photo_processing_session_callback.h"
23 #include "ideferred_video_processing_session_callback.h"
24 #include "ipc_file_descriptor.h"
25 #include "ivideo_process_callbacks.h"
26 #include "photo_session_info.h"
27 #include "task_manager.h"
28 #include "video_session_info.h"
29 
30 namespace OHOS {
31 namespace CameraStandard {
32 namespace DeferredProcessing {
33 class SessionCoordinator : public EnableSharedCreateInit<SessionCoordinator> {
34 public:
35     ~SessionCoordinator();
36 
37     int32_t Initialize() override;
38     void Start();
39     void Stop();
40     void OnStateChanged(const int32_t userId, DpsStatus statusCode);
41 
42     void AddVideoSession(const sptr<VideoSessionInfo>& sessionInfo);
43     void DeleteVideoSession(const int32_t userId);
44     void OnVideoProcessDone(const int32_t userId, const std::string& videoId, const sptr<IPCFileDescriptor>& ipcFd);
45     void OnVideoError(const int32_t userId, const std::string& videoId, DpsError errorCode);
46     void OnVideoStateChanged(const int32_t userId, DpsStatus statusCode);
47     std::shared_ptr<IVideoProcessCallbacks> GetVideoProcCallbacks();
48 
GetPhotoSessionInfo(int32_t userId)49     inline sptr<PhotoSessionInfo> GetPhotoSessionInfo(int32_t userId)
50     {
51         auto iter = photoInfos_.find(userId);
52         if (iter != photoInfos_.end()) {
53             return iter->second;
54         }
55         return nullptr;
56     }
57 
GetRemoteVideoCallback(int32_t userId)58     inline sptr<IDeferredVideoProcessingSessionCallback> GetRemoteVideoCallback(int32_t userId)
59     {
60         auto iter = videoCallbackMap_.find(userId);
61         if (iter != videoCallbackMap_.end()) {
62             return iter->second.promote();
63         }
64         return nullptr;
65     }
66 
67 protected:
68     SessionCoordinator();
69 
70 private:
71     class VideoProcCallbacks;
72 
73     enum struct CallbackType {
74         ON_PROCESS_DONE,
75         ON_ERROR,
76         ON_STATE_CHANGED
77     };
78 
79     struct RequestResult {
80         CallbackType callbackType;
81         const int32_t userId;
82         const std::string requestId;
83         sptr<IPCFileDescriptor> ipcFd;
84         long dataSize;
85         DpsError errorCode;
86         DpsStatus statusCode;
87     };
88 
89     void ProcessVideoResults(sptr<IDeferredVideoProcessingSessionCallback> callback);
90 
91     std::unordered_map<int32_t, sptr<PhotoSessionInfo>> photoInfos_ {};
92     std::shared_ptr<IVideoProcessCallbacks> videoProcCallbacks_ {nullptr};
93     std::unordered_map<int32_t, wptr<IDeferredVideoProcessingSessionCallback>> videoCallbackMap_ {};
94     std::deque<RequestResult> pendingRequestResults_ {};
95 };
96 } // namespace DeferredProcessing
97 } // namespace CameraStandard
98 } // namespace OHOS
99 #endif // OHOS_CAMERA_DPS_SESSION_COORDINATOR_H