• 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 "camera_manager_ndk.h"
17 #include <unistd.h>
18 
19 #include <cinttypes>
20 #include <queue>
21 #include <utility>
22 
23 #define LOG(fmt, ...)           \
24         (void)printf(fmt, ##__VA_ARGS__);           \
25 
26 CameraCallbackCode NDKCamera::cameraCallbackCode_ = NoReceived;
27 
28 Camera_Size SecureSize = {640, 480};
29 Camera_Profile PhotoOutputWithoutSurface = {CAMERA_FORMAT_JPEG, {1920, 1080}};
30 Camera_Profile PreviewOutputSample = {CAMERA_FORMAT_YUV_420_SP, {1920, 1080}};
31 static OH_NativeBuffer_ColorSpace oHNativeBufferColorSpace[15]
32     = {OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE,
33        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL,
34        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL,
35        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL,
36        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL,
37        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL,
38        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL,
39        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL,
40        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT,
41        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT,
42        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT,
43        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT,
44        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT,
45        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT,
46        OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT};
47 
NDKCamera(char * str)48 NDKCamera::NDKCamera(char* str)
49     : cameras_(nullptr), cameraOutputCapability_(nullptr),
50       isAddInput_(false), camera_(nullptr), sceneModes_(nullptr), sceneMode_(NORMAL_PHOTO),
51       secureSeqId_(0), canPreconfig_(false), sceneModesSize_(0), isMovingPhotoSupported_(false), photoNative_(nullptr),
52       mainImage_(nullptr), isTorchSupportedByTorchMode_(false), torchMode_(ON), frameRatesSize_(0),
53       videoFrameRatesSize_(0), colorSpacesSize_(0), colorSpace_(nullptr), activeColorSpace_(OH_COLORSPACE_P3_PQ_LIMIT),
54       setcolorSpace_(OH_COLORSPACE_NONE),
55       frameRateRange_(nullptr), activeFrameRateRange_({0, 0}), videoFrameRateRange_(0),
56       videoActiveFrameRateRange_({0, 0}), isCreatePhotoOutputWithoutSurface_(false),
57       captureSession_(nullptr), size_(0),
58       profile_(nullptr), photoProfile_(nullptr), previewOutput_(nullptr), photoOutput_(nullptr), videoOutput_(nullptr),
59       metaDataObjectType_(nullptr), metadataOutput_(nullptr), cameraInput_(nullptr),
60       isCameraMuted_(nullptr), previewSurfaceId_(str),
61       cameraProfile_(nullptr), videoActiveProfile_(nullptr),
62       ret_(CAMERA_OK)
63 {
64     valid_ = false;
65     Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager_);
66     if (cameraManager_ == nullptr || ret != CAMERA_OK) {
67         LOG("ndkXTS Get CameraManager failed.");
68     }
69     CameraManagerRegisterCallback();
70     valid_ = true;
71 }
72 
~NDKCamera()73 NDKCamera::~NDKCamera() {
74     valid_ = false;
75 
76     Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_);
77     if (ret != CAMERA_OK) {
78         LOG("ndkXTS Release failed.");
79     }
80 
81     if (cameraManager_) {
82         LOG("Release OH_CameraManager_DeleteSupportedCameras. enter");
83         ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_);
84         if (ret != CAMERA_OK) {
85             LOG("Delete Cameras failed.");
86         } else {
87             LOG("Release OH_CameraManager_DeleteSupportedCameras. ok");
88         }
89 
90         ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_);
91         if (ret != CAMERA_OK) {
92             LOG("Delete CameraOutputCapability failed.");
93         } else {
94             LOG("Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok");
95         }
96 
97         ret = OH_Camera_DeleteCameraManager(cameraManager_);
98         if (ret != CAMERA_OK) {
99             LOG("Delete CameraManager failed.");
100         } else {
101             LOG("Release OH_Camera_DeleteCameraManager. ok");
102         }
103         cameraManager_ = nullptr;
104     }
105 
106     PreviewOutputStop();
107     PreviewOutputRelease();
108     PhotoOutputRelease();
109     CameraManagerUnRegisterCallback();
110 }
111 
ReleaseCamera(void)112 Camera_ErrorCode NDKCamera::ReleaseCamera(void)
113 {
114     Camera_ErrorCode ret = CAMERA_OK;
115     if (videoOutput_) {
116         VideoOutputRelease();
117     }
118     if (photoOutput_) {
119         PhotoOutputRelease();
120     }
121     if (previewOutput_) {
122         SessionRemovePreviewOutput();
123         PreviewOutputRelease();
124     }
125     if (cameraInput_) {
126         SessionRemoveInput();
127         CameraInputClose();
128         CameraInputRelease();
129     }
130     if (captureSession_) {
131         SessionRelease();
132     }
133     if (cameraManager_) {
134         CameraManagerUnRegisterCallback();
135         LOG("Release OH_CameraManager_DeleteSupportedCameras. enter");
136         ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_);
137         if (ret != CAMERA_OK) {
138             LOG("Delete Cameras failed.");
139         }
140 
141         ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_);
142         if (ret != CAMERA_OK) {
143             LOG("Delete CameraOutputCapability failed.");
144         }
145 
146         ret = OH_Camera_DeleteCameraManager(cameraManager_);
147         if (ret != CAMERA_OK) {
148             LOG("Delete CameraManager failed.");
149         }
150         cameraManager_ = nullptr;
151     }
152     return ret;
153 }
154 
CreateSession(void)155 Camera_ErrorCode NDKCamera::CreateSession(void)
156 {
157     if (!cameraManager_) {
158           return Camera_ErrorCode::CAMERA_INVALID_ARGUMENT;
159     }
160     Camera_ErrorCode ret =  OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_);
161     if (captureSession_ == nullptr || ret != CAMERA_OK) {
162         LOG("ndkXTS Create captureSession failed.");
163     }
164     CaptureSessionRegisterCallback();
165     return ret;
166 }
167 
HasFlashFn(uint32_t mode)168 Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode)
169 {
170     Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
171     // 检测是否有闪关灯
172     bool hasFlash = false;
173     Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash);
174     if (captureSession_ == nullptr || ret != CAMERA_OK) {
175         LOG("ndkXTS OH_CaptureSession_HasFlash failed.");
176     }
177     if (hasFlash) {
178         LOG("ndkXTS hasFlash success-----");
179     } else {
180         LOG("ndkXTS hasFlash fail-----");
181     }
182 
183     // 检测闪光灯模式是否支持
184     bool isSupported = false;
185     ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported);
186     if (ret != CAMERA_OK) {
187         LOG("ndkXTS OH_CaptureSession_IsFlashModeSupported failed.");
188     }
189     if (isSupported) {
190         LOG("ndkXTS isFlashModeSupported success-----");
191     } else {
192         LOG("ndkXTS isFlashModeSupported fail-----");
193     }
194 
195     // 设置闪光灯模式
196     ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode);
197     if (ret == CAMERA_OK) {
198         LOG("ndkXTS OH_CaptureSession_SetFlashMode success.");
199     } else {
200         LOG("ndkXTS OH_CaptureSession_SetFlashMode failed. %d ", ret);
201     }
202 
203     // 获取当前设备的闪光灯模式
204     ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode);
205     if (ret == CAMERA_OK) {
206         LOG("ndkXTS OH_CaptureSession_GetFlashMode success. flashMode: %d ", flashMode);
207     } else {
208         LOG("ndkXTS OH_CaptureSession_GetFlashMode failed. %d ", ret);
209     }
210     return ret;
211 }
212 
setZoomRatioFn(uint32_t zoomRatio)213 Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio)
214 {
215     float zoom = float(zoomRatio);
216     // 获取支持的变焦范围
217     float minZoom;
218     float maxZoom;
219     Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom);
220     if (captureSession_ == nullptr || ret != CAMERA_OK) {
221         LOG("ndkXTS OH_CaptureSession_GetZoomRatioRange failed.");
222     } else {
223         LOG("ndkXTS OH_CaptureSession_GetZoomRatioRange success. minZoom: %f, maxZoom: %f", minZoom, maxZoom);
224     }
225 
226     // 设置变焦
227     ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom);
228     if (ret == CAMERA_OK) {
229         LOG("ndkXTS OH_CaptureSession_SetZoomRatio success.");
230     } else {
231         LOG("ndkXTS OH_CaptureSession_SetZoomRatio failed. %d ", ret);
232     }
233 
234     // 获取当前设备的变焦值
235     ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom);
236     if (ret == CAMERA_OK) {
237         LOG("ndkXTS OH_CaptureSession_GetZoomRatio success. zoom:%f ", zoom);
238     } else {
239         LOG("ndkXTS OH_CaptureSession_GetZoomRatio failed. %d ", ret);
240     }
241     return ret;
242 }
243 
SessionBegin(void)244 Camera_ErrorCode NDKCamera::SessionBegin(void)
245 {
246     Camera_ErrorCode ret =  OH_CaptureSession_BeginConfig(captureSession_);
247     if (ret == CAMERA_OK) {
248         LOG("ndkXTS OH_CaptureSession_BeginConfig success.");
249     } else {
250         LOG("ndkXTS OH_CaptureSession_BeginConfig failed. %d and captureSession_ addr = %p", ret, captureSession_);
251     }
252     return ret;
253 }
254 
SessionCommitConfig(void)255 Camera_ErrorCode NDKCamera::SessionCommitConfig(void)
256 {
257     Camera_ErrorCode ret =  OH_CaptureSession_CommitConfig(captureSession_);
258     if (ret == CAMERA_OK) {
259         LOG("ndkXTS OH_CaptureSession_CommitConfig success.");
260     } else {
261         LOG("ndkXTS OH_CaptureSession_CommitConfig failed. %d ", ret);
262     }
263     return ret;
264 }
265 
SessionStart(void)266 Camera_ErrorCode NDKCamera::SessionStart(void)
267 {
268     Camera_ErrorCode ret =  OH_CaptureSession_Start(captureSession_);
269     if (ret == CAMERA_OK) {
270         LOG("ndkXTS OH_CaptureSession_Start success.");
271     } else {
272         LOG("ndkXTS OH_CaptureSession_Start failed. %d ", ret);
273     }
274     return ret;
275 }
276 
SessionStop(void)277 Camera_ErrorCode NDKCamera::SessionStop(void)
278 {
279     Camera_ErrorCode ret =  OH_CaptureSession_Stop(captureSession_);
280     if (ret == CAMERA_OK) {
281         LOG("ndkXTS OH_CaptureSession_Stop success.");
282     } else {
283         LOG("ndkXTS OH_CaptureSession_Stop failed. %d ", ret);
284     }
285     return ret;
286 }
287 
CreateCameraInput(void)288 Camera_ErrorCode NDKCamera::CreateCameraInput(void)
289 {
290     LOG("ndkXTS CreateCameraInput start.");
291     if (cameraManager_ == nullptr) {
292         LOG("ndkXTS cameraManager_ is NULL.");
293     } else if (cameras_ == nullptr) {
294         LOG("ndkXTS cameras_ is NULL.");
295     }
296     if (sceneMode_ == SECURE_PHOTO) {
297         ret_ = GetCameraFromCameras(cameras_, &camera_, FRONT_CAMERA);
298         ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, camera_, &cameraInput_);
299     } else {
300         ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, cameras_, &cameraInput_);
301     }
302     if (cameraInput_ == nullptr || ret_ != CAMERA_OK) {
303         LOG("ndkXTS CreateCameraInput failed = %d. cameraInput_ = %p", ret_, cameraInput_);
304         return CAMERA_INVALID_ARGUMENT;
305     }
306     CameraInputRegisterCallback();
307     LOG("ndkXTS CreateCameraInput end.");
308     return ret_;
309 }
310 
CameraInputOpen(void)311 Camera_ErrorCode NDKCamera::CameraInputOpen(void)
312 {
313     ret_ = OH_CameraInput_Open(cameraInput_);
314     if (ret_ != CAMERA_OK) {
315         LOG("ndkXTS CameraInput_Open failed.");
316         return CAMERA_INVALID_ARGUMENT;
317     }
318     return ret_;
319 }
320 
CameraInputClose(void)321 Camera_ErrorCode NDKCamera::CameraInputClose(void)
322 {
323     ret_ = OH_CameraInput_Close(cameraInput_);
324     if (ret_ != CAMERA_OK) {
325         LOG("ndkXTS CameraInput_Close failed.");
326         return CAMERA_INVALID_ARGUMENT;
327     }
328     return ret_;
329 }
330 
CameraInputRelease(void)331 Camera_ErrorCode NDKCamera::CameraInputRelease(void)
332 {
333     ret_ = CameraInputUnRegisterCallback();
334     if (ret_ != CAMERA_OK) {
335         LOG("ndkXTS CameraInputUnRegisterCallback failed.");
336         return CAMERA_INVALID_ARGUMENT;
337     }
338     ret_ = OH_CameraInput_Release(cameraInput_);
339     if (ret_ != CAMERA_OK) {
340         LOG("ndkXTS CameraInput_Release failed.");
341         return CAMERA_INVALID_ARGUMENT;
342     }
343     return ret_;
344 }
345 
GetSupportedCameras(void)346 Camera_ErrorCode NDKCamera::GetSupportedCameras(void)
347 {
348 
349     ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, &size_);
350     if (cameras_ == nullptr || ret_ != CAMERA_OK) {
351         return CAMERA_INVALID_ARGUMENT;
352     }
353     return ret_;
354 }
355 
GetCameraOrientation(void)356 Camera_ErrorCode NDKCamera::GetCameraOrientation(void)
357 {
358     ret_ = OH_CameraDevice_GetCameraOrientation(&cameras_[cameraDeviceIndex_], &orientation_);
359     if (ret_ != CAMERA_OK) {
360         LOG("ndkXTS OH_CameraDevice_GetCameraOrientation failed.");
361         return CAMERA_SERVICE_FATAL_ERROR;
362     }
363     return ret_;
364 }
365 
GetSupportedOutputCapability(void)366 Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void)
367 {
368     if (cameraManager_ == nullptr) {
369         LOG("ndkXTS cameraManager_ is null.");
370     } else if (cameras_ == nullptr) {
371         LOG("ndkXTS cameras_ is null.");
372     }
373     ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, cameras_, &cameraOutputCapability_);
374     if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) {
375         LOG("ndkXTS GetSupportedCameraOutputCapability failed.");
376         return CAMERA_INVALID_ARGUMENT;
377     }
378     return ret_;
379 }
380 
CreatePreviewOutput(void)381 Camera_ErrorCode NDKCamera::CreatePreviewOutput(void)
382 {
383     profile_ = cameraOutputCapability_->previewProfiles[0];
384     if (sceneMode_ == SECURE_PHOTO) {
385         for (decltype(cameraOutputCapability_ -> previewProfilesSize) i = 0;
386              i< cameraOutputCapability_ -> previewProfilesSize; i++) {
387             if (cameraOutputCapability_->previewProfiles[i]->size.width == SecureSize.width &&
388                 cameraOutputCapability_->previewProfiles[i]->size.height == SecureSize.height) {
389                 profile_ = cameraOutputCapability_->previewProfiles[i];
390                 break;
391             }
392         }
393     } else if (isCreatePhotoOutputWithoutSurface_) {
394         for (decltype(cameraOutputCapability_ -> previewProfilesSize) i = 0;
395              i< cameraOutputCapability_ -> previewProfilesSize; i++) {
396             if (cameraOutputCapability_->previewProfiles[i]->size.width == PreviewOutputSample.size.width &&
397                 cameraOutputCapability_->previewProfiles[i]->size.height == PreviewOutputSample.size.height &&
398                 cameraOutputCapability_->previewProfiles[i]->format == PreviewOutputSample.format) {
399                 profile_ = cameraOutputCapability_->previewProfiles[i];
400                 break;
401             }
402         }
403     }
404     if (profile_ == nullptr) {
405         LOG("ndkXTS Get previewProfiles failed.");
406         return CAMERA_INVALID_ARGUMENT;
407     }
408     ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_);
409     if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) {
410         LOG("ndkXTS CreatePreviewOutput failed.");
411         return CAMERA_INVALID_ARGUMENT;
412     }
413     PreviewOutputRegisterCallback();
414     return ret_;
415 }
416 
CreatePhotoOutput(char * photoSurfaceId)417 Camera_ErrorCode NDKCamera::CreatePhotoOutput(char* photoSurfaceId)
418 {
419     LOG("ndkXTS CreatePhotoOutput start.");
420     profile_ = cameraOutputCapability_->photoProfiles[0];
421     LOG("ndkXTS CreatePhotoOutput photoProfiles start.");
422     if (profile_ == nullptr) {
423         LOG("ndkXTS Get photoProfiles failed.");
424         return CAMERA_INVALID_ARGUMENT;
425     }
426 
427     if (photoSurfaceId == nullptr) {
428         LOG("ndkXTS CreatePhotoOutput failed.");
429         return CAMERA_INVALID_ARGUMENT;
430     }
431     LOG("ndkXTS CreatePhotoOutput start.");
432     ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_);
433     PhotoOutputRegisterCallback();
434 
435     return ret_;
436 }
437 
CreateVideoOutput(char * videoId)438 Camera_ErrorCode NDKCamera::CreateVideoOutput(char* videoId)
439 {
440     LOG("ndkXTS CreateVideoOutput start.");
441     videoProfile_ = cameraOutputCapability_->videoProfiles[0];
442     LOG("ndkXTS CreateVideoOutput videoProfiles start.");
443     if (videoProfile_ == nullptr) {
444         LOG("ndkXTS Get videoProfiles failed.");
445         return CAMERA_INVALID_ARGUMENT;
446     }
447     ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_);
448     if (videoId == nullptr || videoOutput_ == nullptr || ret_ != CAMERA_OK) {
449         LOG("ndkXTS CreateVideoOutput failed.");
450         return CAMERA_INVALID_ARGUMENT;
451     }
452 
453     return ret_;
454 }
455 
AddVideoOutput(void)456 Camera_ErrorCode NDKCamera::AddVideoOutput(void)
457 {
458     LOG("ndkXTS AddVideoOutput start.");
459     Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_);
460     if (ret == CAMERA_OK) {
461         LOG("ndkXTS OH_CaptureSession_AddVideoOutput success.");
462     } else {
463         LOG("ndkXTS OH_CaptureSession_AddVideoOutput failed. %d ", ret);
464     }
465     return ret;
466 }
467 
CreateMetadataOutput(void)468 Camera_ErrorCode NDKCamera::CreateMetadataOutput(void)
469 {
470     metaDataObjectType_ = cameraOutputCapability_->supportedMetadataObjectTypes[0];
471 
472     LOG("NDKCamera::CreateMetadataOutput supportedMetadataObjectTypes end.");
473     if (metaDataObjectType_ == nullptr) {
474         LOG("ndkXTS Get metaDataObjectType failed.");
475         return CAMERA_INVALID_ARGUMENT;
476     }
477     ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, &metadataOutput_);
478     if (metadataOutput_ == nullptr || ret_ != CAMERA_OK) {
479         LOG("ndkXTS CreateMetadataOutput failed.");
480         return CAMERA_INVALID_ARGUMENT;
481     }
482     return ret_;
483 }
484 
IsCameraMuted(void)485 Camera_ErrorCode NDKCamera::IsCameraMuted(void)
486 {
487     ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, isCameraMuted_);
488     if (isCameraMuted_ == nullptr || ret_ != CAMERA_OK) {
489         LOG("ndkXTS IsCameraMuted failed.");
490         return CAMERA_INVALID_ARGUMENT;
491     }
492     return ret_;
493 }
494 
PreviewOutputStop(void)495 Camera_ErrorCode NDKCamera::PreviewOutputStop(void)
496 {
497     ret_ = OH_PreviewOutput_Stop(previewOutput_);
498     if (ret_ != CAMERA_OK) {
499         LOG("ndkXTS PreviewOutputStop failed.");
500         return CAMERA_INVALID_ARGUMENT;
501     }
502     return ret_;
503 }
504 
PreviewOutputRelease(void)505 Camera_ErrorCode NDKCamera::PreviewOutputRelease(void)
506 {
507     ret_ = PreviewOutputUnRegisterCallback();
508     if (ret_ != CAMERA_OK) {
509         LOG("ndkXTS PreviewOutputUnRegisterCallback failed.");
510         return CAMERA_INVALID_ARGUMENT;
511     }
512     ret_ = OH_PreviewOutput_Release(previewOutput_);
513     if (ret_ != CAMERA_OK) {
514         LOG("ndkXTS PreviewOutputRelease failed.");
515         return CAMERA_INVALID_ARGUMENT;
516     }
517     return ret_;
518 }
519 
PhotoOutputRelease(void)520 Camera_ErrorCode NDKCamera::PhotoOutputRelease(void)
521 {
522     ret_ = PhotoOutputUnRegisterCallback();
523     if (ret_ != CAMERA_OK) {
524         LOG("ndkXTS PhotoOutputUnRegisterCallback failed.");
525         return CAMERA_INVALID_ARGUMENT;
526     }
527     ret_ = OH_PhotoOutput_Release(photoOutput_);
528     if (ret_ != CAMERA_OK) {
529         LOG("ndkXTS PhotoOutputRelease failed.");
530         return CAMERA_INVALID_ARGUMENT;
531     }
532     return ret_;
533 }
534 
StartVideo(char * videoId)535 Camera_ErrorCode NDKCamera::StartVideo(char* videoId)
536 {
537     LOG("ndkXTS startVideo begin.");
538     Camera_ErrorCode ret = SessionStop();
539     if (ret == CAMERA_OK) {
540         LOG("ndkXTS SessionStop success.");
541     } else {
542         LOG("ndkXTS SessionStop failed. %d ", ret);
543     }
544     ret = SessionBegin();
545     if (ret == CAMERA_OK) {
546         LOG("ndkXTS SessionBegin success.");
547     } else {
548         LOG("ndkXTS SessionBegin failed. %d ", ret);
549     }
550     CreateVideoOutput(videoId);
551     AddVideoOutput();
552     SessionCommitConfig();
553     SessionStart();
554     return ret;
555 }
556 
VideoOutputStart(void)557 Camera_ErrorCode NDKCamera::VideoOutputStart(void)
558 {
559     LOG("ndkXTS VideoOutputStart begin.");
560     Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_);
561     if (ret == CAMERA_OK) {
562         LOG("ndkXTS OH_VideoOutput_Start success.");
563     } else {
564         LOG("ndkXTS OH_VideoOutput_Start failed. %d ", ret);
565     }
566     VideoOutputRegisterCallback();
567     return ret;
568 }
569 
PreviewOutputStart(void)570 Camera_ErrorCode NDKCamera::PreviewOutputStart(void)
571 {
572     LOG("ndkXTS PreviewOutputStart begin.");
573     Camera_ErrorCode ret = OH_PreviewOutput_Start(previewOutput_);
574     if (ret == CAMERA_OK) {
575         LOG("ndkXTS OH_PreviewOutput_Start success.");
576     } else {
577         LOG("ndkXTS OH_PreviewOutput_Start failed. %d ", ret);
578     }
579     return ret;
580 }
581 
PhotoOutputCapture(void)582 Camera_ErrorCode NDKCamera::PhotoOutputCapture(void)
583 {
584     LOG("ndkXTS Capture begin.");
585     Camera_ErrorCode ret = OH_PhotoOutput_Capture(photoOutput_);
586     if (ret == CAMERA_OK) {
587         LOG("ndkXTS OH_PhotoOutput_Capture success.");
588     } else {
589         LOG("ndkXTS OH_PhotoOutput_Capture failed. %d ", ret);
590     }
591     return ret;
592 }
593 
TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting)594 Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting)
595 {
596     Camera_ErrorCode ret = CAMERA_OK;
597     ret = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photoSetting);
598 
599     LOG("ndkXTS takePicture TakePictureWithPhotoSettings ret = %d.", ret);
600     if (ret != CAMERA_OK) {
601         LOG("ndkXTS startPhoto failed.");
602         return CAMERA_INVALID_ARGUMENT;
603     }
604     return ret;
605 }
606 
IsMirrorSupported(void)607 Camera_ErrorCode NDKCamera::IsMirrorSupported(void)
608 {
609     LOG("ndkXTS IsMirrorSupported begin.");
610     Camera_ErrorCode ret = OH_PhotoOutput_IsMirrorSupported(photoOutput_, &IsMirror_);
611     if (ret == CAMERA_OK) {
612         LOG("ndkXTS OH_PhotoOutput_IsMirrorSupported success.");
613     } else {
614         LOG("ndkXTS OH_PhotoOutput_IsMirrorSupported failed. %d ", ret);
615     }
616     return ret;
617 }
618 
VideoOutputStop(void)619 Camera_ErrorCode NDKCamera::VideoOutputStop(void)
620 {
621     LOG("ndkXTS VideoOutputStop begin.");
622     Camera_ErrorCode ret = OH_VideoOutput_Stop(videoOutput_);
623     if (ret == CAMERA_OK) {
624         LOG("ndkXTS OH_VideoOutput_Stop success.");
625     } else {
626         LOG("ndkXTS OH_VideoOutput_Stop failed. %d ", ret);
627     }
628     return ret;
629 }
630 
VideoOutputRelease(void)631 Camera_ErrorCode NDKCamera::VideoOutputRelease(void)
632 {
633     LOG("ndkXTS VideoOutputRelease begin.");
634     ret_ = VideoOutputUnRegisterCallback();
635     if (ret_ != CAMERA_OK) {
636         LOG("ndkXTS VideoOutputUnRegisterCallback failed.");
637         return CAMERA_INVALID_ARGUMENT;
638     }
639     Camera_ErrorCode ret = OH_VideoOutput_Release(videoOutput_);
640     if (ret == CAMERA_OK) {
641         LOG("ndkXTS OH_VideoOutput_Release success.");
642     } else {
643         LOG("ndkXTS OH_VideoOutput_Release failed. %d ", ret);
644     }
645     return ret;
646 }
647 
MetadataOutputStart(void)648 Camera_ErrorCode NDKCamera::MetadataOutputStart(void)
649 {
650     LOG("ndkXTS MetadataOutputStart begin.");
651     Camera_ErrorCode ret = OH_MetadataOutput_Start(metadataOutput_);
652     if (ret == CAMERA_OK) {
653         LOG("ndkXTS OH_MetadataOutput_Start success.");
654     } else {
655         LOG("ndkXTS OH_MetadataOutput_Start failed. %d ", ret);
656     }
657     ret = MetadataOutputRegisterCallback();
658     if (ret != CAMERA_OK) {
659         LOG("ndkXTS MetadataOutputUnRegisterCallback failed.");
660         return CAMERA_INVALID_ARGUMENT;
661     }
662     return ret;
663 }
664 
MetadataOutputStop(void)665 Camera_ErrorCode NDKCamera::MetadataOutputStop(void)
666 {
667     LOG("ndkXTS MetadataOutputStop begin.");
668     Camera_ErrorCode ret = OH_MetadataOutput_Stop(metadataOutput_);
669     if (ret == CAMERA_OK) {
670         LOG("ndkXTS OH_MetadataOutput_Stop success.");
671     } else {
672         LOG("ndkXTS OH_MetadataOutput_Stop failed. %d ", ret);
673     }
674     ret = MetadataOutputUnRegisterCallback();
675     if (ret != CAMERA_OK) {
676         LOG("ndkXTS MetadataOutputUnRegisterCallback failed.");
677         return CAMERA_INVALID_ARGUMENT;
678     }
679     return ret;
680 }
681 
MetadataOutputRelease(void)682 Camera_ErrorCode NDKCamera::MetadataOutputRelease(void)
683 {
684     LOG("ndkXTS MetadataOutputRelease begin.");
685     Camera_ErrorCode ret = OH_MetadataOutput_Release(metadataOutput_);
686     if (ret == CAMERA_OK) {
687         LOG("ndkXTS OH_MetadataOutput_Release success.");
688     } else {
689         LOG("ndkXTS OH_MetadataOutput_Release failed. %d ", ret);
690     }
691     return ret;
692 }
693 
SessionAddInput(void)694 Camera_ErrorCode NDKCamera::SessionAddInput(void)
695 {
696     LOG("ndkXTS CaptureSessionAddInput begin.");
697     Camera_ErrorCode ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_);
698     if (ret == CAMERA_OK) {
699         LOG("ndkXTS OH_CaptureSession_AddInput success.");
700     } else {
701         LOG("ndkXTS OH_CaptureSession_AddInput failed. %d ", ret);
702     }
703     return ret;
704 }
705 
SessionRemoveInput(void)706 Camera_ErrorCode NDKCamera::SessionRemoveInput(void)
707 {
708     LOG("ndkXTS CaptureSessionRemoveInput begin.");
709     Camera_ErrorCode ret = OH_CaptureSession_RemoveInput(captureSession_, cameraInput_);
710     if (ret == CAMERA_OK) {
711         LOG("ndkXTS OH_CaptureSession_RemoveInput success.");
712     } else {
713         LOG("ndkXTS OH_CaptureSession_RemoveInput failed. %d ", ret);
714     }
715     return ret;
716 }
717 
SessionAddPreviewOutput(void)718 Camera_ErrorCode NDKCamera::SessionAddPreviewOutput(void)
719 {
720     LOG("ndkXTS CaptureSessionAddPreviewOutput begin.");
721     Camera_ErrorCode ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_);
722     if (ret == CAMERA_OK) {
723         LOG("ndkXTS OH_CaptureSession_AddPreviewOutput success.");
724     } else {
725         LOG("ndkXTS OH_CaptureSession_AddPreviewOutput failed. %d ", ret);
726     }
727     return ret;
728 }
729 
SessionAddPhotoOutput(void)730 Camera_ErrorCode NDKCamera::SessionAddPhotoOutput(void)
731 {
732     LOG("ndkXTS CaptureSessionAddPhotoOutput begin.");
733     Camera_ErrorCode ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_);
734     if (ret == CAMERA_OK) {
735         LOG("ndkXTS OH_CaptureSession_AddPhotoOutput success.");
736     } else {
737         LOG("ndkXTS OH_CaptureSession_AddPhotoOutput failed. %d ", ret);
738     }
739     return ret;
740 }
741 
SessionAddVideoOutput(void)742 Camera_ErrorCode NDKCamera::SessionAddVideoOutput(void)
743 {
744     LOG("ndkXTS CaptureSessionAddVideoOutput begin.");
745     Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_);
746     if (ret == CAMERA_OK) {
747         LOG("ndkXTS OH_CaptureSession_AddVideoOutput success.");
748     } else {
749         LOG("ndkXTS OH_CaptureSession_AddVideoOutput failed. %d ", ret);
750     }
751     return ret;
752 }
753 
SessionAddMetadataOutput(void)754 Camera_ErrorCode NDKCamera::SessionAddMetadataOutput(void)
755 {
756     LOG("ndkXTS CaptureSessionAddMetadataOutput begin.");
757     Camera_ErrorCode ret = OH_CaptureSession_AddMetadataOutput(captureSession_, metadataOutput_);
758     if (ret == CAMERA_OK) {
759         LOG("ndkXTS OH_CaptureSession_AddMetadataOutput success.");
760     } else {
761         LOG("ndkXTS OH_CaptureSession_AddMetadataOutput failed. %d ", ret);
762     }
763     return ret;
764 }
765 
SessionRemovePreviewOutput(void)766 Camera_ErrorCode NDKCamera::SessionRemovePreviewOutput(void)
767 {
768     LOG("RemovePreviewOutput begin.");
769     Camera_ErrorCode ret = OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_);
770     if (ret == CAMERA_OK) {
771         LOG("OH_CaptureSession_RemovePreviewOutput success.");
772     } else {
773         LOG("OH_CaptureSession_RemovePreviewOutput failed. %d ", ret);
774     }
775     return ret;
776 }
777 
SessionRemovePhotoOutput(void)778 Camera_ErrorCode NDKCamera::SessionRemovePhotoOutput(void)
779 {
780     LOG("RemovePhotoOutput begin.");
781     Camera_ErrorCode ret = OH_CaptureSession_RemovePhotoOutput(captureSession_, photoOutput_);
782     if (ret == CAMERA_OK) {
783         LOG("OH_CaptureSession_RemovePhotoOutput success.");
784     } else {
785         LOG("OH_CaptureSession_RemovePhotoOutput failed. %d ", ret);
786     }
787     return ret;
788 }
789 
SessionRemoveVideoOutput(void)790 Camera_ErrorCode NDKCamera::SessionRemoveVideoOutput(void)
791 {
792     LOG("RemoveVideoOutput begin.");
793     Camera_ErrorCode ret = OH_CaptureSession_RemoveVideoOutput(captureSession_, videoOutput_);
794     if (ret == CAMERA_OK) {
795         LOG("OH_CaptureSession_RemoveVideoOutput success.");
796     } else {
797         LOG("OH_CaptureSession_RemoveVideoOutput failed. %d ", ret);
798     }
799     return ret;
800 }
801 
SessionRemoveMetadataOutput(void)802 Camera_ErrorCode NDKCamera::SessionRemoveMetadataOutput(void)
803 {
804     LOG("RemoveMetadataOutput begin.");
805     Camera_ErrorCode ret = OH_CaptureSession_RemoveMetadataOutput(captureSession_, metadataOutput_);
806     if (ret == CAMERA_OK) {
807         LOG("OH_CaptureSession_RemoveMetadataOutput success.");
808     } else {
809         LOG("OH_CaptureSession_RemoveMetadataOutput failed. %d ", ret);
810     }
811     return ret;
812 }
813 
SessionRelease(void)814 Camera_ErrorCode NDKCamera::SessionRelease(void)
815 {
816     LOG("SessionRelease begin.");
817     ret_ = CaptureSessionUnRegisterCallback();
818     if (ret_ != CAMERA_OK) {
819         LOG("ndkXTS CaptureSessionUnRegisterCallback failed.");
820         return CAMERA_INVALID_ARGUMENT;
821     }
822     Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_);
823     if (ret == CAMERA_OK) {
824         LOG("OH_CaptureSession_Release success.");
825     } else {
826         LOG("OH_CaptureSession_Release failed. %d ", ret);
827     }
828     return ret;
829 }
830 
SessionHasFlash(void)831 Camera_ErrorCode NDKCamera::SessionHasFlash(void)
832 {
833     LOG("HasFlash begin.");
834     Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &HasFlash_);
835     if (ret == CAMERA_OK) {
836         LOG("OH_CaptureSession_HasFlash success.");
837     } else {
838         LOG("OH_CaptureSession_HasFlash failed. %d ", ret);
839     }
840     return ret;
841 }
842 
SessionIsFlashModeSupported(uint32_t mode)843 Camera_ErrorCode NDKCamera::SessionIsFlashModeSupported(uint32_t mode)
844 {
845     LOG("HasFlash begin.");
846     Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
847     Camera_ErrorCode ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &IsFlashMode_);
848     if (ret == CAMERA_OK) {
849         LOG("OH_CaptureSession_HasFlash success.");
850     } else {
851         LOG("OH_CaptureSession_HasFlash failed. %d ", ret);
852     }
853     return ret;
854 }
855 
SessionGetFlashMode(void)856 Camera_ErrorCode NDKCamera::SessionGetFlashMode(void)
857 {
858     LOG("GetFlashMode begin.");
859     Camera_ErrorCode ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode_);
860     if (ret == CAMERA_OK) {
861         LOG("OH_CaptureSession_GetFlashMode success.");
862     } else {
863         LOG("OH_CaptureSession_GetFlashMode failed. %d ", ret);
864     }
865     return ret;
866 }
867 
SessionSetFlashMode(uint32_t mode)868 Camera_ErrorCode NDKCamera::SessionSetFlashMode(uint32_t mode)
869 {
870     LOG("SetFlashMode begin.");
871     Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
872     Camera_ErrorCode ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode);
873     if (ret == CAMERA_OK) {
874         LOG("OH_CaptureSession_SetFlashMode success.");
875     } else {
876         LOG("OH_CaptureSession_SetFlashMode failed. %d ", ret);
877     }
878     return ret;
879 }
880 
SessionGetPhotoRotation(int rotation)881 Camera_ErrorCode NDKCamera::SessionGetPhotoRotation(int rotation)
882 {
883     LOG("GetVideoRotation begin.");
884     int32_t testRotation = static_cast<int32_t>(rotation);
885     Camera_ErrorCode ret = OH_PhotoOutput_GetPhotoRotation(photoOutput_, testRotation, &imageRotation_);
886     if (ret == CAMERA_OK) {
887         LOG("OH_PhotoOutput_GetPhotoRotation success.");
888     } else {
889         LOG("OH_PhotoOutput_GetPhotoRotation failed. %d ", ret);
890     }
891     return ret;
892 }
893 
SessionGetVideoRotation(int rotation)894 Camera_ErrorCode NDKCamera::SessionGetVideoRotation(int rotation)
895 {
896     LOG("GetVideoRotation begin.");
897     int32_t testRotation = static_cast<int32_t>(rotation);
898     Camera_ErrorCode ret = OH_VideoOutput_GetVideoRotation(videoOutput_, testRotation, &imageRotation_);
899     if (ret == CAMERA_OK) {
900         LOG("OH_VideoOutput_GetVideoRotation success.");
901     } else {
902         LOG("OH_VideoOutput_GetVideoRotation failed. %d ", ret);
903     }
904     return ret;
905 }
906 
SessionGetPreviewRotation(int rotation)907 Camera_ErrorCode NDKCamera::SessionGetPreviewRotation(int rotation)
908 {
909     LOG("GetPreviewRotation begin.");
910     int32_t testRotation = static_cast<int32_t>(rotation);
911     Camera_ErrorCode ret = OH_PreviewOutput_GetPreviewRotation(previewOutput_, testRotation, &imageRotation_);
912     if (ret == CAMERA_OK) {
913         LOG("OH_PreviewOutput_GetPreviewRotation success.");
914     } else {
915         LOG("OH_PreviewOutput_GetPreviewRotation failed. %d ", ret);
916     }
917     return ret;
918 }
919 
SessionSetPreviewRotation(int rotation,bool isDisplayLocked)920 Camera_ErrorCode NDKCamera::SessionSetPreviewRotation(int rotation, bool isDisplayLocked)
921 {
922     LOG("SetPreviewRotation begin.");
923     Camera_ImageRotation testRotation = static_cast<Camera_ImageRotation>(rotation);
924     Camera_ErrorCode ret = OH_PreviewOutput_SetPreviewRotation(previewOutput_, testRotation, isDisplayLocked);
925     if (ret == CAMERA_OK) {
926         LOG("SessionSetPreviewRotation success.");
927     } else {
928         LOG("SessionSetPreviewRotation failed. %d ", ret);
929     }
930     return ret;
931 }
SessionIsExposureModeSupported(uint32_t mode)932 Camera_ErrorCode NDKCamera::SessionIsExposureModeSupported(uint32_t mode)
933 {
934     LOG("SetFlashMode begin.");
935     Camera_ExposureMode exposureMode = static_cast<Camera_ExposureMode>(mode);
936     Camera_ErrorCode ret = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode, &IsExposureMode_);
937     if (ret == CAMERA_OK) {
938         LOG("OH_CaptureSession_SetFlashMode success.");
939     } else {
940         LOG("OH_CaptureSession_SetFlashMode failed. %d ", ret);
941     }
942     return ret;
943 }
944 
SessionGetExposureMode(void)945 Camera_ErrorCode NDKCamera::SessionGetExposureMode(void)
946 {
947     LOG("GetExposureMode begin.");
948     Camera_ErrorCode ret = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_);
949     if (ret == CAMERA_OK) {
950         LOG("OH_CaptureSession_GetExposureMode success.");
951     } else {
952         LOG("OH_CaptureSession_GetExposureMode failed. %d ", ret);
953     }
954     return ret;
955 }
956 
SessionSetExposureMode(uint32_t mode)957 Camera_ErrorCode NDKCamera::SessionSetExposureMode(uint32_t mode)
958 {
959     LOG("SetExposureMode begin.");
960     Camera_ExposureMode exposureMode = static_cast<Camera_ExposureMode>(mode);
961     Camera_ErrorCode ret = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode);
962     if (ret == CAMERA_OK) {
963         LOG("OH_CaptureSession_SetExposureMode success.");
964     } else {
965         LOG("OH_CaptureSession_SetExposureMode failed. %d ", ret);
966     }
967     return ret;
968 }
969 
SessionGetMeteringPoint(void)970 Camera_ErrorCode NDKCamera::SessionGetMeteringPoint(void)
971 {
972     LOG("OH_CaptureSession_GetMeteringPoint begin.");
973     Camera_ErrorCode ret = OH_CaptureSession_GetMeteringPoint(captureSession_, &point_);
974     if (ret == CAMERA_OK) {
975         LOG("OH_CaptureSession_GetMeteringPoint success [%f, %f].", point_.x, point_.y);
976     } else {
977         LOG("OH_CaptureSession_GetMeteringPoint failed. %d ", ret);
978     }
979     return ret;
980 }
981 
SessionSetMeteringPoint(double point_x,double point_y)982 Camera_ErrorCode NDKCamera::SessionSetMeteringPoint(double point_x, double point_y)
983 {
984     LOG("SetMeteringPoint begin.");
985     Camera_Point point;
986     point.x = point_x;
987     point.y = point_y;
988     LOG("SetMeteringPoint begin. [%f, %f]", point_x, point_y);
989     Camera_ErrorCode ret = OH_CaptureSession_SetMeteringPoint(captureSession_, point);
990     if (ret == CAMERA_OK) {
991         LOG("OH_CaptureSession_SetMeteringPoint success.");
992     } else {
993         LOG("OH_CaptureSession_SetMeteringPoint failed. %d ", ret);
994     }
995     return ret;
996 }
997 
SessionGetExposureBiasRange(void)998 Camera_ErrorCode NDKCamera::SessionGetExposureBiasRange(void)
999 {
1000     LOG("GetExposureBiasRange begin.");
1001     Camera_ErrorCode ret = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_);
1002     if (ret == CAMERA_OK) {
1003         LOG("OH_CaptureSession_GetExposureBiasRange success[%f, %f].", minExposureBias_, maxExposureBias_);
1004     } else {
1005         LOG("OH_CaptureSession_GetExposureBiasRange failed. %d ", ret);
1006     }
1007     return ret;
1008 }
1009 
SessionSetExposureBias(float exposureBias)1010 Camera_ErrorCode NDKCamera::SessionSetExposureBias(float exposureBias)
1011 {
1012     LOG("SetExposureBias begin.");
1013     Camera_ErrorCode ret = OH_CaptureSession_SetExposureBias(captureSession_, exposureBias);
1014     if (ret == CAMERA_OK) {
1015         LOG("OH_CaptureSession_SetExposureBias success.");
1016     } else {
1017         LOG("OH_CaptureSession_SetExposureBias failed. %d ", ret);
1018     }
1019     return ret;
1020 }
1021 
SessionGetExposureBias(void)1022 Camera_ErrorCode NDKCamera::SessionGetExposureBias(void)
1023 {
1024     LOG("GetExposureBias begin.");
1025     Camera_ErrorCode ret = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBias_);
1026     if (ret == CAMERA_OK) {
1027         LOG("OH_CaptureSession_GetExposureBias success.");
1028     } else {
1029         LOG("OH_CaptureSession_GetExposureBias failed. %d ", ret);
1030     }
1031     return ret;
1032 }
1033 
SessionIsFocusModeSupported(uint32_t mode)1034 Camera_ErrorCode NDKCamera::SessionIsFocusModeSupported(uint32_t mode)
1035 {
1036     LOG("isFocusModeSupported begin.");
1037     Camera_FocusMode focusMode = static_cast<Camera_FocusMode>(mode);
1038     Camera_ErrorCode ret = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusSupported_);
1039     if (ret == CAMERA_OK) {
1040         LOG("OH_CaptureSession_isFocusModeSupported success.");
1041     } else {
1042         LOG("OH_CaptureSession_isFocusModeSupported failed. %d ", ret);
1043     }
1044     return ret;
1045 }
1046 
SessionGetFocusMode(void)1047 Camera_ErrorCode NDKCamera::SessionGetFocusMode(void)
1048 {
1049     LOG("GetFocusMode begin.");
1050     Camera_ErrorCode ret = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode_);
1051     if (ret == CAMERA_OK) {
1052         LOG("OH_CaptureSession_GetFocusMode success.");
1053     } else {
1054         LOG("OH_CaptureSession_GetFocusMode failed. %d ", ret);
1055     }
1056     return ret;
1057 }
1058 
SessionSetFocusMode(uint32_t mode)1059 Camera_ErrorCode NDKCamera::SessionSetFocusMode(uint32_t mode)
1060 {
1061     LOG("SetFocusMode begin.");
1062     Camera_FocusMode focusMode = static_cast<Camera_FocusMode>(mode);
1063     Camera_ErrorCode ret = OH_CaptureSession_SetFocusMode(captureSession_, focusMode);
1064     if (ret == CAMERA_OK) {
1065         LOG("OH_CaptureSession_SetFocusMode success.");
1066     } else {
1067         LOG("OH_CaptureSession_SetFocusMode failed. %d ", ret);
1068     }
1069     return ret;
1070 }
1071 
SessionSetFocusPoint(double point_x,double point_y)1072 Camera_ErrorCode NDKCamera::SessionSetFocusPoint(double point_x, double point_y)
1073 {
1074     LOG("SetFocusPoint begin.");
1075     Camera_Point point;
1076     point.x = point_x;
1077     point.y = point_y;
1078     Camera_ErrorCode ret = OH_CaptureSession_SetFocusPoint(captureSession_, point);
1079     if (ret == CAMERA_OK) {
1080         LOG("OH_CaptureSession_SetFocusPoint success.");
1081     } else {
1082         LOG("OH_CaptureSession_SetFocusPoint failed. %d ", ret);
1083     }
1084     return ret;
1085 }
1086 
SessionGetFocusPoint(void)1087 Camera_ErrorCode NDKCamera::SessionGetFocusPoint(void)
1088 {
1089     LOG("GetFocusMode begin.");
1090     Camera_ErrorCode ret = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint_);
1091     if (ret == CAMERA_OK) {
1092         LOG("OH_CaptureSession_GetFocusMode success.");
1093     } else {
1094         LOG("OH_CaptureSession_GetFocusMode failed. %d ", ret);
1095     }
1096     return ret;
1097 }
1098 
SessionGetZoomRatioRange(void)1099 Camera_ErrorCode NDKCamera::SessionGetZoomRatioRange(void)
1100 {
1101     LOG("GetZoomRatioRange begin.");
1102     Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom_, &maxZoom_);
1103     if (ret == CAMERA_OK) {
1104         LOG("OH_CaptureSession_GetZoomRatioRange success.");
1105     } else {
1106         LOG("OH_CaptureSession_GetZoomRatioRange failed. %d ", ret);
1107     }
1108     return ret;
1109 }
1110 
SessionGetZoomRatio(void)1111 Camera_ErrorCode NDKCamera::SessionGetZoomRatio(void)
1112 {
1113     LOG("GetZoomRatio begin.");
1114     Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom_);
1115     if (ret == CAMERA_OK) {
1116         LOG("OH_CaptureSession_GetZoomRatio success.");
1117     } else {
1118         LOG("OH_CaptureSession_GetZoomRatio failed. %d ", ret);
1119     }
1120     return ret;
1121 }
1122 
SessionSetZoomRatio(float zoom)1123 Camera_ErrorCode NDKCamera::SessionSetZoomRatio(float zoom)
1124 {
1125     LOG("SetZoomRatio begin.");
1126     Camera_ErrorCode ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom);
1127     if (ret == CAMERA_OK) {
1128         LOG("OH_CaptureSession_SetZoomRatio success.");
1129     } else {
1130         LOG("OH_CaptureSession_SetZoomRatio failed. %d ", ret);
1131     }
1132     return ret;
1133 }
1134 
SessionIsVideoStabilizationModeSupported(uint32_t mode)1135 Camera_ErrorCode NDKCamera::SessionIsVideoStabilizationModeSupported(uint32_t mode)
1136 {
1137     LOG("isVideoStabilizationModeSupported begin.");
1138     Camera_VideoStabilizationMode videoMode = static_cast<Camera_VideoStabilizationMode>(mode);
1139     LOG("OH_CaptureSession_IsVideoStabilizationModeSupported begin.");
1140     Camera_ErrorCode ret = OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isVideoSupported_);
1141     if (ret == CAMERA_OK) {
1142         LOG("OH_CaptureSession_isVideoStabilizationModeSupported success.");
1143     } else {
1144         LOG("OH_CaptureSession_isVideoStabilizationModeSupported failed. %d ", ret);
1145     }
1146     return ret;
1147 }
1148 
SessionGetVideoStabilizationMode(void)1149 Camera_ErrorCode NDKCamera::SessionGetVideoStabilizationMode(void)
1150 {
1151     LOG("GetVideoStabilizationMode begin.");
1152     Camera_ErrorCode ret = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode_);
1153     if (ret == CAMERA_OK) {
1154         LOG("OH_CaptureSession_GetVideoStabilizationMode success = %d.", videoMode_);
1155     } else {
1156         LOG("OH_CaptureSession_GetVideoStabilizationMode failed. %d ", ret);
1157     }
1158     return ret;
1159 }
1160 
SessionSetVideoStabilizationMode(uint32_t mode)1161 Camera_ErrorCode NDKCamera::SessionSetVideoStabilizationMode(uint32_t mode)
1162 {
1163     LOG("SetVideoStabilizationMode begin.");
1164     Camera_VideoStabilizationMode videoMode = static_cast<Camera_VideoStabilizationMode>(mode);
1165     Camera_ErrorCode ret = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode);
1166     if (ret == CAMERA_OK) {
1167         LOG("OH_CaptureSession_SetVideoStabilizationMode success.");
1168     } else {
1169         LOG("OH_CaptureSession_SetVideoStabilizationMode failed. %d ", ret);
1170     }
1171     return ret;
1172 }
1173 
1174 // CameraManager Callback
CameraManagerStatusCallback(Camera_Manager * cameraManager,Camera_StatusInfo * status)1175 void CameraManagerStatusCallback(Camera_Manager* cameraManager, Camera_StatusInfo* status)
1176 {
1177     NDKCamera::cameraCallbackCode_ = CameraManager_Status;
1178     LOG("CameraManagerStatusCallback");
1179 }
1180 
GetCameraManagerListener(void)1181 CameraManager_Callbacks* NDKCamera::GetCameraManagerListener(void)
1182 {
1183     static CameraManager_Callbacks cameraManagerListener = {
1184         .onCameraStatus = CameraManagerStatusCallback
1185     };
1186     return &cameraManagerListener;
1187 }
1188 
CameraManagerRegisterCallback(void)1189 Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void)
1190 {
1191     ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener());
1192     if (ret_ != CAMERA_OK) {
1193         LOG("OH_CameraManager_RegisterCallback failed.");
1194     }
1195     return ret_;
1196 }
1197 
CameraManagerUnRegisterCallback(void)1198 Camera_ErrorCode NDKCamera::CameraManagerUnRegisterCallback(void)
1199 {
1200     ret_ = OH_CameraManager_UnregisterCallback(cameraManager_, GetCameraManagerListener());
1201     if (ret_ != CAMERA_OK) {
1202         LOG("OH_CameraManager_UnregisterCallback failed.");
1203     }
1204     return ret_;
1205 }
1206 
1207 // CameraInput Callback
OnCameraInputError(const Camera_Input * cameraInput,Camera_ErrorCode errorCode)1208 void OnCameraInputError(const Camera_Input* cameraInput, Camera_ErrorCode errorCode)
1209 {
1210     NDKCamera::cameraCallbackCode_ = CameraInput_Status;
1211     LOG("OnCameraInput errorCode = %d", errorCode);
1212 }
1213 
GetCameraInputListener(void)1214 CameraInput_Callbacks* NDKCamera::GetCameraInputListener(void)
1215 {
1216     static CameraInput_Callbacks cameraInputCallbacks = {
1217         .onError = OnCameraInputError
1218     };
1219     return &cameraInputCallbacks;
1220 }
1221 
CameraInputRegisterCallback(void)1222 Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void)
1223 {
1224     ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener());
1225     if (ret_ != CAMERA_OK) {
1226         LOG("OH_CameraInput_RegisterCallback failed.");
1227     }
1228     return ret_;
1229 }
1230 
CameraInputUnRegisterCallback(void)1231 Camera_ErrorCode NDKCamera::CameraInputUnRegisterCallback(void)
1232 {
1233     ret_ = OH_CameraInput_UnregisterCallback(cameraInput_, GetCameraInputListener());
1234     if (ret_ != CAMERA_OK) {
1235         LOG("OH_CameraInput_UnregisterCallback failed.");
1236     }
1237     return ret_;
1238 }
1239 
1240 // PreviewOutput Callback
PreviewOutputOnFrameStart(Camera_PreviewOutput * previewOutput)1241 void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput)
1242 {
1243     NDKCamera::cameraCallbackCode_ = Preview_OnFrameStart;
1244     LOG("PreviewOutputOnFrameStart");
1245 }
1246 
PreviewOutputOnFrameEnd(Camera_PreviewOutput * previewOutput,int32_t frameCount)1247 void PreviewOutputOnFrameEnd(Camera_PreviewOutput* previewOutput, int32_t frameCount)
1248 {
1249     NDKCamera::cameraCallbackCode_ = Preview_OnFrameEnd;
1250     LOG("PreviewOutput frameCount = %d", frameCount);
1251 }
1252 
PreviewOutputOnError(Camera_PreviewOutput * previewOutput,Camera_ErrorCode errorCode)1253 void PreviewOutputOnError(Camera_PreviewOutput* previewOutput, Camera_ErrorCode errorCode)
1254 {
1255     NDKCamera::cameraCallbackCode_ = Preview_OnError;
1256     LOG("PreviewOutput errorCode = %d", errorCode);
1257 }
1258 
GetPreviewOutputListener(void)1259 PreviewOutput_Callbacks* NDKCamera::GetPreviewOutputListener(void)
1260 {
1261     static PreviewOutput_Callbacks previewOutputListener = {
1262         .onFrameStart = PreviewOutputOnFrameStart,
1263         .onFrameEnd = PreviewOutputOnFrameEnd,
1264         .onError = PreviewOutputOnError
1265     };
1266     return &previewOutputListener;
1267 }
1268 
PreviewOutputRegisterCallback(void)1269 Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void)
1270 {
1271     ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener());
1272     if (ret_ != CAMERA_OK) {
1273         LOG("OH_PreviewOutput_RegisterCallback failed.");
1274     }
1275     return ret_;
1276 }
1277 
PreviewOutputUnRegisterCallback(void)1278 Camera_ErrorCode NDKCamera::PreviewOutputUnRegisterCallback(void)
1279 {
1280     ret_ = OH_PreviewOutput_UnregisterCallback(previewOutput_, GetPreviewOutputListener());
1281     if (ret_ != CAMERA_OK) {
1282         LOG("OH_PreviewOutput_UnregisterCallback failed.");
1283     }
1284     return ret_;
1285 }
1286 
1287 // PhotoOutput Callback
PhotoOutputOnFrameStart(Camera_PhotoOutput * photoOutput)1288 void PhotoOutputOnFrameStart(Camera_PhotoOutput* photoOutput)
1289 {
1290     NDKCamera::cameraCallbackCode_ = Photo_OnFrameStart;
1291     LOG("PhotoOutputOnFrameStart");
1292 }
1293 
PhotoOutputOnFrameShutter(Camera_PhotoOutput * photoOutput,Camera_FrameShutterInfo * info)1294 void PhotoOutputOnFrameShutter(Camera_PhotoOutput* photoOutput, Camera_FrameShutterInfo* info)
1295 {
1296     NDKCamera::cameraCallbackCode_ = Photo_OnFrameShutter;
1297     LOG("PhotoOutputOnFrameShutter");
1298 }
1299 
PhotoOutputOnFrameEnd(Camera_PhotoOutput * photoOutput,int32_t frameCount)1300 void PhotoOutputOnFrameEnd(Camera_PhotoOutput* photoOutput, int32_t frameCount)
1301 {
1302     NDKCamera::cameraCallbackCode_ = Photo_OnFrameEnd;
1303     LOG("PhotoOutput frameCount = %d", frameCount);
1304 }
1305 
PhotoOutputOnError(Camera_PhotoOutput * photoOutput,Camera_ErrorCode errorCode)1306 void PhotoOutputOnError(Camera_PhotoOutput* photoOutput, Camera_ErrorCode errorCode)
1307 {
1308     NDKCamera::cameraCallbackCode_ = Photo_OnError;
1309     LOG("PhotoOutput errorCode = %d", errorCode);
1310 }
1311 
GetPhotoOutputListener(void)1312 PhotoOutput_Callbacks* NDKCamera::GetPhotoOutputListener(void)
1313 {
1314     static PhotoOutput_Callbacks photoOutputListener = {
1315         .onFrameStart = PhotoOutputOnFrameStart,
1316         .onFrameShutter = PhotoOutputOnFrameShutter,
1317         .onFrameEnd = PhotoOutputOnFrameEnd,
1318         .onError = PhotoOutputOnError
1319     };
1320     return &photoOutputListener;
1321 }
1322 
PhotoOutputRegisterCallback(void)1323 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void)
1324 {
1325     ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener());
1326     if (ret_ != CAMERA_OK) {
1327         LOG("OH_PhotoOutput_RegisterCallback failed.");
1328     }
1329     return ret_;
1330 }
1331 
PhotoOutputUnRegisterCallback(void)1332 Camera_ErrorCode NDKCamera::PhotoOutputUnRegisterCallback(void)
1333 {
1334     ret_ = OH_PhotoOutput_UnregisterCallback(photoOutput_, GetPhotoOutputListener());
1335     if (ret_ != CAMERA_OK) {
1336         LOG("OH_PhotoOutput_UnregisterCallback failed.");
1337     }
1338     return ret_;
1339 }
1340 
1341 // VideoOutput Callback
VideoOutputOnFrameStart(Camera_VideoOutput * videoOutput)1342 void VideoOutputOnFrameStart(Camera_VideoOutput* videoOutput)
1343 {
1344     NDKCamera::cameraCallbackCode_ = Video_OnFrameStart;
1345     LOG("VideoOutputOnFrameStart");
1346 }
1347 
VideoOutputOnFrameEnd(Camera_VideoOutput * videoOutput,int32_t frameCount)1348 void VideoOutputOnFrameEnd(Camera_VideoOutput* videoOutput, int32_t frameCount)
1349 {
1350     NDKCamera::cameraCallbackCode_ = Video_OnFrameEnd;
1351     LOG("VideoOutput frameCount = %d", frameCount);
1352 }
1353 
VideoOutputOnError(Camera_VideoOutput * videoOutput,Camera_ErrorCode errorCode)1354 void VideoOutputOnError(Camera_VideoOutput* videoOutput, Camera_ErrorCode errorCode)
1355 {
1356     NDKCamera::cameraCallbackCode_ = Video_OnError;
1357     LOG("VideoOutput errorCode = %d", errorCode);
1358 }
1359 
GetVideoOutputListener(void)1360 VideoOutput_Callbacks* NDKCamera::GetVideoOutputListener(void)
1361 {
1362     static VideoOutput_Callbacks videoOutputListener = {
1363         .onFrameStart = VideoOutputOnFrameStart,
1364         .onFrameEnd = VideoOutputOnFrameEnd,
1365         .onError = VideoOutputOnError
1366     };
1367     return &videoOutputListener;
1368 }
1369 
VideoOutputRegisterCallback(void)1370 Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void)
1371 {
1372     ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener());
1373     if (ret_ != CAMERA_OK) {
1374         LOG("OH_VideoOutput_RegisterCallback failed.");
1375     }
1376     return ret_;
1377 }
1378 
VideoOutputUnRegisterCallback(void)1379 Camera_ErrorCode NDKCamera::VideoOutputUnRegisterCallback(void)
1380 {
1381     ret_ = OH_VideoOutput_UnregisterCallback(videoOutput_, GetVideoOutputListener());
1382     if (ret_ != CAMERA_OK) {
1383         LOG("OH_VideoOutput_UnregisterCallback failed.");
1384     }
1385     return ret_;
1386 }
1387 
1388 // Metadata Callback
OnMetadataObjectAvailable(Camera_MetadataOutput * metadataOutput,Camera_MetadataObject * metadataObject,uint32_t size)1389 void OnMetadataObjectAvailable(Camera_MetadataOutput* metadataOutput,
1390     Camera_MetadataObject* metadataObject, uint32_t size)
1391 {
1392     NDKCamera::cameraCallbackCode_ = Metadata_Object_Available;
1393     LOG("size = %d", size);
1394 }
1395 
OnMetadataOutputError(Camera_MetadataOutput * metadataOutput,Camera_ErrorCode errorCode)1396 void OnMetadataOutputError(Camera_MetadataOutput* metadataOutput, Camera_ErrorCode errorCode)
1397 {
1398     NDKCamera::cameraCallbackCode_ = Metadata_Output_Error;
1399     LOG("OnMetadataOutput errorCode = %d", errorCode);
1400 }
1401 
GetMetadataOutputListener(void)1402 MetadataOutput_Callbacks* NDKCamera::GetMetadataOutputListener(void)
1403 {
1404     static MetadataOutput_Callbacks metadataOutputListener = {
1405         .onMetadataObjectAvailable = OnMetadataObjectAvailable,
1406         .onError = OnMetadataOutputError
1407     };
1408     return &metadataOutputListener;
1409 }
1410 
MetadataOutputRegisterCallback(void)1411 Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void)
1412 {
1413     ret_ = OH_MetadataOutput_RegisterCallback(metadataOutput_, GetMetadataOutputListener());
1414     if (ret_ != CAMERA_OK) {
1415         LOG("OH_MetadataOutput_RegisterCallback failed.");
1416     }
1417     return ret_;
1418 }
1419 
MetadataOutputUnRegisterCallback(void)1420 Camera_ErrorCode NDKCamera::MetadataOutputUnRegisterCallback(void)
1421 {
1422     ret_ = OH_MetadataOutput_UnregisterCallback(metadataOutput_, GetMetadataOutputListener());
1423     if (ret_ != CAMERA_OK) {
1424         LOG("OH_MetadataOutput_UnregisterCallback failed.");
1425     }
1426     return ret_;
1427 }
1428 
1429 // Session Callback
CaptureSessionOnFocusStateChange(Camera_CaptureSession * session,Camera_FocusState focusState)1430 void CaptureSessionOnFocusStateChange(Camera_CaptureSession* session, Camera_FocusState focusState)
1431 {
1432     NDKCamera::cameraCallbackCode_ = Session_OnFocusState_Change;
1433     LOG("CaptureSessionOnFocusStateChange");
1434 }
1435 
CaptureSessionOnError(Camera_CaptureSession * session,Camera_ErrorCode errorCode)1436 void CaptureSessionOnError(Camera_CaptureSession* session, Camera_ErrorCode errorCode)
1437 {
1438     NDKCamera::cameraCallbackCode_ = Session_OnError;
1439     LOG("CaptureSession errorCode = %d", errorCode);
1440 }
1441 
GetCaptureSessionRegister(void)1442 CaptureSession_Callbacks* NDKCamera::GetCaptureSessionRegister(void)
1443 {
1444     static CaptureSession_Callbacks captureSessionCallbacks = {
1445         .onFocusStateChange = CaptureSessionOnFocusStateChange,
1446         .onError = CaptureSessionOnError
1447     };
1448     return &captureSessionCallbacks;
1449 }
1450 
CaptureSessionRegisterCallback(void)1451 Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void)
1452 {
1453     ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister());
1454     if (ret_ != CAMERA_OK) {
1455         LOG("OH_CaptureSession_RegisterCallback failed.");
1456     }
1457     return ret_;
1458 }
1459 
CaptureSessionUnRegisterCallback(void)1460 Camera_ErrorCode NDKCamera::CaptureSessionUnRegisterCallback(void)
1461 {
1462     ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, GetCaptureSessionRegister());
1463     if (ret_ != CAMERA_OK) {
1464         LOG("OH_CaptureSession_UnregisterCallback failed.");
1465     }
1466     return ret_;
1467 }
1468 
CreateCameraInputWithPositionAndType(Camera_Position position,Camera_Type type)1469 Camera_ErrorCode NDKCamera::CreateCameraInputWithPositionAndType(Camera_Position position, Camera_Type type)
1470 {
1471     LOG("ndkXTS CreateCameraInputWithPositionAndType start.");
1472     if (cameraManager_ == nullptr) {
1473         LOG("ndkXTS cameraManager_ is NULL.");
1474     }
1475     ret_ = OH_CameraManager_CreateCameraInput_WithPositionAndType(cameraManager_, position, type, &cameraInput_);
1476     if (cameraInput_ == nullptr || ret_ != CAMERA_OK) {
1477         LOG("ndkXTS CreateCameraInputWithPositionAndType failed = %d. cameraInput_ = %p", ret_, cameraInput_);
1478         return CAMERA_INVALID_ARGUMENT;
1479     }
1480     LOG("ndkXTS CreateCameraInputWithPositionAndType end.");
1481     return ret_;
1482 }
1483 
GetCaptureSessionRegister(int useCaseCode)1484 CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(int useCaseCode)
1485 {
1486     static CaptureSession_Callbacks captureSessionCallbacks;
1487     if (useCaseCode == ALL_CALLBACK_IS_NULL) {
1488         captureSessionCallbacks = {.onFocusStateChange = nullptr,
1489                                    .onError = nullptr};
1490     } else if (useCaseCode == ONLY_ON_ERROR) {
1491         captureSessionCallbacks = {.onFocusStateChange = nullptr,
1492                                    .onError = CaptureSessionOnError};
1493     } else if (useCaseCode == ONLY_ON_FOCUS_STATE_CHANGE) {
1494         captureSessionCallbacks = {.onFocusStateChange = CaptureSessionOnFocusStateChange,
1495                                    .onError = nullptr};
1496     }
1497     return &captureSessionCallbacks;
1498 }
1499 
CaptureSessionRegisterCallbackOn(int useCaseCode)1500 Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallbackOn(int useCaseCode)
1501 {
1502     ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister(useCaseCode));
1503     if (ret_ != CAMERA_OK) {
1504         LOG("ndkXTS OH_CaptureSession_RegisterCallback failed.%d", ret_);
1505     }
1506     return ret_;
1507 }
CaptureSessionUnregisterCallbackOff(int useCaseCode)1508 Camera_ErrorCode NDKCamera::CaptureSessionUnregisterCallbackOff(int useCaseCode)
1509 {
1510     ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, GetCaptureSessionRegister(useCaseCode));
1511     if (ret_ != CAMERA_OK) {
1512         LOG("ndkXTS OH_CaptureSession_UnregisterCallback failed.%d", ret_);
1513     }
1514     return ret_;
1515 }
1516 
1517 
GetCameraFromCameras(Camera_Device * cameras,Camera_Device ** camera,size_t cameraIndex)1518 Camera_ErrorCode NDKCamera::GetCameraFromCameras(Camera_Device* cameras, Camera_Device** camera,
1519     size_t cameraIndex)
1520 {
1521     if (cameras != nullptr) {
1522         LOG("supported cameras list is not null.");
1523         if (cameraIndex < this->size_) {
1524             *camera = &cameras[cameraIndex];
1525             ret_ = CAMERA_OK;
1526         } else {
1527             ret_ = CAMERA_INVALID_ARGUMENT;
1528             LOG("fail to get valid camera, size is out of supported cameras list range. %d", ret_);
1529         }
1530     } else {
1531         ret_ = CAMERA_INVALID_ARGUMENT;
1532         LOG("get camera from supported cameras list failed, the list is null. %d", ret_);
1533     }
1534     return ret_;
1535 }
1536 
CaptureSessionRegisterCallback(int useCaseCode)1537 Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(int useCaseCode)
1538 {
1539     if (useCaseCode == PARAMETER_OK) {
1540         ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister());
1541     } else if (useCaseCode == PARAMETER2_ERROR) {
1542         ret_ = OH_CaptureSession_RegisterCallback(captureSession_, nullptr);
1543     } else {
1544         ret_ = OH_CaptureSession_RegisterCallback(nullptr, GetCaptureSessionRegister());
1545     }
1546     if (ret_ != CAMERA_OK) {
1547         LOG("ndkXTS CaptureSessionRegisterCallback failed.");
1548     }
1549     return ret_;
1550 }
CaptureSessionUnRegisterCallback(int useCaseCode)1551 Camera_ErrorCode NDKCamera::CaptureSessionUnRegisterCallback(int useCaseCode)
1552 {
1553     if (useCaseCode == PARAMETER_OK) {
1554         ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, GetCaptureSessionRegister());
1555     } else if (useCaseCode == PARAMETER2_ERROR) {
1556         ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, nullptr);
1557     } else {
1558         ret_ = OH_CaptureSession_UnregisterCallback(nullptr, GetCaptureSessionRegister());
1559     }
1560     return ret_;
1561 }
1562 
GetSupportedSceneModes(int useCaseCode)1563 Camera_ErrorCode NDKCamera::GetSupportedSceneModes(int useCaseCode)
1564 {
1565     if (camera_ == nullptr) {
1566         ret_ = GetCameraFromCameras(cameras_, &camera_);
1567     }
1568     if (useCaseCode == PARAMETER_OK) {
1569         ret_ = OH_CameraManager_GetSupportedSceneModes(camera_, &sceneModes_, &sceneModesSize_);
1570     } else if (useCaseCode == PARAMETER3_ERROR) {
1571         ret_ = OH_CameraManager_GetSupportedSceneModes(camera_, &sceneModes_, nullptr);
1572     } else if (useCaseCode == PARAMETER2_ERROR) {
1573         ret_ = OH_CameraManager_GetSupportedSceneModes(camera_, nullptr, &sceneModesSize_);
1574     } else if (useCaseCode == SET_CAMERA_FRONT_FOR_SECURE_PHOTO) {
1575         ret_ = GetCameraFromCameras(cameras_, &camera_, FRONT_CAMERA);
1576         ret_ = OH_CameraManager_GetSupportedSceneModes(camera_, &sceneModes_, &sceneModesSize_);
1577     } else {
1578         ret_ = OH_CameraManager_GetSupportedSceneModes(nullptr, &sceneModes_, &sceneModesSize_);
1579     }
1580     if (ret_ == CAMERA_OK && sceneModesSize_ > 1) {
1581         isNormalPhoto_ = false;
1582         isNormalVideo_ = false;
1583         isSecurePhoto_ = false;
1584         for (decltype(sceneModesSize_) index = 0; index < sceneModesSize_; index++) {
1585             switch (sceneModes_[index]) {
1586                 case NORMAL_PHOTO:
1587                     isNormalPhoto_ = true;
1588                     break;
1589                 case NORMAL_VIDEO:
1590                     isNormalVideo_ = true;
1591                     break;
1592                 case SECURE_PHOTO:
1593                     isSecurePhoto_ = true;
1594                     break;
1595                 default: break;
1596             }
1597         }
1598         LOG("isSupported_NORMAL_PHOTO: %d, isSupported_NORMAL_VIDEO: %d, isSupported_NSECURE_PHOTO: %d.",
1599             isNormalPhoto_, isNormalVideo_, isSecurePhoto_);
1600     } else {
1601         ret_ = CAMERA_INVALID_ARGUMENT;
1602         LOG("ndkXTS OH_CameraManager_GetSupportedSceneModes failed.%d", ret_);
1603     }
1604     return ret_;
1605 }
1606 
DeleteSceneModes(int useCaseCode)1607 Camera_ErrorCode NDKCamera::DeleteSceneModes(int useCaseCode)
1608 {
1609     if (useCaseCode == PARAMETER_OK) {
1610         ret_ = OH_CameraManager_DeleteSceneModes(cameraManager_, sceneModes_);
1611     } else if (useCaseCode == PARAMETER2_ERROR) {
1612         ret_ = OH_CameraManager_DeleteSceneModes(cameraManager_, nullptr);
1613     } else {
1614         ret_ = OH_CameraManager_DeleteSceneModes(nullptr, sceneModes_);
1615     }
1616     if (sceneModes_ != nullptr || ret_ != CAMERA_OK) {
1617         LOG("ndkXTS OH_CameraManager_DeleteSceneModes failed.%d", ret_);
1618     }
1619     return ret_;
1620 }
1621 
GetSupportedCameraOutputCapabilityWithSceneMode(int useCaseCode)1622 Camera_ErrorCode NDKCamera::GetSupportedCameraOutputCapabilityWithSceneMode(int useCaseCode)
1623 {
1624     if (camera_ == nullptr) {
1625         ret_ = GetCameraFromCameras(cameras_, &camera_);
1626     }
1627     if (useCaseCode == PARAMETER_OK) {
1628         if (sceneMode_ == SECURE_PHOTO) {
1629         ret_ = GetCameraFromCameras(cameras_, &camera_, FRONT_CAMERA);
1630         }
1631         ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, camera_, sceneMode_,
1632         &cameraOutputCapability_);
1633     } else if (useCaseCode == PARAMETER4_ERROR) {
1634         ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, camera_, sceneMode_,
1635         nullptr);
1636     } else if (useCaseCode == PARAMETER3_ERROR) {
1637         ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, camera_,
1638             static_cast<Camera_SceneMode>(0), &cameraOutputCapability_);
1639     } else if (useCaseCode == PARAMETER2_ERROR) {
1640         ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, nullptr, sceneMode_,
1641         &cameraOutputCapability_);
1642     } else {
1643         ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(nullptr, camera_, sceneMode_,
1644         &cameraOutputCapability_);
1645     }
1646     if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) {
1647         LOG("ndkXTS OH_CaptureSession_UnregisterCallback failed.%d", ret_);
1648     }
1649     return ret_;
1650 }
1651 
SetSceneMode(int useCaseCode)1652 Camera_ErrorCode NDKCamera::SetSceneMode(int useCaseCode)
1653 {
1654     if (useCaseCode == PARAMETER_OK) {
1655         sceneMode_ = NORMAL_PHOTO;
1656     } else if (useCaseCode == PARAMETER1_ERROR) {
1657         sceneMode_ = NORMAL_VIDEO;
1658     } else if (useCaseCode == PARAMETER2_ERROR) {
1659         sceneMode_ = SECURE_PHOTO;
1660     }
1661     return CAMERA_OK;
1662 }
1663 
SetSessionMode(int useCaseCode)1664 Camera_ErrorCode NDKCamera::SetSessionMode(int useCaseCode)
1665 {
1666     if (useCaseCode == PARAMETER_OK) {
1667         ret_ = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_);
1668     } else if (useCaseCode == PARAMETER2_ERROR) {
1669         ret_ = OH_CaptureSession_SetSessionMode(captureSession_, static_cast<Camera_SceneMode>(0));
1670     } else {
1671         ret_ = OH_CaptureSession_SetSessionMode(nullptr, sceneMode_);
1672     }
1673     if (ret_ == CAMERA_OK) {
1674         LOG("ndkXTS OH_CaptureSession_SetSessionMode successful.%d", ret_);
1675     }
1676     return ret_;
1677 }
1678 
CanAddInput(int useCaseCode)1679 Camera_ErrorCode NDKCamera::CanAddInput(int useCaseCode)
1680 {
1681     isAddInput_ = false;
1682     if (useCaseCode == PARAMETER_OK) {
1683         ret_ = OH_CaptureSession_CanAddInput(captureSession_, cameraInput_, &isAddInput_);
1684     } else if (useCaseCode == PARAMETER3_ERROR) {
1685         ret_ = OH_CaptureSession_CanAddInput(captureSession_, cameraInput_, nullptr);
1686     } else if (useCaseCode == PARAMETER2_ERROR) {
1687         ret_ = OH_CaptureSession_CanAddInput(captureSession_, nullptr, &isAddInput_);
1688     } else {
1689         ret_ = OH_CaptureSession_CanAddInput(nullptr, cameraInput_, &isAddInput_);
1690     }
1691     if (ret_ != CAMERA_OK) {
1692         LOG("ndkXTS OH_CaptureSession_CanAddInput failed.%d", ret_);
1693     } else {
1694         if (isAddInput_ == true) {
1695             LOG("can add input.");
1696         } else {
1697             LOG("can not add input.");
1698         }
1699     }
1700     return ret_;
1701 }
1702 
CanAddPreviewOutput(int useCaseCode)1703 Camera_ErrorCode NDKCamera::CanAddPreviewOutput(int useCaseCode)
1704 {
1705     isAddInput_ = false;
1706     if (useCaseCode == PARAMETER_OK) {
1707         ret_ = OH_CaptureSession_CanAddPreviewOutput(captureSession_, previewOutput_, &isAddInput_);
1708     } else if (useCaseCode == PARAMETER3_ERROR) {
1709         ret_ = OH_CaptureSession_CanAddPreviewOutput(captureSession_, previewOutput_, nullptr);
1710     } else if (useCaseCode == PARAMETER2_ERROR) {
1711         ret_ = OH_CaptureSession_CanAddPreviewOutput(captureSession_, nullptr, &isAddInput_);
1712     } else {
1713         ret_ = OH_CaptureSession_CanAddPreviewOutput(nullptr, previewOutput_, &isAddInput_);
1714     }
1715     if (ret_ != CAMERA_OK) {
1716         LOG("ndkXTS OH_CaptureSession_CanAddPreviewOutput failed.%d", ret_);
1717     } else {
1718         if (isAddInput_ == true) {
1719             LOG("can add preview output.");
1720         } else {
1721             LOG("can not add preview output.");
1722         }
1723     }
1724     return ret_;
1725 }
1726 
CanAddPhotoOutput(int useCaseCode)1727 Camera_ErrorCode NDKCamera::CanAddPhotoOutput(int useCaseCode)
1728 {
1729     isAddInput_ = false;
1730     if (useCaseCode == PARAMETER_OK) {
1731         ret_ = OH_CaptureSession_CanAddPhotoOutput(captureSession_, photoOutput_, &isAddInput_);
1732     } else if (useCaseCode == PARAMETER3_ERROR) {
1733         ret_ = OH_CaptureSession_CanAddPhotoOutput(captureSession_, photoOutput_, nullptr);
1734     } else if (useCaseCode == PARAMETER2_ERROR) {
1735         ret_ = OH_CaptureSession_CanAddPhotoOutput(captureSession_, nullptr, &isAddInput_);
1736     } else {
1737         ret_ = OH_CaptureSession_CanAddPhotoOutput(nullptr, photoOutput_, &isAddInput_);
1738     }
1739     if (ret_ != CAMERA_OK) {
1740         LOG("ndkXTS OH_CaptureSession_CanAddPhotoOutput failed.%d", ret_);
1741     } else {
1742         if (isAddInput_ == true) {
1743             LOG("can add photo output.");
1744         } else {
1745             LOG("can not add photo output.");
1746         }
1747     }
1748     return ret_;
1749 }
1750 
CanAddVideoOutput(int useCaseCode)1751 Camera_ErrorCode NDKCamera::CanAddVideoOutput(int useCaseCode)
1752 {
1753     isAddInput_ = false;
1754     if (useCaseCode == PARAMETER_OK) {
1755         ret_ = OH_CaptureSession_CanAddVideoOutput(captureSession_, videoOutput_, &isAddInput_);
1756     } else if (useCaseCode == PARAMETER3_ERROR) {
1757         ret_ = OH_CaptureSession_CanAddVideoOutput(captureSession_, videoOutput_, nullptr);
1758     } else if (useCaseCode == PARAMETER2_ERROR) {
1759         ret_ = OH_CaptureSession_CanAddVideoOutput(captureSession_, nullptr, &isAddInput_);
1760     } else {
1761         ret_ = OH_CaptureSession_CanAddVideoOutput(nullptr, videoOutput_, &isAddInput_);
1762     }
1763     if (ret_ != CAMERA_OK) {
1764         LOG("ndkXTS OH_CaptureSession_CanAddVideoOutput failed.%d", ret_);
1765     } else {
1766         if (isAddInput_ == true) {
1767             LOG("can add video output.");
1768         } else {
1769             LOG("can not add video output.");
1770         }
1771     }
1772     return ret_;
1773 }
1774 
AddSecureOutput(int useCaseCode)1775 Camera_ErrorCode NDKCamera::AddSecureOutput(int useCaseCode)
1776 {
1777     if (useCaseCode == PARAMETER_OK) {
1778         ret_ = OH_CaptureSession_AddSecureOutput(captureSession_, previewOutput_);
1779     } else if (useCaseCode == PARAMETER2_ERROR) {
1780         ret_ = OH_CaptureSession_AddSecureOutput(captureSession_, nullptr);
1781     } else {
1782         ret_ = OH_CaptureSession_AddSecureOutput(nullptr, previewOutput_);
1783     }
1784     if (ret_ != CAMERA_OK) {
1785         LOG("ndkXTS OH_CaptureSession_AddSecureOutput successful.%d", ret_);
1786     }
1787     return ret_;
1788 }
1789 
OpenSecureCamera(int useCaseCode)1790 Camera_ErrorCode NDKCamera::OpenSecureCamera(int useCaseCode)
1791 {
1792     if (useCaseCode == PARAMETER_OK) {
1793         ret_ = OH_CameraInput_OpenSecureCamera(cameraInput_, &secureSeqId_);
1794     } else if (useCaseCode == PARAMETER2_ERROR) {
1795         ret_ = OH_CameraInput_OpenSecureCamera(cameraInput_, nullptr);
1796     } else {
1797         ret_ = OH_CameraInput_OpenSecureCamera(nullptr, &secureSeqId_);
1798     }
1799     if (ret_ != CAMERA_OK) {
1800         LOG("ndkXTS OH_CameraInput_OpenSecureCamera failed.%d", ret_);
1801     }
1802     return ret_;
1803 }
1804 
CreatePreviewOutputUsedInPreconfig(int useCaseCode)1805 Camera_ErrorCode NDKCamera::CreatePreviewOutputUsedInPreconfig(int useCaseCode)
1806 {
1807     if (useCaseCode == PARAMETER_OK) {
1808         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, previewSurfaceId_, &previewOutput_);
1809     } else if (useCaseCode == PARAMETER3_ERROR) {
1810         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, previewSurfaceId_, nullptr);
1811     } else if (useCaseCode == INVALID_SURFACE_ID) {
1812         const char* abnormalSurfaceId = "0";
1813         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, abnormalSurfaceId, &previewOutput_);
1814     } else if (useCaseCode == PARAMETER2_ERROR) {
1815         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, nullptr, &previewOutput_);
1816     } else {
1817         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(nullptr, previewSurfaceId_, &previewOutput_);
1818     }
1819 
1820     return ret_;
1821 }
1822 
CreatePhotoOutputUsedInPreconfig(char * photoSurfaceId,int useCaseCode)1823 Camera_ErrorCode NDKCamera::CreatePhotoOutputUsedInPreconfig(char *photoSurfaceId, int useCaseCode)
1824 {
1825     if (useCaseCode == PARAMETER_OK) {
1826         ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(cameraManager_, photoSurfaceId, &photoOutput_);
1827     } else if (useCaseCode == PARAMETER3_ERROR) {
1828         ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, photoSurfaceId, nullptr);
1829     } else if (useCaseCode == INVALID_SURFACE_ID) {
1830         const char* abnormalSurfaceId = "0";
1831         ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(cameraManager_, abnormalSurfaceId, &photoOutput_);
1832     } else if (useCaseCode == PARAMETER2_ERROR) {
1833         ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(cameraManager_, nullptr, &photoOutput_);
1834     } else {
1835         ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(nullptr, photoSurfaceId, &photoOutput_);
1836     }
1837 
1838     return ret_;
1839 }
1840 
SessionCanPreconfig(uint32_t mode,int useCaseCode)1841 Camera_ErrorCode NDKCamera::SessionCanPreconfig(uint32_t mode, int useCaseCode)
1842 {
1843     Camera_PreconfigType preconfigType = static_cast<Camera_PreconfigType>(mode);
1844     if (useCaseCode == PARAMETER_OK) {
1845         ret_ = OH_CaptureSession_CanPreconfig(captureSession_, preconfigType, &canPreconfig_);
1846     } else if (useCaseCode == PARAMETER3_ERROR) {
1847         ret_ = OH_CaptureSession_CanPreconfig(captureSession_, preconfigType, nullptr);
1848     } else {
1849         ret_ = OH_CaptureSession_CanPreconfig(nullptr, preconfigType, &canPreconfig_);
1850     }
1851     return ret_;
1852 }
1853 
SessionCanPreconfigWithRatio(uint32_t mode,uint32_t mode2,int useCaseCode)1854 Camera_ErrorCode NDKCamera::SessionCanPreconfigWithRatio(uint32_t mode, uint32_t mode2, int useCaseCode)
1855 {
1856     Camera_PreconfigType preconfigType = static_cast<Camera_PreconfigType>(mode);
1857     Camera_PreconfigRatio preconfigRatio = static_cast<Camera_PreconfigRatio>(mode2);
1858     if (useCaseCode == PARAMETER_OK) {
1859         ret_ = OH_CaptureSession_CanPreconfigWithRatio(captureSession_, preconfigType, preconfigRatio, &canPreconfig_);
1860     } else if (useCaseCode == PARAMETER4_ERROR) {
1861         ret_ = OH_CaptureSession_CanPreconfigWithRatio(captureSession_, preconfigType, preconfigRatio, nullptr);
1862     } else {
1863         ret_ = OH_CaptureSession_CanPreconfigWithRatio(nullptr, preconfigType, preconfigRatio, &canPreconfig_);
1864     }
1865     return ret_;
1866 }
1867 
SessionPreconfig(uint32_t mode,int useCaseCode)1868 Camera_ErrorCode NDKCamera::SessionPreconfig(uint32_t mode, int useCaseCode)
1869 {
1870     Camera_PreconfigType preconfigType = static_cast<Camera_PreconfigType>(mode);
1871     if (useCaseCode == PARAMETER_OK) {
1872         ret_ = OH_CaptureSession_Preconfig(captureSession_, preconfigType);
1873     } else {
1874         ret_ = OH_CaptureSession_Preconfig(nullptr, preconfigType);
1875     }
1876     return ret_;
1877 }
1878 
SessionPreconfigWithRatio(uint32_t mode,uint32_t mode2,int useCaseCode)1879 Camera_ErrorCode NDKCamera::SessionPreconfigWithRatio(uint32_t mode, uint32_t mode2, int useCaseCode)
1880 {
1881     Camera_PreconfigType preconfigType = static_cast<Camera_PreconfigType>(mode);
1882     Camera_PreconfigRatio preconfigRatio = static_cast<Camera_PreconfigRatio>(mode2);
1883     if (useCaseCode == PARAMETER_OK) {
1884         ret_ = OH_CaptureSession_PreconfigWithRatio(captureSession_, preconfigType, preconfigRatio);
1885     } else {
1886         ret_ = OH_CaptureSession_PreconfigWithRatio(nullptr, preconfigType, preconfigRatio);
1887     }
1888     return ret_;
1889 }
1890 
CreateVideoOutputUsedInPreconfig(char * videoId,int useCaseCode)1891 Camera_ErrorCode NDKCamera::CreateVideoOutputUsedInPreconfig(char *videoId, int useCaseCode)
1892 {
1893     if (useCaseCode == PARAMETER_OK) {
1894         ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, videoId, &videoOutput_);
1895     } else if (useCaseCode == PARAMETER3_ERROR) {
1896         ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, videoId, nullptr);
1897     } else if (useCaseCode == INVALID_SURFACE_ID) {
1898         const char* abnormalVideoId = "0";
1899         ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, abnormalVideoId, &videoOutput_);
1900     } else if (useCaseCode == PARAMETER2_ERROR) {
1901         ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, nullptr, &videoOutput_);
1902     } else {
1903         ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(nullptr,  videoId, &videoOutput_);
1904     }
1905     return ret_;
1906 }
1907 
VideoOutputGetActiveProfile(int useCaseCode)1908 Camera_ErrorCode NDKCamera::VideoOutputGetActiveProfile(int useCaseCode)
1909 {
1910     if (useCaseCode == PARAMETER_OK) {
1911         ret_ = OH_VideoOutput_GetActiveProfile(videoOutput_, &videoActiveProfile_);
1912     } else if (useCaseCode == PARAMETER2_ERROR) {
1913         ret_ = OH_VideoOutput_GetActiveProfile(videoOutput_, nullptr);
1914     } else {
1915         ret_ = OH_VideoOutput_GetActiveProfile(nullptr, &videoActiveProfile_);
1916     }
1917     return ret_;
1918 }
1919 
VideoOutputDeleteProfile(int useCaseCode)1920 Camera_ErrorCode NDKCamera::VideoOutputDeleteProfile(int useCaseCode)
1921 {
1922     if (useCaseCode == PARAMETER_OK) {
1923         ret_ = OH_VideoOutput_DeleteProfile(videoActiveProfile_);
1924     } else {
1925         ret_ = OH_VideoOutput_DeleteProfile(nullptr);
1926     }
1927     return ret_;
1928 }
1929 
PreviewOutputGetActiveProfile(int useCaseCode)1930 Camera_ErrorCode NDKCamera::PreviewOutputGetActiveProfile(int useCaseCode)
1931 {
1932     if (useCaseCode == PARAMETER_OK) {
1933         ret_ = OH_PreviewOutput_GetActiveProfile(previewOutput_, &cameraProfile_);
1934     } else if (useCaseCode == PARAMETER2_ERROR) {
1935         ret_ = OH_PreviewOutput_GetActiveProfile(previewOutput_, nullptr);
1936     } else {
1937         ret_ = OH_PreviewOutput_GetActiveProfile(nullptr, &cameraProfile_);
1938     }
1939     return ret_;
1940 }
1941 
PreviewOutputDeleteProfile(int useCaseCode)1942 Camera_ErrorCode NDKCamera::PreviewOutputDeleteProfile(int useCaseCode)
1943 {
1944     if (useCaseCode == PARAMETER_OK) {
1945         ret_ = OH_PreviewOutput_DeleteProfile(cameraProfile_);
1946     } else {
1947         ret_ = OH_PreviewOutput_DeleteProfile(nullptr);
1948     }
1949     return ret_;
1950 }
1951 
PhotoOutputGetActiveProfile(int useCaseCode)1952 Camera_ErrorCode NDKCamera::PhotoOutputGetActiveProfile(int useCaseCode)
1953 {
1954     if (useCaseCode == PARAMETER_OK) {
1955         ret_ = OH_PhotoOutput_GetActiveProfile(photoOutput_, &cameraProfile_);
1956     } else if (useCaseCode == PARAMETER2_ERROR) {
1957         ret_ = OH_PhotoOutput_GetActiveProfile(photoOutput_, nullptr);
1958     } else {
1959         ret_ = OH_PhotoOutput_GetActiveProfile(nullptr, &cameraProfile_);
1960     }
1961     return ret_;
1962 }
1963 
PhotoOutputDeleteProfile(int useCaseCode)1964 Camera_ErrorCode NDKCamera::PhotoOutputDeleteProfile(int useCaseCode)
1965 {
1966     if (useCaseCode == PARAMETER_OK) {
1967         ret_ = OH_PhotoOutput_DeleteProfile(cameraProfile_);
1968     } else {
1969         ret_ = OH_PhotoOutput_DeleteProfile(nullptr);
1970     }
1971     return ret_;
1972 }
1973 
PhotoOutputOnPhotoAvailable(Camera_PhotoOutput * photoOutput,OH_PhotoNative * photo)1974 void PhotoOutputOnPhotoAvailable(Camera_PhotoOutput* photoOutput, OH_PhotoNative* photo)
1975 {
1976     NDKCamera::cameraCallbackCode_ = PHOTO_ON_PHOTO_AVAILABLE;
1977     LOG("PhotoOutputOnPhotoAvailable is called.");
1978 }
1979 
RegisterPhotoAvailableCallback(int useCaseCode)1980 Camera_ErrorCode NDKCamera::RegisterPhotoAvailableCallback(int useCaseCode)
1981 {
1982     if (useCaseCode == PARAMETER_OK) {
1983         ret_ = OH_PhotoOutput_RegisterPhotoAvailableCallback(photoOutput_, PhotoOutputOnPhotoAvailable);
1984     } else if (useCaseCode == PARAMETER2_ERROR) {
1985         ret_ = OH_PhotoOutput_RegisterPhotoAvailableCallback(photoOutput_, nullptr);
1986     } else {
1987         ret_ = OH_PhotoOutput_RegisterPhotoAvailableCallback(nullptr, PhotoOutputOnPhotoAvailable);
1988     }
1989     if (ret_ != CAMERA_OK) {
1990         LOG("OH_PhotoOutput_RegisterPhotoAvailableCallback failed. %d", ret_);
1991     }
1992     return ret_;
1993 }
1994 
UnregisterPhotoAvailableCallback(int useCaseCode)1995 Camera_ErrorCode NDKCamera::UnregisterPhotoAvailableCallback(int useCaseCode)
1996 {
1997     if (useCaseCode == PARAMETER_OK) {
1998         ret_ = OH_PhotoOutput_UnregisterPhotoAvailableCallback(photoOutput_, PhotoOutputOnPhotoAvailable);
1999     } else if (useCaseCode == PARAMETER2_ERROR) {
2000         ret_ = OH_PhotoOutput_UnregisterPhotoAvailableCallback(photoOutput_, nullptr);
2001     } else {
2002         ret_ = OH_PhotoOutput_UnregisterPhotoAvailableCallback(nullptr, PhotoOutputOnPhotoAvailable);
2003     }
2004     if (ret_ != CAMERA_OK) {
2005         LOG("OH_PhotoOutput_UnregisterPhotoAvailableCallback failed. %d", ret_);
2006     }
2007     return ret_;
2008 }
2009 
PhotoOutputOnPhotoAssetAvailable(Camera_PhotoOutput * photoOutput,OH_MediaAsset * photoAsset)2010 void PhotoOutputOnPhotoAssetAvailable(Camera_PhotoOutput* photoOutput, OH_MediaAsset* photoAsset)
2011 {
2012     NDKCamera::cameraCallbackCode_ = PHOTO_ON_PHOTO_ASSET_AVAILABLE;
2013     LOG("PhotoOutputOnPhotoAssetAvailable is called.");
2014 }
2015 
RegisterPhotoAssetAvailableCallback(int useCaseCode)2016 Camera_ErrorCode NDKCamera::RegisterPhotoAssetAvailableCallback(int useCaseCode)
2017 {
2018     if (useCaseCode == PARAMETER_OK) {
2019         ret_ = OH_PhotoOutput_RegisterPhotoAssetAvailableCallback(photoOutput_, PhotoOutputOnPhotoAssetAvailable);
2020     } else if (useCaseCode == PARAMETER2_ERROR) {
2021         ret_ = OH_PhotoOutput_RegisterPhotoAssetAvailableCallback(photoOutput_, nullptr);
2022     } else {
2023         ret_ = OH_PhotoOutput_RegisterPhotoAssetAvailableCallback(nullptr, PhotoOutputOnPhotoAssetAvailable);
2024     }
2025     if (ret_ != CAMERA_OK) {
2026         LOG("OH_PhotoOutput_RegisterPhotoAssetAvailableCallback failed. %d", ret_);
2027     }
2028     return ret_;
2029 }
2030 
UnregisterPhotoAssetAvailableCallback(int useCaseCode)2031 Camera_ErrorCode NDKCamera::UnregisterPhotoAssetAvailableCallback(int useCaseCode)
2032 {
2033     if (useCaseCode == PARAMETER_OK) {
2034         ret_ = OH_PhotoOutput_UnregisterPhotoAssetAvailableCallback(photoOutput_, PhotoOutputOnPhotoAssetAvailable);
2035     } else if (useCaseCode == PARAMETER2_ERROR) {
2036         ret_ = OH_PhotoOutput_UnregisterPhotoAssetAvailableCallback(photoOutput_, nullptr);
2037     } else {
2038         ret_ = OH_PhotoOutput_UnregisterPhotoAssetAvailableCallback(nullptr, PhotoOutputOnPhotoAssetAvailable);
2039     }
2040     if (ret_ != CAMERA_OK) {
2041         LOG("OH_PhotoOutput_UnregisterPhotoAssetAvailableCallback failed. %d", ret_);
2042     }
2043     return ret_;
2044 }
2045 
IsMovingPhotoSupported(int useCaseCode)2046 Camera_ErrorCode NDKCamera::IsMovingPhotoSupported(int useCaseCode)
2047 {
2048     if (useCaseCode == PARAMETER_OK) {
2049         ret_ = OH_PhotoOutput_IsMovingPhotoSupported(photoOutput_, &isMovingPhotoSupported_);
2050     } else if (useCaseCode == PARAMETER2_ERROR) {
2051         ret_ = OH_PhotoOutput_IsMovingPhotoSupported(photoOutput_, nullptr);
2052     } else {
2053         ret_ = OH_PhotoOutput_IsMovingPhotoSupported(nullptr, &isMovingPhotoSupported_);
2054     }
2055     if (ret_ != CAMERA_OK) {
2056         LOG("OH_PhotoOutput_IsMovingPhotoSupported failed. %d", ret_);
2057     } else {
2058         if (isMovingPhotoSupported_ != true) {
2059             LOG("moving photo is not supported.");
2060         } else {
2061             LOG("moving photo is supported.");
2062         }
2063     }
2064     return ret_;
2065 }
2066 
EnableMovingPhoto(int useCaseCode,bool enable)2067 Camera_ErrorCode NDKCamera::EnableMovingPhoto(int useCaseCode, bool enable)
2068 {
2069     if (useCaseCode == PARAMETER_OK) {
2070         ret_ = OH_PhotoOutput_EnableMovingPhoto(photoOutput_, enable);
2071     } else if (useCaseCode == PARAMETER1_ERROR) {
2072         ret_ = OH_PhotoOutput_EnableMovingPhoto(nullptr, enable);
2073     }
2074     if (ret_ != CAMERA_OK) {
2075         LOG("OH_PhotoOutput_EnableMovingPhoto failed. %d", ret_);
2076     }
2077     return ret_;
2078 }
2079 
GetMainImage(int useCaseCode)2080 Camera_ErrorCode NDKCamera::GetMainImage(int useCaseCode)
2081 {
2082     if (useCaseCode == PARAMETER_OK) {
2083         ret_ = OH_PhotoNative_GetMainImage(photoNative_, &mainImage_);
2084     } else if (useCaseCode == PARAMETER2_ERROR) {
2085         ret_ = OH_PhotoNative_GetMainImage(photoNative_, nullptr);
2086     } else {
2087         ret_ = OH_PhotoNative_GetMainImage(nullptr, &mainImage_);
2088     }
2089     if (ret_ != CAMERA_OK) {
2090         LOG("OH_PhotoNative_GetMainImage failed. %d", ret_);
2091     }
2092     return ret_;
2093 }
2094 
PhotoNativeRelease(int useCaseCode)2095 Camera_ErrorCode NDKCamera::PhotoNativeRelease(int useCaseCode)
2096 {
2097     if (useCaseCode == PARAMETER_OK) {
2098         ret_ = OH_PhotoNative_Release(photoNative_);
2099     } else {
2100         ret_ = OH_PhotoNative_Release(nullptr);
2101     }
2102     if (ret_ != CAMERA_OK || !photoNative_) {
2103         LOG("OH_PhotoNative_Release failed. %d", ret_);
2104     }
2105     return ret_;
2106 }
2107 
CreatePhotoOutputWithoutSurface(int useCaseCode)2108 Camera_ErrorCode NDKCamera::CreatePhotoOutputWithoutSurface(int useCaseCode)
2109 {
2110     for (decltype(cameraOutputCapability_->photoProfilesSize) i = 0;
2111             i< cameraOutputCapability_->photoProfilesSize; i++) {
2112         if (cameraOutputCapability_->photoProfiles[i]->size.width == PhotoOutputWithoutSurface.size.width &&
2113             cameraOutputCapability_->photoProfiles[i]->size.height == PhotoOutputWithoutSurface.size.height &&
2114             cameraOutputCapability_->photoProfiles[i]->format == PhotoOutputWithoutSurface.format) {
2115             photoProfile_ = cameraOutputCapability_->photoProfiles[i];
2116             break;
2117         }
2118     }
2119     if (!photoProfile_) {
2120         photoProfile_ = cameraOutputCapability_->photoProfiles[0];
2121     }
2122     if (useCaseCode == PARAMETER_OK) {
2123         ret_ = OH_CameraManager_CreatePhotoOutputWithoutSurface(cameraManager_, photoProfile_, &photoOutput_);
2124     } else if (useCaseCode == PARAMETER3_ERROR) {
2125         ret_ = OH_CameraManager_CreatePhotoOutputWithoutSurface(cameraManager_, photoProfile_, nullptr);
2126     } else if (useCaseCode == PARAMETER2_ERROR) {
2127         ret_ = OH_CameraManager_CreatePhotoOutputWithoutSurface(cameraManager_, nullptr, &photoOutput_);
2128     } else {
2129         ret_ = OH_CameraManager_CreatePhotoOutputWithoutSurface(nullptr, photoProfile_, &photoOutput_);
2130     }
2131     if (ret_ != CAMERA_OK || !photoOutput_) {
2132         ret_ = CAMERA_INVALID_ARGUMENT;
2133         LOG("OH_CameraManager_CreatePhotoOutputWithoutSurface failed. %d", ret_);
2134     }
2135     return ret_;
2136 }
2137 
IsTorchSupported(int useCaseCode)2138 Camera_ErrorCode NDKCamera::IsTorchSupported(int useCaseCode)
2139 {
2140     if (useCaseCode == PARAMETER_OK) {
2141         ret_ = OH_CameraManager_IsTorchSupported(cameraManager_, &isTorchSupported_);
2142     } else if (useCaseCode == PARAMETER1_ERROR) {
2143         ret_ = OH_CameraManager_IsTorchSupported(nullptr, &isTorchSupported_);
2144     } else if (useCaseCode == PARAMETER2_ERROR) {
2145         ret_ = OH_CameraManager_IsTorchSupported(cameraManager_, nullptr);
2146     }
2147     if (ret_ != CAMERA_OK) {
2148         LOG("OH_CameraManager_IsTorchSupported failed.");
2149     }
2150     return ret_;
2151 }
2152 
TorchMode(int useCaseCode)2153 Camera_ErrorCode NDKCamera::TorchMode(int useCaseCode)
2154 {
2155     if (useCaseCode == PARAMETER_OK) {
2156         torchMode_ = OFF;
2157     } else if (useCaseCode == PARAMETER1_ERROR) {
2158         torchMode_ = ON;
2159     } else if (useCaseCode == PARAMETER2_ERROR) {
2160         torchMode_ = AUTO;
2161     }
2162     if (ret_ != CAMERA_OK) {
2163         LOG("OH_CameraManager_IsTorchSupported failed.");
2164     }
2165     return ret_;
2166 }
2167 
IsTorchSupportedByTorchMode(int useCaseCode)2168 Camera_ErrorCode NDKCamera::IsTorchSupportedByTorchMode(int useCaseCode)
2169 {
2170     if (useCaseCode == PARAMETER_OK) {
2171         ret_ = OH_CameraManager_IsTorchSupportedByTorchMode(cameraManager_, torchMode_, &isTorchSupportedByTorchMode_);
2172     } else if (useCaseCode == PARAMETER1_ERROR) {
2173         ret_ = OH_CameraManager_IsTorchSupportedByTorchMode(nullptr, torchMode_, &isTorchSupportedByTorchMode_);
2174     } else if (useCaseCode == PARAMETER2_ERROR) {
2175         ret_ = OH_CameraManager_IsTorchSupportedByTorchMode(cameraManager_, static_cast<Camera_TorchMode>(-1),
2176             &isTorchSupported_);
2177     } else if (useCaseCode == PARAMETER3_ERROR) {
2178         ret_ = OH_CameraManager_IsTorchSupportedByTorchMode(cameraManager_, torchMode_, nullptr);
2179     }
2180     if (ret_ != CAMERA_OK) {
2181         LOG("OH_CameraManager_IsTorchSupportedByTorchMode failed.");
2182     }
2183     return ret_;
2184 }
2185 
SetTorchMode(int useCaseCode)2186 Camera_ErrorCode NDKCamera::SetTorchMode(int useCaseCode)
2187 {
2188     if (useCaseCode == PARAMETER_OK) {
2189         ret_ = OH_CameraManager_SetTorchMode(cameraManager_, torchMode_);
2190     } else if (useCaseCode == PARAMETER1_ERROR) {
2191         ret_ = OH_CameraManager_SetTorchMode(nullptr, torchMode_);
2192     } else if (useCaseCode == PARAMETER2_ERROR) {
2193         ret_ = OH_CameraManager_SetTorchMode(cameraManager_, static_cast<Camera_TorchMode>(-1));
2194     }
2195     if (ret_ != CAMERA_OK) {
2196         LOG("OH_CameraManager_SetTorchMode failed.");
2197     }
2198     return ret_;
2199 }
2200 
GetExposureValue(int useCaseCode)2201 Camera_ErrorCode NDKCamera::GetExposureValue(int useCaseCode)
2202 {
2203     float exposureValue;
2204     if (useCaseCode == PARAMETER_OK) {
2205         ret_ = OH_CaptureSession_GetExposureValue(captureSession_, &exposureValue);
2206     } else if (useCaseCode == PARAMETER1_ERROR) {
2207         ret_ = OH_CaptureSession_GetExposureValue(nullptr, &exposureValue);
2208     } else if (useCaseCode == PARAMETER2_ERROR) {
2209         ret_ = OH_CaptureSession_GetExposureValue(captureSession_, nullptr);
2210     }
2211     if (ret_ != CAMERA_OK) {
2212         LOG("OH_CaptureSession_GetExposureValue failed.");
2213     }
2214     return ret_;
2215 }
2216 
GetFocalLength(int useCaseCode)2217 Camera_ErrorCode NDKCamera::GetFocalLength(int useCaseCode)
2218 {
2219     float focalLength = 0;
2220     if (useCaseCode == PARAMETER_OK) {
2221         ret_ = OH_CaptureSession_GetFocalLength(captureSession_, &focalLength);
2222     } else if (useCaseCode == PARAMETER1_ERROR) {
2223         ret_ = OH_CaptureSession_GetFocalLength(nullptr, &focalLength);
2224     } else if (useCaseCode == PARAMETER2_ERROR) {
2225         ret_ = OH_CaptureSession_GetFocalLength(captureSession_, nullptr);
2226     }
2227     if (focalLength == 0 || ret_ != CAMERA_OK) {
2228         LOG("OH_CaptureSession_GetFocalLength failed.");
2229     }
2230     return ret_;
2231 }
2232 
SetSmoothZoom(int useCaseCode)2233 Camera_ErrorCode NDKCamera::SetSmoothZoom(int useCaseCode)
2234 {
2235     float targetZoom = TARGET_ZOOM;
2236     Camera_SmoothZoomMode smoothZoomMode = NORMAL;
2237     if (useCaseCode == PARAMETER_OK) {
2238         ret_ = OH_CaptureSession_SetSmoothZoom(captureSession_, targetZoom, smoothZoomMode);
2239     } else if (useCaseCode == PARAMETER1_ERROR) {
2240         ret_ = OH_CaptureSession_SetSmoothZoom(nullptr, targetZoom, smoothZoomMode);
2241     }
2242     if (ret_ != CAMERA_OK) {
2243         LOG("OH_CaptureSession_SetSmoothZoom failed.");
2244     }
2245     return ret_;
2246 }
2247 
GetSupportedColorSpaces(int useCaseCode)2248 Camera_ErrorCode NDKCamera::GetSupportedColorSpaces(int useCaseCode)
2249 {
2250     if (useCaseCode == PARAMETER_OK) {
2251         ret_ = OH_CaptureSession_GetSupportedColorSpaces(captureSession_, &colorSpace_, &colorSpacesSize_);
2252     } else if (useCaseCode == PARAMETER1_ERROR) {
2253         ret_ = OH_CaptureSession_GetSupportedColorSpaces(nullptr, &colorSpace_, &colorSpacesSize_);
2254     } else if (useCaseCode == PARAMETER2_ERROR) {
2255         ret_ = OH_CaptureSession_GetSupportedColorSpaces(captureSession_, nullptr, &colorSpacesSize_);
2256     } else if (useCaseCode == PARAMETER3_ERROR) {
2257         ret_ = OH_CaptureSession_GetSupportedColorSpaces(captureSession_, &colorSpace_, nullptr);
2258     }
2259     if (colorSpace_ == nullptr || colorSpacesSize_ == 0 || ret_ != CAMERA_OK) {
2260         LOG("OH_CaptureSession_GetSupportedColorSpaces failed.");
2261     }
2262     return ret_;
2263 }
DeleteColorSpaces(int useCaseCode)2264 Camera_ErrorCode NDKCamera::DeleteColorSpaces(int useCaseCode)
2265 {
2266     if (useCaseCode == PARAMETER_OK) {
2267         ret_ = OH_CaptureSession_DeleteColorSpaces(captureSession_, colorSpace_);
2268     } else if (useCaseCode == PARAMETER1_ERROR) {
2269         ret_ = OH_CaptureSession_DeleteColorSpaces(nullptr, colorSpace_);
2270     } else if (useCaseCode == PARAMETER2_ERROR) {
2271         ret_ = OH_CaptureSession_DeleteColorSpaces(captureSession_, nullptr);
2272     }
2273     if (ret_ != CAMERA_OK) {
2274         LOG("OH_CaptureSession_DeleteColorSpaces failed.");
2275     }
2276     return ret_;
2277 }
GetActiveColorSpace(int useCaseCode)2278 Camera_ErrorCode NDKCamera::GetActiveColorSpace(int useCaseCode)
2279 {
2280     if (useCaseCode == PARAMETER_OK) {
2281         ret_ = OH_CaptureSession_GetActiveColorSpace(captureSession_, &activeColorSpace_);
2282     } else if (useCaseCode == PARAMETER1_ERROR) {
2283         ret_ = OH_CaptureSession_GetActiveColorSpace(nullptr, &activeColorSpace_);
2284     } else if (useCaseCode == PARAMETER2_ERROR) {
2285         ret_ = OH_CaptureSession_GetActiveColorSpace(captureSession_, nullptr);
2286     }
2287     if (ret_ != CAMERA_OK) {
2288         LOG("OH_CaptureSession_GetActiveColorSpace failed.");
2289     }
2290     return ret_;
2291 }
ColorSpace(void)2292 int32_t NDKCamera::ColorSpace(void)
2293 {
2294     int32_t nativeColorSpaceSize = sizeof(oHNativeBufferColorSpace)/sizeof(oHNativeBufferColorSpace[0]);
2295     bool flag = false;
2296     ret_ = OH_CaptureSession_GetSupportedColorSpaces(captureSession_, &colorSpace_, &colorSpacesSize_);
2297     if (colorSpacesSize_ == 0) {
2298         setcolorSpace_ = oHNativeBufferColorSpace[SET_OH_COLORSPACE_SRGB_FULL];
2299         return COLOR_SPACE_NOT_SUPPORTED;
2300     }
2301     for (uint32_t nativeIndex = 0; nativeIndex < nativeColorSpaceSize; nativeIndex++) {
2302         flag = false;
2303         for (int32_t supportedIndex = 0; supportedIndex < colorSpacesSize_; supportedIndex++) {
2304             if (oHNativeBufferColorSpace[nativeIndex] == colorSpace_[supportedIndex]) {
2305                 flag = true;
2306                 break;
2307             }
2308         }
2309         if (!flag) {
2310             setcolorSpace_ = oHNativeBufferColorSpace[nativeIndex];
2311             return COLOR_SPACE_NOT_SUPPORTED;
2312         }
2313     }
2314     return colorSpacesSize_;
2315 }
SetColorSpace(int useCaseCode)2316 Camera_ErrorCode NDKCamera::SetColorSpace(int useCaseCode)
2317 {
2318     if (useCaseCode == PARAMETER_OK) {
2319         ret_ = OH_CaptureSession_SetActiveColorSpace(captureSession_, activeColorSpace_);
2320     } else if (useCaseCode == PARAMETER1_ERROR) {
2321         ret_ = OH_CaptureSession_SetActiveColorSpace(nullptr, activeColorSpace_);
2322     } else if (useCaseCode == PARAMETER2_ERROR) {
2323         ret_ = OH_CaptureSession_SetActiveColorSpace(captureSession_, static_cast<OH_NativeBuffer_ColorSpace>(-1));
2324     } else if (useCaseCode == COLOR_SPACE_NOT_SUPPORTED_MODE) {
2325         ret_ = OH_CaptureSession_SetActiveColorSpace(captureSession_, setcolorSpace_);
2326     }
2327     if (ret_ != CAMERA_OK) {
2328         LOG("OH_CaptureSession_SetActiveColorSpace failed.");
2329     }
2330     return ret_;
2331 }
GetSupportedFrameRates(int useCaseCode)2332 Camera_ErrorCode NDKCamera::GetSupportedFrameRates(int useCaseCode)
2333 {
2334     if (useCaseCode == PARAMETER_OK) {
2335         ret_ = OH_PreviewOutput_GetSupportedFrameRates(previewOutput_, &frameRateRange_, &frameRatesSize_);
2336     } else if (useCaseCode == PARAMETER1_ERROR) {
2337         ret_ = OH_PreviewOutput_GetSupportedFrameRates(nullptr, &frameRateRange_, &frameRatesSize_);
2338     } else if (useCaseCode == PARAMETER2_ERROR) {
2339         ret_ = OH_PreviewOutput_GetSupportedFrameRates(previewOutput_, nullptr, &frameRatesSize_);
2340     } else if (useCaseCode == PARAMETER3_ERROR) {
2341         ret_ = OH_PreviewOutput_GetSupportedFrameRates(previewOutput_, &frameRateRange_, nullptr);
2342     }
2343     if (ret_ != CAMERA_OK) {
2344         LOG("OH_PreviewOutput_GetSupportedFrameRates failed.");
2345     }
2346     return ret_;
2347 }
DeleteFrameRates(int useCaseCode)2348 Camera_ErrorCode NDKCamera::DeleteFrameRates(int useCaseCode)
2349 {
2350     if (useCaseCode == PARAMETER_OK) {
2351         ret_ = OH_PreviewOutput_DeleteFrameRates(previewOutput_, frameRateRange_);
2352     } else if (useCaseCode == PARAMETER1_ERROR) {
2353         ret_ = OH_PreviewOutput_DeleteFrameRates(nullptr, frameRateRange_);
2354     } else if (useCaseCode == PARAMETER2_ERROR) {
2355         ret_ = OH_PreviewOutput_DeleteFrameRates(previewOutput_, nullptr);
2356     }
2357     if (ret_ != CAMERA_OK) {
2358         LOG("OH_PreviewOutput_DeleteFrameRates failed.");
2359     }
2360     return ret_;
2361 }
SetFrameRate(int useCaseCode)2362 Camera_ErrorCode NDKCamera::SetFrameRate(int useCaseCode)
2363 {
2364     int32_t minFps = activeFrameRateRange_.min;
2365     int32_t maxFps = activeFrameRateRange_.max;
2366     bool flag = false;
2367     for (uint32_t i = 0; i < frameRatesSize_; i++) {
2368         if (frameRateRange_[i].min != activeFrameRateRange_.min ||
2369             frameRateRange_[i].max != activeFrameRateRange_.max) {
2370             minFps = frameRateRange_[i].min;
2371             maxFps = frameRateRange_[i].max;
2372             flag = true;
2373             break;
2374         }
2375     }
2376     if (!flag) {
2377         if (maxFps > minFps) {
2378             minFps++;
2379         }
2380     }
2381     if (useCaseCode == PARAMETER_OK) {
2382         if (maxFps <= minFps + INVALID_MIN_FPS) {
2383             return CAMERA_OK;
2384         }
2385         ret_ = OH_PreviewOutput_SetFrameRate(previewOutput_, minFps, maxFps);
2386     } else if (useCaseCode == PARAMETER1_ERROR) {
2387         ret_ = OH_PreviewOutput_SetFrameRate(nullptr, minFps, maxFps);
2388     } else if (useCaseCode == PARAMETER2_ERROR) {
2389         ret_ = OH_PreviewOutput_SetFrameRate(previewOutput_, INVALID_MIN_FPS, maxFps + INVALID_MAX_FPS);
2390     }
2391     if (ret_ != CAMERA_OK) {
2392         LOG("OH_PreviewOutput_DeleteFrameRates failed.");
2393     }
2394     return ret_;
2395 }
GetActiveFrameRate(int useCaseCode)2396 Camera_ErrorCode NDKCamera::GetActiveFrameRate(int useCaseCode)
2397 {
2398     if (useCaseCode == PARAMETER_OK) {
2399         ret_ = OH_PreviewOutput_GetActiveFrameRate(previewOutput_, &activeFrameRateRange_);
2400     } else if (useCaseCode == PARAMETER1_ERROR) {
2401         ret_ = OH_PreviewOutput_GetActiveFrameRate(nullptr, &activeFrameRateRange_);
2402     } else if (useCaseCode == PARAMETER2_ERROR) {
2403         ret_ = OH_PreviewOutput_GetActiveFrameRate(previewOutput_, nullptr);
2404     }
2405     if (ret_ != CAMERA_OK) {
2406         LOG("OH_PreviewOutput_GetActiveFrameRate failed.");
2407     }
2408     return ret_;
2409 }
VideoOutputGetSupportedFrameRates(int useCaseCode)2410 Camera_ErrorCode NDKCamera::VideoOutputGetSupportedFrameRates(int useCaseCode)
2411 {
2412     if (useCaseCode == PARAMETER_OK) {
2413         ret_ = OH_VideoOutput_GetSupportedFrameRates(videoOutput_, &videoFrameRateRange_, &videoFrameRatesSize_);
2414     } else if (useCaseCode == PARAMETER1_ERROR) {
2415         ret_ = OH_VideoOutput_GetSupportedFrameRates(nullptr, &videoFrameRateRange_, &videoFrameRatesSize_);
2416     } else if (useCaseCode == PARAMETER2_ERROR) {
2417         ret_ = OH_VideoOutput_GetSupportedFrameRates(videoOutput_, nullptr, &videoFrameRatesSize_);
2418     } else if (useCaseCode == PARAMETER2_ERROR) {
2419         ret_ = OH_VideoOutput_GetSupportedFrameRates(videoOutput_, &videoFrameRateRange_, nullptr);
2420     }
2421     if (videoFrameRatesSize_ == 0 || ret_ != CAMERA_OK) {
2422         LOG("OH_VideoOutput_GetSupportedFrameRates failed.");
2423     }
2424     return ret_;
2425 }
VideoOutputGetActiveFrameRate(int useCaseCode)2426 Camera_ErrorCode NDKCamera::VideoOutputGetActiveFrameRate(int useCaseCode)
2427 {
2428     if (useCaseCode == PARAMETER_OK) {
2429         ret_ = OH_VideoOutput_GetActiveFrameRate(videoOutput_, &videoActiveFrameRateRange_);
2430     } else if (useCaseCode == PARAMETER1_ERROR) {
2431         ret_ = OH_VideoOutput_GetActiveFrameRate(nullptr, &videoActiveFrameRateRange_);
2432     } else if (useCaseCode == PARAMETER2_ERROR) {
2433         ret_ = OH_VideoOutput_GetActiveFrameRate(videoOutput_, nullptr);
2434     }
2435     if (ret_ != CAMERA_OK) {
2436         LOG("OH_VideoOutput_GetActiveFrameRate failed.");
2437     }
2438     return ret_;
2439 }
VideoOutputSetFrameRate(int useCaseCode)2440 Camera_ErrorCode NDKCamera::VideoOutputSetFrameRate(int useCaseCode)
2441 {
2442     uint32_t minFps = videoActiveFrameRateRange_.min;
2443     uint32_t maxFps = videoActiveFrameRateRange_.max;
2444     bool flag = false;
2445     for (uint32_t i = 0; i < videoFrameRatesSize_; i++) {
2446         if (videoFrameRateRange_[i].min != videoActiveFrameRateRange_.min ||
2447             videoFrameRateRange_[i].max != videoActiveFrameRateRange_.max) {
2448             minFps = videoFrameRateRange_[i].min;
2449             maxFps = videoFrameRateRange_[i].max;
2450             flag = true;
2451             break;
2452         }
2453     }
2454     if (!flag) {
2455         if (maxFps > minFps) {
2456             minFps++;
2457         }
2458     }
2459     if (useCaseCode == PARAMETER_OK) {
2460         if (maxFps <= minFps + INVALID_MIN_FPS) {
2461             return CAMERA_OK;
2462         }
2463         ret_ = OH_VideoOutput_SetFrameRate(videoOutput_, minFps, maxFps);
2464     } else if (useCaseCode == PARAMETER1_ERROR) {
2465         ret_ = OH_VideoOutput_SetFrameRate(nullptr, minFps, maxFps);
2466     } else if (useCaseCode == PARAMETER2_ERROR) {
2467         ret_ = OH_VideoOutput_SetFrameRate(videoOutput_, INVALID_MIN_FPS, maxFps + INVALID_MAX_FPS);
2468     }
2469     if (ret_ != CAMERA_OK) {
2470         LOG("OH_VideoOutput_SetFrameRate failed.");
2471     }
2472     return ret_;
2473 }
VideoOutputDeleteFrameRates(int useCaseCode)2474 Camera_ErrorCode NDKCamera::VideoOutputDeleteFrameRates(int useCaseCode)
2475 {
2476     if (useCaseCode == PARAMETER_OK) {
2477         ret_ = OH_VideoOutput_DeleteFrameRates(videoOutput_, videoFrameRateRange_);
2478     } else if (useCaseCode == PARAMETER1_ERROR) {
2479         ret_ = OH_VideoOutput_DeleteFrameRates(nullptr, videoFrameRateRange_);
2480     } else if (useCaseCode == PARAMETER2_ERROR) {
2481         ret_ = OH_VideoOutput_DeleteFrameRates(videoOutput_, nullptr);
2482     }
2483     if (ret_ != CAMERA_OK) {
2484         LOG("OH_VideoOutput_DeleteFrameRates failed.");
2485     }
2486     return ret_;
2487 }
CameraManagerTorchStatusCallback(Camera_Manager * cameraManager,Camera_TorchStatusInfo * status)2488 void CameraManagerTorchStatusCallback(Camera_Manager *cameraManager, Camera_TorchStatusInfo *status)
2489 {
2490     LOG("CameraManagerTorchStatusCallback");
2491 }
CameraManagerRegisterTorchStatusCallback(int useCaseCode)2492 Camera_ErrorCode NDKCamera::CameraManagerRegisterTorchStatusCallback(int useCaseCode)
2493 {
2494     if (useCaseCode == PARAMETER_OK) {
2495         ret_ = OH_CameraManager_RegisterTorchStatusCallback(cameraManager_, CameraManagerTorchStatusCallback);
2496     } else if (useCaseCode == PARAMETER1_ERROR) {
2497         ret_ = OH_CameraManager_RegisterTorchStatusCallback(nullptr, CameraManagerTorchStatusCallback);
2498     } else if (useCaseCode == PARAMETER2_ERROR) {
2499         ret_ = OH_CameraManager_RegisterTorchStatusCallback(cameraManager_, nullptr);
2500     }
2501     if (ret_ != CAMERA_OK) {
2502         LOG("OH_CameraManager_RegisterTorchStatusCallback failed.");
2503     }
2504     return ret_;
2505 }
CameraManagerUnregisterTorchStatusCallback(int useCaseCode)2506 Camera_ErrorCode NDKCamera::CameraManagerUnregisterTorchStatusCallback(int useCaseCode)
2507 {
2508     if (useCaseCode == PARAMETER_OK) {
2509         ret_ = OH_CameraManager_UnregisterTorchStatusCallback(cameraManager_, CameraManagerTorchStatusCallback);
2510     } else if (useCaseCode == PARAMETER1_ERROR) {
2511         ret_ = OH_CameraManager_UnregisterTorchStatusCallback(nullptr, CameraManagerTorchStatusCallback);
2512     } else if (useCaseCode == PARAMETER2_ERROR) {
2513         ret_ = OH_CameraManager_UnregisterTorchStatusCallback(cameraManager_, nullptr);
2514     }
2515     if (ret_ != CAMERA_OK) {
2516         LOG("OH_CameraManager_UnregisterTorchStatusCallback failed.");
2517     }
2518     return ret_;
2519 }
CaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession * session,Camera_SmoothZoomInfo * smoothZoomInfo)2520 void CaptureSessionSmoothZoomInfoCallback(Camera_CaptureSession *session, Camera_SmoothZoomInfo *smoothZoomInfo)
2521 {
2522     LOG("CaptureSessionSmoothZoomInfoCallback");
2523 }
CaptureSessionRegisterSmoothZoomInfoCallback(int useCaseCode)2524 Camera_ErrorCode NDKCamera::CaptureSessionRegisterSmoothZoomInfoCallback(int useCaseCode)
2525 {
2526     if (useCaseCode == PARAMETER_OK) {
2527         ret_ = OH_CaptureSession_RegisterSmoothZoomInfoCallback(captureSession_, CaptureSessionSmoothZoomInfoCallback);
2528     } else if (useCaseCode == PARAMETER1_ERROR) {
2529         ret_ = OH_CaptureSession_RegisterSmoothZoomInfoCallback(nullptr, CaptureSessionSmoothZoomInfoCallback);
2530     } else if (useCaseCode == PARAMETER2_ERROR) {
2531         ret_ = OH_CaptureSession_RegisterSmoothZoomInfoCallback(captureSession_, nullptr);
2532     }
2533     if (ret_ != CAMERA_OK) {
2534         LOG("OH_CaptureSession_RegisterSmoothZoomInfoCallback failed.");
2535     }
2536     return ret_;
2537 }
CaptureSessionUnregisterSmoothZoomInfoCallback(int useCaseCode)2538 Camera_ErrorCode NDKCamera::CaptureSessionUnregisterSmoothZoomInfoCallback(int useCaseCode)
2539 {
2540     if (useCaseCode == PARAMETER_OK) {
2541         ret_ = OH_CaptureSession_UnregisterSmoothZoomInfoCallback(captureSession_,
2542             CaptureSessionSmoothZoomInfoCallback);
2543     } else if (useCaseCode == PARAMETER1_ERROR) {
2544         ret_ = OH_CaptureSession_UnregisterSmoothZoomInfoCallback(nullptr, CaptureSessionSmoothZoomInfoCallback);
2545     } else if (useCaseCode == PARAMETER2_ERROR) {
2546         ret_ = OH_CaptureSession_UnregisterSmoothZoomInfoCallback(captureSession_, nullptr);
2547     }
2548     if (ret_ != CAMERA_OK) {
2549         LOG("OH_CaptureSession_UnregisterSmoothZoomInfoCallback failed.");
2550     }
2551     return ret_;
2552 }
PhotoOutputCaptureStartWithInfoCallback(Camera_PhotoOutput * photoOutput,Camera_CaptureStartInfo * Info)2553 void PhotoOutputCaptureStartWithInfoCallback(Camera_PhotoOutput* photoOutput, Camera_CaptureStartInfo* Info)
2554 {
2555     LOG("PhotoOutputCaptureStartWithInfoCallback");
2556 }
PhotoOutputRegisterCaptureStartWithInfoCallback(int useCaseCode)2557 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCaptureStartWithInfoCallback(int useCaseCode)
2558 {
2559     if (useCaseCode == PARAMETER_OK) {
2560         ret_ = OH_PhotoOutput_RegisterCaptureStartWithInfoCallback(photoOutput_,
2561             PhotoOutputCaptureStartWithInfoCallback);
2562     } else if (useCaseCode == PARAMETER1_ERROR) {
2563         ret_ = OH_PhotoOutput_RegisterCaptureStartWithInfoCallback(nullptr, PhotoOutputCaptureStartWithInfoCallback);
2564     } else if (useCaseCode == PARAMETER2_ERROR) {
2565         ret_ = OH_PhotoOutput_RegisterCaptureStartWithInfoCallback(photoOutput_, nullptr);
2566     }
2567     if (ret_ != CAMERA_OK) {
2568         LOG("OH_PhotoOutput_RegisterCaptureStartWithInfoCallback failed.");
2569     }
2570     return ret_;
2571 }
PhotoOutputUnregisterCaptureStartWithInfoCallback(int useCaseCode)2572 Camera_ErrorCode NDKCamera::PhotoOutputUnregisterCaptureStartWithInfoCallback(int useCaseCode)
2573 {
2574     if (useCaseCode == PARAMETER_OK) {
2575         ret_ = OH_PhotoOutput_UnregisterCaptureStartWithInfoCallback(photoOutput_,
2576             PhotoOutputCaptureStartWithInfoCallback);
2577     } else if (useCaseCode == PARAMETER1_ERROR) {
2578         ret_ = OH_PhotoOutput_UnregisterCaptureStartWithInfoCallback(nullptr, PhotoOutputCaptureStartWithInfoCallback);
2579     } else if (useCaseCode == PARAMETER2_ERROR) {
2580         ret_ = OH_PhotoOutput_UnregisterCaptureStartWithInfoCallback(photoOutput_, nullptr);
2581     }
2582     if (ret_ != CAMERA_OK) {
2583         LOG("OH_PhotoOutput_UnregisterCaptureStartWithInfoCallback failed.");
2584     }
2585     return ret_;
2586 }
PhotoOutputCaptureEndCallback(Camera_PhotoOutput * photoOutput,int32_t frameCount)2587 void PhotoOutputCaptureEndCallback(Camera_PhotoOutput* photoOutput, int32_t frameCount)
2588 {
2589     LOG("PhotoOutputCaptureEndCallback");
2590 }
PhotoOutputRegisterCaptureEndCallback(int useCaseCode)2591 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCaptureEndCallback(int useCaseCode)
2592 {
2593     if (useCaseCode == PARAMETER_OK) {
2594         ret_ = OH_PhotoOutput_RegisterCaptureEndCallback(photoOutput_, PhotoOutputCaptureEndCallback);
2595     } else if (useCaseCode == PARAMETER1_ERROR) {
2596         ret_ = OH_PhotoOutput_RegisterCaptureEndCallback(nullptr, PhotoOutputCaptureEndCallback);
2597     } else if (useCaseCode == PARAMETER2_ERROR) {
2598         ret_ = OH_PhotoOutput_RegisterCaptureEndCallback(photoOutput_, nullptr);
2599     }
2600     if (ret_ != CAMERA_OK) {
2601         LOG("OH_PhotoOutput_RegisterCaptureEndCallback failed.");
2602     }
2603     return ret_;
2604 }
PhotoOutputUnregisterCaptureEndCallback(int useCaseCode)2605 Camera_ErrorCode NDKCamera::PhotoOutputUnregisterCaptureEndCallback(int useCaseCode)
2606 {
2607     if (useCaseCode == PARAMETER_OK) {
2608         ret_ = OH_PhotoOutput_UnregisterCaptureEndCallback(photoOutput_, PhotoOutputCaptureEndCallback);
2609     } else if (useCaseCode == PARAMETER1_ERROR) {
2610         ret_ = OH_PhotoOutput_UnregisterCaptureEndCallback(nullptr, PhotoOutputCaptureEndCallback);
2611     } else if (useCaseCode == PARAMETER2_ERROR) {
2612         ret_ = OH_PhotoOutput_UnregisterCaptureEndCallback(photoOutput_, nullptr);
2613     }
2614     if (ret_ != CAMERA_OK) {
2615         LOG("CaptureSessionUnregisterSmoothZoomInfoCallback failed.");
2616     }
2617     return ret_;
2618 }
PhotoOutputFrameShutterEndCallback(Camera_PhotoOutput * photoOutput,Camera_FrameShutterInfo * Info)2619 void PhotoOutputFrameShutterEndCallback(Camera_PhotoOutput* photoOutput, Camera_FrameShutterInfo* Info)
2620 {
2621     LOG("PhotoOutputFrameShutterEndCallback");
2622 }
PhotoOutputRegisterFrameShutterEndCallback(int useCaseCode)2623 Camera_ErrorCode NDKCamera::PhotoOutputRegisterFrameShutterEndCallback(int useCaseCode)
2624 {
2625     if (useCaseCode == PARAMETER_OK) {
2626         ret_ = OH_PhotoOutput_RegisterFrameShutterEndCallback(photoOutput_, PhotoOutputFrameShutterEndCallback);
2627     } else if (useCaseCode == PARAMETER1_ERROR) {
2628         ret_ = OH_PhotoOutput_RegisterFrameShutterEndCallback(nullptr, PhotoOutputFrameShutterEndCallback);
2629     } else if (useCaseCode == PARAMETER2_ERROR) {
2630         ret_ = OH_PhotoOutput_RegisterFrameShutterEndCallback(photoOutput_, nullptr);
2631     }
2632     if (ret_ != CAMERA_OK) {
2633         LOG("OH_PhotoOutput_RegisterFrameShutterEndCallback failed.");
2634     }
2635     return ret_;
2636 }
PhotoOutputUnregisterFrameShutterEndCallback(int useCaseCode)2637 Camera_ErrorCode NDKCamera::PhotoOutputUnregisterFrameShutterEndCallback(int useCaseCode)
2638 {
2639     if (useCaseCode == PARAMETER_OK) {
2640         ret_ = OH_PhotoOutput_UnregisterFrameShutterEndCallback(photoOutput_, PhotoOutputFrameShutterEndCallback);
2641     } else if (useCaseCode == PARAMETER1_ERROR) {
2642         ret_ = OH_PhotoOutput_UnregisterFrameShutterEndCallback(nullptr, PhotoOutputFrameShutterEndCallback);
2643     } else if (useCaseCode == PARAMETER2_ERROR) {
2644         ret_ = OH_PhotoOutput_UnregisterFrameShutterEndCallback(photoOutput_, nullptr);
2645     }
2646     if (ret_ != CAMERA_OK) {
2647         LOG("OH_PhotoOutput_UnregisterFrameShutterEndCallback failed.");
2648     }
2649     return ret_;
2650 }
PhotoOutputCaptureReadyCallback(Camera_PhotoOutput * photoOutput)2651 void PhotoOutputCaptureReadyCallback(Camera_PhotoOutput* photoOutput)
2652 {
2653     LOG("PhotoOutputCaptureReadyCallback");
2654 }
PhotoOutputRegisterCaptureReadyCallback(int useCaseCode)2655 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCaptureReadyCallback(int useCaseCode)
2656 {
2657     if (useCaseCode == PARAMETER_OK) {
2658         ret_ = OH_PhotoOutput_RegisterCaptureReadyCallback(photoOutput_, PhotoOutputCaptureReadyCallback);
2659     } else if (useCaseCode == PARAMETER1_ERROR) {
2660         ret_ = OH_PhotoOutput_RegisterCaptureReadyCallback(nullptr, PhotoOutputCaptureReadyCallback);
2661     } else if (useCaseCode == PARAMETER2_ERROR) {
2662         ret_ = OH_PhotoOutput_RegisterCaptureReadyCallback(photoOutput_, nullptr);
2663     }
2664     if (ret_ != CAMERA_OK) {
2665         LOG("OH_PhotoOutput_RegisterCaptureReadyCallback failed.");
2666     }
2667     return ret_;
2668 }
PhotoOutputUnregisterCaptureReadyCallback(int useCaseCode)2669 Camera_ErrorCode NDKCamera::PhotoOutputUnregisterCaptureReadyCallback(int useCaseCode)
2670 {
2671     if (useCaseCode == PARAMETER_OK) {
2672         ret_ = OH_PhotoOutput_UnregisterCaptureReadyCallback(photoOutput_, PhotoOutputCaptureReadyCallback);
2673     } else if (useCaseCode == PARAMETER1_ERROR) {
2674         ret_ = OH_PhotoOutput_UnregisterCaptureReadyCallback(nullptr, PhotoOutputCaptureReadyCallback);
2675     } else if (useCaseCode == PARAMETER2_ERROR) {
2676         ret_ = OH_PhotoOutput_UnregisterCaptureReadyCallback(photoOutput_, nullptr);
2677     }
2678     if (ret_ != CAMERA_OK) {
2679         LOG("OH_PhotoOutput_UnregisterCaptureReadyCallback failed.");
2680     }
2681     return ret_;
2682 }
PhotoOutputEstimatedCaptureDurationCallback(Camera_PhotoOutput * photoOutput,int64_t duration)2683 void PhotoOutputEstimatedCaptureDurationCallback(Camera_PhotoOutput* photoOutput, int64_t duration)
2684 {
2685     LOG("PhotoOutputEstimatedCaptureDurationCallback");
2686 }
PhotoOutputRegisterEstimatedCaptureDurationCallback(int useCaseCode)2687 Camera_ErrorCode NDKCamera::PhotoOutputRegisterEstimatedCaptureDurationCallback(int useCaseCode)
2688 {
2689     if (useCaseCode == PARAMETER_OK) {
2690         ret_ = OH_PhotoOutput_RegisterEstimatedCaptureDurationCallback(photoOutput_,
2691             PhotoOutputEstimatedCaptureDurationCallback);
2692     } else if (useCaseCode == PARAMETER1_ERROR) {
2693         ret_ = OH_PhotoOutput_RegisterEstimatedCaptureDurationCallback(nullptr,
2694             PhotoOutputEstimatedCaptureDurationCallback);
2695     } else if (useCaseCode == PARAMETER2_ERROR) {
2696         ret_ = OH_PhotoOutput_RegisterEstimatedCaptureDurationCallback(photoOutput_, nullptr);
2697     }
2698     if (ret_ != CAMERA_OK) {
2699         LOG("OH_PhotoOutput_RegisterEstimatedCaptureDurationCallback failed.");
2700     }
2701     return ret_;
2702 }
PhotoOutputUnregisterEstimatedCaptureDurationCallback(int useCaseCode)2703 Camera_ErrorCode NDKCamera::PhotoOutputUnregisterEstimatedCaptureDurationCallback(int useCaseCode)
2704 {
2705     if (useCaseCode == PARAMETER_OK) {
2706         ret_ = OH_PhotoOutput_UnregisterEstimatedCaptureDurationCallback(photoOutput_,
2707             PhotoOutputEstimatedCaptureDurationCallback);
2708     } else if (useCaseCode == PARAMETER1_ERROR) {
2709         ret_ = OH_PhotoOutput_UnregisterEstimatedCaptureDurationCallback(nullptr,
2710             PhotoOutputEstimatedCaptureDurationCallback);
2711     } else if (useCaseCode == PARAMETER2_ERROR) {
2712         ret_ = OH_PhotoOutput_UnregisterEstimatedCaptureDurationCallback(photoOutput_, nullptr);
2713     }
2714     if (ret_ != CAMERA_OK) {
2715         LOG("OH_PhotoOutput_UnregisterEstimatedCaptureDurationCallback failed.");
2716     }
2717     return ret_;
2718 }
ReadyCreatePhotoOutputWithoutSurface()2719 Camera_ErrorCode NDKCamera::ReadyCreatePhotoOutputWithoutSurface()
2720 {
2721     isCreatePhotoOutputWithoutSurface_ = true;
2722     return CAMERA_OK;
2723 }
2724 
IsAutoDeviceSwitchSupported(bool * isSupported)2725 Camera_ErrorCode NDKCamera::IsAutoDeviceSwitchSupported(bool* isSupported)
2726 {
2727     ret_ = OH_CaptureSession_IsAutoDeviceSwitchSupported(captureSession_, isSupported);
2728     if (ret_ != CAMERA_OK) {
2729         LOG("OH_CaptureSession_IsAutoDeviceSwitchSupported failed.");
2730     }
2731     return ret_;
2732 }
2733 
EnableAutoDeviceSwitch(bool isEnable)2734 Camera_ErrorCode NDKCamera::EnableAutoDeviceSwitch(bool isEnable)
2735 {
2736     ret_ = OH_CaptureSession_EnableAutoDeviceSwitch(captureSession_, isEnable);
2737     if (ret_ != CAMERA_OK) {
2738         LOG("OH_PhotoOutput_UnregisterEstimatedCaptureDurationCallback failed.");
2739     }
2740     return ret_;
2741 }
2742 
CameraAutoDeviceSwitchStatusInfoCallback(Camera_CaptureSession * session,Camera_AutoDeviceSwitchStatusInfo * autoDeviceSwitchStatusInfo)2743 void CameraAutoDeviceSwitchStatusInfoCallback(Camera_CaptureSession* session,
2744     Camera_AutoDeviceSwitchStatusInfo* autoDeviceSwitchStatusInfo)
2745 {
2746     LOG("CameraAutoDeviceSwitchStatusInfoCallback is called.");
2747 }
RegisterAutoDeviceSwitchStatusCallback(int useCaseCode)2748 Camera_ErrorCode NDKCamera::RegisterAutoDeviceSwitchStatusCallback(int useCaseCode)
2749 {
2750     if (useCaseCode == PARAMETER_OK) {
2751         ret_ = OH_CaptureSession_RegisterAutoDeviceSwitchStatusCallback(captureSession_,
2752             CameraAutoDeviceSwitchStatusInfoCallback);
2753     } else if (useCaseCode == PARAMETER1_ERROR) {
2754         ret_ = OH_CaptureSession_RegisterAutoDeviceSwitchStatusCallback(nullptr,
2755             CameraAutoDeviceSwitchStatusInfoCallback);
2756     } else if (useCaseCode == PARAMETER2_ERROR) {
2757         ret_ = OH_CaptureSession_RegisterAutoDeviceSwitchStatusCallback(captureSession_, nullptr);
2758     }
2759     if (ret_ != CAMERA_OK) {
2760         LOG("OH_CaptureSession_RegisterAutoDeviceSwitchStatusCallback failed.");
2761     }
2762     return ret_;
2763 }
2764 
UnegisterAutoDeviceSwitchStatusCallback(int useCaseCode)2765 Camera_ErrorCode NDKCamera::UnegisterAutoDeviceSwitchStatusCallback(int useCaseCode)
2766 {
2767     if (useCaseCode == PARAMETER_OK) {
2768         ret_ = OH_CaptureSession_UnregisterAutoDeviceSwitchStatusCallback(captureSession_,
2769             CameraAutoDeviceSwitchStatusInfoCallback);
2770     } else if (useCaseCode == PARAMETER1_ERROR) {
2771         ret_ = OH_CaptureSession_UnregisterAutoDeviceSwitchStatusCallback(nullptr,
2772             CameraAutoDeviceSwitchStatusInfoCallback);
2773     } else if (useCaseCode == PARAMETER2_ERROR) {
2774         ret_ = OH_CaptureSession_UnregisterAutoDeviceSwitchStatusCallback(captureSession_, nullptr);
2775     }
2776     if (ret_ != CAMERA_OK) {
2777         LOG("OH_CaptureSession_UnregisterAutoDeviceSwitchStatusCallback failed.");
2778     }
2779     return ret_;
2780 }
2781 
CameraFoldStatusInfoCallback(Camera_Manager * cameraManager,Camera_FoldStatusInfo * foldStatusInfo)2782 void CameraFoldStatusInfoCallback(Camera_Manager *cameraManager, Camera_FoldStatusInfo *foldStatusInfo)
2783 {
2784     LOG("CameraFoldStatusInfoCallback is called.");
2785 }
2786 
CameraManagerRegisterFoldStatusCallback(int useCaseCode)2787 Camera_ErrorCode NDKCamera::CameraManagerRegisterFoldStatusCallback(int useCaseCode)
2788 {
2789     if (useCaseCode == PARAMETER_OK) {
2790         ret_ = OH_CameraManager_RegisterFoldStatusInfoCallback(cameraManager_, CameraFoldStatusInfoCallback);
2791     } else if (useCaseCode == PARAMETER1_ERROR) {
2792         ret_ = OH_CameraManager_RegisterFoldStatusInfoCallback(nullptr, CameraFoldStatusInfoCallback);
2793     } else {
2794         ret_ = OH_CameraManager_RegisterFoldStatusInfoCallback(cameraManager_, nullptr);
2795     }
2796     return ret_;
2797 }
2798 
CameraManagerUnregisterFoldStatusCallback(int useCaseCode)2799 Camera_ErrorCode NDKCamera::CameraManagerUnregisterFoldStatusCallback(int useCaseCode)
2800 {
2801     if (useCaseCode == PARAMETER_OK) {
2802         ret_ = OH_CameraManager_UnregisterFoldStatusInfoCallback(cameraManager_, CameraFoldStatusInfoCallback);
2803     } else if (useCaseCode == PARAMETER1_ERROR) {
2804         ret_ = OH_CameraManager_UnregisterFoldStatusInfoCallback(nullptr, CameraFoldStatusInfoCallback);
2805     } else {
2806         ret_ = OH_CameraManager_UnregisterFoldStatusInfoCallback(cameraManager_, nullptr);
2807     }
2808     return ret_;
2809 }
2810