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