• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #include "capture_session_impl.h"
17 #include <cstdint>
18 #include <vector>
19 #include "camera_log.h"
20 #include "camera_util.h"
21 #include "capture_scene_const.h"
22 #include "capture_session.h"
23 #include "icapture_session_callback.h"
24 
25 using namespace std;
26 using namespace OHOS;
27 using namespace OHOS::CameraStandard;
28 namespace {
29 const std::unordered_map<Camera_SceneMode, SceneMode> g_ndkToFwMode_ = {
30     {Camera_SceneMode::NORMAL_PHOTO, SceneMode::CAPTURE},
31     {Camera_SceneMode::NORMAL_VIDEO, SceneMode::VIDEO},
32     {Camera_SceneMode::SECURE_PHOTO, SceneMode::SECURE},
33 };
34 const std::unordered_map<Camera_PreconfigType, PreconfigType> g_ndkToFwPreconfig = {
35     {Camera_PreconfigType::PRECONFIG_720P, PreconfigType::PRECONFIG_720P},
36     {Camera_PreconfigType::PRECONFIG_1080P, PreconfigType::PRECONFIG_1080P},
37     {Camera_PreconfigType::PRECONFIG_4K, PreconfigType::PRECONFIG_4K},
38     {Camera_PreconfigType::PRECONFIG_HIGH_QUALITY, PreconfigType::PRECONFIG_HIGH_QUALITY}
39 };
40 const std::unordered_map<Camera_PreconfigRatio, ProfileSizeRatio> g_ndkToFwPreconfigRatio = {
41     {Camera_PreconfigRatio::PRECONFIG_RATIO_1_1, ProfileSizeRatio::RATIO_1_1},
42     {Camera_PreconfigRatio::PRECONFIG_RATIO_4_3, ProfileSizeRatio::RATIO_4_3},
43     {Camera_PreconfigRatio::PRECONFIG_RATIO_16_9, ProfileSizeRatio::RATIO_16_9}
44 };
45 const std::unordered_map<ColorSpace, OH_NativeBuffer_ColorSpace> g_fwToNdkColorSpace_ = {
46     {ColorSpace::COLOR_SPACE_UNKNOWN, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE},
47     {ColorSpace::DISPLAY_P3, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL},
48     {ColorSpace::SRGB, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL},
49     {ColorSpace::BT709, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL},
50     {ColorSpace::BT2020_HLG, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL},
51     {ColorSpace::BT2020_PQ, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL},
52     {ColorSpace::P3_HLG, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL},
53     {ColorSpace::P3_PQ, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL},
54     {ColorSpace::DISPLAY_P3_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT},
55     {ColorSpace::SRGB_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT},
56     {ColorSpace::BT709_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT},
57     {ColorSpace::BT2020_HLG_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT},
58     {ColorSpace::BT2020_PQ_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT},
59     {ColorSpace::P3_HLG_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT},
60     {ColorSpace::P3_PQ_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT}
61 };
62 const std::unordered_map<OH_NativeBuffer_ColorSpace, ColorSpace> g_ndkToFwColorSpace_ = {
63     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE, ColorSpace::COLOR_SPACE_UNKNOWN},
64     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL, ColorSpace::DISPLAY_P3},
65     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL, ColorSpace::SRGB},
66     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL, ColorSpace::BT709},
67     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL, ColorSpace::BT2020_HLG},
68     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL, ColorSpace::BT2020_PQ},
69     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL, ColorSpace::P3_HLG},
70     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL, ColorSpace::P3_PQ},
71     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT, ColorSpace::DISPLAY_P3_LIMIT},
72     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT, ColorSpace::SRGB_LIMIT},
73     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT, ColorSpace::BT709_LIMIT},
74     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT, ColorSpace::BT2020_HLG_LIMIT},
75     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT, ColorSpace::BT2020_PQ_LIMIT},
76     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT, ColorSpace::P3_HLG_LIMIT},
77     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT, ColorSpace::P3_PQ_LIMIT}
78 };
79 
80 const int32_t MAX_EFFECT_TYPES_SIZE = 2;
81 
82 class InnerCaptureSessionCallback : public SessionCallback, public FocusCallback {
83 public:
InnerCaptureSessionCallback(Camera_CaptureSession * captureSession,CaptureSession_Callbacks * callback)84     InnerCaptureSessionCallback(Camera_CaptureSession* captureSession, CaptureSession_Callbacks* callback)
85         : captureSession_(captureSession), callback_(*callback) {}
86     ~InnerCaptureSessionCallback() = default;
87 
OnFocusState(FocusState state)88     void OnFocusState(FocusState state) override
89     {
90         MEDIA_DEBUG_LOG("OnFrameStarted is called!");
91         CHECK_EXECUTE(captureSession_ != nullptr && callback_.onFocusStateChange != nullptr,
92             callback_.onFocusStateChange(captureSession_, static_cast<Camera_FocusState>(state)));
93     }
94 
OnError(const int32_t errorCode)95     void OnError(const int32_t errorCode) override
96     {
97         MEDIA_DEBUG_LOG("OnError is called!, errorCode: %{public}d", errorCode);
98         CHECK_EXECUTE(captureSession_ != nullptr && callback_.onError != nullptr,
99             callback_.onError(captureSession_, FrameworkToNdkCameraError(errorCode)));
100     }
101 
102 private:
103     Camera_CaptureSession* captureSession_;
104     CaptureSession_Callbacks callback_;
105 };
106 
107 class InnerCaptureSessionSmoothZoomInfoCallback : public SmoothZoomCallback {
108 public:
InnerCaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)109     InnerCaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession* captureSession,
110         OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
111         : captureSession_(captureSession), smoothZoomInfoCallback_(smoothZoomInfoCallback) {};
112     ~InnerCaptureSessionSmoothZoomInfoCallback() = default;
113 
OnSmoothZoom(int32_t duration)114     void OnSmoothZoom(int32_t duration) override
115     {
116         MEDIA_DEBUG_LOG("OnSmoothZoom is called!");
117         if (captureSession_ != nullptr && smoothZoomInfoCallback_ != nullptr) {
118             Camera_SmoothZoomInfo info;
119             info.duration = duration;
120             smoothZoomInfoCallback_(captureSession_, &info);
121         }
122     }
123 
124 private:
125     Camera_CaptureSession* captureSession_;
126     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback_ = nullptr;
127 };
128 
129 class InnerCaptureSessionAutoDeviceSwitchStatusCallback : public AutoDeviceSwitchCallback {
130 public:
InnerCaptureSessionAutoDeviceSwitchStatusCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback)131     InnerCaptureSessionAutoDeviceSwitchStatusCallback(Camera_CaptureSession* captureSession,
132         OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback)
133         : captureSession_(captureSession), autoDeviceSwitchStatusCallback_(autoDeviceSwitchStatusCallback) {};
134     ~InnerCaptureSessionAutoDeviceSwitchStatusCallback() = default;
135 
OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched,bool isDeviceCapabilityChanged) const136     void OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched, bool isDeviceCapabilityChanged) const override
137     {
138         MEDIA_DEBUG_LOG("OnAutoDeviceSwitchStatusChange is called!");
139         if (captureSession_ != nullptr && autoDeviceSwitchStatusCallback_ != nullptr) {
140             Camera_AutoDeviceSwitchStatusInfo info;
141             info.isDeviceSwitched = isDeviceSwitched;
142             info.isDeviceCapabilityChanged = isDeviceCapabilityChanged;
143             autoDeviceSwitchStatusCallback_(captureSession_, &info);
144         }
145     }
146 
147 private:
148     Camera_CaptureSession* captureSession_;
149     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback_ = nullptr;
150 };
151 
152 class InnerPressureStatusCallback : public PressureCallback {
153 public:
InnerPressureStatusCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)154     InnerPressureStatusCallback(Camera_CaptureSession* captureSession,
155         OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)
156         : captureSession_(captureSession), systemPressureLevel_(*systemPressureLevel) {};
157     ~InnerPressureStatusCallback() = default;
158 
OnPressureStatusChanged(PressureStatus status)159     void OnPressureStatusChanged(PressureStatus status) override
160     {
161         MEDIA_INFO_LOG("OnPressureStatusChanged is called!");
162         if (captureSession_ != nullptr && systemPressureLevel_ != nullptr) {
163             Camera_SystemPressureLevel level = (Camera_SystemPressureLevel)status;
164             systemPressureLevel_(captureSession_, level);
165         }
166     }
167 
168 private:
169     Camera_CaptureSession* captureSession_;
170     OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel_ = nullptr;
171 };
172 
173 class InnerControlCenterEffectStatusCallback : public ControlCenterEffectCallback {
174 public:
InnerControlCenterEffectStatusCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterEffectStatusChange)175     InnerControlCenterEffectStatusCallback(Camera_CaptureSession* captureSession,
176         OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterEffectStatusChange)
177         : captureSession_(captureSession), controlCenterEffectStatusChange_(*controlCenterEffectStatusChange) {};
178     ~InnerControlCenterEffectStatusCallback() = default;
179 
OnControlCenterEffectStatusChanged(ControlCenterStatusInfo status)180     void OnControlCenterEffectStatusChanged(ControlCenterStatusInfo status) override
181     {
182         MEDIA_INFO_LOG("OnControlCenterEffectStatusChanged is called!");
183         CHECK_RETURN(captureSession_ == nullptr || controlCenterEffectStatusChange_ == nullptr);
184         Camera_ControlCenterStatusInfo statusInfo;
185         statusInfo.effectType = static_cast<Camera_ControlCenterEffectType>(status.effectType);
186         statusInfo.isActive = status.isActive;
187         controlCenterEffectStatusChange_(captureSession_, &statusInfo);
188     }
189 private:
190     Camera_CaptureSession* captureSession_;
191     OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterEffectStatusChange_ = nullptr;
192 };
193 
194 class InnerCaptureSessionMacroStatusCallback : public MacroStatusCallback {
195 public:
InnerCaptureSessionMacroStatusCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnMacroStatusChange macroStatusCallback)196     InnerCaptureSessionMacroStatusCallback(Camera_CaptureSession* captureSession,
197         OH_CaptureSession_OnMacroStatusChange macroStatusCallback)
198         : captureSession_(captureSession), macroStatusCallback_(macroStatusCallback) {};
199     ~InnerCaptureSessionMacroStatusCallback() = default;
200 
OnMacroStatusChanged(MacroStatus status)201     void OnMacroStatusChanged(MacroStatus status) override
202     {
203         MEDIA_DEBUG_LOG("OnMacroStatusCallbackChange is called!");
204         CHECK_RETURN(captureSession_ == nullptr || macroStatusCallback_ == nullptr);
205         bool macroStatus = (status == MacroStatus::ACTIVE ? true : false);
206         macroStatusCallback_(captureSession_, macroStatus);
207     }
208 
209 private:
210     Camera_CaptureSession* captureSession_;
211     OH_CaptureSession_OnMacroStatusChange macroStatusCallback_ = nullptr;
212 };
213 
IsCurrentModeInList(OHOS::sptr<CaptureSession> innerCaptureSession,const std::vector<SceneMode> modes)214 bool IsCurrentModeInList(OHOS::sptr<CaptureSession> innerCaptureSession, const std::vector<SceneMode> modes)
215 {
216     CHECK_RETURN_RET(innerCaptureSession == nullptr, false);
217     SceneMode currentMode = innerCaptureSession->GetMode();
218     for (auto& mode : modes) {
219         CHECK_RETURN_RET(currentMode == mode, true);
220     }
221     MEDIA_ERR_LOG("IsCurrentModeInList check fail, current mode is:%{public}d", currentMode);
222     return false;
223 }
224 }
225 
Camera_CaptureSession(sptr<CaptureSession> & innerCaptureSession)226 Camera_CaptureSession::Camera_CaptureSession(sptr<CaptureSession> &innerCaptureSession)
227     : innerCaptureSession_(innerCaptureSession)
228 {
229     MEDIA_DEBUG_LOG("Camera_CaptureSession Constructor is called");
230 }
231 
~Camera_CaptureSession()232 Camera_CaptureSession::~Camera_CaptureSession()
233 {
234     MEDIA_DEBUG_LOG("~Camera_CaptureSession is called");
235     CHECK_RETURN(!innerCaptureSession_);
236     innerCaptureSession_ = nullptr;
237 }
238 
RegisterCallback(CaptureSession_Callbacks * callback)239 Camera_ErrorCode Camera_CaptureSession::RegisterCallback(CaptureSession_Callbacks* callback)
240 {
241     shared_ptr<InnerCaptureSessionCallback> innerCallback =
242         make_shared<InnerCaptureSessionCallback>(this, callback);
243     CHECK_RETURN_RET_ELOG(innerCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
244         "create innerCallback failed!");
245     CHECK_EXECUTE(callback->onError != nullptr, innerCaptureSession_->SetCallback(innerCallback));
246     CHECK_EXECUTE(callback->onFocusStateChange != nullptr, innerCaptureSession_->SetFocusCallback(innerCallback));
247     return CAMERA_OK;
248 }
249 
UnregisterCallback(CaptureSession_Callbacks * callback)250 Camera_ErrorCode Camera_CaptureSession::UnregisterCallback(CaptureSession_Callbacks* callback)
251 {
252     CHECK_EXECUTE(callback->onError != nullptr, innerCaptureSession_->SetCallback(nullptr));
253     CHECK_EXECUTE(callback->onFocusStateChange != nullptr, innerCaptureSession_->SetFocusCallback(nullptr));
254     return CAMERA_OK;
255 }
256 
RegisterSmoothZoomInfoCallback(OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)257 Camera_ErrorCode Camera_CaptureSession::RegisterSmoothZoomInfoCallback(
258     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
259 {
260     shared_ptr<InnerCaptureSessionSmoothZoomInfoCallback> innerSmoothZoomInfoCallback =
261         make_shared<InnerCaptureSessionSmoothZoomInfoCallback>(this, smoothZoomInfoCallback);
262     CHECK_RETURN_RET_ELOG(innerSmoothZoomInfoCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
263         "create innerCallback failed!");
264     innerCaptureSession_->SetSmoothZoomCallback(innerSmoothZoomInfoCallback);
265     return CAMERA_OK;
266 }
267 
UnregisterSmoothZoomInfoCallback(OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)268 Camera_ErrorCode Camera_CaptureSession::UnregisterSmoothZoomInfoCallback(
269     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
270 {
271     innerCaptureSession_->SetSmoothZoomCallback(nullptr);
272     return CAMERA_OK;
273 }
274 
SetSessionMode(Camera_SceneMode sceneMode)275 Camera_ErrorCode Camera_CaptureSession::SetSessionMode(Camera_SceneMode sceneMode)
276 {
277     CHECK_RETURN_RET_ELOG(innerCaptureSession_->IsSessionConfiged() || innerCaptureSession_->IsSessionCommited(),
278         CAMERA_OPERATION_NOT_ALLOWED, "Camera_Manager::SetSessionMode can not set sceneMode after BeginConfig!");
279     auto itr = g_ndkToFwMode_.find(static_cast<Camera_SceneMode>(sceneMode));
280     CHECK_RETURN_RET_ELOG(itr == g_ndkToFwMode_.end(), CAMERA_INVALID_ARGUMENT,
281         "Camera_CaptureSession::SetSessionMode sceneMode not found!");
282     SceneMode innerSceneMode = static_cast<SceneMode>(itr->second);
283     switch (innerSceneMode) {
284         case SceneMode::CAPTURE:
285             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::CAPTURE);
286             break;
287         case SceneMode::VIDEO:
288             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::VIDEO);
289             break;
290         case SceneMode::SECURE:
291             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::SECURE);
292             break;
293         default:
294             MEDIA_ERR_LOG("Camera_CaptureSession::SetSessionMode sceneMode = %{public}d not supported", sceneMode);
295             return CAMERA_INVALID_ARGUMENT;
296     }
297     return CAMERA_OK;
298 }
299 
AddSecureOutput(Camera_PreviewOutput * previewOutput)300 Camera_ErrorCode Camera_CaptureSession::AddSecureOutput(Camera_PreviewOutput* previewOutput)
301 {
302     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddSecureOutput is called");
303     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
304     int32_t ret = innerCaptureSession_->AddSecureOutput(innerPreviewOutput);
305     return FrameworkToNdkCameraError(ServiceToCameraError(ret));
306 }
307 
BeginConfig()308 Camera_ErrorCode Camera_CaptureSession::BeginConfig()
309 {
310     int32_t ret = innerCaptureSession_->BeginConfig();
311     return FrameworkToNdkCameraError(ret);
312 }
313 
CommitConfig()314 Camera_ErrorCode Camera_CaptureSession::CommitConfig()
315 {
316     int32_t ret = innerCaptureSession_->CommitConfig();
317     return FrameworkToNdkCameraError(ret);
318 }
319 
AddInput(Camera_Input * cameraInput)320 Camera_ErrorCode Camera_CaptureSession::AddInput(Camera_Input* cameraInput)
321 {
322     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
323     int32_t ret = innerCaptureSession_->AddInput(innerCameraInput);
324     return FrameworkToNdkCameraError(ret);
325 }
326 
RemoveInput(Camera_Input * cameraInput)327 Camera_ErrorCode Camera_CaptureSession::RemoveInput(Camera_Input* cameraInput)
328 {
329     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
330     int32_t ret = innerCaptureSession_->RemoveInput(innerCameraInput);
331     return FrameworkToNdkCameraError(ret);
332 }
333 
AddPreviewOutput(Camera_PreviewOutput * previewOutput)334 Camera_ErrorCode Camera_CaptureSession::AddPreviewOutput(Camera_PreviewOutput* previewOutput)
335 {
336     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
337     int32_t ret = innerCaptureSession_->AddOutput(innerPreviewOutput);
338     return FrameworkToNdkCameraError(ret);
339 }
340 
RemovePreviewOutput(Camera_PreviewOutput * previewOutput)341 Camera_ErrorCode Camera_CaptureSession::RemovePreviewOutput(Camera_PreviewOutput* previewOutput)
342 {
343     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
344     int32_t ret = innerCaptureSession_->RemoveOutput(innerPreviewOutput);
345     return FrameworkToNdkCameraError(ret);
346 }
347 
AddPhotoOutput(Camera_PhotoOutput * photoOutput)348 Camera_ErrorCode Camera_CaptureSession::AddPhotoOutput(Camera_PhotoOutput* photoOutput)
349 {
350     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddPhotoOutput is called");
351     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
352     int32_t ret = innerCaptureSession_->AddOutput(innerPhotoOutput);
353     return FrameworkToNdkCameraError(ret);
354 }
355 
RemovePhotoOutput(Camera_PhotoOutput * photoOutput)356 Camera_ErrorCode Camera_CaptureSession::RemovePhotoOutput(Camera_PhotoOutput* photoOutput)
357 {
358     MEDIA_DEBUG_LOG("Camera_CaptureSession::RemovePhotoOutput is called");
359     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
360     int32_t ret = innerCaptureSession_->RemoveOutput(innerPhotoOutput);
361     return FrameworkToNdkCameraError(ret);
362 }
363 
AddMetaDataOutput(Camera_MetadataOutput * metadataOutput)364 Camera_ErrorCode Camera_CaptureSession::AddMetaDataOutput(Camera_MetadataOutput* metadataOutput)
365 {
366     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddMetaDataOutput is called");
367     sptr<CaptureOutput> innerMetaDataOutput = metadataOutput->GetInnerMetadataOutput();
368     int32_t ret = innerCaptureSession_->AddOutput(innerMetaDataOutput);
369     return FrameworkToNdkCameraError(ret);
370 }
371 
RemoveMetaDataOutput(Camera_MetadataOutput * metadataOutput)372 Camera_ErrorCode Camera_CaptureSession::RemoveMetaDataOutput(Camera_MetadataOutput* metadataOutput)
373 {
374     MEDIA_DEBUG_LOG("Camera_CaptureSession::RemoveMetaDataOutput is called");
375     sptr<CaptureOutput> innerMetaDataOutput = metadataOutput->GetInnerMetadataOutput();
376     CHECK_RETURN_RET(innerCaptureSession_ == nullptr, CAMERA_SERVICE_FATAL_ERROR);
377     int32_t ret = innerCaptureSession_->AddOutput(innerMetaDataOutput);
378     return FrameworkToNdkCameraError(ret);
379 }
380 
IsVideoStabilizationModeSupported(Camera_VideoStabilizationMode mode,bool * isSupported)381 Camera_ErrorCode Camera_CaptureSession::IsVideoStabilizationModeSupported(Camera_VideoStabilizationMode mode,
382     bool* isSupported)
383 {
384     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsVideoStabilizationModeSupported is called");
385     VideoStabilizationMode innerVideoStabilizationMode = static_cast<VideoStabilizationMode>(mode);
386     int32_t ret = innerCaptureSession_->IsVideoStabilizationModeSupported(innerVideoStabilizationMode, *isSupported);
387     return FrameworkToNdkCameraError(ret);
388 }
389 
GetVideoStabilizationMode(Camera_VideoStabilizationMode * mode)390 Camera_ErrorCode Camera_CaptureSession::GetVideoStabilizationMode(Camera_VideoStabilizationMode* mode)
391 {
392     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetVideoStabilizationMode is called");
393 
394     *mode = static_cast<Camera_VideoStabilizationMode>(innerCaptureSession_->GetActiveVideoStabilizationMode());
395     return CAMERA_OK;
396 }
397 
SetVideoStabilizationMode(Camera_VideoStabilizationMode mode)398 Camera_ErrorCode Camera_CaptureSession::SetVideoStabilizationMode(Camera_VideoStabilizationMode mode)
399 {
400     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetVideoStabilizationMode is called");
401 
402     VideoStabilizationMode innerVideoStabilizationMode = static_cast<VideoStabilizationMode>(mode);
403     int32_t ret = innerCaptureSession_->SetVideoStabilizationMode(innerVideoStabilizationMode);
404     return FrameworkToNdkCameraError(ret);
405 }
406 
GetZoomRatioRange(float * minZoom,float * maxZoom)407 Camera_ErrorCode Camera_CaptureSession::GetZoomRatioRange(float* minZoom, float* maxZoom)
408 {
409     std::vector<float> vecZoomRatioList = innerCaptureSession_->GetZoomRatioRange();
410     if (vecZoomRatioList.empty()) {
411         MEDIA_ERR_LOG("Camera_CaptureSession::GetZoomRatioRange vecZoomRatioList  size is null ");
412     } else {
413         *minZoom = vecZoomRatioList[0];
414         *maxZoom = vecZoomRatioList[1];
415     }
416     return CAMERA_OK;
417 }
418 
GetZoomRatio(float * zoom)419 Camera_ErrorCode Camera_CaptureSession::GetZoomRatio(float* zoom)
420 {
421     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetZoomRatio is called");
422     *zoom = innerCaptureSession_->GetZoomRatio();
423 
424     return CAMERA_OK;
425 }
426 
SetZoomRatio(float zoom)427 Camera_ErrorCode Camera_CaptureSession::SetZoomRatio(float zoom)
428 {
429     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetZoomRatio is called");
430 
431     innerCaptureSession_->LockForControl();
432     int32_t ret = innerCaptureSession_->SetZoomRatio(zoom);
433     innerCaptureSession_->UnlockForControl();
434 
435     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
436     return FrameworkToNdkCameraError(ret);
437 }
438 
IsFocusModeSupported(Camera_FocusMode focusMode,bool * isSupported)439 Camera_ErrorCode Camera_CaptureSession::IsFocusModeSupported(Camera_FocusMode focusMode, bool* isSupported)
440 {
441     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsFocusModeSupported is called");
442     FocusMode innerFocusMode = static_cast<FocusMode>(focusMode);
443     int32_t ret = innerCaptureSession_->IsFocusModeSupported(innerFocusMode, *isSupported);
444     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
445     return FrameworkToNdkCameraError(ret);
446 }
447 
GetFocusMode(Camera_FocusMode * focusMode)448 Camera_ErrorCode Camera_CaptureSession::GetFocusMode(Camera_FocusMode* focusMode)
449 {
450     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusMode is called");
451 
452     *focusMode = static_cast<Camera_FocusMode>(innerCaptureSession_->GetFocusMode());
453     return CAMERA_OK;
454 }
455 
SetFocusMode(Camera_FocusMode focusMode)456 Camera_ErrorCode Camera_CaptureSession::SetFocusMode(Camera_FocusMode focusMode)
457 {
458     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusMode is called");
459 
460     FocusMode innerFocusMode = static_cast<FocusMode>(focusMode);
461     innerCaptureSession_->LockForControl();
462     int32_t ret = innerCaptureSession_->SetFocusMode(innerFocusMode);
463     innerCaptureSession_->UnlockForControl();
464 
465     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
466     return FrameworkToNdkCameraError(ret);
467 }
468 
SetFocusPoint(Camera_Point focusPoint)469 Camera_ErrorCode Camera_CaptureSession::SetFocusPoint(Camera_Point focusPoint)
470 {
471     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusPoint is called");
472 
473     Point innerFocusPoint;
474     innerFocusPoint.x = focusPoint.x;
475     innerFocusPoint.y = focusPoint.y;
476 
477     innerCaptureSession_->LockForControl();
478     int32_t ret = innerCaptureSession_->SetFocusPoint(innerFocusPoint);
479     innerCaptureSession_->UnlockForControl();
480 
481     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
482     return FrameworkToNdkCameraError(ret);
483 }
484 
GetFocusPoint(Camera_Point * focusPoint)485 Camera_ErrorCode Camera_CaptureSession::GetFocusPoint(Camera_Point* focusPoint)
486 {
487     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusPoint is called");
488     Point innerFocusPoint = innerCaptureSession_->GetFocusPoint();
489     (*focusPoint).x = innerFocusPoint.x;
490     (*focusPoint).y = innerFocusPoint.y;
491 
492     return CAMERA_OK;
493 }
494 
HasFlash(bool * hasFlash)495 Camera_ErrorCode Camera_CaptureSession::HasFlash(bool* hasFlash)
496 {
497     MEDIA_DEBUG_LOG("Camera_CaptureSession::HasFlash is called");
498 
499     *hasFlash = innerCaptureSession_->HasFlash();
500 
501     return CAMERA_OK;
502 }
503 
IsFlashModeSupported(Camera_FlashMode flashMode,bool * isSupported)504 Camera_ErrorCode Camera_CaptureSession::IsFlashModeSupported(Camera_FlashMode flashMode, bool* isSupported)
505 {
506     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsFlashModeSupported is called");
507     FlashMode innerFlashMode = static_cast<FlashMode>(flashMode);
508 
509     *isSupported = innerCaptureSession_->IsFlashModeSupported(innerFlashMode);
510 
511     return CAMERA_OK;
512 }
513 
GetFlashMode(Camera_FlashMode * flashMode)514 Camera_ErrorCode Camera_CaptureSession::GetFlashMode(Camera_FlashMode* flashMode)
515 {
516     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFlashMode is called");
517     *flashMode = static_cast<Camera_FlashMode>(innerCaptureSession_->GetFlashMode());
518 
519     return CAMERA_OK;
520 }
521 
SetFlashMode(Camera_FlashMode flashMode)522 Camera_ErrorCode Camera_CaptureSession::SetFlashMode(Camera_FlashMode flashMode)
523 {
524     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFlashMode is called");
525 
526     FlashMode innerFlashMode = static_cast<FlashMode>(flashMode);
527     innerCaptureSession_->LockForControl();
528     int32_t ret = innerCaptureSession_->SetFlashMode(innerFlashMode);
529     innerCaptureSession_->UnlockForControl();
530 
531     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
532     return FrameworkToNdkCameraError(ret);
533 }
534 
IsExposureModeSupported(Camera_ExposureMode exposureMode,bool * isSupported)535 Camera_ErrorCode Camera_CaptureSession::IsExposureModeSupported(Camera_ExposureMode exposureMode, bool* isSupported)
536 {
537     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsExposureModeSupported is called");
538     ExposureMode innerExposureMode = static_cast<ExposureMode>(exposureMode);
539     int32_t ret = innerCaptureSession_->IsExposureModeSupported(innerExposureMode, *isSupported);
540     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
541     return FrameworkToNdkCameraError(ret);
542 }
543 
GetExposureMode(Camera_ExposureMode * exposureMode)544 Camera_ErrorCode Camera_CaptureSession::GetExposureMode(Camera_ExposureMode* exposureMode)
545 {
546     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureMode is called");
547 
548     *exposureMode = static_cast<Camera_ExposureMode>(innerCaptureSession_->GetExposureMode());
549     return CAMERA_OK;
550 }
551 
SetExposureMode(Camera_ExposureMode exposureMode)552 Camera_ErrorCode Camera_CaptureSession::SetExposureMode(Camera_ExposureMode exposureMode)
553 {
554     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureMode is called");
555 
556     ExposureMode innerExposureMode = static_cast<ExposureMode>(exposureMode);
557     innerCaptureSession_->LockForControl();
558     int32_t ret = innerCaptureSession_->SetExposureMode(innerExposureMode);
559     innerCaptureSession_->UnlockForControl();
560 
561     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
562     return FrameworkToNdkCameraError(ret);
563 }
564 
GetMeteringPoint(Camera_Point * point)565 Camera_ErrorCode Camera_CaptureSession::GetMeteringPoint(Camera_Point* point)
566 {
567     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetMeteringPoint is called");
568 
569     Point innerFocusPoint = innerCaptureSession_->GetMeteringPoint();
570     (*point).x = innerFocusPoint.x;
571     (*point).y = innerFocusPoint.y;
572     return CAMERA_OK;
573 }
574 
SetMeteringPoint(Camera_Point point)575 Camera_ErrorCode Camera_CaptureSession::SetMeteringPoint(Camera_Point point)
576 {
577     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetMeteringPoint is called");
578     Point innerExposurePoint;
579     innerExposurePoint.x = point.x;
580     innerExposurePoint.y = point.y;
581 
582     innerCaptureSession_->LockForControl();
583     int32_t ret = innerCaptureSession_->SetMeteringPoint(innerExposurePoint);
584     innerCaptureSession_->UnlockForControl();
585 
586     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
587     return FrameworkToNdkCameraError(ret);
588 }
589 
GetExposureBiasRange(float * minExposureBias,float * maxExposureBias,float * step)590 Camera_ErrorCode Camera_CaptureSession::GetExposureBiasRange(float* minExposureBias,
591     float* maxExposureBias, float* step)
592 {
593     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBiasRange is called");
594 
595     std::vector<float> vecExposureBiasList = innerCaptureSession_->GetExposureBiasRange();
596     constexpr int32_t ARGS_TWO = 2;
597     if (!vecExposureBiasList.empty() && vecExposureBiasList.size() >= ARGS_TWO) {
598         *minExposureBias = vecExposureBiasList[0];
599         *maxExposureBias = vecExposureBiasList[1];
600     } else {
601         MEDIA_ERR_LOG("Camera_CaptureSession::GetExposureBiasRange vecZoomRatioList illegal.");
602     }
603     return CAMERA_OK;
604 }
605 
SetExposureBias(float exposureBias)606 Camera_ErrorCode Camera_CaptureSession::SetExposureBias(float exposureBias)
607 {
608     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureBias is called");
609 
610     innerCaptureSession_->LockForControl();
611     int32_t ret = innerCaptureSession_->SetExposureBias(exposureBias);
612     innerCaptureSession_->UnlockForControl();
613 
614     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
615     return FrameworkToNdkCameraError(ret);
616 }
617 
GetExposureBias(float * exposureBias)618 Camera_ErrorCode Camera_CaptureSession::GetExposureBias(float* exposureBias)
619 {
620     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBias is called");
621 
622     *exposureBias = innerCaptureSession_->GetExposureValue();
623 
624     return CAMERA_OK;
625 }
626 
AddVideoOutput(Camera_VideoOutput * videoOutput)627 Camera_ErrorCode Camera_CaptureSession::AddVideoOutput(Camera_VideoOutput* videoOutput)
628 {
629     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
630     int32_t ret = innerCaptureSession_->AddOutput(innerVideoOutput);
631     return FrameworkToNdkCameraError(ret);
632 }
633 
RemoveVideoOutput(Camera_VideoOutput * videoOutput)634 Camera_ErrorCode Camera_CaptureSession::RemoveVideoOutput(Camera_VideoOutput* videoOutput)
635 {
636     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
637     int32_t ret = innerCaptureSession_->RemoveOutput(innerVideoOutput);
638     return FrameworkToNdkCameraError(ret);
639 }
640 
Start()641 Camera_ErrorCode Camera_CaptureSession::Start()
642 {
643     int32_t ret = innerCaptureSession_->Start();
644     return FrameworkToNdkCameraError(ret);
645 }
646 
Stop()647 Camera_ErrorCode Camera_CaptureSession::Stop()
648 {
649     int32_t ret = innerCaptureSession_->Stop();
650     return FrameworkToNdkCameraError(ret);
651 }
652 
Release()653 Camera_ErrorCode Camera_CaptureSession::Release()
654 {
655     int32_t ret = innerCaptureSession_->Release();
656     return FrameworkToNdkCameraError(ret);
657 }
658 
CanAddInput(Camera_Input * cameraInput,bool * isSuccessful)659 Camera_ErrorCode Camera_CaptureSession::CanAddInput(Camera_Input* cameraInput, bool* isSuccessful)
660 {
661     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
662     *isSuccessful = innerCaptureSession_->CanAddInput(innerCameraInput);
663     return CAMERA_OK;
664 }
665 
CanAddPreviewOutput(Camera_PreviewOutput * previewOutput,bool * isSuccessful)666 Camera_ErrorCode Camera_CaptureSession::CanAddPreviewOutput(Camera_PreviewOutput* previewOutput, bool* isSuccessful)
667 {
668     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
669     *isSuccessful = innerCaptureSession_->CanAddOutput(innerPreviewOutput);
670     return CAMERA_OK;
671 }
672 
CanAddPhotoOutput(Camera_PhotoOutput * photoOutput,bool * isSuccessful)673 Camera_ErrorCode Camera_CaptureSession::CanAddPhotoOutput(Camera_PhotoOutput* photoOutput, bool* isSuccessful)
674 {
675     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
676     *isSuccessful = innerCaptureSession_->CanAddOutput(innerPhotoOutput);
677     return CAMERA_OK;
678 }
679 
CanAddVideoOutput(Camera_VideoOutput * videoOutput,bool * isSuccessful)680 Camera_ErrorCode Camera_CaptureSession::CanAddVideoOutput(Camera_VideoOutput* videoOutput, bool* isSuccessful)
681 {
682     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
683     *isSuccessful = innerCaptureSession_->CanAddOutput(innerVideoOutput);
684     return CAMERA_OK;
685 }
686 
CanPreconfig(Camera_PreconfigType preconfigType,bool * canPreconfig)687 Camera_ErrorCode Camera_CaptureSession::CanPreconfig(Camera_PreconfigType preconfigType, bool* canPreconfig)
688 {
689     auto itr = g_ndkToFwPreconfig.find(preconfigType);
690     if (itr == g_ndkToFwPreconfig.end()) {
691         MEDIA_ERR_LOG("Camera_CaptureSession::CanPreconfig preconfigType: [%{public}d] is invalid!", preconfigType);
692         *canPreconfig = false;
693         return CAMERA_INVALID_ARGUMENT;
694     }
695 
696     *canPreconfig = innerCaptureSession_->CanPreconfig(itr->second, ProfileSizeRatio::UNSPECIFIED);
697     return CAMERA_OK;
698 }
699 
CanPreconfigWithRatio(Camera_PreconfigType preconfigType,Camera_PreconfigRatio preconfigRatio,bool * canPreconfig)700 Camera_ErrorCode Camera_CaptureSession::CanPreconfigWithRatio(Camera_PreconfigType preconfigType,
701     Camera_PreconfigRatio preconfigRatio, bool* canPreconfig)
702 {
703     auto type = g_ndkToFwPreconfig.find(preconfigType);
704     auto ratio = g_ndkToFwPreconfigRatio.find(preconfigRatio);
705     if (type == g_ndkToFwPreconfig.end() || ratio == g_ndkToFwPreconfigRatio.end()) {
706         MEDIA_ERR_LOG("Camera_CaptureSession::CanPreconfigWithRatio preconfigType: [%{public}d] "
707             "or preconfigRatio: [%{public}d] is invalid!", preconfigType, preconfigRatio);
708         *canPreconfig = false;
709         return CAMERA_INVALID_ARGUMENT;
710     }
711 
712     *canPreconfig = innerCaptureSession_->CanPreconfig(type->second, ratio->second);
713     return CAMERA_OK;
714 }
715 
Preconfig(Camera_PreconfigType preconfigType)716 Camera_ErrorCode Camera_CaptureSession::Preconfig(Camera_PreconfigType preconfigType)
717 {
718     auto itr = g_ndkToFwPreconfig.find(preconfigType);
719     CHECK_RETURN_RET_ELOG(itr == g_ndkToFwPreconfig.end(), CAMERA_INVALID_ARGUMENT,
720         "Camera_CaptureSession::Preconfig preconfigType: [%{public}d] is invalid!", preconfigType);
721 
722     int32_t ret = innerCaptureSession_->Preconfig(itr->second, ProfileSizeRatio::UNSPECIFIED);
723     return FrameworkToNdkCameraError(ret);
724 }
725 
PreconfigWithRatio(Camera_PreconfigType preconfigType,Camera_PreconfigRatio preconfigRatio)726 Camera_ErrorCode Camera_CaptureSession::PreconfigWithRatio(Camera_PreconfigType preconfigType,
727     Camera_PreconfigRatio preconfigRatio)
728 {
729     auto type = g_ndkToFwPreconfig.find(preconfigType);
730     auto ratio = g_ndkToFwPreconfigRatio.find(preconfigRatio);
731     CHECK_RETURN_RET_ELOG(type == g_ndkToFwPreconfig.end(), CAMERA_INVALID_ARGUMENT,
732         "Camera_CaptureSession::PreconfigWithRatio preconfigType: [%{public}d] is invalid!", preconfigType);
733     CHECK_RETURN_RET_ELOG(ratio == g_ndkToFwPreconfigRatio.end(), CAMERA_INVALID_ARGUMENT,
734         "Camera_CaptureSession::PreconfigWithRatio preconfigRatio: [%{public}d] is invalid!", preconfigRatio);
735 
736     int32_t ret = innerCaptureSession_->Preconfig(type->second, ratio->second);
737     return FrameworkToNdkCameraError(ret);
738 }
739 
GetExposureValue(float * exposureValue)740 Camera_ErrorCode Camera_CaptureSession::GetExposureValue(float* exposureValue)
741 {
742     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureValue is called");
743 
744     int32_t ret = innerCaptureSession_->GetExposureValue(*exposureValue);
745     return FrameworkToNdkCameraError(ret);
746 }
747 
GetFocalLength(float * focalLength)748 Camera_ErrorCode Camera_CaptureSession::GetFocalLength(float* focalLength)
749 {
750     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocalLength is called");
751 
752     int32_t ret = innerCaptureSession_->GetFocalLength(*focalLength);
753     return FrameworkToNdkCameraError(ret);
754 }
755 
SetSmoothZoom(float targetZoom,Camera_SmoothZoomMode smoothZoomMode)756 Camera_ErrorCode Camera_CaptureSession::SetSmoothZoom(float targetZoom, Camera_SmoothZoomMode smoothZoomMode)
757 {
758     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetSmoothZoom is called");
759 
760     int32_t ret = innerCaptureSession_->SetSmoothZoom(targetZoom, static_cast<uint32_t>(smoothZoomMode));
761     return FrameworkToNdkCameraError(ret);
762 }
763 
GetSupportedColorSpaces(OH_NativeBuffer_ColorSpace ** colorSpace,uint32_t * size)764 Camera_ErrorCode Camera_CaptureSession::GetSupportedColorSpaces(OH_NativeBuffer_ColorSpace** colorSpace,
765     uint32_t* size)
766 {
767     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetSupportedColorSpaces is called");
768 
769     auto colorSpaces = innerCaptureSession_->GetSupportedColorSpaces();
770     if (colorSpaces.empty()) {
771         MEDIA_ERR_LOG("Supported ColorSpace is empty!");
772         *size = 0;
773         return CAMERA_OK;
774     }
775 
776     std::vector<OH_NativeBuffer_ColorSpace> cameraColorSpace;
777     for (size_t i = 0; i < colorSpaces.size(); ++i) {
778         auto itr = g_fwToNdkColorSpace_.find(colorSpaces[i]);
779         CHECK_EXECUTE(itr != g_fwToNdkColorSpace_.end(), cameraColorSpace.push_back(itr->second));
780     }
781 
782     if (cameraColorSpace.size() == 0) {
783         MEDIA_ERR_LOG("Supported ColorSpace is empty!");
784         *size = 0;
785         return CAMERA_OK;
786     }
787 
788     OH_NativeBuffer_ColorSpace* newColorSpace = new OH_NativeBuffer_ColorSpace[cameraColorSpace.size()];
789     CHECK_RETURN_RET_ELOG(newColorSpace == nullptr, CAMERA_SERVICE_FATAL_ERROR,
790         "Failed to allocate memory for color space!");
791     for (size_t index = 0; index < cameraColorSpace.size(); index++) {
792         newColorSpace[index] = cameraColorSpace[index];
793     }
794 
795     *size = cameraColorSpace.size();
796     *colorSpace = newColorSpace;
797     return CAMERA_OK;
798 }
799 
DeleteColorSpaces(OH_NativeBuffer_ColorSpace * colorSpace)800 Camera_ErrorCode Camera_CaptureSession::DeleteColorSpaces(OH_NativeBuffer_ColorSpace* colorSpace)
801 {
802     if (colorSpace != nullptr) {
803         delete[] colorSpace;
804         colorSpace = nullptr;
805     }
806 
807     return CAMERA_OK;
808 }
809 
GetSupportedEffectTypes(Camera_ControlCenterEffectType ** types,uint32_t * size)810 Camera_ErrorCode Camera_CaptureSession::GetSupportedEffectTypes(Camera_ControlCenterEffectType** types, uint32_t* size)
811 {
812     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetSupportedEffectTypes is called");
813     std::vector<ControlCenterEffectType> effectTypes = innerCaptureSession_->GetSupportedEffectTypes();
814     uint32_t effectTypesSize = effectTypes.size();
815     CHECK_RETURN_RET_ELOG(effectTypesSize == 0, CAMERA_INVALID_ARGUMENT, "Invalid effect types size.");
816     if (effectTypesSize > 0 && effectTypesSize <= MAX_EFFECT_TYPES_SIZE) {
817         Camera_ControlCenterEffectType* newEffectType = new Camera_ControlCenterEffectType[effectTypesSize];
818         CHECK_RETURN_RET_ELOG(newEffectType == nullptr, CAMERA_SERVICE_FATAL_ERROR,
819             "Failed to allocate memory for color space!");
820         for (size_t index = 0; index < effectTypesSize; index++) {
821             newEffectType[index] = static_cast<Camera_ControlCenterEffectType>(effectTypes[index]);
822         }
823         *size = effectTypesSize;
824         *types = newEffectType;
825     } else {
826         CHECK_RETURN_RET_ELOG(true, CAMERA_INVALID_ARGUMENT, "Effect types size out of valid range.");
827     }
828     return CAMERA_OK;
829 }
830 
DeleteEffectTypes(Camera_ControlCenterEffectType * types)831 Camera_ErrorCode Camera_CaptureSession::DeleteEffectTypes(Camera_ControlCenterEffectType* types)
832 {
833     CHECK_RETURN_RET(types == nullptr, CAMERA_OK);
834     delete[] types;
835     types = nullptr;
836 
837     return CAMERA_OK;
838 }
839 
EnableControlCenter(bool enabled)840 Camera_ErrorCode Camera_CaptureSession::EnableControlCenter(bool enabled)
841 {
842     MEDIA_DEBUG_LOG("Camera_CaptureSession::EnableControlCenter");
843     innerCaptureSession_->EnableControlCenter(enabled);
844     return CAMERA_OK;
845 }
846 
GetActiveColorSpace(OH_NativeBuffer_ColorSpace * colorSpace)847 Camera_ErrorCode Camera_CaptureSession::GetActiveColorSpace(OH_NativeBuffer_ColorSpace* colorSpace)
848 {
849     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetActiveColorSpace is called");
850 
851     ColorSpace innerColorSpace;
852     int32_t ret = innerCaptureSession_->GetActiveColorSpace(innerColorSpace);
853     CHECK_RETURN_RET(ret != SUCCESS, FrameworkToNdkCameraError(ret));
854     auto itr = g_fwToNdkColorSpace_.find(innerColorSpace);
855     CHECK_RETURN_RET_ELOG(itr == g_fwToNdkColorSpace_.end(),
856         CAMERA_SERVICE_FATAL_ERROR, "colorSpace[%{public}d] is invalid", innerColorSpace);
857     *colorSpace = itr->second;
858     return CAMERA_OK;
859 }
860 
SetActiveColorSpace(OH_NativeBuffer_ColorSpace colorSpace)861 Camera_ErrorCode Camera_CaptureSession::SetActiveColorSpace(OH_NativeBuffer_ColorSpace colorSpace)
862 {
863     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetActiveColorSpace is called");
864 
865     auto itr = g_ndkToFwColorSpace_.find(colorSpace);
866     CHECK_RETURN_RET_ELOG(itr == g_ndkToFwColorSpace_.end(), CAMERA_INVALID_ARGUMENT,
867         "colorSpace[%{public}d] is invalid", colorSpace);
868     int32_t ret = innerCaptureSession_->SetColorSpace(itr->second);
869     return FrameworkToNdkCameraError(ret);
870 }
871 
RegisterAutoDeviceSwitchStatusCallback(OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)872 Camera_ErrorCode Camera_CaptureSession::RegisterAutoDeviceSwitchStatusCallback(
873     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)
874 {
875     shared_ptr<InnerCaptureSessionAutoDeviceSwitchStatusCallback> innerDeviceSwitchStatusCallback =
876         make_shared<InnerCaptureSessionAutoDeviceSwitchStatusCallback>(this, autoDeviceSwitchStatusChange);
877     CHECK_RETURN_RET_ELOG(innerDeviceSwitchStatusCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
878         "create innerCallback failed!");
879     innerCaptureSession_->SetAutoDeviceSwitchCallback(innerDeviceSwitchStatusCallback);
880     return CAMERA_OK;
881 }
882 
UnregisterAutoDeviceSwitchStatusCallback(OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)883 Camera_ErrorCode Camera_CaptureSession::UnregisterAutoDeviceSwitchStatusCallback(
884     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)
885 {
886     innerCaptureSession_->SetAutoDeviceSwitchCallback(nullptr);
887     return CAMERA_OK;
888 }
889 
RegisterSystemPressureLevelCallback(OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)890 Camera_ErrorCode Camera_CaptureSession::RegisterSystemPressureLevelCallback(
891     OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)
892 {
893     MEDIA_INFO_LOG("Camera_CaptureSession::RegisterSystemPressureLevelCallback");
894     shared_ptr<InnerPressureStatusCallback> innerPressureStatusCallback =
895         make_shared<InnerPressureStatusCallback>(this, systemPressureLevel);
896     CHECK_RETURN_RET_ELOG(innerPressureStatusCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
897         "create innerCallback failed!");
898     SceneMode currentMode = innerCaptureSession_->GetMode();
899     if (currentMode != SceneMode::CAPTURE && currentMode != SceneMode::VIDEO) {
900         MEDIA_ERR_LOG("SystemPressureLevelCallback do not support current session: %{public}d", currentMode);
901         return CAMERA_INVALID_ARGUMENT;
902     }
903     innerCaptureSession_->SetPressureCallback(innerPressureStatusCallback);
904     return CAMERA_OK;
905 }
906 
UnRegisterSystemPressureLevelCallback(OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)907 Camera_ErrorCode Camera_CaptureSession::UnRegisterSystemPressureLevelCallback(
908     OH_CaptureSession_OnSystemPressureLevelChange systemPressureLevel)
909 {
910     MEDIA_INFO_LOG("Camera_CaptureSession::UnregisterSystemPressureLevelCallback");
911     innerCaptureSession_->SetPressureCallback(nullptr);
912     return CAMERA_OK;
913 }
914 
RegisterControlCenterEffectStatusChangeCallback(OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterEffectStatusChange)915 Camera_ErrorCode Camera_CaptureSession::RegisterControlCenterEffectStatusChangeCallback(
916     OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterEffectStatusChange)
917 {
918     MEDIA_INFO_LOG("Camera_CaptureSession::RegisterControlCenterEffectStatusChangeCallback");
919     CHECK_PRINT_ELOG(controlCenterEffectStatusChange == nullptr,
920         "RegisterControlCenterEffectStatusChangeCallback controlCenterEffectStatusChange is null.");
921     shared_ptr<InnerControlCenterEffectStatusCallback> innerControlCenterEffectCallback =
922         make_shared<InnerControlCenterEffectStatusCallback>(this, controlCenterEffectStatusChange);
923     CHECK_RETURN_RET_ELOG(innerControlCenterEffectCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
924         "create innerCallback failed!");
925     innerCaptureSession_->SetControlCenterEffectStatusCallback(innerControlCenterEffectCallback);
926     return CAMERA_OK;
927 }
928 
UnregisterControlCenterEffectStatusChangeCallback(OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterStatusChange)929 Camera_ErrorCode Camera_CaptureSession::UnregisterControlCenterEffectStatusChangeCallback(
930     OH_CaptureSession_OnControlCenterEffectStatusChange controlCenterStatusChange)
931 {
932     MEDIA_INFO_LOG("Camera_CaptureSession::UnregisterControlCenterEffectStatusChangeCallback");
933     innerCaptureSession_->UnSetControlCenterEffectStatusCallback();
934     return CAMERA_OK;
935 }
IsAutoDeviceSwitchSupported(bool * isSupported)936 Camera_ErrorCode Camera_CaptureSession::IsAutoDeviceSwitchSupported(bool* isSupported)
937 {
938     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsAutoDeviceSwitchSupported is called");
939     *isSupported = innerCaptureSession_->IsAutoDeviceSwitchSupported();
940     return CAMERA_OK;
941 }
942 
IsControlCenterSupported(bool * isSupported)943 Camera_ErrorCode Camera_CaptureSession::IsControlCenterSupported(bool* isSupported)
944 {
945     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsControlCenterSupported is called");
946     *isSupported = innerCaptureSession_->IsControlCenterSupported();
947     return CAMERA_OK;
948 }
949 
EnableAutoDeviceSwitch(bool enabled)950 Camera_ErrorCode Camera_CaptureSession::EnableAutoDeviceSwitch(bool enabled)
951 {
952     MEDIA_DEBUG_LOG("Camera_CaptureSession::EnableAutoDeviceSwitch is called");
953     int32_t ret = innerCaptureSession_->EnableAutoDeviceSwitch(enabled);
954     return FrameworkToNdkCameraError(ret);
955 }
956 
SetQualityPrioritization(Camera_QualityPrioritization qualityPrioritization)957 Camera_ErrorCode Camera_CaptureSession::SetQualityPrioritization(Camera_QualityPrioritization qualityPrioritization)
958 {
959     MEDIA_INFO_LOG("Camera_CaptureSession::SetQualityPrioritization is called");
960     QualityPrioritization innerQualityPrioritization = static_cast<QualityPrioritization>(qualityPrioritization);
961     innerCaptureSession_->LockForControl();
962     int32_t ret = innerCaptureSession_->SetQualityPrioritization(innerQualityPrioritization);
963     innerCaptureSession_->UnlockForControl();
964     return FrameworkToNdkCameraError(ret);
965 }
966 
IsMacroSupported(bool * isSupported)967 Camera_ErrorCode Camera_CaptureSession::IsMacroSupported(bool* isSupported)
968 {
969     *isSupported = false;
970     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsMacroSupported is called");
971 
972     CHECK_RETURN_RET_ELOG(!IsCurrentModeInList(innerCaptureSession_, { SceneMode::CAPTURE, SceneMode::VIDEO }),
973         CAMERA_INVALID_ARGUMENT, "Camera_CaptureSession::IsMacroSupported Session is not supported");
974 
975     CHECK_RETURN_RET_ELOG(
976         !(innerCaptureSession_->IsSessionCommited() || innerCaptureSession_->IsSessionConfiged()),
977         CAMERA_SESSION_NOT_CONFIG, "Camera_CaptureSession::IsMacroSupported Session is not config");
978     *isSupported = innerCaptureSession_->IsMacroSupported();
979     return CAMERA_OK;
980 }
981 
EnableMacro(bool enabled)982 Camera_ErrorCode Camera_CaptureSession::EnableMacro(bool enabled)
983 {
984     MEDIA_DEBUG_LOG("Camera_CaptureSession::EnableMacro is called %{public}d", enabled);
985     CHECK_RETURN_RET_ELOG(!IsCurrentModeInList(innerCaptureSession_, { SceneMode::CAPTURE, SceneMode::VIDEO }),
986         CAMERA_INVALID_ARGUMENT, "Camera_CaptureSession::IsMacroSupported Session is not supported");
987     innerCaptureSession_->LockForControl();
988     int32_t ret = innerCaptureSession_->EnableMacro(enabled);
989     innerCaptureSession_->UnlockForControl();
990     return FrameworkToNdkCameraError(ret);
991 }
992 
IsWhiteBalanceModeSupported(Camera_WhiteBalanceMode whiteBalanceMode,bool * isSupported)993 Camera_ErrorCode Camera_CaptureSession::IsWhiteBalanceModeSupported(Camera_WhiteBalanceMode whiteBalanceMode,
994     bool* isSupported)
995 {
996     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsWhiteBalanceModeSupported is called");
997     CHECK_RETURN_RET_ELOG(
998         innerCaptureSession_->IsWhiteBalanceModeSupported(
999             static_cast<WhiteBalanceMode>(whiteBalanceMode), *isSupported) != CameraErrorCode::SUCCESS,
1000         CAMERA_SESSION_NOT_CONFIG,
1001         "Camera_CaptureSession::IsWhiteBalanceModeSupported session is not config");
1002     return CAMERA_OK;
1003 }
1004 
GetWhiteBalanceMode(Camera_WhiteBalanceMode * whiteBalanceMode)1005 Camera_ErrorCode Camera_CaptureSession::GetWhiteBalanceMode(Camera_WhiteBalanceMode *whiteBalanceMode)
1006 {
1007     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetWhiteBalanceMode is called");
1008     WhiteBalanceMode mode;
1009     int32_t ret = innerCaptureSession_->GetWhiteBalanceMode(mode);
1010     CHECK_RETURN_RET_ELOG(ret == CameraErrorCode::SESSION_NOT_CONFIG,
1011         CAMERA_SESSION_NOT_CONFIG,
1012         "Camera_CaptureSession::GetWhiteBalanceMode session is not config");
1013     CHECK_RETURN_RET_ELOG(ret == CameraErrorCode::INVALID_ARGUMENT,
1014         CAMERA_INVALID_ARGUMENT,
1015         "Camera_CaptureSession::GetWhiteBalanceMode invalid argument");
1016     *whiteBalanceMode = static_cast<Camera_WhiteBalanceMode>(mode);
1017     return CAMERA_OK;
1018 }
1019 
GetWhiteBalanceRange(int32_t * minColorTemperature,int32_t * maxColorTemperature)1020 Camera_ErrorCode Camera_CaptureSession::GetWhiteBalanceRange(int32_t *minColorTemperature, int32_t *maxColorTemperature)
1021 {
1022     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetWhiteBalanceRange is called");
1023     std::vector<int32_t> whiteBalanceRange;
1024     CHECK_RETURN_RET_ELOG(
1025         innerCaptureSession_->GetManualWhiteBalanceRange(whiteBalanceRange) != CameraErrorCode::SUCCESS,
1026         CAMERA_SESSION_NOT_CONFIG,
1027         "Camera_CaptureSession::GetWhiteBalanceRange session is not config");
1028     *minColorTemperature = 0;
1029     *maxColorTemperature = 0;
1030     size_t minLength = 2;
1031     CHECK_RETURN_RET_ELOG(whiteBalanceRange.size() < minLength,
1032         CAMERA_SERVICE_FATAL_ERROR,
1033         "The length of whiteBalanceRange is less than 2.");
1034     *minColorTemperature = whiteBalanceRange.front();
1035     *maxColorTemperature = whiteBalanceRange.back();
1036     return CAMERA_OK;
1037 }
1038 
GetWhiteBalance(int32_t * colorTemperature)1039 Camera_ErrorCode Camera_CaptureSession::GetWhiteBalance(int32_t *colorTemperature)
1040 {
1041     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetWhiteBalance is called");
1042     int32_t wbValue = 0;
1043     CHECK_RETURN_RET_ELOG(innerCaptureSession_->GetManualWhiteBalance(wbValue) != CameraErrorCode::SUCCESS,
1044         CAMERA_SESSION_NOT_CONFIG,
1045         "Camera_CaptureSession::GetWhiteBalance session is not config");
1046     *colorTemperature = wbValue;
1047     return CAMERA_OK;
1048 }
1049 
SetWhiteBalance(int32_t colorTemperature)1050 Camera_ErrorCode Camera_CaptureSession::SetWhiteBalance(int32_t colorTemperature)
1051 {
1052     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetWhiteBalance is called");
1053     innerCaptureSession_->LockForControl();
1054     innerCaptureSession_->SetManualWhiteBalance(colorTemperature);
1055     innerCaptureSession_->UnlockForControl();
1056     return CAMERA_OK;
1057 }
1058 
SetWhiteBalanceMode(Camera_WhiteBalanceMode whiteBalanceMode)1059 Camera_ErrorCode Camera_CaptureSession::SetWhiteBalanceMode(Camera_WhiteBalanceMode whiteBalanceMode)
1060 {
1061     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetWhiteBalanceMode is called");
1062     innerCaptureSession_->LockForControl();
1063     innerCaptureSession_->SetWhiteBalanceMode(static_cast<WhiteBalanceMode>(whiteBalanceMode));
1064     innerCaptureSession_->UnlockForControl();
1065     return CAMERA_OK;
1066 }
1067 
RegisterMacroStatusCallback(OH_CaptureSession_OnMacroStatusChange controlMacroStatusChange)1068 Camera_ErrorCode Camera_CaptureSession::RegisterMacroStatusCallback(
1069     OH_CaptureSession_OnMacroStatusChange controlMacroStatusChange)
1070 {
1071     shared_ptr<InnerCaptureSessionMacroStatusCallback> innerMacroStatusCallback =
1072         make_shared<InnerCaptureSessionMacroStatusCallback>(this, controlMacroStatusChange);
1073     CHECK_RETURN_RET_ELOG(
1074         innerMacroStatusCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR, "create innerCallback failed!");
1075     innerCaptureSession_->SetMacroStatusCallback(innerMacroStatusCallback);
1076     return CAMERA_OK;
1077 }
1078 
UnregisterMacroStatusCallback(OH_CaptureSession_OnMacroStatusChange controlMacroStatusChange)1079 Camera_ErrorCode Camera_CaptureSession::UnregisterMacroStatusCallback(
1080     OH_CaptureSession_OnMacroStatusChange controlMacroStatusChange)
1081 {
1082     MEDIA_INFO_LOG("Camera_CaptureSession::UnregisterMacroStatusCallback");
1083     innerCaptureSession_->SetMacroStatusCallback(nullptr);
1084     return CAMERA_OK;
1085 }