• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 CameraCallbackCode NDKCamera::cameraCallbackCode_ = NO_RECEIVED;
19 
CameraManagerStatusCallback(Camera_Manager * cameraManager,Camera_StatusInfo * status)20 void CameraManagerStatusCallback(Camera_Manager *cameraManager, Camera_StatusInfo *status)
21 {
22     NDKCamera::cameraCallbackCode_ = CAMERA_MANAGER_STATUS;
23     LOG("状态码回调%{public}d", status);
24 }
25 
GetCameraManagerListener(void)26 CameraManager_Callbacks *NDKCamera::GetCameraManagerListener(void)
27 {
28     static CameraManager_Callbacks cameraManagerListener = {.onCameraStatus = CameraManagerStatusCallback};
29     return &cameraManagerListener;
30 }
PreviewOutputOnFrameStart(Camera_PreviewOutput * previewOutput)31 void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput)
32 {
33     NDKCamera::cameraCallbackCode_ = PREVIEW_ON_FRAME_START;
34     LOG("PreviewOutputOnFrameStart");
35 }
36 
PreviewOutputOnFrameEnd(Camera_PreviewOutput * previewOutput,int32_t frameCount)37 void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameCount)
38 {
39     NDKCamera::cameraCallbackCode_ = PREVIEW_ON_FRAME_END;
40     LOG("PreviewOutput frameCount = %d", frameCount);
41 }
42 
PreviewOutputOnError(Camera_PreviewOutput * previewOutput,Camera_ErrorCode errorCode)43 void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode)
44 {
45     NDKCamera::cameraCallbackCode_ = PREVIEW_ON_ERROR;
46     LOG("PreviewOutput errorCode = %d", errorCode);
47 }
GetPreviewOutputListener(void)48 PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void)
49 {
50     static PreviewOutput_Callbacks previewOutputListener = {.onFrameStart = PreviewOutputOnFrameStart,
51                                                             .onFrameEnd = PreviewOutputOnFrameEnd,
52                                                             .onError = PreviewOutputOnError};
53     return &previewOutputListener;
54 }
NDKCamera(char * str,int index)55 NDKCamera::NDKCamera(char *str, int index)
56     : cameras_(nullptr), cameraOutputCapability_(nullptr), captureSession_(nullptr), size_(0), profile_(nullptr),
57       previewOutput_(nullptr), photoOutput_(nullptr), videoOutput_(nullptr), metaDataObjectType_(nullptr),
58       metadataOutput_(nullptr), cameraInput_(nullptr), isCameraMuted_(nullptr), previewSurfaceId_(str),
59       ret_(CAMERA_OK) {
60     valid_ = false;
61     // 创建CameraManager实例。
62     Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager_);
63     if (cameraManager_ == nullptr || ret != CAMERA_OK) {
64         LOG("创建CameraManager实例 失败. %{public}d", ret);
65     }
66     CameraManagerRegisterCallback(index);
67     valid_ = true;
68 }
~NDKCamera()69 NDKCamera::~NDKCamera()
70 {
71     valid_ = false;
72 
73     Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_);
74     if (ret != CAMERA_OK) {
75         LOG("释放捕获会话 失败. %{public}d", ret);
76     }
77 
78     if (cameraManager_) {
79         ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_);
80         if (ret != CAMERA_OK) {
81             LOG("删除支持的相机成功. %{public}d", ret);
82         } else {
83             LOG("删除支持的相机失败. %{public}d", ret);
84         }
85 
86         ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_);
87         if (ret != CAMERA_OK) {
88             LOG("删除支持的输出功能成功. %{public}d", ret);
89         } else {
90             LOG("删除支持的输出功能失败. %{public}d", ret);
91         }
92 
93         ret = OH_Camera_DeleteCameraManager(cameraManager_);
94         if (ret != CAMERA_OK) {
95             LOG("删除CameraManager实例成功. %{public}d", ret);
96         } else {
97             LOG("删除CameraManager实例失败. %{public}d", ret);
98         }
99         cameraManager_ = nullptr;
100     }
101 
102     CameraManagerUnRegisterCallback(PARAMETER_OK);
103 }
104 
105 
CameraManagerDeleteSupportedCameraOutputCapability(int useCaseCode)106 Camera_ErrorCode NDKCamera::CameraManagerDeleteSupportedCameraOutputCapability(int useCaseCode)
107 {
108     if (useCaseCode == PARAMETER_OK) {
109         ret_ = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_);
110     } else if (useCaseCode == PARAMETER2_ERROR) {
111         ret_ = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, nullptr);
112     } else {
113         ret_ = OH_CameraManager_DeleteSupportedCameraOutputCapability(nullptr, cameraOutputCapability_);
114     }
115 
116     return ret_;
117 }
CameraManagerDeleteSupportedCameras(int useCaseCode)118 Camera_ErrorCode NDKCamera::CameraManagerDeleteSupportedCameras(int useCaseCode)
119 {
120     if (useCaseCode == PARAMETER_OK) {
121         ret_ = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_);
122     } else if (useCaseCode == PARAMETER3_ERROR) {
123         return CAMERA_INVALID_ARGUMENT;
124         ret_ = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, -1);
125     } else if (useCaseCode == PARAMETER2_ERROR) {
126         ret_ = OH_CameraManager_DeleteSupportedCameras(cameraManager_, nullptr, size_);
127     } else {
128         ret_ = OH_CameraManager_DeleteSupportedCameras(nullptr, cameras_, size_);
129     }
130     if (ret_ != CAMERA_OK) {
131         LOG("删除支持的相机成功. %{public}d", ret_);
132     } else {
133         LOG("删除支持的相机失败. %{public}d", ret_);
134     }
135     return ret_;
136 }
CameraDeleteCameraManager(int useCaseCode)137 Camera_ErrorCode NDKCamera::CameraDeleteCameraManager(int useCaseCode)
138 {
139     if (useCaseCode == PARAMETER_OK) {
140         ret_ = OH_Camera_DeleteCameraManager(cameraManager_);
141     } else {
142         ret_ = OH_Camera_DeleteCameraManager(nullptr);
143     }
144     if (ret_ != CAMERA_OK) {
145         LOG("删除CameraManager实例失败. %{public}d", ret_);
146     }
147     return ret_;
148 }
149 
CameraManagerUnRegisterCallback(int useCaseCode)150 Camera_ErrorCode NDKCamera::CameraManagerUnRegisterCallback(int useCaseCode)
151 {
152     if (useCaseCode == PARAMETER_OK) {
153         ret_ = OH_CameraManager_UnregisterCallback(cameraManager_, GetCameraManagerListener());
154     } else if (useCaseCode == PARAMETER1_ERROR) {
155         ret_ = OH_CameraManager_UnregisterCallback(nullptr, GetCameraManagerListener());
156     } else {
157         ret_ = OH_CameraManager_UnregisterCallback(cameraManager_, nullptr);
158     }
159     if (ret_ != CAMERA_OK) {
160         LOG("注销摄像机状态更改事件回调失败. %{public}d", ret_);
161     }
162     return ret_;
163 }
164 
165 
CameraManagerRegisterCallback(int useCaseCode)166 Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(int useCaseCode)
167 {
168     if (useCaseCode == PARAMETER_OK) {
169         ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener());
170     } else if (useCaseCode == PARAMETER1_ERROR) {
171         ret_ = OH_CameraManager_RegisterCallback(nullptr, GetCameraManagerListener());
172     } else {
173         ret_ = OH_CameraManager_RegisterCallback(cameraManager_, nullptr);
174     }
175 
176     return ret_;
177 }
GetSupportedCameras(int useCaseCode)178 Camera_ErrorCode NDKCamera::GetSupportedCameras(int useCaseCode)
179 {
180     if (useCaseCode == PARAMETER_OK) {
181         ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, &size_);
182     } else if (useCaseCode == PARAMETER3_ERROR) {
183         ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, &cameras_, nullptr);
184     } else if (useCaseCode == PARAMETER2_ERROR) {
185         ret_ = OH_CameraManager_GetSupportedCameras(cameraManager_, nullptr, &size_);
186     } else {
187         ret_ = OH_CameraManager_GetSupportedCameras(nullptr, &cameras_, &size_);
188     }
189     if (cameras_ == nullptr || ret_ != CAMERA_OK) {
190         LOG("获取支持相机的描述失败. %{public}d", ret_);
191     }
192     return ret_;
193 }
194 
GetSupportedOutputCapability(int useCaseCode)195 Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(int useCaseCode)
196 {
197     if (useCaseCode == PARAMETER_OK) {
198         ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, cameras_, &cameraOutputCapability_);
199     } else if (useCaseCode == PARAMETER3_ERROR) {
200         ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, cameras_, nullptr);
201     } else if (useCaseCode == PARAMETER2_ERROR) {
202         return CAMERA_INVALID_ARGUMENT;
203         ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, nullptr, &cameraOutputCapability_);
204     } else {
205         ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(nullptr, cameras_, &cameraOutputCapability_);
206     }
207 
208     if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) {
209         LOG("获取特定相机和特定模式支持的输出功能失败");
210     }
211     return ret_;
212 }
213 
CreatePreviewOutput(int useCaseCode)214 Camera_ErrorCode NDKCamera::CreatePreviewOutput(int useCaseCode)
215 {
216     profile_ = cameraOutputCapability_->previewProfiles[0];
217 
218     if (useCaseCode == PARAMETER_OK) {
219         ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_);
220     } else if (useCaseCode == PARAMETER4_ERROR) {
221         ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, nullptr);
222     } else if (useCaseCode == PARAMETER3_ERROR) {
223         ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, nullptr, &previewOutput_);
224     } else if (useCaseCode == PARAMETER2_ERROR) {
225         ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, nullptr, previewSurfaceId_, &previewOutput_);
226     } else {
227         ret_ = OH_CameraManager_CreatePreviewOutput(nullptr, profile_, previewSurfaceId_, &previewOutput_);
228     }
229 
230     return ret_;
231 }
CreateCameraInput(int useCaseCode)232 Camera_ErrorCode NDKCamera::CreateCameraInput(int useCaseCode)
233 {
234     if (useCaseCode == PARAMETER_OK) {
235         ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, cameras_, &cameraInput_);
236     } else if (useCaseCode == PARAMETER3_ERROR) {
237         ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, cameras_, nullptr);
238     } else if (useCaseCode == PARAMETER2_ERROR) {
239         ret_ = OH_CameraManager_CreateCameraInput(cameraManager_, nullptr, &cameraInput_);
240     } else {
241         ret_ = OH_CameraManager_CreateCameraInput(nullptr, cameras_, &cameraInput_);
242     }
243     return ret_;
244 }
CreateCameraInputWithPositionAndType(Camera_Position position,Camera_Type type,int useCaseCode)245 Camera_ErrorCode NDKCamera::CreateCameraInputWithPositionAndType(Camera_Position position, Camera_Type type,
246                                                                  int useCaseCode)
247 {
248     if (useCaseCode == PARAMETER_OK) {
249         ret_ = OH_CameraManager_CreateCameraInput_WithPositionAndType(cameraManager_, position, type, &cameraInput_);
250     } else if (useCaseCode == PARAMETER4_ERROR) {
251         ret_ = OH_CameraManager_CreateCameraInput_WithPositionAndType(cameraManager_, position, type, nullptr);
252     } else {
253         ret_ = OH_CameraManager_CreateCameraInput_WithPositionAndType(nullptr, position, type, &cameraInput_);
254     }
255 
256     return ret_;
257 }
CreateSession(int useCaseCode)258 Camera_ErrorCode NDKCamera::CreateSession(int useCaseCode)
259 {
260     if (useCaseCode == PARAMETER_OK) {
261         ret_ = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_);
262     } else if (useCaseCode == PARAMETER2_ERROR) {
263         ret_ = OH_CameraManager_CreateCaptureSession(cameraManager_, nullptr);
264     } else {
265         ret_ = OH_CameraManager_CreateCaptureSession(nullptr, &captureSession_);
266     }
267     return ret_;
268 }
PreviewOutputRegisterCallback(int useCaseCode)269 Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(int useCaseCode)
270 {
271     if (useCaseCode == PARAMETER_OK) {
272         ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener());
273     } else if (useCaseCode == PARAMETER2_ERROR) {
274         ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, nullptr);
275     } else {
276         ret_ = OH_PreviewOutput_RegisterCallback(nullptr, GetPreviewOutputListener());
277     }
278     return ret_;
279 }
PreviewOutputUnRegisterCallback(int useCaseCode)280 Camera_ErrorCode NDKCamera::PreviewOutputUnRegisterCallback(int useCaseCode)
281 {
282     if (useCaseCode == PARAMETER_OK) {
283         ret_ = OH_PreviewOutput_UnregisterCallback(previewOutput_, GetPreviewOutputListener());
284     } else if (useCaseCode == PARAMETER2_ERROR) {
285         ret_ = OH_PreviewOutput_UnregisterCallback(previewOutput_, nullptr);
286     } else {
287         ret_ = OH_PreviewOutput_UnregisterCallback(nullptr, GetPreviewOutputListener());
288     }
289     return ret_;
290 }
CreatePhotoOutput(char * photoSurfaceId,int useCaseCode)291 Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId, int useCaseCode)
292 {
293     profile_ = cameraOutputCapability_->photoProfiles[0];
294 
295     if (useCaseCode == PARAMETER_OK) {
296         ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_);
297     } else if (useCaseCode == PARAMETER4_ERROR) {
298         ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, nullptr);
299     } else if (useCaseCode == PARAMETER3_ERROR) {
300         ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, nullptr, &photoOutput_);
301     } else if (useCaseCode == PARAMETER2_ERROR) {
302         ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, nullptr, photoSurfaceId, &photoOutput_);
303     } else {
304         ret_ = OH_CameraManager_CreatePhotoOutput(nullptr, profile_, photoSurfaceId, &photoOutput_);
305     }
306 
307     return ret_;
308 }
CreateMetadataOutput(int useCaseCode)309 Camera_ErrorCode NDKCamera::CreateMetadataOutput(int useCaseCode)
310 {
311     LOG("创建元数据输出实例1 %{public}p", cameraOutputCapability_);
312     metaDataObjectType_ = cameraOutputCapability_->supportedMetadataObjectTypes[0];
313     LOG("创建元数据输出实例2%{public}s", metaDataObjectType_);
314     if (useCaseCode == PARAMETER_OK) {
315         ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, &metadataOutput_);
316     } else if (useCaseCode == PARAMETER3_ERROR) {
317         ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, metaDataObjectType_, nullptr);
318     } else if (useCaseCode == PARAMETER2_ERROR) {
319         ret_ = OH_CameraManager_CreateMetadataOutput(cameraManager_, nullptr, &metadataOutput_);
320     } else {
321         ret_ = OH_CameraManager_CreateMetadataOutput(nullptr, metaDataObjectType_, &metadataOutput_);
322     }
323     if (metadataOutput_ == nullptr || ret_ != CAMERA_OK) {
324         LOG("创建元数据输出实例 失败.");
325     }
326     return ret_;
327 }
328 
CameraInputOpen(int useCaseCode)329 Camera_ErrorCode NDKCamera::CameraInputOpen(int useCaseCode)
330 {
331     if (useCaseCode == PARAMETER_OK) {
332         ret_ = OH_CameraInput_Open(cameraInput_);
333     } else {
334         ret_ = OH_CameraInput_Open(nullptr);
335     }
336 
337     if (ret_ != CAMERA_OK) {
338         LOG("打开相机 failed.");
339     }
340     return ret_;
341 }
CameraInputClose(int useCaseCode)342 Camera_ErrorCode NDKCamera::CameraInputClose(int useCaseCode)
343 {
344     if (useCaseCode == PARAMETER_OK) {
345         ret_ = OH_CameraInput_Close(cameraInput_);
346     } else {
347         ret_ = OH_CameraInput_Close(nullptr);
348     }
349     if (ret_ != CAMERA_OK) {
350         LOG("ndkXTS CameraInput_Close failed.");
351     }
352     return ret_;
353 }
CameraInputRelease(int useCaseCode)354 Camera_ErrorCode NDKCamera::CameraInputRelease(int useCaseCode)
355 {
356     if (useCaseCode == PARAMETER_OK) {
357         ret_ = OH_CameraInput_Release(cameraInput_);
358     } else {
359         ret_ = OH_CameraInput_Release(nullptr);
360     }
361     if (ret_ != CAMERA_OK) {
362         LOG("释放相机输入实例。失败");
363     }
364     return ret_;
365 }
OnCameraInputError(const Camera_Input * cameraInput,Camera_ErrorCode errorCode)366 void OnCameraInputError(const Camera_Input *cameraInput, Camera_ErrorCode errorCode)
367 {
368     NDKCamera::cameraCallbackCode_ = CAMERA_INPUT_STATUS;
369     LOG("OnCameraInput errorCode = %d", errorCode);
370 }
371 
GetCameraInputListener(void)372 CameraInput_Callbacks *NDKCamera::GetCameraInputListener(void)
373 {
374     static CameraInput_Callbacks cameraInputCallbacks = {.onError = OnCameraInputError};
375     return &cameraInputCallbacks;
376 }
CameraInputRegisterCallback(int useCaseCode)377 Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(int useCaseCode)
378 {
379     if (useCaseCode == PARAMETER_OK) {
380         ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener());
381     } else if (useCaseCode == PARAMETER2_ERROR) {
382         ret_ = OH_CameraInput_RegisterCallback(cameraInput_, nullptr);
383     } else {
384         ret_ = OH_CameraInput_RegisterCallback(nullptr, GetCameraInputListener());
385     }
386     if (ret_ != CAMERA_OK) {
387         LOG("OH_CameraInput_RegisterCallback failed.");
388     }
389     return ret_;
390 }
CameraInputUnRegisterCallback(int useCaseCode)391 Camera_ErrorCode NDKCamera::CameraInputUnRegisterCallback(int useCaseCode)
392 {
393     if (useCaseCode == PARAMETER_OK) {
394         ret_ = OH_CameraInput_UnregisterCallback(cameraInput_, GetCameraInputListener());
395     } else if (useCaseCode == PARAMETER2_ERROR) {
396         ret_ = OH_CameraInput_UnregisterCallback(cameraInput_, nullptr);
397     } else {
398         ret_ = OH_CameraInput_UnregisterCallback(nullptr, GetCameraInputListener());
399     }
400     if (ret_ != CAMERA_OK) {
401         LOG("注册相机输入更改事件回调失败");
402     }
403     return ret_;
404 }
SessionBegin(int useCaseCode)405 Camera_ErrorCode NDKCamera::SessionBegin(int useCaseCode)
406 {
407     if (useCaseCode == PARAMETER_OK) {
408         ret_ = OH_CaptureSession_BeginConfig(captureSession_);
409     } else {
410         ret_ = OH_CaptureSession_BeginConfig(nullptr);
411     }
412     if (ret_ != CAMERA_OK) {
413         LOG("开始捕获会话配置 失败. %d and captureSession_ addr = %p", ret_, captureSession_);
414     }
415     return ret_;
416 }
SessionCommitConfig(int useCaseCode)417 Camera_ErrorCode NDKCamera::SessionCommitConfig(int useCaseCode)
418 {
419     if (useCaseCode == PARAMETER_OK) {
420         ret_ = OH_CaptureSession_CommitConfig(captureSession_);
421     } else {
422         ret_ = OH_CaptureSession_CommitConfig(nullptr);
423     }
424     return ret_;
425 }
SessionStart(int useCaseCode)426 Camera_ErrorCode NDKCamera::SessionStart(int useCaseCode)
427 {
428     if (useCaseCode == PARAMETER_OK) {
429         ret_ = OH_CaptureSession_Start(captureSession_);
430     } else {
431         ret_ = OH_CaptureSession_Start(nullptr);
432     }
433     return ret_;
434 }
435 
SessionStop(int useCaseCode)436 Camera_ErrorCode NDKCamera::SessionStop(int useCaseCode)
437 {
438     if (useCaseCode == PARAMETER_OK) {
439         ret_ = OH_CaptureSession_Stop(captureSession_);
440     } else {
441         ret_ = OH_CaptureSession_Stop(nullptr);
442     }
443     return ret_;
444 }
SessionRelease(int useCaseCode)445 Camera_ErrorCode NDKCamera::SessionRelease(int useCaseCode)
446 {
447     if (useCaseCode == PARAMETER_OK) {
448         ret_ = OH_CaptureSession_Release(captureSession_);
449     } else {
450         ret_ = OH_CaptureSession_Release(nullptr);
451     }
452     return ret_;
453 }
CaptureSessionOnFocusStateChange(Camera_CaptureSession * session,Camera_FocusState focusState)454 void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState)
455 {
456     NDKCamera::cameraCallbackCode_ = SESSION_ON_FOCUS_STATE_CHANGE;
457     LOG("CaptureSessionOnFocusStateChange");
458 }
459 
CaptureSessionOnError(Camera_CaptureSession * session,Camera_ErrorCode errorCode)460 void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode)
461 {
462     NDKCamera::cameraCallbackCode_ = SESSION_ON_ERROR;
463     LOG("CaptureSession errorCode = %d", errorCode);
464 }
465 
GetCaptureSessionRegister(void)466 CaptureSession_Callbacks *NDKCamera::GetCaptureSessionRegister(void)
467 {
468     static CaptureSession_Callbacks captureSessionCallbacks = {.onFocusStateChange = CaptureSessionOnFocusStateChange,
469                                                                .onError = CaptureSessionOnError};
470     return &captureSessionCallbacks;
471 }
CaptureSessionRegisterCallback(int useCaseCode)472 Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(int useCaseCode)
473 {
474     if (useCaseCode == PARAMETER_OK) {
475         ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister());
476     } else if (useCaseCode == PARAMETER2_ERROR) {
477         ret_ = OH_CaptureSession_RegisterCallback(captureSession_, nullptr);
478     } else {
479         ret_ = OH_CaptureSession_RegisterCallback(nullptr, GetCaptureSessionRegister());
480     }
481     if (ret_ != CAMERA_OK) {
482         LOG("注册捕获会话事件回调监听");
483     }
484     return ret_;
485 }
CaptureSessionUnRegisterCallback(int useCaseCode)486 Camera_ErrorCode NDKCamera::CaptureSessionUnRegisterCallback(int useCaseCode)
487 {
488     if (useCaseCode == PARAMETER_OK) {
489         ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, GetCaptureSessionRegister());
490     } else if (useCaseCode == PARAMETER2_ERROR) {
491         ret_ = OH_CaptureSession_UnregisterCallback(captureSession_, nullptr);
492     } else {
493         ret_ = OH_CaptureSession_UnregisterCallback(nullptr, GetCaptureSessionRegister());
494     }
495     return ret_;
496 }
SessionGetExposureBias(int useCaseCode)497 Camera_ErrorCode NDKCamera::SessionGetExposureBias(int useCaseCode)
498 {
499     if (useCaseCode == PARAMETER_OK) {
500         ret_ = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBias_);
501         LOG("获取当前曝光补偿 %{public}f", &exposureBias_);
502     } else if (useCaseCode == PARAMETER2_ERROR) {
503         ret_ = OH_CaptureSession_GetExposureBias(captureSession_, nullptr);
504     } else {
505         ret_ = OH_CaptureSession_GetExposureBias(nullptr, &exposureBias_);
506     }
507     return ret_;
508 }
SessionAddInput(int useCaseCode)509 Camera_ErrorCode NDKCamera::SessionAddInput(int useCaseCode)
510 {
511     if (useCaseCode == PARAMETER_OK) {
512         ret_ = OH_CaptureSession_AddInput(captureSession_, cameraInput_);
513     } else if (useCaseCode == PARAMETER2_ERROR) {
514         ret_ = OH_CaptureSession_AddInput(captureSession_, nullptr);
515     } else {
516         ret_ = OH_CaptureSession_AddInput(nullptr, cameraInput_);
517     }
518     return ret_;
519 }
SessionRemoveInput(int useCaseCode)520 Camera_ErrorCode NDKCamera::SessionRemoveInput(int useCaseCode)
521 {
522     if (useCaseCode == PARAMETER_OK) {
523         ret_ = OH_CaptureSession_RemoveInput(captureSession_, cameraInput_);
524     } else if (useCaseCode == PARAMETER2_ERROR) {
525         ret_ = OH_CaptureSession_RemoveInput(captureSession_, nullptr);
526     } else {
527         ret_ =OH_CaptureSession_RemoveInput(nullptr, cameraInput_);
528     }
529     return ret_;
530 }
531 
SessionAddPreviewOutput(int useCaseCode)532 Camera_ErrorCode NDKCamera::SessionAddPreviewOutput(int useCaseCode)
533 {
534     if (useCaseCode == PARAMETER_OK) {
535         ret_ = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_);
536     } else if (useCaseCode == PARAMETER2_ERROR) {
537         ret_ = OH_CaptureSession_AddPreviewOutput(captureSession_, nullptr);
538     } else {
539         ret_ = OH_CaptureSession_AddPreviewOutput(nullptr, previewOutput_);
540     }
541     return ret_;
542 }
SessionAddPhotoOutput(int useCaseCode)543 Camera_ErrorCode NDKCamera::SessionAddPhotoOutput(int useCaseCode)
544 {
545     if (useCaseCode == PARAMETER_OK) {
546         ret_ = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_);
547     } else if (useCaseCode == PARAMETER2_ERROR) {
548         ret_ = OH_CaptureSession_AddPhotoOutput(captureSession_, nullptr);
549     } else {
550         ret_ = OH_CaptureSession_AddPhotoOutput(nullptr, photoOutput_);
551     }
552     return ret_;
553 }
SessionGetExposureBiasRange(int useCaseCode)554 Camera_ErrorCode NDKCamera::SessionGetExposureBiasRange(int useCaseCode)
555 {
556     if (useCaseCode == PARAMETER_OK) {
557         ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_);
558     } else if (useCaseCode == PARAMETER4_ERROR) {
559         ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, nullptr);
560     } else if (useCaseCode == PARAMETER3_ERROR) {
561         ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, nullptr, &step_);
562     } else if (useCaseCode == PARAMETER2_ERROR) {
563         ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, nullptr, &maxExposureBias_, &step_);
564     } else {
565         ret_ = OH_CaptureSession_GetExposureBiasRange(nullptr, &minExposureBias_, &maxExposureBias_, &step_);
566     }
567     return ret_;
568 }
IsCameraMuted(int useCaseCode)569 Camera_ErrorCode NDKCamera::IsCameraMuted(int useCaseCode)
570 {
571     LOG("确定相机是否静音");
572     if (useCaseCode == PARAMETER_OK) {
573         ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, isCameraMuted_);
574         LOG("确定相机是否静音 %{public}d", ret_);
575     } else if (useCaseCode == PARAMETER2_ERROR) {
576         ret_ = OH_CameraManager_IsCameraMuted(cameraManager_, nullptr);
577     } else {
578         ret_ = OH_CameraManager_IsCameraMuted(nullptr, isCameraMuted_);
579     }
580     return ret_;
581 }
SessionGetExposureMode(int useCaseCode)582 Camera_ErrorCode NDKCamera::SessionGetExposureMode(int useCaseCode)
583 {
584     if (useCaseCode == PARAMETER_OK) {
585         ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_);
586     } else if (useCaseCode == PARAMETER2_ERROR) {
587         ret_ = OH_CaptureSession_GetExposureMode(captureSession_, nullptr);
588     } else {
589         ret_ = OH_CaptureSession_GetExposureMode(nullptr, &exposureMode_);
590     }
591     return ret_;
592 }
SessionIsExposureModeSupported(uint32_t mode,int useCaseCode)593 Camera_ErrorCode NDKCamera::SessionIsExposureModeSupported(uint32_t mode, int useCaseCode)
594 {
595     Camera_ExposureMode exposureMode = static_cast<Camera_ExposureMode>(mode);
596     if (useCaseCode == PARAMETER_OK) {
597         ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode, &isExposureMode_);
598         LOG("检查是否支持指定的曝光模式 %{public}d 曝光:%{public}d", exposureMode, isExposureMode_);
599     } else if (useCaseCode == PARAMETER3_ERROR) {
600         ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode, nullptr);
601     } else if (useCaseCode == PARAMETER2_ERROR) {
602         return CAMERA_INVALID_ARGUMENT;
603         LOG("确定相机是否静音 %{public}d", exposureMode);
604         ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode, &isExposureMode_);
605     } else {
606         ret_ = OH_CaptureSession_IsExposureModeSupported(nullptr, exposureMode, &isExposureMode_);
607     }
608     return ret_;
609 }
SessionSetExposureMode(uint32_t mode,int useCaseCode)610 Camera_ErrorCode NDKCamera::SessionSetExposureMode(uint32_t mode, int useCaseCode)
611 {
612     Camera_ExposureMode exposureMode = static_cast<Camera_ExposureMode>(mode);
613     if (useCaseCode == PARAMETER_OK) {
614         ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode);
615     } else if (useCaseCode == PARAMETER2_ERROR) {
616         return CAMERA_INVALID_ARGUMENT;
617         ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode);
618     } else {
619         ret_ = OH_CaptureSession_SetExposureMode(nullptr, exposureMode);
620     }
621     return ret_;
622 }
SessionSetExposureBias(float exposureBias,int useCaseCode)623 Camera_ErrorCode NDKCamera::SessionSetExposureBias(float exposureBias, int useCaseCode)
624 {
625     ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_);
626     LOG("最小曝光 %{public}.2f 最大曝光%{public}.2f", minExposureBias_, maxExposureBias_);
627     if (useCaseCode == PARAMETER_OK) {
628         ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBias);
629     } else if (useCaseCode == PARAMETER2_ERROR) {
630         ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBias);
631     } else {
632         ret_ = OH_CaptureSession_SetExposureBias(nullptr, exposureBias);
633     }
634     return ret_;
635 }
SessionHasFlash(int useCaseCode)636 Camera_ErrorCode NDKCamera::SessionHasFlash(int useCaseCode)
637 {
638     if (useCaseCode == PARAMETER_OK) {
639         ret_ = OH_CaptureSession_HasFlash(captureSession_, &hasFlash_);
640     } else if (useCaseCode == PARAMETER2_ERROR) {
641         ret_ = OH_CaptureSession_HasFlash(captureSession_, nullptr);
642     } else {
643         ret_ = OH_CaptureSession_HasFlash(nullptr, &hasFlash_);
644     }
645     return ret_;
646 }
SessionIsFlashModeSupported(uint32_t mode,int useCaseCode)647 Camera_ErrorCode NDKCamera::SessionIsFlashModeSupported(uint32_t mode, int useCaseCode)
648 {
649     Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
650     if (useCaseCode == PARAMETER_OK) {
651         ret_ = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isFlashMode_);
652     } else if (useCaseCode == PARAMETER3_ERROR) {
653         ret_ = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, nullptr);
654     } else if (useCaseCode == PARAMETER2_ERROR) {
655         ret_ = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isFlashMode_);
656     } else {
657         ret_ = OH_CaptureSession_IsFlashModeSupported(nullptr, flashMode, &isFlashMode_);
658     }
659     return ret_;
660 }
SessionSetFlashMode(uint32_t mode,int useCaseCode)661 Camera_ErrorCode NDKCamera::SessionSetFlashMode(uint32_t mode, int useCaseCode)
662 {
663     Camera_FlashMode flashMode = static_cast<Camera_FlashMode>(mode);
664     if (useCaseCode == PARAMETER_OK) {
665         ret_ = OH_CaptureSession_SetFlashMode(captureSession_, flashMode);
666     } else if (useCaseCode == PARAMETER2_ERROR) {
667         return CAMERA_INVALID_ARGUMENT;
668         ret_ = OH_CaptureSession_SetFlashMode(captureSession_, flashMode);
669     } else {
670         ret_ = OH_CaptureSession_SetFlashMode(nullptr, flashMode);
671     }
672     return ret_;
673 }
SessionGetFlashMode(int useCaseCode)674 Camera_ErrorCode NDKCamera::SessionGetFlashMode(int useCaseCode)
675 {
676     if (useCaseCode == PARAMETER_OK) {
677         ret_ = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode_);
678     } else if (useCaseCode == PARAMETER2_ERROR) {
679         ret_ = OH_CaptureSession_GetFlashMode(captureSession_, nullptr);
680     } else {
681         ret_ = OH_CaptureSession_GetFlashMode(nullptr, &flashMode_);
682     }
683     return ret_;
684 }
SessionIsFocusModeSupported(uint32_t mode,int useCaseCode)685 Camera_ErrorCode NDKCamera::SessionIsFocusModeSupported(uint32_t mode, int useCaseCode)
686 {
687     Camera_FocusMode focusMode = static_cast<Camera_FocusMode>(mode);
688     if (useCaseCode == PARAMETER_OK) {
689         ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusSupported_);
690     } else if (useCaseCode == PARAMETER3_ERROR) {
691         ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, nullptr);
692     } else if (useCaseCode == PARAMETER2_ERROR) {
693         return CAMERA_INVALID_ARGUMENT;
694         ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusSupported_);
695     } else {
696         ret_ = OH_CaptureSession_IsFocusModeSupported(nullptr, focusMode, &isFocusSupported_);
697     }
698     return ret_;
699 }
SessionGetFocusMode(int useCaseCode)700 Camera_ErrorCode NDKCamera::SessionGetFocusMode(int useCaseCode)
701 {
702     if (useCaseCode == PARAMETER_OK) {
703         ret_ = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode_);
704     } else if (useCaseCode == PARAMETER2_ERROR) {
705         ret_ = OH_CaptureSession_GetFocusMode(captureSession_, nullptr);
706     } else {
707         ret_ = OH_CaptureSession_GetFocusMode(nullptr, &focusMode_);
708     }
709     return ret_;
710 }
SessionGetFocusPoint(int useCaseCode)711 Camera_ErrorCode NDKCamera::SessionGetFocusPoint(int useCaseCode)
712 {
713     if (useCaseCode == PARAMETER_OK) {
714         ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint_);
715     } else if (useCaseCode == PARAMETER2_ERROR) {
716         ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, nullptr);
717     } else {
718         ret_ = OH_CaptureSession_GetFocusPoint(nullptr, &focusPoint_);
719     }
720     return ret_;
721 }
SessionSetFocusPoint(double point_x,double point_y,int useCaseCode)722 Camera_ErrorCode NDKCamera::SessionSetFocusPoint(double point_x, double point_y, int useCaseCode)
723 {
724     Camera_Point point;
725     point.x = point_x;
726     point.y = point_y;
727     if (useCaseCode == PARAMETER_OK) {
728         ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, point);
729     } else if (useCaseCode == PARAMETER2_ERROR) {
730         return CAMERA_INVALID_ARGUMENT;
731         ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, point);
732     } else {
733         ret_ = OH_CaptureSession_SetFocusPoint(nullptr, point);
734     }
735     return ret_;
736 }
SessionGetMeteringPoint(int useCaseCode)737 Camera_ErrorCode NDKCamera::SessionGetMeteringPoint(int useCaseCode)
738 {
739     if (useCaseCode == PARAMETER_OK) {
740         ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, &point_);
741     } else if (useCaseCode == PARAMETER2_ERROR) {
742         ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, nullptr);
743     } else {
744         ret_ = OH_CaptureSession_GetMeteringPoint(nullptr, &point_);
745     }
746     return ret_;
747 }
SessionGetZoomRatio(int useCaseCode)748 Camera_ErrorCode NDKCamera::SessionGetZoomRatio(int useCaseCode)
749 {
750     if (useCaseCode == PARAMETER_OK) {
751         ret_ = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom_);
752     } else if (useCaseCode == PARAMETER2_ERROR) {
753         ret_ = OH_CaptureSession_GetZoomRatio(captureSession_, nullptr);
754     } else {
755         ret_ = OH_CaptureSession_GetZoomRatio(nullptr, &zoom_);
756     }
757     return ret_;
758 }
SessionGetZoomRatioRange(int useCaseCode)759 Camera_ErrorCode NDKCamera::SessionGetZoomRatioRange(int useCaseCode)
760 {
761     if (useCaseCode == PARAMETER_OK) {
762         ret_ = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom_, &maxZoom_);
763         LOG("最小缩放 %{public}.2f 最大缩放%{public}.2f", minZoom_, maxZoom_);
764     } else if (useCaseCode == PARAMETER2_ERROR) {
765         ret_ = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom_, nullptr);
766     } else if (useCaseCode == PARAMETER2_ERROR) {
767         ret_ = OH_CaptureSession_GetZoomRatioRange(captureSession_, nullptr, &maxZoom_);
768     } else {
769         ret_ = OH_CaptureSession_GetZoomRatioRange(nullptr, &minZoom_, &maxZoom_);
770     }
771     return ret_;
772 }
SessionSetZoomRatio(float zoom,int useCaseCode)773 Camera_ErrorCode NDKCamera::SessionSetZoomRatio(float zoom, int useCaseCode)
774 {
775     if (useCaseCode == PARAMETER_OK) {
776         ret_ = OH_CaptureSession_SetZoomRatio(captureSession_, zoom);
777     } else if (useCaseCode == PARAMETER2_ERROR) {
778         ret_ = OH_CaptureSession_SetZoomRatio(captureSession_, zoom);
779     } else {
780         ret_ = OH_CaptureSession_SetZoomRatio(nullptr, zoom);
781     }
782     return ret_;
783 }
SessionSetMeteringPoint(double point_x,double point_y,int useCaseCode)784 Camera_ErrorCode NDKCamera::SessionSetMeteringPoint(double point_x, double point_y, int useCaseCode)
785 {
786     Camera_Point point;
787     point.x = point_x;
788     point.y = point_y;
789     if (useCaseCode == PARAMETER_OK) {
790         ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, point);
791     } else if (useCaseCode == PARAMETER2_ERROR) {
792         ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, point);
793     } else {
794         ret_ = OH_CaptureSession_SetMeteringPoint(nullptr, point);
795     }
796     return ret_;
797 }
SessionIsVideoStabilizationModeSupported(uint32_t mode,int useCaseCode)798 Camera_ErrorCode NDKCamera::SessionIsVideoStabilizationModeSupported(uint32_t mode, int useCaseCode)
799 {
800     Camera_VideoStabilizationMode videoMode = static_cast<Camera_VideoStabilizationMode>(mode);
801     if (useCaseCode == PARAMETER_OK) {
802         ret_ =OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isVideoSupported_);
803     } else if (useCaseCode == PARAMETER3_ERROR) {
804         ret_ =OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, nullptr);
805     } else if (useCaseCode == PARAMETER2_ERROR) {
806         return CAMERA_INVALID_ARGUMENT;
807         ret_ = OH_CaptureSession_IsVideoStabilizationModeSupported(captureSession_, videoMode, &isVideoSupported_);
808     } else {
809         ret_ = OH_CaptureSession_IsVideoStabilizationModeSupported(nullptr, videoMode, &isVideoSupported_);
810     }
811     return ret_;
812 }
SessionGetVideoStabilizationMode(int useCaseCode)813 Camera_ErrorCode NDKCamera::SessionGetVideoStabilizationMode(int useCaseCode)
814 {
815     if (useCaseCode == PARAMETER_OK) {
816         ret_ = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode_);
817     } else if (useCaseCode == PARAMETER2_ERROR) {
818         ret_ = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, nullptr);
819     } else {
820         ret_ = OH_CaptureSession_GetVideoStabilizationMode(nullptr, &videoMode_);
821     }
822     return ret_;
823 }
SessionSetVideoStabilizationMode(uint32_t mode,int useCaseCode)824 Camera_ErrorCode NDKCamera::SessionSetVideoStabilizationMode(uint32_t mode, int useCaseCode)
825 {
826     Camera_VideoStabilizationMode videoMode = static_cast<Camera_VideoStabilizationMode>(mode);
827     if (useCaseCode == PARAMETER_OK) {
828         ret_ = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode);
829     } else if (useCaseCode == PARAMETER2_ERROR) {
830         return CAMERA_INVALID_ARGUMENT;
831         ret_ = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode);
832     } else {
833         ret_ = OH_CaptureSession_SetVideoStabilizationMode(nullptr, videoMode);
834     }
835     return ret_;
836 }
837 
SessionRemovePreviewOutput(int useCaseCode)838 Camera_ErrorCode NDKCamera::SessionRemovePreviewOutput(int useCaseCode)
839 {
840     if (useCaseCode == PARAMETER_OK) {
841         ret_ = OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_);
842     } else if (useCaseCode == PARAMETER2_ERROR) {
843         ret_ = OH_CaptureSession_RemovePreviewOutput(captureSession_, nullptr);
844     } else {
845         ret_ = OH_CaptureSession_RemovePreviewOutput(nullptr, previewOutput_);
846     }
847     return ret_;
848 }
SessionRemovePhotoOutput(int useCaseCode)849 Camera_ErrorCode NDKCamera::SessionRemovePhotoOutput(int useCaseCode)
850 {
851     if (useCaseCode == PARAMETER_OK) {
852         ret_ = OH_CaptureSession_RemovePhotoOutput(captureSession_, photoOutput_);
853     } else if (useCaseCode == PARAMETER2_ERROR) {
854         ret_ = OH_CaptureSession_RemovePhotoOutput(captureSession_, nullptr);
855     } else {
856         ret_ = OH_CaptureSession_RemovePhotoOutput(nullptr, photoOutput_);
857     }
858     return ret_;
859 }
AddVideoOutput(int useCaseCode)860 Camera_ErrorCode NDKCamera::AddVideoOutput(int useCaseCode)
861 {
862     if (useCaseCode == PARAMETER_OK) {
863         ret_ = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_);
864     } else if (useCaseCode == PARAMETER2_ERROR) {
865         ret_ = OH_CaptureSession_AddVideoOutput(captureSession_, nullptr);
866     } else {
867         ret_ = OH_CaptureSession_AddVideoOutput(nullptr, videoOutput_);
868     }
869     return ret_;
870 }
CreateVideoOutput(char * videoId,int useCaseCode)871 Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId, int useCaseCode)
872 {
873     vProfile_ = cameraOutputCapability_->videoProfiles[0];
874 
875     if (useCaseCode == PARAMETER_OK) {
876         ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, vProfile_, videoId, &videoOutput_);
877     } else if (useCaseCode == PARAMETER4_ERROR) {
878         ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, vProfile_, videoId, nullptr);
879     } else if (useCaseCode == PARAMETER3_ERROR) {
880         ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, vProfile_, nullptr, &videoOutput_);
881     } else if (useCaseCode == PARAMETER2_ERROR) {
882         ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, nullptr, videoId, &videoOutput_);
883     } else {
884         ret_ = OH_CameraManager_CreateVideoOutput(nullptr, vProfile_, videoId, &videoOutput_);
885     }
886     return ret_;
887 }
VideoOutputOnFrameStart(Camera_VideoOutput * videoOutput)888 void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput)
889 {
890     NDKCamera::cameraCallbackCode_ = VIDEO_ON_FRAME_START;
891     LOG("VideoOutputOnFrameStart");
892 }
893 
VideoOutputOnFrameEnd(Camera_VideoOutput * videoOutput,int32_t frameCount)894 void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount)
895 {
896     NDKCamera::cameraCallbackCode_ = VIDEO_ON_FRAME_END;
897     LOG("VideoOutput frameCount = %d", frameCount);
898 }
899 
VideoOutputOnError(Camera_VideoOutput * videoOutput,Camera_ErrorCode errorCode)900 void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode)
901 {
902     NDKCamera::cameraCallbackCode_ = VIDEO_ON_ERROR;
903     LOG("VideoOutput errorCode = %d", errorCode);
904 }
GetVideoOutputListener(void)905 VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void)
906 {
907     static VideoOutput_Callbacks videoOutputListener = {
908         .onFrameStart = VideoOutputOnFrameStart, .onFrameEnd = VideoOutputOnFrameEnd, .onError = VideoOutputOnError};
909     return &videoOutputListener;
910 }
VideoOutputRegisterCallback(int useCaseCode)911 Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(int useCaseCode)
912 {
913     if (useCaseCode == PARAMETER_OK) {
914         ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener());
915     } else if (useCaseCode == PARAMETER2_ERROR) {
916         ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, nullptr);
917     } else {
918         ret_ = OH_VideoOutput_RegisterCallback(nullptr, GetVideoOutputListener());
919     }
920     return ret_;
921 }
VideoOutputUnRegisterCallback(int useCaseCode)922 Camera_ErrorCode NDKCamera::VideoOutputUnRegisterCallback(int useCaseCode)
923 {
924     if (useCaseCode == PARAMETER_OK) {
925         ret_ = OH_VideoOutput_UnregisterCallback(videoOutput_, GetVideoOutputListener());
926     } else if (useCaseCode == PARAMETER2_ERROR) {
927         ret_ = OH_VideoOutput_UnregisterCallback(videoOutput_, nullptr);
928     } else {
929         ret_ = OH_VideoOutput_UnregisterCallback(nullptr, GetVideoOutputListener());
930     }
931     return ret_;
932 }
VideoOutputStart(int useCaseCode)933 Camera_ErrorCode NDKCamera::VideoOutputStart(int useCaseCode)
934 {
935     if (useCaseCode == PARAMETER_OK) {
936         ret_ = OH_VideoOutput_Start(videoOutput_);
937     } else {
938         ret_ = OH_VideoOutput_Start(nullptr);
939     }
940     return ret_;
941 }
VideoOutputStop(int useCaseCode)942 Camera_ErrorCode NDKCamera::VideoOutputStop(int useCaseCode)
943 {
944     if (useCaseCode == PARAMETER_OK) {
945         ret_ = OH_VideoOutput_Stop(videoOutput_);
946     } else {
947         ret_ = OH_VideoOutput_Stop(nullptr);
948     }
949     return ret_;
950 }
SessionRemoveVideoOutput(int useCaseCode)951 Camera_ErrorCode NDKCamera::SessionRemoveVideoOutput(int useCaseCode)
952 {
953     if (useCaseCode == PARAMETER_OK) {
954         ret_ = OH_CaptureSession_RemoveVideoOutput(captureSession_, videoOutput_);
955     } else if (useCaseCode == PARAMETER2_ERROR) {
956         ret_ = OH_CaptureSession_RemoveVideoOutput(captureSession_, nullptr);
957     } else {
958         ret_ = OH_CaptureSession_RemoveVideoOutput(nullptr, videoOutput_);
959     }
960     return ret_;
961 }
VideoOutputRelease(int useCaseCode)962 Camera_ErrorCode NDKCamera::VideoOutputRelease(int useCaseCode)
963 {
964     if (useCaseCode == PARAMETER_OK) {
965         ret_ = OH_VideoOutput_Release(videoOutput_);
966     } else {
967         ret_ = OH_VideoOutput_Release(nullptr);
968     }
969     return ret_;
970 }
PreviewOutputStart(int useCaseCode)971 Camera_ErrorCode NDKCamera::PreviewOutputStart(int useCaseCode)
972 {
973     if (useCaseCode == PARAMETER_OK) {
974         ret_ = OH_PreviewOutput_Start(previewOutput_);
975     } else {
976         ret_ = OH_PreviewOutput_Start(nullptr);
977     }
978     return ret_;
979 }
PreviewOutputStop(int useCaseCode)980 Camera_ErrorCode NDKCamera::PreviewOutputStop(int useCaseCode)
981 {
982     if (useCaseCode == PARAMETER_OK) {
983         ret_ = OH_PreviewOutput_Stop(previewOutput_);
984     } else {
985         ret_ = OH_PreviewOutput_Stop(nullptr);
986     }
987     return ret_;
988 }
PhotoOutputOnFrameStart(Camera_PhotoOutput * photoOutput)989 void PhotoOutputOnFrameStart(Camera_PhotoOutput *photoOutput)
990 {
991     NDKCamera::cameraCallbackCode_ = PHOTO_ON_FRAME_START;
992     LOG("PhotoOutputOnFrameStart");
993 }
994 
PhotoOutputOnFrameShutter(Camera_PhotoOutput * photoOutput,Camera_FrameShutterInfo * info)995 void PhotoOutputOnFrameShutter(Camera_PhotoOutput *photoOutput, Camera_FrameShutterInfo *info)
996 {
997     NDKCamera::cameraCallbackCode_ = PHOTO_ON_FRAME_SHUTTER;
998     LOG("PhotoOutputOnFrameShutter");
999 }
1000 
PhotoOutputOnFrameEnd(Camera_PhotoOutput * photoOutput,int32_t frameCount)1001 void PhotoOutputOnFrameEnd(Camera_PhotoOutput *photoOutput, int32_t frameCount)
1002 {
1003     NDKCamera::cameraCallbackCode_ = PHOTO_ON_FRAME_END;
1004     LOG("PhotoOutput frameCount = %d", frameCount);
1005 }
1006 
PhotoOutputOnError(Camera_PhotoOutput * photoOutput,Camera_ErrorCode errorCode)1007 void PhotoOutputOnError(Camera_PhotoOutput *photoOutput, Camera_ErrorCode errorCode)
1008 {
1009     NDKCamera::cameraCallbackCode_ = PHOTO_ON_ERROR;
1010     LOG("PhotoOutput errorCode = %d", errorCode);
1011 }
1012 
PreviewOutputRelease(int useCaseCode)1013 Camera_ErrorCode NDKCamera::PreviewOutputRelease(int useCaseCode)
1014 {
1015     if (useCaseCode == PARAMETER_OK) {
1016         ret_ = OH_PreviewOutput_Release(previewOutput_);
1017     } else {
1018         ret_ = OH_PreviewOutput_Release(nullptr);
1019     }
1020     return ret_;
1021 }
GetPhotoOutputListener(void)1022 PhotoOutput_Callbacks *NDKCamera::GetPhotoOutputListener(void)
1023 {
1024     static PhotoOutput_Callbacks photoOutputListener = {.onFrameStart = PhotoOutputOnFrameStart,
1025                                                         .onFrameShutter = PhotoOutputOnFrameShutter,
1026                                                         .onFrameEnd = PhotoOutputOnFrameEnd,
1027                                                         .onError = PhotoOutputOnError};
1028     return &photoOutputListener;
1029 }
1030 
PhotoOutputRegisterCallback(int useCaseCode)1031 Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(int useCaseCode)
1032 {
1033     if (useCaseCode == PARAMETER_OK) {
1034         ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener());
1035     } else if (useCaseCode == PARAMETER2_ERROR) {
1036         ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, nullptr);
1037     } else {
1038         ret_ = OH_PhotoOutput_RegisterCallback(nullptr, GetPhotoOutputListener());
1039     }
1040     return ret_;
1041 }
PhotoOutputUnRegisterCallback(int useCaseCode)1042 Camera_ErrorCode NDKCamera::PhotoOutputUnRegisterCallback(int useCaseCode)
1043 {
1044     if (useCaseCode == PARAMETER_OK) {
1045         ret_ = OH_PhotoOutput_UnregisterCallback(photoOutput_, GetPhotoOutputListener());
1046     } else if (useCaseCode == PARAMETER2_ERROR) {
1047         ret_ = OH_PhotoOutput_UnregisterCallback(photoOutput_, nullptr);
1048     } else {
1049         ret_ = OH_PhotoOutput_UnregisterCallback(nullptr, GetPhotoOutputListener());
1050     }
1051     return ret_;
1052 }
IsMirrorSupported(int useCaseCode)1053 Camera_ErrorCode NDKCamera::IsMirrorSupported(int useCaseCode)
1054 {
1055     if (useCaseCode == PARAMETER_OK) {
1056         ret_ = OH_PhotoOutput_IsMirrorSupported(photoOutput_, &isMirror_);
1057     } else if (useCaseCode == PARAMETER2_ERROR) {
1058         ret_ = OH_PhotoOutput_IsMirrorSupported(photoOutput_, nullptr);
1059     } else {
1060         ret_ = OH_PhotoOutput_IsMirrorSupported(nullptr, &isMirror_);
1061     }
1062     return ret_;
1063 }
EnableMirror(int useCaseCode)1064 Camera_ErrorCode NDKCamera::EnableMirror(int useCaseCode)
1065 {
1066     if (useCaseCode == PARAMETER_OK) {
1067         ret_ = OH_PhotoOutput_EnableMirror(photoOutput_, isEnableMirror_);
1068     } else if (useCaseCode == PARAMETER2_ERROR) {
1069         ret_ = OH_PhotoOutput_EnableMirror(photoOutput_, 0);
1070     } else {
1071         ret_ = OH_PhotoOutput_EnableMirror(nullptr, isEnableMirror_);
1072     }
1073     return ret_;
1074 }
PhotoOutputCapture(int useCaseCode)1075 Camera_ErrorCode NDKCamera::PhotoOutputCapture(int useCaseCode)
1076 {
1077     if (useCaseCode == PARAMETER_OK) {
1078         ret_ = OH_PhotoOutput_Capture(photoOutput_);
1079     } else {
1080         ret_ = OH_PhotoOutput_Capture(nullptr);
1081     }
1082     return ret_;
1083 }
TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting,int useCaseCode)1084 Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting, int useCaseCode)
1085 {
1086     if (useCaseCode == PARAMETER_OK) {
1087         ret_ = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photoSetting);
1088     } else if (useCaseCode == PARAMETER2_ERROR) {
1089         ret_ = OH_PhotoOutput_Capture_WithCaptureSetting(photoOutput_, photoSetting);
1090     } else {
1091         ret_ = OH_PhotoOutput_Capture_WithCaptureSetting(nullptr, photoSetting);
1092     }
1093     return ret_;
1094 }
PhotoOutputRelease(int useCaseCode)1095 Camera_ErrorCode NDKCamera::PhotoOutputRelease(int useCaseCode)
1096 {
1097     if (useCaseCode == PARAMETER_OK) {
1098         ret_ = OH_PhotoOutput_Release(photoOutput_);
1099     } else {
1100         ret_ = OH_PhotoOutput_Release(nullptr);
1101     }
1102     return ret_;
1103 }