1 /*
2 * Copyright (c) 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.h"
17
18 #define LOG_TAG "DEMO:"
19 #define LOG_DOMAIN 0x3200
20
21 namespace OHOS_CAMERA_SAMPLE {
22 NDKCamera *NDKCamera::ndkCamera_ = nullptr;
23 std::mutex NDKCamera::mtx_;
24
NDKCamera(char * str,uint32_t focusMode,uint32_t cameraDeviceIndex)25 NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex)
26 : previewSurfaceId_(str), cameras_(nullptr), focusMode_(focusMode), cameraDeviceIndex_(cameraDeviceIndex),
27 cameraOutputCapability_(nullptr), cameraInput_(nullptr), captureSession_(nullptr), size_(0),
28 isCameraMuted_(nullptr), profile_(nullptr), photoSurfaceId_(nullptr), previewOutput_(nullptr),
29 photoOutput_(nullptr), metaDataObjectType_(nullptr), metadataOutput_(nullptr),
30 isExposureModeSupported_(false), isFocusModeSupported_(false), exposureMode_(EXPOSURE_MODE_LOCKED),
31 minExposureBias_(0), maxExposureBias_(0), step_(0), ret_(CAMERA_OK) {
32 valid_ = false;
33 ReleaseCamera();
34 Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager_);
35 if (cameraManager_ == nullptr || ret != CAMERA_OK) {
36 OH_LOG_ERROR(LOG_APP, "Get CameraManager failed.");
37 }
38
39 ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_);
40 if (captureSession_ == nullptr || ret != CAMERA_OK) {
41 OH_LOG_ERROR(LOG_APP, "Create captureSession failed.");
42 }
43 CaptureSessionRegisterCallback();
44 GetSupportedCameras();
45 GetSupportedOutputCapability();
46 CreatePreviewOutput();
47 CreateCameraInput();
48 CameraInputOpen();
49 CameraManagerRegisterCallback();
50 SessionFlowFn();
51 valid_ = true;
52 }
53
~NDKCamera()54 NDKCamera::~NDKCamera()
55 {
56 valid_ = false;
57 OH_LOG_ERROR(LOG_APP, "~NDKCamera");
58 Camera_ErrorCode ret = CAMERA_OK;
59
60 if (cameraManager_) {
61 OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. enter");
62 ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_);
63 if (ret != CAMERA_OK) {
64 OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed.");
65 } else {
66 OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok");
67 }
68
69 OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. enter");
70 ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_);
71 if (ret != CAMERA_OK) {
72 OH_LOG_ERROR(LOG_APP, "Delete Cameras failed.");
73 } else {
74 OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. ok");
75 }
76
77 ret = OH_Camera_DeleteCameraManager(cameraManager_);
78 if (ret != CAMERA_OK) {
79 OH_LOG_ERROR(LOG_APP, "Delete CameraManager failed.");
80 } else {
81 OH_LOG_ERROR(LOG_APP, "Release OH_Camera_DeleteCameraMananger. ok");
82 }
83 cameraManager_ = nullptr;
84 }
85 OH_LOG_ERROR(LOG_APP, "~NDKCamera exit");
86 }
87
ReleaseCamera(void)88 Camera_ErrorCode NDKCamera::ReleaseCamera(void)
89 {
90 OH_LOG_ERROR(LOG_APP, " enter ReleaseCamera");
91 if (previewOutput_) {
92 PreviewOutputStop();
93 PreviewOutputRelease();
94 OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_);
95 }
96 if (photoOutput_) {
97 PhotoOutputRelease();
98 }
99 if (captureSession_) {
100 SessionRealese();
101 }
102 if (cameraInput_) {
103 CameraInputClose();
104 }
105 OH_LOG_ERROR(LOG_APP, " exit ReleaseCamera");
106 return ret_;
107 }
108
ReleaseSession(void)109 Camera_ErrorCode NDKCamera::ReleaseSession(void)
110 {
111 OH_LOG_ERROR(LOG_APP, " enter ReleaseSession");
112 PreviewOutputStop();
113 PhotoOutputRelease();
114 SessionRealese();
115 OH_LOG_ERROR(LOG_APP, " exit ReleaseSession");
116 return ret_;
117 }
118
SessionRealese(void)119 Camera_ErrorCode NDKCamera::SessionRealese(void)
120 {
121 OH_LOG_ERROR(LOG_APP, " enter SessionRealese");
122 Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_);
123 captureSession_ = nullptr;
124 OH_LOG_ERROR(LOG_APP, " exit SessionRealese");
125 return ret;
126 }
127
HasFlashFn(uint32_t mode)128 Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode)
129 {
130 Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
131 // Check for flashing lights
132 bool hasFlash = false;
133 Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash);
134 if (captureSession_ == nullptr || ret != CAMERA_OK) {
135 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed.");
136 }
137 if (hasFlash) {
138 OH_LOG_INFO(LOG_APP, "hasFlash success-----");
139 } else {
140 OH_LOG_ERROR(LOG_APP, "hasFlash fail-----");
141 }
142
143 // Check if the flash mode is supported
144 bool isSupported = false;
145 ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported);
146 if (ret != CAMERA_OK) {
147 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed.");
148 }
149 if (isSupported) {
150 OH_LOG_INFO(LOG_APP, "isFlashModeSupported success-----");
151 } else {
152 OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail-----");
153 }
154
155 // Set flash mode
156 ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode);
157 if (ret == CAMERA_OK) {
158 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success.");
159 } else {
160 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret);
161 }
162
163 // Obtain the flash mode of the current device
164 ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode);
165 if (ret == CAMERA_OK) {
166 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success. flashMode:%{public}d ", flashMode);
167 } else {
168 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode failed. %d ", ret);
169 }
170 return ret;
171 }
172
IsVideoStabilizationModeSupportedFn(uint32_t mode)173 Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode)
174 {
175 Camera_VideoStabilizationMode videoMode = static_cast<Camera_VideoStabilizationMode>(mode);
176 // Check if the specified video anti shake mode is supported
177 bool isSupported = false;
178 Camera_ErrorCode ret =
179 OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isSupported);
180 if (ret != CAMERA_OK) {
181 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported failed.");
182 }
183 if (isSupported) {
184 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported success-----");
185 } else {
186 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported fail-----");
187 }
188
189 // Set video stabilization
190 ret = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode);
191 if (ret == CAMERA_OK) {
192 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode success.");
193 } else {
194 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode failed. %{public}d ", ret);
195 }
196
197 ret = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode);
198 if (ret == CAMERA_OK) {
199 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode success. videoMode:%{public}f ",
200 videoMode);
201 } else {
202 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode failed. %{public}d ", ret);
203 }
204 return ret;
205 }
206
setZoomRatioFn(uint32_t zoomRatio)207 Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio)
208 {
209 float zoom = float(zoomRatio);
210 // Obtain supported zoom range
211 float minZoom;
212 float maxZoom;
213 Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom);
214 if (captureSession_ == nullptr || ret != CAMERA_OK) {
215 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed.");
216 } else {
217 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f",
218 minZoom, maxZoom);
219 }
220
221 // Set Zoom
222 ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom);
223 if (ret == CAMERA_OK) {
224 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success.");
225 } else {
226 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret);
227 }
228
229 // Obtain the zoom value of the current device
230 ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom);
231 if (ret == CAMERA_OK) {
232 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom:%{public}f ", zoom);
233 } else {
234 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret);
235 }
236 return ret;
237 }
238
SessionBegin(void)239 Camera_ErrorCode NDKCamera::SessionBegin(void)
240 {
241 Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_);
242 if (ret == CAMERA_OK) {
243 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_BeginConfig success.");
244 } else {
245 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_BeginConfig failed. %d ", ret);
246 }
247 return ret;
248 }
249
SessionCommitConfig(void)250 Camera_ErrorCode NDKCamera::SessionCommitConfig(void)
251 {
252 Camera_ErrorCode ret = OH_CaptureSession_CommitConfig(captureSession_);
253 if (ret == CAMERA_OK) {
254 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_CommitConfig success.");
255 } else {
256 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_CommitConfig failed. %d ", ret);
257 }
258 return ret;
259 }
260
SessionStart(void)261 Camera_ErrorCode NDKCamera::SessionStart(void)
262 {
263 Camera_ErrorCode ret = OH_CaptureSession_Start(captureSession_);
264 if (ret == CAMERA_OK) {
265 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Start success.");
266 } else {
267 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Start failed. %d ", ret);
268 }
269 return ret;
270 }
271
SessionStop(void)272 Camera_ErrorCode NDKCamera::SessionStop(void)
273 {
274 Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_);
275 if (ret == CAMERA_OK) {
276 OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Stop success.");
277 } else {
278 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Stop failed. %d ", ret);
279 }
280 return ret;
281 }
282
SessionFlowFn(void)283 Camera_ErrorCode NDKCamera::SessionFlowFn(void)
284 {
285 OH_LOG_INFO(LOG_APP, "Start SessionFlowFn IN.");
286 // Start configuring session
287 OH_LOG_INFO(LOG_APP, "session beginConfig.");
288 Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_);
289
290 // Add CameraInput to the session
291 OH_LOG_INFO(LOG_APP, "session addInput.");
292 ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_);
293
294 // Add previewOutput to the session
295 OH_LOG_INFO(LOG_APP, "session add Preview Output.");
296 ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_);
297
298 // Adding PhotoOutput to the Session
299 OH_LOG_INFO(LOG_APP, "session add Photo Output.");
300
301 // Submit configuration information
302 OH_LOG_INFO(LOG_APP, "session commitConfig");
303 ret = OH_CaptureSession_CommitConfig(captureSession_);
304
305 // Start Session Work
306 OH_LOG_INFO(LOG_APP, "session start");
307 ret = OH_CaptureSession_Start(captureSession_);
308 OH_LOG_INFO(LOG_APP, "session success");
309
310 // Start focusing
311 OH_LOG_INFO(LOG_APP, "IsFocusMode start");
312 ret = IsFocusMode(focusMode_);
313 OH_LOG_INFO(LOG_APP, "IsFocusMode success");
314 return ret;
315 }
316
CreateCameraInput(void)317 Camera_ErrorCode NDKCamera::CreateCameraInput(void)
318 {
319 OH_LOG_ERROR(LOG_APP, "enter CreateCameraInput.");
320 ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, &cameras_[cameraDeviceIndex_], &cameraInput_);
321 if (cameraInput_ == nullptr || ret_ != CAMERA_OK) {
322 OH_LOG_ERROR(LOG_APP, "CreateCameraInput failed.");
323 return CAMERA_INVALID_ARGUMENT;
324 }
325 OH_LOG_ERROR(LOG_APP, "exit CreateCameraInput.");
326 CameraInputRegisterCallback();
327 return ret_;
328 }
329
CameraInputOpen(void)330 Camera_ErrorCode NDKCamera::CameraInputOpen(void)
331 {
332 OH_LOG_ERROR(LOG_APP, "enter CameraInputOpen.");
333 ret_ = OH_CameraInput_Open(cameraInput_);
334 if (ret_ != CAMERA_OK) {
335 OH_LOG_ERROR(LOG_APP, "CameraInput_Open failed.");
336 return CAMERA_INVALID_ARGUMENT;
337 }
338 OH_LOG_ERROR(LOG_APP, "exit CameraInputOpen.");
339 return ret_;
340 }
341
CameraInputClose(void)342 Camera_ErrorCode NDKCamera::CameraInputClose(void)
343 {
344 OH_LOG_ERROR(LOG_APP, "enter CameraInput_Close.");
345 ret_ = OH_CameraInput_Close(cameraInput_);
346 if (ret_ != CAMERA_OK) {
347 OH_LOG_ERROR(LOG_APP, "CameraInput_Close failed.");
348 return CAMERA_INVALID_ARGUMENT;
349 }
350 OH_LOG_ERROR(LOG_APP, "exit CameraInput_Close.");
351 return ret_;
352 }
353
CameraInputRelease(void)354 Camera_ErrorCode NDKCamera::CameraInputRelease(void)
355 {
356 OH_LOG_ERROR(LOG_APP, "enter CameraInputRelease.");
357 ret_ = OH_CameraInput_Release(cameraInput_);
358 if (ret_ != CAMERA_OK) {
359 OH_LOG_ERROR(LOG_APP, "CameraInput_Release failed.");
360 return CAMERA_INVALID_ARGUMENT;
361 }
362 OH_LOG_ERROR(LOG_APP, "exit CameraInputRelease.");
363 return ret_;
364 }
365
GetSupportedCameras(void)366 Camera_ErrorCode NDKCamera::GetSupportedCameras(void)
367 {
368 ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, &size_);
369 if (cameras_ == nullptr || &size_ == nullptr || ret_ != CAMERA_OK) {
370 OH_LOG_ERROR(LOG_APP, "Get supported cameras failed.");
371 return CAMERA_INVALID_ARGUMENT;
372 }
373 return ret_;
374 }
375
GetSupportedOutputCapability(void)376 Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void)
377 {
378 ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, &cameras_[cameraDeviceIndex_],
379 &cameraOutputCapability_);
380 if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) {
381 OH_LOG_ERROR(LOG_APP, "GetSupportedCameraOutputCapability failed.");
382 return CAMERA_INVALID_ARGUMENT;
383 }
384 return ret_;
385 }
386
CreatePreviewOutput(void)387 Camera_ErrorCode NDKCamera::CreatePreviewOutput(void)
388 {
389 profile_ = cameraOutputCapability_->previewProfiles[0];
390 if (profile_ == nullptr) {
391 OH_LOG_ERROR(LOG_APP, "Get previewProfiles failed.");
392 return CAMERA_INVALID_ARGUMENT;
393 }
394 ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_);
395 if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) {
396 OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed.");
397 return CAMERA_INVALID_ARGUMENT;
398 }
399 return ret_;
400 PreviewOutputRegisterCallback();
401 }
402
CreatePhotoOutput(char * photoSurfaceId)403 Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId)
404 {
405 profile_ = cameraOutputCapability_->photoProfiles[0];
406 if (profile_ == nullptr) {
407 OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed.");
408 return CAMERA_INVALID_ARGUMENT;
409 }
410
411 if (photoSurfaceId == nullptr) {
412 OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed.");
413 return CAMERA_INVALID_ARGUMENT;
414 }
415
416 ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_);
417 PhotoOutputRegisterCallback();
418 return ret_;
419 }
420
CreateVideoOutput(char * videoId)421 Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId)
422 {
423 videoProfile_ = cameraOutputCapability_->videoProfiles[0];
424
425 if (videoProfile_ == nullptr) {
426 OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed.");
427 return CAMERA_INVALID_ARGUMENT;
428 }
429 ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_);
430 if (videoId == nullptr || videoOutput_ == nullptr || ret_ != CAMERA_OK) {
431 OH_LOG_ERROR(LOG_APP, "CreateVideoOutput failed.");
432 return CAMERA_INVALID_ARGUMENT;
433 }
434
435 return ret_;
436 }
437
AddVideoOutput(void)438 Camera_ErrorCode NDKCamera::AddVideoOutput(void)
439 {
440 Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_);
441 if (ret == CAMERA_OK) {
442 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddVideoOutput success.");
443 } else {
444 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddVideoOutput failed. %d ", ret);
445 }
446 return ret;
447 }
448
AddPhotoOutput()449 Camera_ErrorCode NDKCamera::AddPhotoOutput()
450 {
451 Camera_ErrorCode ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_);
452 if (ret == CAMERA_OK) {
453 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput success.");
454 } else {
455 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed. %d ", ret);
456 }
457 return ret;
458 }
459
CreateMetadataOutput(void)460 Camera_ErrorCode NDKCamera::CreateMetadataOutput(void)
461 {
462 metaDataObjectType_ = cameraOutputCapability_->supportedMetadataObjectTypes[0];
463 if (metaDataObjectType_ == nullptr) {
464 OH_LOG_ERROR(LOG_APP, "Get metaDataObjectType failed.");
465 return CAMERA_INVALID_ARGUMENT;
466 }
467 ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, &metadataOutput_);
468 if (metadataOutput_ == nullptr || ret_ != CAMERA_OK) {
469 OH_LOG_ERROR(LOG_APP, "CreateMetadataOutput failed.");
470 return CAMERA_INVALID_ARGUMENT;
471 }
472 MetadataOutputRegisterCallback();
473 return ret_;
474 }
475
IsCameraMuted(void)476 Camera_ErrorCode NDKCamera::IsCameraMuted(void)
477 {
478 ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, isCameraMuted_);
479 if (isCameraMuted_ == nullptr || ret_ != CAMERA_OK) {
480 OH_LOG_ERROR(LOG_APP, "IsCameraMuted failed.");
481 return CAMERA_INVALID_ARGUMENT;
482 }
483 return ret_;
484 }
485
PreviewOutputStop(void)486 Camera_ErrorCode NDKCamera::PreviewOutputStop(void)
487 {
488 OH_LOG_ERROR(LOG_APP, "enter PreviewOutputStop.");
489 ret_ = OH_PreviewOutput_Stop(previewOutput_);
490 if (ret_ != CAMERA_OK) {
491 OH_LOG_ERROR(LOG_APP, "PreviewOutputStop failed.");
492 return CAMERA_INVALID_ARGUMENT;
493 }
494 return ret_;
495 }
496
PreviewOutputRelease(void)497 Camera_ErrorCode NDKCamera::PreviewOutputRelease(void)
498 {
499 OH_LOG_ERROR(LOG_APP, "enter PreviewOutputRelease.");
500 ret_ = OH_PreviewOutput_Release(previewOutput_);
501 if (ret_ != CAMERA_OK) {
502 OH_LOG_ERROR(LOG_APP, "PreviewOutputRelease failed.");
503 return CAMERA_INVALID_ARGUMENT;
504 }
505 return ret_;
506 }
507
PhotoOutputRelease(void)508 Camera_ErrorCode NDKCamera::PhotoOutputRelease(void)
509 {
510 OH_LOG_ERROR(LOG_APP, "enter PhotoOutputRelease.");
511 ret_ = OH_PhotoOutput_Release(photoOutput_);
512 if (ret_ != CAMERA_OK) {
513 OH_LOG_ERROR(LOG_APP, "PhotoOutputRelease failed.");
514 return CAMERA_INVALID_ARGUMENT;
515 }
516 return ret_;
517 }
518
StartVideo(char * videoId,char * photoId)519 Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId)
520 {
521 OH_LOG_INFO(LOG_APP, "StartVideo begin.");
522 Camera_ErrorCode ret = SessionStop();
523 if (ret == CAMERA_OK) {
524 OH_LOG_INFO(LOG_APP, "SessionStop success.");
525 } else {
526 OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret);
527 }
528 ret = SessionBegin();
529 if (ret == CAMERA_OK) {
530 OH_LOG_INFO(LOG_APP, "SessionBegin success.");
531 } else {
532 OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret);
533 }
534 OH_CaptureSession_RemovePhotoOutput(captureSession_, photoOutput_);
535 CreatePhotoOutput(photoId);
536 AddPhotoOutput();
537 CreateVideoOutput(videoId);
538 AddVideoOutput();
539 SessionCommitConfig();
540 SessionStart();
541 VideoOutputRegisterCallback();
542 return ret;
543 }
544
VideoOutputStart(void)545 Camera_ErrorCode NDKCamera::VideoOutputStart(void)
546 {
547 OH_LOG_INFO(LOG_APP, "VideoOutputStart begin.");
548 Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_);
549 if (ret == CAMERA_OK) {
550 OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start success.");
551 } else {
552 OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_Start failed. %d ", ret);
553 }
554 return ret;
555 }
556
StartPhoto(char * mSurfaceId)557 Camera_ErrorCode NDKCamera::StartPhoto(char *mSurfaceId)
558 {
559 Camera_ErrorCode ret = CAMERA_OK;
560 if (takePictureTimes == 0) {
561 ret = SessionStop();
562 if (ret == CAMERA_OK) {
563 OH_LOG_INFO(LOG_APP, "SessionStop success.");
564 } else {
565 OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret);
566 }
567 ret = SessionBegin();
568 if (ret == CAMERA_OK) {
569 OH_LOG_INFO(LOG_APP, "SessionBegin success.");
570 } else {
571 OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret);
572 }
573 OH_LOG_INFO(LOG_APP, "startPhoto begin.");
574 ret = CreatePhotoOutput(mSurfaceId);
575
576 OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret);
577 ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_);
578 OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret);
579 ret = SessionCommitConfig();
580
581 OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret);
582 ret = SessionStart();
583 OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret);
584 }
585 ret = TakePicture();
586 OH_LOG_INFO(LOG_APP, "startPhoto OH_PhotoOutput_Capture ret = %{public}d.", ret);
587 if (ret_ != CAMERA_OK) {
588 OH_LOG_ERROR(LOG_APP, "startPhoto failed.");
589 return CAMERA_INVALID_ARGUMENT;
590 }
591 takePictureTimes++;
592 return ret_;
593 }
594
595 // exposure mode
IsExposureModeSupportedFn(uint32_t mode)596 Camera_ErrorCode NDKCamera::IsExposureModeSupportedFn(uint32_t mode)
597 {
598 OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn start.");
599 exposureMode_ = static_cast<Camera_ExposureMode>(mode);
600 ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode_, &isExposureModeSupported_);
601 if (&isExposureModeSupported_ == nullptr || ret_ != CAMERA_OK) {
602 OH_LOG_ERROR(LOG_APP, "IsExposureModeSupported failed.");
603 return CAMERA_INVALID_ARGUMENT;
604 }
605 ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode_);
606 if (ret_ != CAMERA_OK) {
607 OH_LOG_ERROR(LOG_APP, "SetExposureMode failed.");
608 return CAMERA_INVALID_ARGUMENT;
609 }
610 ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_);
611 if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) {
612 OH_LOG_ERROR(LOG_APP, "GetExposureMode failed.");
613 return CAMERA_INVALID_ARGUMENT;
614 }
615 OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn end.");
616 return ret_;
617 }
618
IsMeteringPoint(int x,int y)619 Camera_ErrorCode NDKCamera::IsMeteringPoint(int x, int y)
620 {
621 OH_LOG_INFO(LOG_APP, "IsMeteringPoint start.");
622 ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_);
623 if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) {
624 OH_LOG_ERROR(LOG_APP, "GetExposureMode failed.");
625 return CAMERA_INVALID_ARGUMENT;
626 }
627 Camera_Point exposurePoint;
628 exposurePoint.x = x;
629 exposurePoint.y = y;
630 ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, exposurePoint);
631 if (ret_ != CAMERA_OK) {
632 OH_LOG_ERROR(LOG_APP, "SetMeteringPoint failed.");
633 return CAMERA_INVALID_ARGUMENT;
634 }
635 ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, &exposurePoint);
636 if (ret_ != CAMERA_OK) {
637 OH_LOG_ERROR(LOG_APP, "GetMeteringPoint failed.");
638 return CAMERA_INVALID_ARGUMENT;
639 }
640 OH_LOG_INFO(LOG_APP, "IsMeteringPoint end.");
641 return ret_;
642 }
643
IsExposureBiasRange(int exposureBias)644 Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias)
645 {
646 OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end.");
647 float exposureBiasValue = (float)exposureBias;
648 ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_);
649 if (&minExposureBias_ == nullptr || &maxExposureBias_ == nullptr || &step_ == nullptr || ret_ != CAMERA_OK) {
650 OH_LOG_ERROR(LOG_APP, "GetExposureBiasRange failed.");
651 return CAMERA_INVALID_ARGUMENT;
652 }
653 ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBiasValue);
654 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetExposureBias end.");
655 if (ret_ != CAMERA_OK) {
656 OH_LOG_ERROR(LOG_APP, "SetExposureBias failed.");
657 return CAMERA_INVALID_ARGUMENT;
658 }
659 ret_ = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBiasValue);
660 if (&exposureBiasValue == nullptr || ret_ != CAMERA_OK) {
661 OH_LOG_ERROR(LOG_APP, "GetExposureBias failed.");
662 return CAMERA_INVALID_ARGUMENT;
663 }
664 OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end.");
665 return ret_;
666 }
667
668 // focus mode
IsFocusModeSupported(uint32_t mode)669 Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode)
670 {
671 Camera_FocusMode focusMode = static_cast<Camera_FocusMode>(mode);
672 ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_);
673 if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) {
674 OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed.");
675 return CAMERA_INVALID_ARGUMENT;
676 }
677 return ret_;
678 }
679
IsFocusMode(uint32_t mode)680 Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode)
681 {
682 OH_LOG_INFO(LOG_APP, "IsFocusMode start.");
683 Camera_FocusMode focusMode = static_cast<Camera_FocusMode>(mode);
684 ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_);
685 if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) {
686 OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed.");
687 return CAMERA_INVALID_ARGUMENT;
688 }
689 ret_ = OH_CaptureSession_SetFocusMode(captureSession_, focusMode);
690 if (ret_ != CAMERA_OK) {
691 OH_LOG_ERROR(LOG_APP, "SetFocusMode failed.");
692 return CAMERA_INVALID_ARGUMENT;
693 }
694 ret_ = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode);
695 if (&focusMode == nullptr || ret_ != CAMERA_OK) {
696 OH_LOG_ERROR(LOG_APP, "GetFocusMode failed.");
697 return CAMERA_INVALID_ARGUMENT;
698 }
699 OH_LOG_INFO(LOG_APP, "IsFocusMode end.");
700 return ret_;
701 }
702
IsFocusPoint(float x,float y)703 Camera_ErrorCode NDKCamera::IsFocusPoint(float x, float y)
704 {
705 OH_LOG_INFO(LOG_APP, "IsFocusPoint start.");
706 Camera_Point focusPoint;
707 focusPoint.x = x;
708 focusPoint.y = y;
709 ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, focusPoint);
710 if (ret_ != CAMERA_OK) {
711 OH_LOG_ERROR(LOG_APP, "SetFocusPoint failed.");
712 return CAMERA_INVALID_ARGUMENT;
713 }
714 ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint);
715 if (&focusPoint == nullptr || ret_ != CAMERA_OK) {
716 OH_LOG_ERROR(LOG_APP, "GetFocusPoint failed.");
717 return CAMERA_INVALID_ARGUMENT;
718 }
719 OH_LOG_INFO(LOG_APP, "IsFocusPoint end.");
720 return ret_;
721 }
722
GetVideoFrameWidth(void)723 int32_t NDKCamera::GetVideoFrameWidth(void)
724 {
725 videoProfile_ = cameraOutputCapability_->videoProfiles[0];
726 if (videoProfile_ == nullptr) {
727 OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed.");
728 return CAMERA_INVALID_ARGUMENT;
729 }
730 return videoProfile_->size.width;
731 }
732
GetVideoFrameHeight(void)733 int32_t NDKCamera::GetVideoFrameHeight(void)
734 {
735 videoProfile_ = cameraOutputCapability_->videoProfiles[0];
736 if (videoProfile_ == nullptr) {
737 OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed.");
738 return CAMERA_INVALID_ARGUMENT;
739 }
740 return videoProfile_->size.height;
741 }
742
GetVideoFrameRate(void)743 int32_t NDKCamera::GetVideoFrameRate(void)
744 {
745 videoProfile_ = cameraOutputCapability_->videoProfiles[0];
746 if (videoProfile_ == nullptr) {
747 OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed.");
748 return CAMERA_INVALID_ARGUMENT;
749 }
750 return videoProfile_->range.min;
751 }
752
VideoOutputStop(void)753 Camera_ErrorCode NDKCamera::VideoOutputStop(void)
754 {
755 OH_LOG_ERROR(LOG_APP, "enter VideoOutputStop.");
756 ret_ = OH_VideoOutput_Stop(videoOutput_);
757 if (ret_ != CAMERA_OK) {
758 OH_LOG_ERROR(LOG_APP, "VideoOutputStop failed.");
759 return CAMERA_INVALID_ARGUMENT;
760 }
761 return ret_;
762 }
763
VideoOutputRelease(void)764 Camera_ErrorCode NDKCamera::VideoOutputRelease(void)
765 {
766 OH_LOG_ERROR(LOG_APP, "enter VideoOutputRelease.");
767 ret_ = OH_VideoOutput_Release(videoOutput_);
768 if (ret_ != CAMERA_OK) {
769 OH_LOG_ERROR(LOG_APP, "VideoOutputRelease failed.");
770 return CAMERA_INVALID_ARGUMENT;
771 }
772 return ret_;
773 }
774
TakePicture(void)775 Camera_ErrorCode NDKCamera::TakePicture(void)
776 {
777 Camera_ErrorCode ret = CAMERA_OK;
778 ret = OH_PhotoOutput_Capture(photoOutput_);
779 OH_LOG_ERROR(LOG_APP, "takePicture OH_PhotoOutput_Capture ret = %{public}d.", ret);
780 if (ret != CAMERA_OK) {
781 OH_LOG_ERROR(LOG_APP, "startPhoto failed.");
782 return CAMERA_INVALID_ARGUMENT;
783 }
784 return ret;
785 }
786
TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting)787 Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting)
788 {
789 Camera_ErrorCode ret = CAMERA_OK;
790 ret = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photoSetting);
791
792 OH_LOG_INFO(LOG_APP,
793 "TakePictureWithPhotoSettings get quality %{public}d, rotation %{public}d, mirror %{public}d, "
794 "latitude, %{public}d, longitude %{public}d, altitude %{public}d",
795 photoSetting.quality, photoSetting.rotation, photoSetting.mirror, photoSetting.location->latitude,
796 photoSetting.location->longitude, photoSetting.location->altitude);
797
798 OH_LOG_ERROR(LOG_APP, "takePicture TakePictureWithPhotoSettings ret = %{public}d.", ret);
799 if (ret != CAMERA_OK) {
800 OH_LOG_ERROR(LOG_APP, "startPhoto failed.");
801 return CAMERA_INVALID_ARGUMENT;
802 }
803 return ret;
804 }
805
806 // CameraManager Callback
CameraManagerStatusCallback(Camera_Manager * cameraManager,Camera_StatusInfo * status)807 void CameraManagerStatusCallback(Camera_Manager *cameraManager, Camera_StatusInfo *status)
808 {
809 OH_LOG_INFO(LOG_APP, "CameraManagerStatusCallback");
810 }
811
GetCameraManagerListener(void)812 CameraManager_Callbacks *NDKCamera::GetCameraManagerListener(void)
813 {
814 static CameraManager_Callbacks cameraManagerListener = {.onCameraStatus = CameraManagerStatusCallback};
815 return &cameraManagerListener;
816 }
817
CameraManagerRegisterCallback(void)818 Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void)
819 {
820 ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener());
821 if (ret_ != CAMERA_OK) {
822 OH_LOG_ERROR(LOG_APP, "OH_CameraManager_RegisterCallback failed.");
823 }
824 return ret_;
825 }
826
827 // CameraInput Callback
OnCameraInputError(const Camera_Input * cameraInput,Camera_ErrorCode errorCode)828 void OnCameraInputError(const Camera_Input *cameraInput, Camera_ErrorCode errorCode)
829 {
830 OH_LOG_INFO(LOG_APP, "OnCameraInput errorCode = %{public}d", errorCode);
831 }
832
GetCameraInputListener(void)833 CameraInput_Callbacks *NDKCamera::GetCameraInputListener(void)
834 {
835 static CameraInput_Callbacks cameraInputCallbacks = {.onError = OnCameraInputError};
836 return &cameraInputCallbacks;
837 }
838
CameraInputRegisterCallback(void)839 Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void)
840 {
841 ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener());
842 if (ret_ != CAMERA_OK) {
843 OH_LOG_ERROR(LOG_APP, "OH_CameraInput_RegisterCallback failed.");
844 }
845 return ret_;
846 }
847
848 // PreviewOutput Callback
PreviewOutputOnFrameStart(Camera_PreviewOutput * previewOutput)849 void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput)
850 {
851 OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart");
852 }
853
PreviewOutputOnFrameEnd(Camera_PreviewOutput * previewOutput,int32_t frameCount)854 void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameCount)
855 {
856 OH_LOG_INFO(LOG_APP, "PreviewOutput frameCount = %{public}d", frameCount);
857 }
858
PreviewOutputOnError(Camera_PreviewOutput * previewOutput,Camera_ErrorCode errorCode)859 void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode)
860 {
861 OH_LOG_INFO(LOG_APP, "PreviewOutput errorCode = %{public}d", errorCode);
862 }
863
GetPreviewOutputListener(void)864 PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void)
865 {
866 static PreviewOutput_Callbacks previewOutputListener = {
867 .onFrameStart = PreviewOutputOnFrameStart,
868 .onFrameEnd = PreviewOutputOnFrameEnd,
869 .onError = PreviewOutputOnError
870 };
871 return &previewOutputListener;
872 }
873
PreviewOutputRegisterCallback(void)874 Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void)
875 {
876 ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener());
877 if (ret_ != CAMERA_OK) {
878 OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_RegisterCallback failed.");
879 }
880 return ret_;
881 }
882
883 // PhotoOutput Callback
PhotoOutputOnFrameStart(Camera_PhotoOutput * photoOutput)884 void PhotoOutputOnFrameStart(Camera_PhotoOutput *photoOutput)
885 {
886 OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameStart");
887 }
888
PhotoOutputOnFrameShutter(Camera_PhotoOutput * photoOutput,Camera_FrameShutterInfo * info)889 void PhotoOutputOnFrameShutter(Camera_PhotoOutput *photoOutput, Camera_FrameShutterInfo *info)
890 {
891 OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameShutter");
892 }
893
PhotoOutputOnFrameEnd(Camera_PhotoOutput * photoOutput,int32_t frameCount)894 void PhotoOutputOnFrameEnd(Camera_PhotoOutput *photoOutput, int32_t frameCount)
895 {
896 OH_LOG_INFO(LOG_APP, "PhotoOutput frameCount = %{public}d", frameCount);
897 }
898
PhotoOutputOnError(Camera_PhotoOutput * photoOutput,Camera_ErrorCode errorCode)899 void PhotoOutputOnError(Camera_PhotoOutput *photoOutput, Camera_ErrorCode errorCode)
900 {
901 OH_LOG_INFO(LOG_APP, "PhotoOutput errorCode = %{public}d", errorCode);
902 }
903
GetPhotoOutputListener(void)904 PhotoOutput_Callbacks *NDKCamera::GetPhotoOutputListener(void)
905 {
906 static PhotoOutput_Callbacks photoOutputListener = {
907 .onFrameStart = PhotoOutputOnFrameStart,
908 .onFrameShutter = PhotoOutputOnFrameShutter,
909 .onFrameEnd = PhotoOutputOnFrameEnd,
910 .onError = PhotoOutputOnError
911 };
912 return &photoOutputListener;
913 }
914
PhotoOutputRegisterCallback(void)915 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void)
916 {
917 ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener());
918 if (ret_ != CAMERA_OK) {
919 OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed.");
920 }
921 return ret_;
922 }
923
924 // VideoOutput Callback
VideoOutputOnFrameStart(Camera_VideoOutput * videoOutput)925 void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput)
926 {
927 OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart");
928 }
929
VideoOutputOnFrameEnd(Camera_VideoOutput * videoOutput,int32_t frameCount)930 void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount)
931 {
932 OH_LOG_INFO(LOG_APP, "VideoOutput frameCount = %{public}d", frameCount);
933 }
934
VideoOutputOnError(Camera_VideoOutput * videoOutput,Camera_ErrorCode errorCode)935 void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode)
936 {
937 OH_LOG_INFO(LOG_APP, "VideoOutput errorCode = %{public}d", errorCode);
938 }
939
GetVideoOutputListener(void)940 VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void)
941 {
942 static VideoOutput_Callbacks videoOutputListener = {
943 .onFrameStart = VideoOutputOnFrameStart,
944 .onFrameEnd = VideoOutputOnFrameEnd,
945 .onError = VideoOutputOnError
946 };
947 return &videoOutputListener;
948 }
949
VideoOutputRegisterCallback(void)950 Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void)
951 {
952 ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener());
953 if (ret_ != CAMERA_OK) {
954 OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_RegisterCallback failed.");
955 }
956 return ret_;
957 }
958
959 // Metadata Callback
OnMetadataObjectAvailable(Camera_MetadataOutput * metadataOutput,Camera_MetadataObject * metadataObject,uint32_t size)960 void OnMetadataObjectAvailable(Camera_MetadataOutput *metadataOutput, Camera_MetadataObject *metadataObject,
961 uint32_t size)
962 {
963 OH_LOG_INFO(LOG_APP, "size = %{public}d", size);
964 }
965
OnMetadataOutputError(Camera_MetadataOutput * metadataOutput,Camera_ErrorCode errorCode)966 void OnMetadataOutputError(Camera_MetadataOutput *metadataOutput, Camera_ErrorCode errorCode)
967 {
968 OH_LOG_INFO(LOG_APP, "OnMetadataOutput errorCode = %{public}d", errorCode);
969 }
970
GetMetadataOutputListener(void)971 MetadataOutput_Callbacks *NDKCamera::GetMetadataOutputListener(void)
972 {
973 static MetadataOutput_Callbacks metadataOutputListener = {
974 .onMetadataObjectAvailable = OnMetadataObjectAvailable,
975 .onError = OnMetadataOutputError
976 };
977 return &metadataOutputListener;
978 }
979
MetadataOutputRegisterCallback(void)980 Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void)
981 {
982 ret_ = OH_MetadataOutput_RegisterCallback(metadataOutput_, GetMetadataOutputListener());
983 if (ret_ != CAMERA_OK) {
984 OH_LOG_ERROR(LOG_APP, "OH_MetadataOutput_RegisterCallback failed.");
985 }
986 return ret_;
987 }
988
989 // Session Callback
CaptureSessionOnFocusStateChange(Camera_CaptureSession * session,Camera_FocusState focusState)990 void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState)
991 {
992 OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange");
993 }
994
CaptureSessionOnError(Camera_CaptureSession * session,Camera_ErrorCode errorCode)995 void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode)
996 {
997 OH_LOG_INFO(LOG_APP, "CaptureSession errorCode = %{public}d", errorCode);
998 }
999
GetCaptureSessionRegister(void)1000 CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(void)
1001 {
1002 static CaptureSession_Callbacks captureSessionCallbacks = {
1003 .onFocusStateChange = CaptureSessionOnFocusStateChange,
1004 .onError = CaptureSessionOnError
1005 };
1006 return &captureSessionCallbacks;
1007 }
1008
CaptureSessionRegisterCallback(void)1009 Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void)
1010 {
1011 ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister());
1012 if (ret_ != CAMERA_OK) {
1013 OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_RegisterCallback failed.");
1014 }
1015 return ret_;
1016 }
1017 } // namespace OHOS_CAMERA_SAMPLE