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