1 /* 2 * Copyright (c) 2023-2023 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 "iimage_process_callbacks.h" 20 #include "ivideo_process_callbacks.h" 21 #include "ipc_file_descriptor.h" 22 #include "ideferred_photo_processing_session_callback.h" 23 #include "ideferred_video_processing_session_callback.h" 24 #include "video_session_info.h" 25 #include "task_manager.h" 26 27 namespace OHOS::Media { 28 class Picture; 29 } 30 namespace OHOS { 31 namespace CameraStandard { 32 namespace DeferredProcessing { 33 class SessionCoordinator : public std::enable_shared_from_this<SessionCoordinator> { 34 public: 35 SessionCoordinator(); 36 ~SessionCoordinator(); 37 void Initialize(); 38 void Start(); 39 void Stop(); 40 41 void OnProcessDone(const int32_t userId, const std::string& imageId, 42 const sptr<IPCFileDescriptor>& ipcFd, const int32_t dataSize, bool isCloudImageEnhanceSupported); 43 void OnProcessDoneExt(int userId, const std::string& imageId, std::shared_ptr<Media::Picture> picture, 44 bool isCloudImageEnhanceSupported); 45 void OnError(const int32_t userId, const std::string& imageId, DpsError errorCode); 46 void OnStateChanged(const int32_t userId, DpsStatus statusCode); 47 std::shared_ptr<IImageProcessCallbacks> GetImageProcCallbacks(); 48 void NotifySessionCreated(const int32_t userId, sptr<IDeferredPhotoProcessingSessionCallback> callback, 49 TaskManager* taskManager); 50 void NotifyCallbackDestroyed(const int32_t userId); 51 52 void AddSession(const sptr<VideoSessionInfo>& sessionInfo); 53 void DeleteSession(const int32_t userId); 54 void OnVideoProcessDone(const int32_t userId, const std::string& videoId, const sptr<IPCFileDescriptor>& ipcFd); 55 void OnVideoError(const int32_t userId, const std::string& videoId, DpsError errorCode); 56 void OnVideoStateChanged(const int32_t userId, DpsStatus statusCode); 57 std::shared_ptr<IVideoProcessCallbacks> GetVideoProcCallbacks(); 58 59 private: 60 class ImageProcCallbacks; 61 class VideoProcCallbacks; 62 63 enum struct CallbackType { 64 ON_PROCESS_DONE, 65 ON_ERROR, 66 ON_STATE_CHANGED 67 }; 68 69 struct ImageResult { 70 CallbackType callbackType; 71 const int32_t userId; 72 std::string imageId; 73 sptr<IPCFileDescriptor> ipcFd; 74 long dataSize; 75 DpsError errorCode; 76 DpsStatus statusCode; 77 bool isCloudImageEnhanceSupported; 78 }; 79 80 struct ImageResultExt { 81 CallbackType callbackType; 82 int userId; 83 std::string imageId; 84 std::shared_ptr<Media::Picture> picture; 85 long dataSize; 86 DpsError errorCode; 87 DpsStatus statusCode; 88 }; 89 90 struct RequestResult { 91 CallbackType callbackType; 92 const int32_t userId; 93 const std::string requestId; 94 sptr<IPCFileDescriptor> ipcFd; 95 long dataSize; 96 DpsError errorCode; 97 DpsStatus statusCode; 98 }; 99 100 void ProcessPendingResults(sptr<IDeferredPhotoProcessingSessionCallback> callback); 101 void ProcessVideoResults(sptr<IDeferredVideoProcessingSessionCallback> callback); 102 103 std::mutex mutex_; 104 std::shared_ptr<IImageProcessCallbacks> imageProcCallbacks_; 105 std::map<int32_t, wptr<IDeferredPhotoProcessingSessionCallback>> remoteImageCallbacksMap_; 106 std::deque<ImageResult> pendingImageResults_; 107 std::shared_ptr<IVideoProcessCallbacks> videoProcCallbacks_; 108 std::map<int32_t, wptr<IDeferredVideoProcessingSessionCallback>> remoteVideoCallbacksMap_; 109 std::deque<RequestResult> pendingRequestResults_; 110 }; 111 } // namespace DeferredProcessing 112 } // namespace CameraStandard 113 } // namespace OHOS 114 #endif // OHOS_CAMERA_DPS_SESSION_COORDINATOR_H