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_PHOTO_POST_PROCESSOR_H 17 #define OHOS_CAMERA_DPS_PHOTO_POST_PROCESSOR_H 18 19 #include <list> 20 #include <atomic> 21 22 #include "ipc_file_descriptor.h" 23 #include "safe_map.h" 24 #include "v1_2/icamera_host_callback.h" 25 #include "v1_2/iimage_process_service.h" 26 #include "v1_2/iimage_process_session.h" 27 #include "v1_2/iimage_process_callback.h" 28 #include "v1_2/types.h" 29 #include "iremote_object.h" 30 #include "deferred_photo_job.h" 31 #include "iimage_process_callbacks.h" 32 #include "task_manager.h" 33 34 namespace OHOS { 35 namespace CameraStandard { 36 namespace DeferredProcessing { 37 enum class IveResult : int32_t { 38 ERROR = 0 39 }; 40 41 enum class IveErrorCode : int32_t { 42 ERROR = 0 43 }; 44 45 enum class IveStateCode : int32_t { 46 ERROR = 0 47 }; 48 49 class PhotoPostProcessor { 50 public: 51 PhotoPostProcessor(const int32_t userId, TaskManager* taskManager, IImageProcessCallbacks* callbacks); 52 ~PhotoPostProcessor(); 53 54 void Initialize(); 55 int GetConcurrency(ExecutionMode mode); 56 bool GetPendingImages(std::vector<std::string>& pendingImages); 57 void SetExecutionMode(ExecutionMode executionMode); 58 void SetDefaultExecutionMode(); 59 void ProcessImage(std::string imageId); 60 void RemoveImage(std::string imageId); 61 void Interrupt(); 62 void Reset(); 63 void OnSessionDied(); 64 int32_t GetUserId(); 65 66 private: 67 class PhotoProcessListener; 68 class SessionDeathRecipient; 69 70 void OnProcessDone(const std::string& imageId, std::shared_ptr<BufferInfo> bufferInfo); 71 72 void OnProcessDoneExt(const std::string& imageId, std::shared_ptr<BufferInfoExt> bufferInfo); 73 74 void OnError(const std::string& imageId, DpsError errorCode); 75 void OnStateChanged(HdiStatus HdiStatus); 76 bool ConnectServiceIfNecessary(); 77 void DisconnectServiceIfNecessary(); 78 void ScheduleConnectService(); 79 void StopTimer(const std::string& imageId); 80 81 std::mutex mutex_; 82 const int32_t userId_; 83 TaskManager* taskManager_; 84 std::shared_ptr<IImageProcessCallbacks> processCallacks_; 85 sptr<PhotoProcessListener> listener_; 86 sptr<OHOS::HDI::Camera::V1_2::IImageProcessSession> session_; 87 sptr<IRemoteObject::DeathRecipient> sessionDeathRecipient_; 88 SafeMap<std::string, uint32_t> imageId2Handle_; 89 std::unordered_map<std::string, uint32_t> imageId2CrashCount_; 90 std::list<std::string> removeNeededList_; 91 std::atomic<int> consecutiveTimeoutCount_; 92 }; 93 } // namespace DeferredProcessing 94 } // namespace CameraStandard 95 } // namespace OHOS 96 #endif // OHOS_CAMERA_DPS_PHOTO_POST_PROCESSOR_H