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 
109 /**
110  * @since 12
111  * @version 1.0
112  */
OH_PreviewOutput_GetActiveProfile(Camera_PreviewOutput * previewOutput,Camera_Profile ** profile)113 Camera_ErrorCode OH_PreviewOutput_GetActiveProfile(Camera_PreviewOutput* previewOutput, Camera_Profile** profile)
114 {
115     MEDIA_DEBUG_LOG("OH_PreviewOutput_GetActiveProfile is called.");
116     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
117         "Invaild argument, previewOutput is null!");
118     CHECK_AND_RETURN_RET_LOG(profile != nullptr, CAMERA_INVALID_ARGUMENT,
119         "Invaild argument, profile is null!");
120 
121     return previewOutput->GetActiveProfile(profile);
122 }
123 
124 /**
125  * @since 12
126  * @version 1.0
127  */
OH_PreviewOutput_DeleteProfile(Camera_Profile * profile)128 Camera_ErrorCode OH_PreviewOutput_DeleteProfile(Camera_Profile* profile)
129 {
130     MEDIA_DEBUG_LOG("OH_PreviewOutput_DeleteProfile is called.");
131     CHECK_AND_RETURN_RET_LOG(profile != nullptr, CAMERA_INVALID_ARGUMENT,
132         "Invaild argument, profile is null!");
133 
134     delete profile;
135     profile = nullptr;
136     return CAMERA_OK;
137 }
138 
139 /**
140  * @since 12
141  * @version 1.0
142  */
OH_PreviewOutput_GetSupportedFrameRates(Camera_PreviewOutput * previewOutput,Camera_FrameRateRange ** frameRateRange,uint32_t * size)143 Camera_ErrorCode OH_PreviewOutput_GetSupportedFrameRates(Camera_PreviewOutput* previewOutput,
144     Camera_FrameRateRange** frameRateRange, uint32_t* size)
145 {
146     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
147         "Invaild argument, previewOutput is null!");
148     CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
149         "Invaild argument, frameRateRange is null!");
150     CHECK_AND_RETURN_RET_LOG(size != nullptr, CAMERA_INVALID_ARGUMENT,
151         "Invaild argument, size is null!");
152 
153     return previewOutput->GetSupportedFrameRates(frameRateRange, size);
154 }
155 
156 /**
157  * @since 12
158  * @version 1.0
159  */
OH_PreviewOutput_DeleteFrameRates(Camera_PreviewOutput * previewOutput,Camera_FrameRateRange * frameRateRange)160 Camera_ErrorCode OH_PreviewOutput_DeleteFrameRates(Camera_PreviewOutput* previewOutput,
161     Camera_FrameRateRange* frameRateRange)
162 {
163     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
164         "Invaild argument, previewOutput is null!");
165     CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
166         "Invaild argument, frameRateRange is null!");
167 
168     return previewOutput->DeleteFrameRates(frameRateRange);
169 }
170 
171 /**
172  * @since 12
173  * @version 1.0
174  */
OH_PreviewOutput_SetFrameRate(Camera_PreviewOutput * previewOutput,int32_t minFps,int32_t maxFps)175 Camera_ErrorCode OH_PreviewOutput_SetFrameRate(Camera_PreviewOutput* previewOutput,
176     int32_t minFps, int32_t maxFps)
177 {
178     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
179         "Invaild argument, previewOutput is null!");
180 
181     return previewOutput->SetFrameRate(minFps, maxFps);
182 }
183 
184 /**
185  * @since 12
186  * @version 1.0
187  */
OH_PreviewOutput_GetActiveFrameRate(Camera_PreviewOutput * previewOutput,Camera_FrameRateRange * frameRateRange)188 Camera_ErrorCode OH_PreviewOutput_GetActiveFrameRate(Camera_PreviewOutput* previewOutput,
189     Camera_FrameRateRange* frameRateRange)
190 {
191     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
192         "Invaild argument, previewOutput is null!");
193     CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
194         "Invaild argument, frameRateRange is null!");
195 
196     return previewOutput->GetActiveFrameRate(frameRateRange);
197 }
198 
OH_PreviewOutput_GetPreviewRotation(Camera_PreviewOutput * previewOutput,int displayRotation,Camera_ImageRotation * imageRotation)199 Camera_ErrorCode OH_PreviewOutput_GetPreviewRotation(Camera_PreviewOutput* previewOutput, int displayRotation,
200     Camera_ImageRotation* imageRotation)
201 {
202     MEDIA_DEBUG_LOG("OH_PreviewOutput_GetPreviewRotation is called.");
203     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
204         "Invaild argument, previewOutput is null!");
205     CHECK_AND_RETURN_RET_LOG(imageRotation != nullptr, CAMERA_INVALID_ARGUMENT,
206         "Invaild argument, imageRotation is null!");
207     return previewOutput->GetPreviewRotation(displayRotation, imageRotation);
208 }
209 
OH_PreviewOutput_SetPreviewRotation(Camera_PreviewOutput * previewOutput,Camera_ImageRotation previewRotation,bool isDisplayLocked)210 Camera_ErrorCode OH_PreviewOutput_SetPreviewRotation(Camera_PreviewOutput* previewOutput,
211     Camera_ImageRotation previewRotation, bool isDisplayLocked)
212 {
213     MEDIA_DEBUG_LOG("OH_PreviewOutput_SetPreviewRotation is called.");
214     CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT,
215         "Invaild argument, previewOutput is null!");
216     return previewOutput->SetPreviewRotation(previewRotation, isDisplayLocked);
217 }
218 #ifdef __cplusplus
219 }
220 #endif