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_DEFERRED_VIDEO_JOB_H 17 #define OHOS_CAMERA_DPS_DEFERRED_VIDEO_JOB_H 18 19 #include "basic_definitions.h" 20 #include "dp_utils.h" 21 #include "ipc_file_descriptor.h" 22 23 namespace OHOS { 24 namespace CameraStandard { 25 namespace DeferredProcessing { 26 enum class VideoJobStatus { 27 NONE = 0, 28 PAUSE = 1, 29 PENDING = 2, 30 FAILED = 3, 31 DELETED = 4, 32 RUNNING = 5, 33 COMPLETED = 6, 34 ERROR = 7, 35 }; 36 37 class DeferredVideoJob { 38 public: 39 DeferredVideoJob(const std::string& videoId, const sptr<IPCFileDescriptor>& srcFd, 40 const sptr<IPCFileDescriptor>& dstFd); 41 ~DeferredVideoJob(); 42 GetCurStatus()43 inline VideoJobStatus GetCurStatus() 44 { 45 DP_DEBUG_LOG("videoId: %{public}s, current status: %{public}d, previous status: %{public}d", 46 videoId_.c_str(), curStatus_, preStatus_); 47 return curStatus_; 48 } 49 GetPreStatus()50 inline VideoJobStatus GetPreStatus() 51 { 52 DP_DEBUG_LOG("videoId: %{public}s, current status: %{public}d, previous status: %{public}d", 53 videoId_.c_str(), curStatus_, preStatus_); 54 return preStatus_; 55 } 56 GetVideoId()57 inline std::string GetVideoId() 58 { 59 return videoId_; 60 } 61 GetInputFd()62 inline sptr<IPCFileDescriptor> GetInputFd() 63 { 64 return srcFd_; 65 } 66 GetOutputFd()67 inline sptr<IPCFileDescriptor> GetOutputFd() 68 { 69 return dstFd_; 70 } 71 72 bool operator==(const DeferredVideoJob& other) const 73 { 74 return videoId_ == other.videoId_; 75 } 76 77 bool operator>(const DeferredVideoJob& other) const 78 { 79 if (curStatus_ == other.curStatus_) { 80 return createTime_ < other.createTime_; 81 } 82 return curStatus_ < other.curStatus_; 83 } 84 85 private: 86 friend class VideoJobRepository; 87 bool SetJobStatus(VideoJobStatus curStatus); 88 89 const std::string videoId_; 90 sptr<IPCFileDescriptor> srcFd_; 91 sptr<IPCFileDescriptor> dstFd_; 92 VideoJobStatus preStatus_ {VideoJobStatus::NONE}; 93 VideoJobStatus curStatus_ {VideoJobStatus::NONE}; 94 SteadyTimePoint createTime_; 95 }; 96 using DeferredVideoJobPtr = std::shared_ptr<DeferredVideoJob>; 97 98 class DeferredVideoWork { 99 public: 100 DeferredVideoWork(const DeferredVideoJobPtr& jobPtr, ExecutionMode mode, bool isAutoSuspend); 101 ~DeferredVideoWork(); 102 GetDeferredVideoJob()103 inline DeferredVideoJobPtr GetDeferredVideoJob() const 104 { 105 return jobPtr_; 106 } 107 GetExecutionMode()108 inline ExecutionMode GetExecutionMode() const 109 { 110 return executionMode_; 111 } 112 IsSuspend()113 inline bool IsSuspend() const 114 { 115 return !isCharging_; 116 } 117 GetStartTime()118 inline SteadyTimePoint GetStartTime() const 119 { 120 return startTime_; 121 } 122 GetExecutionTime()123 inline uint32_t GetExecutionTime() const 124 { 125 return static_cast<uint32_t>(GetDiffTime<Milli>(GetStartTime())); 126 } 127 GetTimeId()128 inline uint32_t GetTimeId() const 129 { 130 return timeId_; 131 } 132 SetTimeId(const uint32_t timeId)133 inline void SetTimeId(const uint32_t timeId) 134 { 135 timeId_ = timeId; 136 } 137 138 private: 139 DeferredVideoJobPtr jobPtr_; 140 ExecutionMode executionMode_; 141 SteadyTimePoint startTime_; 142 bool isCharging_; 143 uint32_t timeId_ {0}; 144 }; 145 using DeferredVideoWorkPtr = std::shared_ptr<DeferredVideoWork>; 146 } // namespace DeferredProcessing 147 } // namespace CameraStandard 148 } // namespace OHOS 149 #endif // OHOS_CAMERA_DPS_DEFERRED_VIDEO_JOB_H