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_VIDEO_STRATEGY_CENTER_H 17 #define OHOS_CAMERA_DPS_VIDEO_STRATEGY_CENTER_H 18 19 #include <functional> 20 21 #include "basic_definitions.h" 22 #include "ischeduler_video_state.h" 23 #include "ivideo_state_change_listener.h" 24 #include "video_job_repository.h" 25 26 namespace OHOS { 27 namespace CameraStandard { 28 namespace DeferredProcessing { 29 constexpr uint32_t TIME_OK = 0b0; 30 using EventCallback = std::function<void(const int32_t)>; 31 32 class VideoStrategyCenter : public std::enable_shared_from_this<VideoStrategyCenter> { 33 public: 34 ~VideoStrategyCenter(); 35 36 void Initialize(); 37 void InitHandleEvent(); 38 void InitScheduleState(); 39 void RegisterStateChangeListener(const std::weak_ptr<IVideoStateChangeListener>& listener); 40 DeferredVideoWorkPtr GetWork(); 41 DeferredVideoJobPtr GetJob(); 42 ExecutionMode GetExecutionMode(); 43 void UpdateSingleTime(bool isOk); 44 void UpdateAvailableTime(bool isNeedReset, int32_t useTime); 45 GetAvailableTime()46 inline int32_t GetAvailableTime() 47 { 48 return availableTime_; 49 } 50 IsReady()51 inline bool IsReady() 52 { 53 DP_INFO_LOG("isSchedulerOk is: %{public}d", !isNeedStop_); 54 return !isNeedStop_; 55 } 56 IsTimeReady()57 inline bool IsTimeReady() 58 { 59 DP_INFO_LOG("isTimeOk is: 0x%{public}x", isTimeOk_); 60 return isTimeOk_ == TIME_OK; 61 } 62 isCharging()63 inline bool isCharging() 64 { 65 DP_INFO_LOG("isCharging is: %{public}d", isCharging_); 66 return isCharging_; 67 } 68 69 protected: 70 VideoStrategyCenter(const int32_t userId, const std::shared_ptr<VideoJobRepository>& repository); 71 72 private: 73 class EventsListener; 74 75 void HandleEventChanged(EventType event, int32_t value); 76 void HandleCameraEvent(int32_t value); 77 void HandleHalEvent(int32_t value); 78 void HandleMedialLibraryEvent(int32_t value); 79 void HandleScreenEvent(int32_t value); 80 void HandleChargingEvent(int32_t value); 81 void HandleBatteryEvent(int32_t value); 82 void HandleBatteryLevelEvent(int32_t value); 83 void HandleTemperatureEvent(int32_t value); 84 void HandlePhotoProcessEvent(int32_t value); 85 void UpdateValue(ScheduleType type, int32_t value); 86 ScheduleInfo ReevaluateSchedulerInfo(); 87 ScheduleInfo GetScheduleInfo(ScheduleType type); 88 std::shared_ptr<ISchedulerVideoState> GetScheduleState(ScheduleType type); 89 ConvertThermalLevel(int32_t level)90 inline VideoThermalLevel ConvertThermalLevel(int32_t level) 91 { 92 DP_CHECK_RETURN_RET(level == ThermalLevel::LEVEL_0, VideoThermalLevel::COOL); 93 return VideoThermalLevel::HOT; 94 } 95 ConvertProcessState(int32_t size)96 inline PhotoProcessStatus ConvertProcessState(int32_t size) 97 { 98 DP_CHECK_RETURN_RET(size > 0, PhotoProcessStatus::BUSY); 99 return PhotoProcessStatus::IDLE; 100 } 101 102 const int32_t userId_; 103 bool isCharging_ {false}; 104 bool isNeedStop_ {true}; 105 uint32_t isTimeOk_ {0}; 106 int32_t availableTime_ {TOTAL_PROCESS_TIME}; 107 std::shared_ptr<EventsListener> eventsListener_ {nullptr}; 108 std::shared_ptr<VideoJobRepository> videoJobRepository_ {nullptr}; 109 std::weak_ptr<IVideoStateChangeListener> videoStateChangeListener_; 110 std::unordered_map<EventType, EventCallback> eventHandlerList_ {}; 111 std::unordered_map<ScheduleType, std::shared_ptr<ISchedulerVideoState>> scheduleStateList_ {}; 112 }; 113 } // namespace DeferredProcessing 114 } // namespace CameraStandard 115 } // namespace OHOS 116 #endif // OHOS_CAMERA_DPS_VIDEO_STRATEGY_CENTER_H