1 /* 2 * Copyright (c) 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 CAMERA_SESSION_IMPL_H 17 #define CAMERA_SESSION_IMPL_H 18 19 #include <mutex> 20 #include <refbase.h> 21 #include <string> 22 #include "capture_session.h" 23 24 #include "camera_input_impl.h" 25 #include "camera_output_impl.h" 26 #include "camera_utils.h" 27 #include "cj_common_ffi.h" 28 29 namespace OHOS { 30 31 namespace CameraStandard { 32 33 class CJSmoothZoomCallback : public SmoothZoomCallback, public ListenerBase<int32_t> { 34 public: 35 CJSmoothZoomCallback() = default; 36 ~CJSmoothZoomCallback() = default; 37 void OnSmoothZoom(int32_t duration) override; 38 }; 39 40 class CJSessionCallback : public SessionCallback, public ListenerBase<int32_t> { 41 public: 42 CJSessionCallback() = default; 43 ~CJSessionCallback() = default; 44 void OnError(int32_t errorCode) override; 45 }; 46 47 class CJFocusStateCallback : public FocusCallback, public ListenerBase<int32_t> { 48 public: 49 CJFocusStateCallback() = default; 50 ~CJFocusStateCallback() = default; 51 void OnFocusState(FocusState state) override; 52 }; 53 54 class CJSession : public OHOS::FFI::FFIData { 55 public: GetRuntimeType()56 OHOS::FFI::RuntimeType *GetRuntimeType() override 57 { 58 return GetClassType(); 59 } 60 61 explicit CJSession(sptr<CameraStandard::CaptureSession> session); 62 63 sptr<CameraStandard::CaptureSession> GetCaptureSession(); 64 65 int32_t BeginConfig(); 66 67 int32_t CommitConfig(); 68 69 bool CanAddInput(OHOS::sptr<CJCameraInput> cameraInput); 70 71 int32_t AddInput(OHOS::sptr<CJCameraInput> cameraInput); 72 73 int32_t RemoveInput(OHOS::sptr<CJCameraInput> cameraInput); 74 75 bool CanAddOutput(sptr<CameraOutput> cameraOutput); 76 77 int32_t AddOutput(sptr<CameraOutput> cameraOutput); 78 79 int32_t RemoveOutput(sptr<CameraOutput> cameraOutput); 80 81 int32_t Start(); 82 83 int32_t Stop(); 84 85 int32_t Release(); 86 87 // sessio common 88 int32_t CanPreconfig(PreconfigType preconfigType, ProfileSizeRatio preconfigRatio, bool &isSupported); 89 int32_t Preconfig(PreconfigType preconfigType, ProfileSizeRatio preconfigRatio); 90 int32_t AddSecureOutput(sptr<CameraOutput> cameraOutput); 91 92 // auto exposure 93 int32_t IsExposureModeSupported(ExposureMode mode, bool &isSupported); 94 int32_t GetExposureBiasRange(CArrFloat32 &ranges); 95 int32_t GetExposureMode(ExposureMode &mode); 96 int32_t SetExposureMode(ExposureMode mode); 97 int32_t GetMeteringPoint(CameraPoint &point); 98 int32_t SetMeteringPoint(CameraPoint point); 99 int32_t SetExposureBias(float value); 100 int32_t GetExposureValue(float &value); 101 102 // color management 103 void GetSupportedColorSpaces(CArrI32 &colorSpaces); 104 int32_t SetColorSpace(ColorSpace colorSpace); 105 int32_t GetActiveColorSpace(ColorSpace &colorSpace); 106 107 // flash 108 int32_t IsFlashModeSupported(FlashMode mode, bool &isSupported); 109 int32_t HasFlash(bool &hasFlash); 110 int32_t GetFlashMode(FlashMode &mode); 111 int32_t SetFlashMode(FlashMode mode); 112 113 // focus 114 int32_t IsFocusModeSupported(FocusMode mode, bool &isSupported); 115 int32_t SetFocusMode(FocusMode mode); 116 int32_t GetFocusMode(FocusMode &mode); 117 int32_t SetFocusPoint(CameraPoint point); 118 int32_t GetFocusPoint(CameraPoint &point); 119 int32_t GetFocalLength(float &focalLength); 120 121 // stabilization 122 int32_t IsVideoStabilizationModeSupported(VideoStabilizationMode mode, bool &isSupported); 123 int32_t GetActiveVideoStabilizationMode(VideoStabilizationMode &mode); 124 int32_t SetVideoStabilizationMode(VideoStabilizationMode mode); 125 126 // zoom 127 int32_t GetZoomRatioRange(CArrFloat32 &ranges); 128 int32_t SetZoomRatio(float ratio); 129 int32_t GetZoomRatio(float &ratio); 130 int32_t SetSmoothZoom(float targetZoomRatio, uint32_t smoothZoomType); 131 132 // callbacks 133 void OnSmoothZoom(int64_t callbackId); 134 void OffSmoothZoom(int64_t callbackId); 135 void OffAllSmoothZoom(); 136 137 void OnError(int64_t callbackId); 138 void OffError(int64_t callbackId); 139 void OffAllError(); 140 141 void OnFocusStateChange(int64_t callbackId); 142 void OffFocusStateChange(int64_t callbackId); 143 void OffAllFocusStateChange(); 144 145 private: 146 sptr<CameraStandard::CaptureSession> session_; 147 std::shared_ptr<CJSmoothZoomCallback> smoothZoomCallback_; 148 std::shared_ptr<CJSessionCallback> errorCallback_; 149 std::shared_ptr<CJFocusStateCallback> focusStateCallback_; 150 151 friend class OHOS::FFI::RuntimeType; 152 friend class OHOS::FFI::TypeBase; GetClassType()153 static OHOS::FFI::RuntimeType *GetClassType() 154 { 155 static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("CJSession"); 156 return &runtimeType; 157 } 158 }; 159 160 } // namespace CameraStandard 161 } // namespace OHOS 162 163 #endif