• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #include <memory>
21 
22 #include "ideferred_photo_processing_session_callback.h"
23 #include "ideferred_video_processing_session_callback.h"
24 #include "iimage_process_callbacks.h"
25 #include "ipc_file_descriptor.h"
26 #include "ivideo_process_callbacks.h"
27 #include "photo_session_info.h"
28 #include "task_manager.h"
29 #include "video_session_info.h"
30 
31 namespace OHOS {
32 namespace CameraStandard {
33 namespace DeferredProcessing {
34 class SessionCoordinator : public std::enable_shared_from_this<SessionCoordinator> {
35 public:
36     ~SessionCoordinator();
37 
38     void Initialize();
39     void Start();
40     void Stop();
41     void AddPhotoSession(const sptr<PhotoSessionInfo>& sessionInfo);
42     void DeletePhotoSession(const int32_t userId);
43     void OnProcessDone(const int32_t userId, const std::string& imageId,
44         const sptr<IPCFileDescriptor>& ipcFd, const int32_t dataSize, uint32_t cloudImageEnhanceFlag);
45     void OnProcessDoneExt(int userId, const std::string& imageId, std::shared_ptr<PictureIntf> picture,
46         uint32_t cloudImageEnhanceFlag);
47     void OnError(const int32_t userId, const std::string& imageId, DpsError errorCode);
48     void OnStateChanged(const int32_t userId, DpsStatus statusCode);
49     std::shared_ptr<IImageProcessCallbacks> GetImageProcCallbacks();
50 
51     void AddVideoSession(const sptr<VideoSessionInfo>& sessionInfo);
52     void DeleteVideoSession(const int32_t userId);
53     void OnVideoProcessDone(const int32_t userId, const std::string& videoId, const sptr<IPCFileDescriptor>& ipcFd);
54     void OnVideoError(const int32_t userId, const std::string& videoId, DpsError errorCode);
55     void OnVideoStateChanged(const int32_t userId, DpsStatus statusCode);
56     std::shared_ptr<IVideoProcessCallbacks> GetVideoProcCallbacks();
57 
58 protected:
59     SessionCoordinator();
60 
61 private:
62     class ImageProcCallbacks;
63     class VideoProcCallbacks;
64 
65     enum struct CallbackType {
66         ON_PROCESS_DONE,
67         ON_ERROR,
68         ON_STATE_CHANGED
69     };
70 
71     struct ImageResult {
72         CallbackType callbackType;
73         const int32_t userId;
74         std::string imageId;
75         sptr<IPCFileDescriptor> ipcFd;
76         long dataSize;
77         DpsError errorCode;
78         DpsStatus statusCode;
79         uint32_t cloudImageEnhanceFlag;
80     };
81 
82     struct ImageResultExt {
83         CallbackType callbackType;
84         int userId;
85         std::string imageId;
86         std::shared_ptr<PictureIntf> picture;
87         long dataSize;
88         DpsError errorCode;
89         DpsStatus statusCode;
90     };
91 
92     struct RequestResult {
93         CallbackType callbackType;
94         const int32_t userId;
95         const std::string requestId;
96         sptr<IPCFileDescriptor> ipcFd;
97         long dataSize;
98         DpsError errorCode;
99         DpsStatus statusCode;
100     };
101 
102     void ProcessPendingResults(sptr<IDeferredPhotoProcessingSessionCallback> callback);
103     void ProcessVideoResults(sptr<IDeferredVideoProcessingSessionCallback> callback);
104 
GetRemoteImageCallback(int32_t userId)105     inline sptr<IDeferredPhotoProcessingSessionCallback> GetRemoteImageCallback(int32_t userId)
106     {
107         auto iter = photoCallbackMap_.find(userId);
108         if (iter != photoCallbackMap_.end()) {
109             return iter->second.promote();
110         }
111         return nullptr;
112     }
113 
GetRemoteVideoCallback(int32_t userId)114     inline sptr<IDeferredVideoProcessingSessionCallback> GetRemoteVideoCallback(int32_t userId)
115     {
116         auto iter = videoCallbackMap_.find(userId);
117         if (iter != videoCallbackMap_.end()) {
118             return iter->second.promote();
119         }
120         return nullptr;
121     }
122 
123     std::shared_ptr<IImageProcessCallbacks> imageProcCallbacks_ {nullptr};
124     std::unordered_map<int32_t, wptr<IDeferredPhotoProcessingSessionCallback>> photoCallbackMap_ {};
125     std::deque<ImageResult> pendingImageResults_ {};
126     std::shared_ptr<IVideoProcessCallbacks> videoProcCallbacks_ {nullptr};
127     std::unordered_map<int32_t, wptr<IDeferredVideoProcessingSessionCallback>> videoCallbackMap_ {};
128     std::deque<RequestResult> pendingRequestResults_ {};
129 };
130 } // namespace DeferredProcessing
131 } // namespace CameraStandard
132 } // namespace OHOS
133 #endif // OHOS_CAMERA_DPS_SESSION_COORDINATOR_H