• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "kits/native/include/camera/preview_output.h"
17 #include "impl/preview_output_impl.h"
18 #include "camera_log.h"
19 #include "hilog/log.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @since 11
27  * @version 1.0
28  */
OH_PreviewOutput_RegisterCallback(Camera_PreviewOutput * previewOutput,PreviewOutput_Callbacks * callback)29 Camera_ErrorCode OH_PreviewOutput_RegisterCallback(Camera_PreviewOutput* previewOutput,
30     PreviewOutput_Callbacks* callback)
31 {
32     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
33         "invaild argument! previewOutput is null!");
34     CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
35         "invaild argument! callback is null!");
36     CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
37         "invaild argument! callback onFrameStart is null!");
38     CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
39         "invaild argument! callback onFrameEnd is null!");
40     CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
41         "invaild argument! callback onError is null!");
42 
43     previewOutput->RegisterCallback(callback);
44     return CAMERA_OK;
45 }
46 
47 /**
48  * @since 11
49  * @version 1.0
50  */
OH_PreviewOutput_UnregisterCallback(Camera_PreviewOutput * previewOutput,PreviewOutput_Callbacks * callback)51 Camera_ErrorCode OH_PreviewOutput_UnregisterCallback(Camera_PreviewOutput* previewOutput,
52     PreviewOutput_Callbacks* callback)
53 {
54     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
55         "invaild argument! previewOutput is null!");
56     CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
57         "invaild argument! callback is null!");
58     CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
59         "invaild argument! callback onFrameStart is null!");
60     CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
61         "invaild argument! callback onFrameEnd is null!");
62     CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
63         "invaild argument! callback onError is null!");
64 
65     previewOutput->UnregisterCallback(callback);
66     return CAMERA_OK;
67 }
68 
69 /**
70  * @since 11
71  * @version 1.0
72  */
OH_PreviewOutput_Start(Camera_PreviewOutput * previewOutput)73 Camera_ErrorCode OH_PreviewOutput_Start(Camera_PreviewOutput* previewOutput)
74 {
75     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
76         "invaild argument! previewOutput is null!");
77 
78     return previewOutput->Start();
79 }
80 
81 /**
82  * @since 11
83  * @version 1.0
84  */
OH_PreviewOutput_Stop(Camera_PreviewOutput * previewOutput)85 Camera_ErrorCode OH_PreviewOutput_Stop(Camera_PreviewOutput* previewOutput)
86 {
87     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
88         "invaild argument! previewOutput is null!");
89 
90     return previewOutput->Stop();
91 }
92 
93 /**
94  * @since 11
95  * @version 1.0
96  */
OH_PreviewOutput_Release(Camera_PreviewOutput * previewOutput)97 Camera_ErrorCode OH_PreviewOutput_Release(Camera_PreviewOutput* previewOutput)
98 {
99     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
100         "invaild argument! previewOutput is null!");
101 
102     Camera_ErrorCode retCode = previewOutput->Release();
103     if (previewOutput != nullptr) {
104         delete previewOutput;
105     }
106     return retCode;
107 }
108 #ifdef __cplusplus
109 }
110 #endif