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