• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "capture_session_impl.h"
17 #include "camera_log.h"
18 #include "camera_util.h"
19 #include "capture_scene_const.h"
20 
21 using namespace std;
22 using namespace OHOS;
23 using namespace OHOS::CameraStandard;
24 const int32_t ARGS_TWO = 2;
25 const std::unordered_map<Camera_SceneMode, SceneMode> g_ndkToFwMode_ = {
26     {Camera_SceneMode::NORMAL_PHOTO, SceneMode::CAPTURE},
27     {Camera_SceneMode::NORMAL_VIDEO, SceneMode::VIDEO},
28     {Camera_SceneMode::SECURE_PHOTO, SceneMode::SECURE},
29 };
30 const std::unordered_map<Camera_PreconfigType, PreconfigType> g_ndkToFwPreconfig = {
31     {Camera_PreconfigType::PRECONFIG_720P, PreconfigType::PRECONFIG_720P},
32     {Camera_PreconfigType::PRECONFIG_1080P, PreconfigType::PRECONFIG_1080P},
33     {Camera_PreconfigType::PRECONFIG_4K, PreconfigType::PRECONFIG_4K},
34     {Camera_PreconfigType::PRECONFIG_HIGH_QUALITY, PreconfigType::PRECONFIG_HIGH_QUALITY}
35 };
36 const std::unordered_map<Camera_PreconfigRatio, ProfileSizeRatio> g_ndkToFwPreconfigRatio = {
37     {Camera_PreconfigRatio::PRECONFIG_RATIO_1_1, ProfileSizeRatio::RATIO_1_1},
38     {Camera_PreconfigRatio::PRECONFIG_RATIO_4_3, ProfileSizeRatio::RATIO_4_3},
39     {Camera_PreconfigRatio::PRECONFIG_RATIO_16_9, ProfileSizeRatio::RATIO_16_9}
40 };
41 const std::unordered_map<ColorSpace, OH_NativeBuffer_ColorSpace> g_fwToNdkColorSpace_ = {
42     {ColorSpace::COLOR_SPACE_UNKNOWN, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE},
43     {ColorSpace::DISPLAY_P3, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL},
44     {ColorSpace::SRGB, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL},
45     {ColorSpace::BT709, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL},
46     {ColorSpace::BT2020_HLG, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL},
47     {ColorSpace::BT2020_PQ, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL},
48     {ColorSpace::P3_HLG, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL},
49     {ColorSpace::P3_PQ, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL},
50     {ColorSpace::DISPLAY_P3_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT},
51     {ColorSpace::SRGB_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT},
52     {ColorSpace::BT709_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT},
53     {ColorSpace::BT2020_HLG_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT},
54     {ColorSpace::BT2020_PQ_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT},
55     {ColorSpace::P3_HLG_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT},
56     {ColorSpace::P3_PQ_LIMIT, OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT}
57 };
58 const std::unordered_map<OH_NativeBuffer_ColorSpace, ColorSpace> g_ndkToFwColorSpace_ = {
59     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE, ColorSpace::COLOR_SPACE_UNKNOWN},
60     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL, ColorSpace::DISPLAY_P3},
61     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL, ColorSpace::SRGB},
62     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL, ColorSpace::BT709},
63     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL, ColorSpace::BT2020_HLG},
64     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL, ColorSpace::BT2020_PQ},
65     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL, ColorSpace::P3_HLG},
66     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL, ColorSpace::P3_PQ},
67     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT, ColorSpace::DISPLAY_P3_LIMIT},
68     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT, ColorSpace::SRGB_LIMIT},
69     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT, ColorSpace::BT709_LIMIT},
70     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT, ColorSpace::BT2020_HLG_LIMIT},
71     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT, ColorSpace::BT2020_PQ_LIMIT},
72     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT, ColorSpace::P3_HLG_LIMIT},
73     {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT, ColorSpace::P3_PQ_LIMIT}
74 };
75 
76 class InnerCaptureSessionCallback : public SessionCallback, public FocusCallback {
77 public:
InnerCaptureSessionCallback(Camera_CaptureSession * captureSession,CaptureSession_Callbacks * callback)78     InnerCaptureSessionCallback(Camera_CaptureSession* captureSession, CaptureSession_Callbacks* callback)
79         : captureSession_(captureSession), callback_(*callback) {}
80     ~InnerCaptureSessionCallback() = default;
81 
OnFocusState(FocusState state)82     void OnFocusState(FocusState state) override
83     {
84         MEDIA_DEBUG_LOG("OnFrameStarted is called!");
85         CHECK_EXECUTE(captureSession_ != nullptr && callback_.onFocusStateChange != nullptr,
86             callback_.onFocusStateChange(captureSession_, static_cast<Camera_FocusState>(state)));
87     }
88 
OnError(const int32_t errorCode)89     void OnError(const int32_t errorCode) override
90     {
91         MEDIA_DEBUG_LOG("OnError is called!, errorCode: %{public}d", errorCode);
92         CHECK_EXECUTE(captureSession_ != nullptr && callback_.onError != nullptr,
93             callback_.onError(captureSession_, FrameworkToNdkCameraError(errorCode)));
94     }
95 
96 private:
97     Camera_CaptureSession* captureSession_;
98     CaptureSession_Callbacks callback_;
99 };
100 
101 class InnerCaptureSessionSmoothZoomInfoCallback : public SmoothZoomCallback {
102 public:
InnerCaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)103     InnerCaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession* captureSession,
104         OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
105         : captureSession_(captureSession), smoothZoomInfoCallback_(smoothZoomInfoCallback) {};
106     ~InnerCaptureSessionSmoothZoomInfoCallback() = default;
107 
OnSmoothZoom(int32_t duration)108     void OnSmoothZoom(int32_t duration) override
109     {
110         MEDIA_DEBUG_LOG("OnSmoothZoom is called!");
111         if (captureSession_ != nullptr && smoothZoomInfoCallback_ != nullptr) {
112             Camera_SmoothZoomInfo info;
113             info.duration = duration;
114             smoothZoomInfoCallback_(captureSession_, &info);
115         }
116     }
117 
118 private:
119     Camera_CaptureSession* captureSession_;
120     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback_ = nullptr;
121 };
122 
123 class InnerCaptureSessionAutoDeviceSwitchStatusCallback : public AutoDeviceSwitchCallback {
124 public:
InnerCaptureSessionAutoDeviceSwitchStatusCallback(Camera_CaptureSession * captureSession,OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback)125     InnerCaptureSessionAutoDeviceSwitchStatusCallback(Camera_CaptureSession* captureSession,
126         OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback)
127         : captureSession_(captureSession), autoDeviceSwitchStatusCallback_(autoDeviceSwitchStatusCallback) {};
128     ~InnerCaptureSessionAutoDeviceSwitchStatusCallback() = default;
129 
OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched,bool isDeviceCapabilityChanged) const130     void OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched, bool isDeviceCapabilityChanged) const override
131     {
132         MEDIA_DEBUG_LOG("OnAutoDeviceSwitchStatusChange is called!");
133         if (captureSession_ != nullptr && autoDeviceSwitchStatusCallback_ != nullptr) {
134             Camera_AutoDeviceSwitchStatusInfo info;
135             info.isDeviceSwitched = isDeviceSwitched;
136             info.isDeviceCapabilityChanged = isDeviceCapabilityChanged;
137             autoDeviceSwitchStatusCallback_(captureSession_, &info);
138         }
139     }
140 
141 private:
142     Camera_CaptureSession* captureSession_;
143     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusCallback_ = nullptr;
144 };
145 
Camera_CaptureSession(sptr<CaptureSession> & innerCaptureSession)146 Camera_CaptureSession::Camera_CaptureSession(sptr<CaptureSession> &innerCaptureSession)
147     : innerCaptureSession_(innerCaptureSession)
148 {
149     MEDIA_DEBUG_LOG("Camera_CaptureSession Constructor is called");
150 }
151 
~Camera_CaptureSession()152 Camera_CaptureSession::~Camera_CaptureSession()
153 {
154     MEDIA_DEBUG_LOG("~Camera_CaptureSession is called");
155     if (innerCaptureSession_) {
156         innerCaptureSession_ = nullptr;
157     }
158 }
159 
RegisterCallback(CaptureSession_Callbacks * callback)160 Camera_ErrorCode Camera_CaptureSession::RegisterCallback(CaptureSession_Callbacks* callback)
161 {
162     shared_ptr<InnerCaptureSessionCallback> innerCallback =
163         make_shared<InnerCaptureSessionCallback>(this, callback);
164     CHECK_ERROR_RETURN_RET_LOG(innerCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
165         "create innerCallback failed!");
166     CHECK_EXECUTE(callback->onError != nullptr, innerCaptureSession_->SetCallback(innerCallback));
167     CHECK_EXECUTE(callback->onFocusStateChange != nullptr, innerCaptureSession_->SetFocusCallback(innerCallback));
168     return CAMERA_OK;
169 }
170 
UnregisterCallback(CaptureSession_Callbacks * callback)171 Camera_ErrorCode Camera_CaptureSession::UnregisterCallback(CaptureSession_Callbacks* callback)
172 {
173     CHECK_EXECUTE(callback->onError != nullptr, innerCaptureSession_->SetCallback(nullptr));
174     CHECK_EXECUTE(callback->onFocusStateChange != nullptr, innerCaptureSession_->SetFocusCallback(nullptr));
175     return CAMERA_OK;
176 }
177 
RegisterSmoothZoomInfoCallback(OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)178 Camera_ErrorCode Camera_CaptureSession::RegisterSmoothZoomInfoCallback(
179     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
180 {
181     shared_ptr<InnerCaptureSessionSmoothZoomInfoCallback> innerSmoothZoomInfoCallback =
182         make_shared<InnerCaptureSessionSmoothZoomInfoCallback>(this, smoothZoomInfoCallback);
183     CHECK_ERROR_RETURN_RET_LOG(innerSmoothZoomInfoCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
184         "create innerCallback failed!");
185     innerCaptureSession_->SetSmoothZoomCallback(innerSmoothZoomInfoCallback);
186     return CAMERA_OK;
187 }
188 
UnregisterSmoothZoomInfoCallback(OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)189 Camera_ErrorCode Camera_CaptureSession::UnregisterSmoothZoomInfoCallback(
190     OH_CaptureSession_OnSmoothZoomInfo smoothZoomInfoCallback)
191 {
192     innerCaptureSession_->SetSmoothZoomCallback(nullptr);
193     return CAMERA_OK;
194 }
195 
SetSessionMode(Camera_SceneMode sceneMode)196 Camera_ErrorCode Camera_CaptureSession::SetSessionMode(Camera_SceneMode sceneMode)
197 {
198     CHECK_ERROR_RETURN_RET_LOG(innerCaptureSession_->IsSessionConfiged() || innerCaptureSession_->IsSessionCommited(),
199         CAMERA_OPERATION_NOT_ALLOWED, "Camera_Manager::SetSessionMode can not set sceneMode after BeginConfig!");
200     auto itr = g_ndkToFwMode_.find(static_cast<Camera_SceneMode>(sceneMode));
201     CHECK_ERROR_RETURN_RET_LOG(itr == g_ndkToFwMode_.end(), CAMERA_INVALID_ARGUMENT,
202         "Camera_CaptureSession::SetSessionMode sceneMode not found!");
203     SceneMode innerSceneMode = static_cast<SceneMode>(itr->second);
204     switch (innerSceneMode) {
205         case SceneMode::CAPTURE:
206             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::CAPTURE);
207             break;
208         case SceneMode::VIDEO:
209             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::VIDEO);
210             break;
211         case SceneMode::SECURE:
212             innerCaptureSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::SECURE);
213             break;
214         default:
215             MEDIA_ERR_LOG("Camera_CaptureSession::SetSessionMode sceneMode = %{public}d not supported", sceneMode);
216             return CAMERA_INVALID_ARGUMENT;
217     }
218     return CAMERA_OK;
219 }
220 
AddSecureOutput(Camera_PreviewOutput * previewOutput)221 Camera_ErrorCode Camera_CaptureSession::AddSecureOutput(Camera_PreviewOutput* previewOutput)
222 {
223     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddSecureOutput is called");
224     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
225     int32_t ret = innerCaptureSession_->AddSecureOutput(innerPreviewOutput);
226     return FrameworkToNdkCameraError(ServiceToCameraError(ret));
227 }
228 
BeginConfig()229 Camera_ErrorCode Camera_CaptureSession::BeginConfig()
230 {
231     int32_t ret = innerCaptureSession_->BeginConfig();
232     return FrameworkToNdkCameraError(ret);
233 }
234 
CommitConfig()235 Camera_ErrorCode Camera_CaptureSession::CommitConfig()
236 {
237     int32_t ret = innerCaptureSession_->CommitConfig();
238     return FrameworkToNdkCameraError(ret);
239 }
240 
AddInput(Camera_Input * cameraInput)241 Camera_ErrorCode Camera_CaptureSession::AddInput(Camera_Input* cameraInput)
242 {
243     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
244     int32_t ret = innerCaptureSession_->AddInput(innerCameraInput);
245     return FrameworkToNdkCameraError(ret);
246 }
247 
RemoveInput(Camera_Input * cameraInput)248 Camera_ErrorCode Camera_CaptureSession::RemoveInput(Camera_Input* cameraInput)
249 {
250     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
251     int32_t ret = innerCaptureSession_->RemoveInput(innerCameraInput);
252     return FrameworkToNdkCameraError(ret);
253 }
254 
AddPreviewOutput(Camera_PreviewOutput * previewOutput)255 Camera_ErrorCode Camera_CaptureSession::AddPreviewOutput(Camera_PreviewOutput* previewOutput)
256 {
257     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
258     int32_t ret = innerCaptureSession_->AddOutput(innerPreviewOutput);
259     return FrameworkToNdkCameraError(ret);
260 }
261 
RemovePreviewOutput(Camera_PreviewOutput * previewOutput)262 Camera_ErrorCode Camera_CaptureSession::RemovePreviewOutput(Camera_PreviewOutput* previewOutput)
263 {
264     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
265     int32_t ret = innerCaptureSession_->RemoveOutput(innerPreviewOutput);
266     return FrameworkToNdkCameraError(ret);
267 }
268 
AddPhotoOutput(Camera_PhotoOutput * photoOutput)269 Camera_ErrorCode Camera_CaptureSession::AddPhotoOutput(Camera_PhotoOutput* photoOutput)
270 {
271     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddPhotoOutput is called");
272     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
273     int32_t ret = innerCaptureSession_->AddOutput(innerPhotoOutput);
274     return FrameworkToNdkCameraError(ret);
275 }
276 
RemovePhotoOutput(Camera_PhotoOutput * photoOutput)277 Camera_ErrorCode Camera_CaptureSession::RemovePhotoOutput(Camera_PhotoOutput* photoOutput)
278 {
279     MEDIA_DEBUG_LOG("Camera_CaptureSession::RemovePhotoOutput is called");
280     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
281     int32_t ret = innerCaptureSession_->RemoveOutput(innerPhotoOutput);
282     return FrameworkToNdkCameraError(ret);
283 }
284 
AddMetaDataOutput(Camera_MetadataOutput * metadataOutput)285 Camera_ErrorCode Camera_CaptureSession::AddMetaDataOutput(Camera_MetadataOutput* metadataOutput)
286 {
287     MEDIA_DEBUG_LOG("Camera_CaptureSession::AddMetaDataOutput is called");
288     sptr<CaptureOutput> innerMetaDataOutput = metadataOutput->GetInnerMetadataOutput();
289     int32_t ret = innerCaptureSession_->AddOutput(innerMetaDataOutput);
290     return FrameworkToNdkCameraError(ret);
291 }
292 
RemoveMetaDataOutput(Camera_MetadataOutput * metadataOutput)293 Camera_ErrorCode Camera_CaptureSession::RemoveMetaDataOutput(Camera_MetadataOutput* metadataOutput)
294 {
295     MEDIA_DEBUG_LOG("Camera_CaptureSession::RemoveMetaDataOutput is called");
296     sptr<CaptureOutput> innerMetaDataOutput = metadataOutput->GetInnerMetadataOutput();
297     CHECK_ERROR_RETURN_RET(innerCaptureSession_ == nullptr, CAMERA_SERVICE_FATAL_ERROR);
298     int32_t ret = innerCaptureSession_->AddOutput(innerMetaDataOutput);
299     return FrameworkToNdkCameraError(ret);
300 }
301 
IsVideoStabilizationModeSupported(Camera_VideoStabilizationMode mode,bool * isSupported)302 Camera_ErrorCode Camera_CaptureSession::IsVideoStabilizationModeSupported(Camera_VideoStabilizationMode mode,
303     bool* isSupported)
304 {
305     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsVideoStabilizationModeSupported is called");
306     VideoStabilizationMode innerVideoStabilizationMode = static_cast<VideoStabilizationMode>(mode);
307     int32_t ret = innerCaptureSession_->IsVideoStabilizationModeSupported(innerVideoStabilizationMode, *isSupported);
308     return FrameworkToNdkCameraError(ret);
309 }
310 
GetVideoStabilizationMode(Camera_VideoStabilizationMode * mode)311 Camera_ErrorCode Camera_CaptureSession::GetVideoStabilizationMode(Camera_VideoStabilizationMode* mode)
312 {
313     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetVideoStabilizationMode is called");
314 
315     *mode = static_cast<Camera_VideoStabilizationMode>(innerCaptureSession_->GetActiveVideoStabilizationMode());
316     return CAMERA_OK;
317 }
318 
SetVideoStabilizationMode(Camera_VideoStabilizationMode mode)319 Camera_ErrorCode Camera_CaptureSession::SetVideoStabilizationMode(Camera_VideoStabilizationMode mode)
320 {
321     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetVideoStabilizationMode is called");
322 
323     VideoStabilizationMode innerVideoStabilizationMode = static_cast<VideoStabilizationMode>(mode);
324     int32_t ret = innerCaptureSession_->SetVideoStabilizationMode(innerVideoStabilizationMode);
325     return FrameworkToNdkCameraError(ret);
326 }
327 
GetZoomRatioRange(float * minZoom,float * maxZoom)328 Camera_ErrorCode Camera_CaptureSession::GetZoomRatioRange(float* minZoom, float* maxZoom)
329 {
330     std::vector<float> vecZoomRatioList = innerCaptureSession_->GetZoomRatioRange();
331     if (vecZoomRatioList.empty()) {
332         MEDIA_ERR_LOG("Camera_CaptureSession::GetZoomRatioRange vecZoomRatioList  size is null ");
333     } else {
334         *minZoom = vecZoomRatioList[0];
335         *maxZoom = vecZoomRatioList[1];
336     }
337     return CAMERA_OK;
338 }
339 
GetZoomRatio(float * zoom)340 Camera_ErrorCode Camera_CaptureSession::GetZoomRatio(float* zoom)
341 {
342     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetZoomRatio is called");
343     *zoom = innerCaptureSession_->GetZoomRatio();
344 
345     return CAMERA_OK;
346 }
347 
SetZoomRatio(float zoom)348 Camera_ErrorCode Camera_CaptureSession::SetZoomRatio(float zoom)
349 {
350     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetZoomRatio is called");
351 
352     innerCaptureSession_->LockForControl();
353     int32_t ret = innerCaptureSession_->SetZoomRatio(zoom);
354     innerCaptureSession_->UnlockForControl();
355 
356     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
357     return FrameworkToNdkCameraError(ret);
358 }
359 
IsFocusModeSupported(Camera_FocusMode focusMode,bool * isSupported)360 Camera_ErrorCode Camera_CaptureSession::IsFocusModeSupported(Camera_FocusMode focusMode, bool* isSupported)
361 {
362     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsFocusModeSupported is called");
363     FocusMode innerFocusMode = static_cast<FocusMode>(focusMode);
364     int32_t ret = innerCaptureSession_->IsFocusModeSupported(innerFocusMode, *isSupported);
365     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
366     return FrameworkToNdkCameraError(ret);
367 }
368 
GetFocusMode(Camera_FocusMode * focusMode)369 Camera_ErrorCode Camera_CaptureSession::GetFocusMode(Camera_FocusMode* focusMode)
370 {
371     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusMode is called");
372 
373     *focusMode = static_cast<Camera_FocusMode>(innerCaptureSession_->GetFocusMode());
374     return CAMERA_OK;
375 }
376 
SetFocusMode(Camera_FocusMode focusMode)377 Camera_ErrorCode Camera_CaptureSession::SetFocusMode(Camera_FocusMode focusMode)
378 {
379     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusMode is called");
380 
381     FocusMode innerFocusMode = static_cast<FocusMode>(focusMode);
382     innerCaptureSession_->LockForControl();
383     int32_t ret = innerCaptureSession_->SetFocusMode(innerFocusMode);
384     innerCaptureSession_->UnlockForControl();
385 
386     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
387     return FrameworkToNdkCameraError(ret);
388 }
389 
SetFocusPoint(Camera_Point focusPoint)390 Camera_ErrorCode Camera_CaptureSession::SetFocusPoint(Camera_Point focusPoint)
391 {
392     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusPoint is called");
393 
394     Point innerFocusPoint;
395     innerFocusPoint.x = focusPoint.x;
396     innerFocusPoint.y = focusPoint.y;
397 
398     innerCaptureSession_->LockForControl();
399     int32_t ret = innerCaptureSession_->SetFocusPoint(innerFocusPoint);
400     innerCaptureSession_->UnlockForControl();
401 
402     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
403     return FrameworkToNdkCameraError(ret);
404 }
405 
GetFocusPoint(Camera_Point * focusPoint)406 Camera_ErrorCode Camera_CaptureSession::GetFocusPoint(Camera_Point* focusPoint)
407 {
408     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusPoint is called");
409     Point innerFocusPoint = innerCaptureSession_->GetFocusPoint();
410     (*focusPoint).x = innerFocusPoint.x;
411     (*focusPoint).y = innerFocusPoint.y;
412 
413     return CAMERA_OK;
414 }
415 
HasFlash(bool * hasFlash)416 Camera_ErrorCode Camera_CaptureSession::HasFlash(bool* hasFlash)
417 {
418     MEDIA_DEBUG_LOG("Camera_CaptureSession::HasFlash is called");
419 
420     *hasFlash = innerCaptureSession_->HasFlash();
421 
422     return CAMERA_OK;
423 }
424 
IsFlashModeSupported(Camera_FlashMode flashMode,bool * isSupported)425 Camera_ErrorCode Camera_CaptureSession::IsFlashModeSupported(Camera_FlashMode flashMode, bool* isSupported)
426 {
427     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsFlashModeSupported is called");
428     FlashMode innerFlashMode = static_cast<FlashMode>(flashMode);
429 
430     *isSupported = innerCaptureSession_->IsFlashModeSupported(innerFlashMode);
431 
432     return CAMERA_OK;
433 }
434 
GetFlashMode(Camera_FlashMode * flashMode)435 Camera_ErrorCode Camera_CaptureSession::GetFlashMode(Camera_FlashMode* flashMode)
436 {
437     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFlashMode is called");
438     *flashMode = static_cast<Camera_FlashMode>(innerCaptureSession_->GetFlashMode());
439 
440     return CAMERA_OK;
441 }
442 
SetFlashMode(Camera_FlashMode flashMode)443 Camera_ErrorCode Camera_CaptureSession::SetFlashMode(Camera_FlashMode flashMode)
444 {
445     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFlashMode is called");
446 
447     FlashMode innerFlashMode = static_cast<FlashMode>(flashMode);
448     innerCaptureSession_->LockForControl();
449     int32_t ret = innerCaptureSession_->SetFlashMode(innerFlashMode);
450     innerCaptureSession_->UnlockForControl();
451 
452     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
453     return FrameworkToNdkCameraError(ret);
454 }
455 
IsExposureModeSupported(Camera_ExposureMode exposureMode,bool * isSupported)456 Camera_ErrorCode Camera_CaptureSession::IsExposureModeSupported(Camera_ExposureMode exposureMode, bool* isSupported)
457 {
458     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsExposureModeSupported is called");
459     ExposureMode innerExposureMode = static_cast<ExposureMode>(exposureMode);
460     int32_t ret = innerCaptureSession_->IsExposureModeSupported(innerExposureMode, *isSupported);
461     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
462     return FrameworkToNdkCameraError(ret);
463 }
464 
GetExposureMode(Camera_ExposureMode * exposureMode)465 Camera_ErrorCode Camera_CaptureSession::GetExposureMode(Camera_ExposureMode* exposureMode)
466 {
467     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureMode is called");
468 
469     *exposureMode = static_cast<Camera_ExposureMode>(innerCaptureSession_->GetExposureMode());
470     return CAMERA_OK;
471 }
472 
SetExposureMode(Camera_ExposureMode exposureMode)473 Camera_ErrorCode Camera_CaptureSession::SetExposureMode(Camera_ExposureMode exposureMode)
474 {
475     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureMode is called");
476 
477     ExposureMode innerExposureMode = static_cast<ExposureMode>(exposureMode);
478     innerCaptureSession_->LockForControl();
479     int32_t ret = innerCaptureSession_->SetExposureMode(innerExposureMode);
480     innerCaptureSession_->UnlockForControl();
481 
482     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
483     return FrameworkToNdkCameraError(ret);
484 }
485 
GetMeteringPoint(Camera_Point * point)486 Camera_ErrorCode Camera_CaptureSession::GetMeteringPoint(Camera_Point* point)
487 {
488     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetMeteringPoint is called");
489 
490     Point innerFocusPoint = innerCaptureSession_->GetMeteringPoint();
491     (*point).x = innerFocusPoint.x;
492     (*point).y = innerFocusPoint.y;
493     return CAMERA_OK;
494 }
495 
SetMeteringPoint(Camera_Point point)496 Camera_ErrorCode Camera_CaptureSession::SetMeteringPoint(Camera_Point point)
497 {
498     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetMeteringPoint is called");
499     Point innerExposurePoint;
500     innerExposurePoint.x = point.x;
501     innerExposurePoint.y = point.y;
502 
503     innerCaptureSession_->LockForControl();
504     int32_t ret = innerCaptureSession_->SetMeteringPoint(innerExposurePoint);
505     innerCaptureSession_->UnlockForControl();
506 
507     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
508     return FrameworkToNdkCameraError(ret);
509 }
510 
GetExposureBiasRange(float * minExposureBias,float * maxExposureBias,float * step)511 Camera_ErrorCode Camera_CaptureSession::GetExposureBiasRange(float* minExposureBias,
512     float* maxExposureBias, float* step)
513 {
514     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBiasRange is called");
515 
516     std::vector<float> vecExposureBiasList = innerCaptureSession_->GetExposureBiasRange();
517     if (!vecExposureBiasList.empty() && vecExposureBiasList.size() >= ARGS_TWO) {
518         *minExposureBias = vecExposureBiasList[0];
519         *maxExposureBias = vecExposureBiasList[1];
520     } else {
521         MEDIA_ERR_LOG("Camera_CaptureSession::GetExposureBiasRange vecZoomRatioList illegal.");
522     }
523     return CAMERA_OK;
524 }
525 
SetExposureBias(float exposureBias)526 Camera_ErrorCode Camera_CaptureSession::SetExposureBias(float exposureBias)
527 {
528     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureBias is called");
529 
530     innerCaptureSession_->LockForControl();
531     int32_t ret = innerCaptureSession_->SetExposureBias(exposureBias);
532     innerCaptureSession_->UnlockForControl();
533 
534     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, CAMERA_SERVICE_FATAL_ERROR);
535     return FrameworkToNdkCameraError(ret);
536 }
537 
GetExposureBias(float * exposureBias)538 Camera_ErrorCode Camera_CaptureSession::GetExposureBias(float* exposureBias)
539 {
540     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBias is called");
541 
542     *exposureBias = innerCaptureSession_->GetExposureValue();
543 
544     return CAMERA_OK;
545 }
546 
AddVideoOutput(Camera_VideoOutput * videoOutput)547 Camera_ErrorCode Camera_CaptureSession::AddVideoOutput(Camera_VideoOutput* videoOutput)
548 {
549     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
550     int32_t ret = innerCaptureSession_->AddOutput(innerVideoOutput);
551     return FrameworkToNdkCameraError(ret);
552 }
553 
RemoveVideoOutput(Camera_VideoOutput * videoOutput)554 Camera_ErrorCode Camera_CaptureSession::RemoveVideoOutput(Camera_VideoOutput* videoOutput)
555 {
556     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
557     int32_t ret = innerCaptureSession_->RemoveOutput(innerVideoOutput);
558     return FrameworkToNdkCameraError(ret);
559 }
560 
Start()561 Camera_ErrorCode Camera_CaptureSession::Start()
562 {
563     int32_t ret = innerCaptureSession_->Start();
564     return FrameworkToNdkCameraError(ret);
565 }
566 
Stop()567 Camera_ErrorCode Camera_CaptureSession::Stop()
568 {
569     int32_t ret = innerCaptureSession_->Stop();
570     return FrameworkToNdkCameraError(ret);
571 }
572 
Release()573 Camera_ErrorCode Camera_CaptureSession::Release()
574 {
575     int32_t ret = innerCaptureSession_->Release();
576     return FrameworkToNdkCameraError(ret);
577 }
578 
CanAddInput(Camera_Input * cameraInput,bool * isSuccessful)579 Camera_ErrorCode Camera_CaptureSession::CanAddInput(Camera_Input* cameraInput, bool* isSuccessful)
580 {
581     sptr<CaptureInput> innerCameraInput = cameraInput->GetInnerCameraInput();
582     *isSuccessful = innerCaptureSession_->CanAddInput(innerCameraInput);
583     return CAMERA_OK;
584 }
585 
CanAddPreviewOutput(Camera_PreviewOutput * previewOutput,bool * isSuccessful)586 Camera_ErrorCode Camera_CaptureSession::CanAddPreviewOutput(Camera_PreviewOutput* previewOutput, bool* isSuccessful)
587 {
588     sptr<CaptureOutput> innerPreviewOutput = previewOutput->GetInnerPreviewOutput();
589     *isSuccessful = innerCaptureSession_->CanAddOutput(innerPreviewOutput);
590     return CAMERA_OK;
591 }
592 
CanAddPhotoOutput(Camera_PhotoOutput * photoOutput,bool * isSuccessful)593 Camera_ErrorCode Camera_CaptureSession::CanAddPhotoOutput(Camera_PhotoOutput* photoOutput, bool* isSuccessful)
594 {
595     sptr<CaptureOutput> innerPhotoOutput = photoOutput->GetInnerPhotoOutput();
596     *isSuccessful = innerCaptureSession_->CanAddOutput(innerPhotoOutput);
597     return CAMERA_OK;
598 }
599 
CanAddVideoOutput(Camera_VideoOutput * videoOutput,bool * isSuccessful)600 Camera_ErrorCode Camera_CaptureSession::CanAddVideoOutput(Camera_VideoOutput* videoOutput, bool* isSuccessful)
601 {
602     sptr<CaptureOutput> innerVideoOutput = videoOutput->GetInnerVideoOutput();
603     *isSuccessful = innerCaptureSession_->CanAddOutput(innerVideoOutput);
604     return CAMERA_OK;
605 }
606 
CanPreconfig(Camera_PreconfigType preconfigType,bool * canPreconfig)607 Camera_ErrorCode Camera_CaptureSession::CanPreconfig(Camera_PreconfigType preconfigType, bool* canPreconfig)
608 {
609     auto itr = g_ndkToFwPreconfig.find(preconfigType);
610     if (itr == g_ndkToFwPreconfig.end()) {
611         MEDIA_ERR_LOG("Camera_CaptureSession::CanPreconfig preconfigType: [%{public}d] is invalid!", preconfigType);
612         *canPreconfig = false;
613         return CAMERA_INVALID_ARGUMENT;
614     }
615 
616     *canPreconfig = innerCaptureSession_->CanPreconfig(itr->second, ProfileSizeRatio::UNSPECIFIED);
617     return CAMERA_OK;
618 }
619 
CanPreconfigWithRatio(Camera_PreconfigType preconfigType,Camera_PreconfigRatio preconfigRatio,bool * canPreconfig)620 Camera_ErrorCode Camera_CaptureSession::CanPreconfigWithRatio(Camera_PreconfigType preconfigType,
621     Camera_PreconfigRatio preconfigRatio, bool* canPreconfig)
622 {
623     auto type = g_ndkToFwPreconfig.find(preconfigType);
624     auto ratio = g_ndkToFwPreconfigRatio.find(preconfigRatio);
625     if (type == g_ndkToFwPreconfig.end() || ratio == g_ndkToFwPreconfigRatio.end()) {
626         MEDIA_ERR_LOG("Camera_CaptureSession::CanPreconfigWithRatio preconfigType: [%{public}d] "
627             "or preconfigRatio: [%{public}d] is invalid!", preconfigType, preconfigRatio);
628         *canPreconfig = false;
629         return CAMERA_INVALID_ARGUMENT;
630     }
631 
632     *canPreconfig = innerCaptureSession_->CanPreconfig(type->second, ratio->second);
633     return CAMERA_OK;
634 }
635 
Preconfig(Camera_PreconfigType preconfigType)636 Camera_ErrorCode Camera_CaptureSession::Preconfig(Camera_PreconfigType preconfigType)
637 {
638     auto itr = g_ndkToFwPreconfig.find(preconfigType);
639     CHECK_ERROR_RETURN_RET_LOG(itr == g_ndkToFwPreconfig.end(), CAMERA_INVALID_ARGUMENT,
640         "Camera_CaptureSession::Preconfig preconfigType: [%{public}d] is invalid!", preconfigType);
641 
642     int32_t ret = innerCaptureSession_->Preconfig(itr->second, ProfileSizeRatio::UNSPECIFIED);
643     return FrameworkToNdkCameraError(ret);
644 }
645 
PreconfigWithRatio(Camera_PreconfigType preconfigType,Camera_PreconfigRatio preconfigRatio)646 Camera_ErrorCode Camera_CaptureSession::PreconfigWithRatio(Camera_PreconfigType preconfigType,
647     Camera_PreconfigRatio preconfigRatio)
648 {
649     auto type = g_ndkToFwPreconfig.find(preconfigType);
650     auto ratio = g_ndkToFwPreconfigRatio.find(preconfigRatio);
651     CHECK_ERROR_RETURN_RET_LOG(type == g_ndkToFwPreconfig.end(), CAMERA_INVALID_ARGUMENT,
652         "Camera_CaptureSession::PreconfigWithRatio preconfigType: [%{public}d] is invalid!", preconfigType);
653     CHECK_ERROR_RETURN_RET_LOG(ratio == g_ndkToFwPreconfigRatio.end(), CAMERA_INVALID_ARGUMENT,
654         "Camera_CaptureSession::PreconfigWithRatio preconfigRatio: [%{public}d] is invalid!", preconfigRatio);
655 
656     int32_t ret = innerCaptureSession_->Preconfig(type->second, ratio->second);
657     return FrameworkToNdkCameraError(ret);
658 }
659 
GetExposureValue(float * exposureValue)660 Camera_ErrorCode Camera_CaptureSession::GetExposureValue(float* exposureValue)
661 {
662     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureValue is called");
663 
664     int32_t ret = innerCaptureSession_->GetExposureValue(*exposureValue);
665     return FrameworkToNdkCameraError(ret);
666 }
667 
GetFocalLength(float * focalLength)668 Camera_ErrorCode Camera_CaptureSession::GetFocalLength(float* focalLength)
669 {
670     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocalLength is called");
671 
672     int32_t ret = innerCaptureSession_->GetFocalLength(*focalLength);
673     return FrameworkToNdkCameraError(ret);
674 }
675 
SetSmoothZoom(float targetZoom,Camera_SmoothZoomMode smoothZoomMode)676 Camera_ErrorCode Camera_CaptureSession::SetSmoothZoom(float targetZoom, Camera_SmoothZoomMode smoothZoomMode)
677 {
678     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetSmoothZoom is called");
679 
680     int32_t ret = innerCaptureSession_->SetSmoothZoom(targetZoom, static_cast<uint32_t>(smoothZoomMode));
681     return FrameworkToNdkCameraError(ret);
682 }
683 
GetSupportedColorSpaces(OH_NativeBuffer_ColorSpace ** colorSpace,uint32_t * size)684 Camera_ErrorCode Camera_CaptureSession::GetSupportedColorSpaces(OH_NativeBuffer_ColorSpace** colorSpace,
685     uint32_t* size)
686 {
687     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetSupportedColorSpaces is called");
688 
689     auto colorSpaces = innerCaptureSession_->GetSupportedColorSpaces();
690     if (colorSpaces.empty()) {
691         MEDIA_ERR_LOG("Supported ColorSpace is empty!");
692         *size = 0;
693         return CAMERA_OK;
694     }
695 
696     std::vector<OH_NativeBuffer_ColorSpace> cameraColorSpace;
697     for (size_t i = 0; i < colorSpaces.size(); ++i) {
698         auto itr = g_fwToNdkColorSpace_.find(colorSpaces[i]);
699         CHECK_EXECUTE(itr != g_fwToNdkColorSpace_.end(), cameraColorSpace.push_back(itr->second));
700     }
701 
702     if (cameraColorSpace.size() == 0) {
703         MEDIA_ERR_LOG("Supported ColorSpace is empty!");
704         *size = 0;
705         return CAMERA_OK;
706     }
707 
708     OH_NativeBuffer_ColorSpace* newColorSpace = new OH_NativeBuffer_ColorSpace[cameraColorSpace.size()];
709     CHECK_ERROR_RETURN_RET_LOG(newColorSpace == nullptr, CAMERA_SERVICE_FATAL_ERROR,
710         "Failed to allocate memory for color space!");
711     for (size_t index = 0; index < cameraColorSpace.size(); index++) {
712         newColorSpace[index] = cameraColorSpace[index];
713     }
714 
715     *size = cameraColorSpace.size();
716     *colorSpace = newColorSpace;
717     return CAMERA_OK;
718 }
719 
DeleteColorSpaces(OH_NativeBuffer_ColorSpace * colorSpace)720 Camera_ErrorCode Camera_CaptureSession::DeleteColorSpaces(OH_NativeBuffer_ColorSpace* colorSpace)
721 {
722     if (colorSpace != nullptr) {
723         delete[] colorSpace;
724         colorSpace = nullptr;
725     }
726 
727     return CAMERA_OK;
728 }
729 
GetActiveColorSpace(OH_NativeBuffer_ColorSpace * colorSpace)730 Camera_ErrorCode Camera_CaptureSession::GetActiveColorSpace(OH_NativeBuffer_ColorSpace* colorSpace)
731 {
732     MEDIA_DEBUG_LOG("Camera_CaptureSession::GetActiveColorSpace is called");
733 
734     ColorSpace innerColorSpace;
735     int32_t ret = innerCaptureSession_->GetActiveColorSpace(innerColorSpace);
736     CHECK_ERROR_RETURN_RET(ret != SUCCESS, FrameworkToNdkCameraError(ret));
737     auto itr = g_fwToNdkColorSpace_.find(innerColorSpace);
738     if (itr != g_fwToNdkColorSpace_.end()) {
739         *colorSpace = itr->second;
740     } else {
741         MEDIA_ERR_LOG("colorSpace[%{public}d] is invalid", innerColorSpace);
742         return CAMERA_SERVICE_FATAL_ERROR;
743     }
744     return CAMERA_OK;
745 }
746 
SetActiveColorSpace(OH_NativeBuffer_ColorSpace colorSpace)747 Camera_ErrorCode Camera_CaptureSession::SetActiveColorSpace(OH_NativeBuffer_ColorSpace colorSpace)
748 {
749     MEDIA_DEBUG_LOG("Camera_CaptureSession::SetActiveColorSpace is called");
750 
751     auto itr = g_ndkToFwColorSpace_.find(colorSpace);
752     CHECK_ERROR_RETURN_RET_LOG(itr == g_ndkToFwColorSpace_.end(), CAMERA_INVALID_ARGUMENT,
753         "colorSpace[%{public}d] is invalid", colorSpace);
754     int32_t ret = innerCaptureSession_->SetColorSpace(itr->second);
755     return FrameworkToNdkCameraError(ret);
756 }
757 
RegisterAutoDeviceSwitchStatusCallback(OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)758 Camera_ErrorCode Camera_CaptureSession::RegisterAutoDeviceSwitchStatusCallback(
759     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)
760 {
761     shared_ptr<InnerCaptureSessionAutoDeviceSwitchStatusCallback> innerDeviceSwitchStatusCallback =
762         make_shared<InnerCaptureSessionAutoDeviceSwitchStatusCallback>(this, autoDeviceSwitchStatusChange);
763     CHECK_ERROR_RETURN_RET_LOG(innerDeviceSwitchStatusCallback == nullptr, CAMERA_SERVICE_FATAL_ERROR,
764         "create innerCallback failed!");
765     innerCaptureSession_->SetAutoDeviceSwitchCallback(innerDeviceSwitchStatusCallback);
766     return CAMERA_OK;
767 }
768 
UnregisterAutoDeviceSwitchStatusCallback(OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)769 Camera_ErrorCode Camera_CaptureSession::UnregisterAutoDeviceSwitchStatusCallback(
770     OH_CaptureSession_OnAutoDeviceSwitchStatusChange autoDeviceSwitchStatusChange)
771 {
772     innerCaptureSession_->SetAutoDeviceSwitchCallback(nullptr);
773     return CAMERA_OK;
774 }
775 
IsAutoDeviceSwitchSupported(bool * isSupported)776 Camera_ErrorCode Camera_CaptureSession::IsAutoDeviceSwitchSupported(bool* isSupported)
777 {
778     MEDIA_DEBUG_LOG("Camera_CaptureSession::IsAutoDeviceSwitchSupported is called");
779     *isSupported = innerCaptureSession_->IsAutoDeviceSwitchSupported();
780     return CAMERA_OK;
781 }
782 
EnableAutoDeviceSwitch(bool enabled)783 Camera_ErrorCode Camera_CaptureSession::EnableAutoDeviceSwitch(bool enabled)
784 {
785     MEDIA_DEBUG_LOG("Camera_CaptureSession::EnableAutoDeviceSwitch is called");
786     int32_t ret = innerCaptureSession_->EnableAutoDeviceSwitch(enabled);
787     return FrameworkToNdkCameraError(ret);
788 }
789 
SetQualityPrioritization(Camera_QualityPrioritization qualityPrioritization)790 Camera_ErrorCode Camera_CaptureSession::SetQualityPrioritization(Camera_QualityPrioritization qualityPrioritization)
791 {
792     MEDIA_INFO_LOG("Camera_CaptureSession::SetQualityPrioritization is called");
793     QualityPrioritization innerQualityPrioritization = static_cast<QualityPrioritization>(qualityPrioritization);
794     innerCaptureSession_->LockForControl();
795     int32_t ret = innerCaptureSession_->SetQualityPrioritization(innerQualityPrioritization);
796     innerCaptureSession_->UnlockForControl();
797     return FrameworkToNdkCameraError(ret);
798 }
799