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_TIME_LAPSE_PHOTO_SESSION_H 17 #define OHOS_CAMERA_TIME_LAPSE_PHOTO_SESSION_H 18 19 #include "session/profession_session.h" 20 21 namespace OHOS { 22 namespace CameraStandard { 23 24 enum class TimeLapseRecordState : int32_t { 25 IDLE = 0, 26 RECORDING = 1, 27 }; 28 29 enum class TimeLapsePreviewType : int32_t { 30 DARK = 1, 31 LIGHT = 2, 32 }; 33 34 struct TryAEInfo { 35 bool isTryAEDone; 36 bool isTryAEHintNeeded; 37 TimeLapsePreviewType previewType; 38 int32_t captureInterval; 39 }; 40 41 class TryAEInfoCallback { 42 public: 43 TryAEInfoCallback() = default; 44 virtual ~TryAEInfoCallback() = default; 45 virtual void OnTryAEInfoChanged(TryAEInfo info) = 0; 46 }; 47 48 class TimeLapsePhotoSession; 49 50 class TimeLapsePhotoSessionMetadataResultProcessor : public MetadataResultProcessor { 51 public: TimeLapsePhotoSessionMetadataResultProcessor(wptr<TimeLapsePhotoSession> session)52 TimeLapsePhotoSessionMetadataResultProcessor(wptr<TimeLapsePhotoSession> session) : session_(session) {} 53 virtual void ProcessCallbacks( 54 const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata>& result) override; 55 private: 56 wptr<TimeLapsePhotoSession> session_; 57 }; 58 59 class TimeLapsePhotoSession : public CaptureSession { 60 public: 61 static const unordered_map<ExposureHintMode, camera_exposure_hint_mode_enum_t> fwkExposureHintModeMap_; 62 static const unordered_map<camera_awb_mode_t, WhiteBalanceMode> metaWhiteBalanceModeMap_; 63 static const unordered_map<WhiteBalanceMode, camera_awb_mode_t> fwkWhiteBalanceModeMap_; 64 static const unordered_map<MeteringMode, camera_meter_mode_t> fwkMeteringModeMap_; 65 static const unordered_map<camera_meter_mode_t, MeteringMode> metaMeteringModeMap_; 66 TimeLapsePhotoSession(sptr<ICaptureSession> & session,vector<sptr<CameraDevice>> devices)67 explicit TimeLapsePhotoSession(sptr<ICaptureSession> &session, vector<sptr<CameraDevice>> devices) 68 : CaptureSession(session) 69 { 70 metadataResultProcessor_ = make_shared<TimeLapsePhotoSessionMetadataResultProcessor>(this); 71 supportedDevices_.resize(devices.size()); 72 std::copy(devices.begin(), devices.end(), supportedDevices_.begin()); 73 luminationValue_ = 0.0; 74 info_.isTryAEHintNeeded = false; 75 info_.captureInterval = 0; 76 info_.previewType = TimeLapsePreviewType::DARK; 77 info_.isTryAEDone = false; 78 iso_ = 0; 79 } 80 std::shared_ptr<OHOS::Camera::CameraMetadata> GetMetadata() override; 81 82 int32_t IsTryAENeeded(bool& result); 83 int32_t StartTryAE(); 84 int32_t StopTryAE(); 85 int32_t GetSupportedTimeLapseIntervalRange(vector<int32_t>& result); 86 int32_t GetTimeLapseInterval(int32_t& result); 87 int32_t SetTimeLapseInterval(int32_t interval); 88 int32_t SetTimeLapseRecordState(TimeLapseRecordState state); 89 int32_t SetTimeLapsePreviewType(TimeLapsePreviewType type); 90 int32_t SetExposureHintMode(ExposureHintMode mode); 91 92 void SetIsoInfoCallback(shared_ptr<IsoInfoCallback> callback); 93 void SetExposureInfoCallback(shared_ptr<ExposureInfoCallback> callback); 94 void SetLuminationInfoCallback(shared_ptr<LuminationInfoCallback> callback); 95 void SetTryAEInfoCallback(shared_ptr<TryAEInfoCallback> callback); 96 97 void ProcessIsoInfoChange(const shared_ptr<OHOS::Camera::CameraMetadata>& meta); 98 void ProcessExposureChange(const shared_ptr<OHOS::Camera::CameraMetadata>& meta); 99 void ProcessLuminationChange(const shared_ptr<OHOS::Camera::CameraMetadata>& meta); 100 void ProcessSetTryAEChange(const shared_ptr<OHOS::Camera::CameraMetadata>& meta); 101 void ProcessPhysicalCameraSwitch(const shared_ptr<OHOS::Camera::CameraMetadata>& meta); 102 // ManualExposure 103 int32_t GetExposure(uint32_t& result); 104 int32_t SetExposure(uint32_t exposure); 105 int32_t GetSupportedExposureRange(vector<uint32_t>& result); 106 int32_t GetSupportedMeteringModes(vector<MeteringMode>& result); 107 int32_t IsExposureMeteringModeSupported(MeteringMode mode, bool& result); 108 int32_t GetExposureMeteringMode(MeteringMode& result); 109 int32_t SetExposureMeteringMode(MeteringMode mode); 110 // ManualIso 111 int32_t GetIso(int32_t& result); 112 int32_t SetIso(int32_t iso); 113 int32_t IsManualIsoSupported(bool& result); 114 int32_t GetIsoRange(vector<int32_t>& result); 115 // WhiteBalance 116 int32_t IsWhiteBalanceModeSupported(WhiteBalanceMode mode, bool& result); 117 int32_t GetWhiteBalanceRange(vector<int32_t>& result); 118 int32_t GetWhiteBalanceMode(WhiteBalanceMode& result); 119 int32_t SetWhiteBalanceMode(WhiteBalanceMode mode); 120 int32_t GetWhiteBalance(int32_t& result); 121 int32_t SetWhiteBalance(int32_t wb); 122 int32_t GetSupportedWhiteBalanceModes(vector<WhiteBalanceMode> &result); 123 private: 124 shared_ptr<IsoInfoCallback> isoInfoCallback_; 125 shared_ptr<ExposureInfoCallback> exposureInfoCallback_; 126 shared_ptr<LuminationInfoCallback> luminationInfoCallback_; 127 shared_ptr<TryAEInfoCallback> tryAEInfoCallback_; 128 129 std::atomic<uint8_t> physicalCameraId_ = 0; 130 std::vector<sptr<CameraDevice> > supportedDevices_; 131 mutex cbMtx_; 132 float luminationValue_; 133 TryAEInfo info_; 134 uint32_t iso_; 135 }; 136 137 } // namespace CameraStandard 138 } // namespace OHOS 139 #endif