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/video_output.h"
17 #include "impl/video_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_VideoOutput_RegisterCallback(Camera_VideoOutput * videoOutput,VideoOutput_Callbacks * callback)29 Camera_ErrorCode OH_VideoOutput_RegisterCallback(Camera_VideoOutput* videoOutput, VideoOutput_Callbacks* callback)
30 {
31 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
32 "Invalid argument, videoOutput is null!");
33 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARGUMENT,
34 "Invalid argument, callback is null!");
35 CHECK_ERROR_RETURN_RET_LOG(callback->onFrameStart == nullptr, CAMERA_INVALID_ARGUMENT,
36 "Invalid argument, callback onFrameStart is null!");
37 CHECK_ERROR_RETURN_RET_LOG(callback->onFrameEnd == nullptr, CAMERA_INVALID_ARGUMENT,
38 "Invalid argument, callback onFrameEnd is null!");
39 CHECK_ERROR_RETURN_RET_LOG(callback->onError == nullptr, CAMERA_INVALID_ARGUMENT,
40 "Invalid argument, callback onError is null!");
41
42 videoOutput->RegisterCallback(callback);
43 return CAMERA_OK;
44 }
45
46 /**
47 * @since 11
48 * @version 1.0
49 */
OH_VideoOutput_UnregisterCallback(Camera_VideoOutput * videoOutput,VideoOutput_Callbacks * callback)50 Camera_ErrorCode OH_VideoOutput_UnregisterCallback(Camera_VideoOutput* videoOutput, VideoOutput_Callbacks* callback)
51 {
52 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
53 "Invalid argument, videoOutput is null!");
54 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARGUMENT,
55 "Invalid argument, callback is null!");
56 CHECK_ERROR_RETURN_RET_LOG(callback->onFrameStart == nullptr, CAMERA_INVALID_ARGUMENT,
57 "Invalid argument, callback onFrameStart is null!");
58 CHECK_ERROR_RETURN_RET_LOG(callback->onFrameEnd == nullptr, CAMERA_INVALID_ARGUMENT,
59 "Invalid argument, callback onFrameEnd is null!");
60 CHECK_ERROR_RETURN_RET_LOG(callback->onError == nullptr, CAMERA_INVALID_ARGUMENT,
61 "Invalid argument, callback onError is null!");
62
63 videoOutput->UnregisterCallback(callback);
64 return CAMERA_OK;
65 }
66
67 /**
68 * @since 11
69 * @version 1.0
70 */
OH_VideoOutput_Start(Camera_VideoOutput * videoOutput)71 Camera_ErrorCode OH_VideoOutput_Start(Camera_VideoOutput* videoOutput)
72 {
73 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
74 "Invalid argument, videoOutput is null!");
75
76 return videoOutput->Start();
77 }
78
79 /**
80 * @since 11
81 * @version 1.0
82 */
OH_VideoOutput_Stop(Camera_VideoOutput * videoOutput)83 Camera_ErrorCode OH_VideoOutput_Stop(Camera_VideoOutput* videoOutput)
84 {
85 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
86 "Invalid argument, videoOutput is null!");
87
88 return videoOutput->Stop();
89 }
90
91 /**
92 * @since 11
93 * @version 1.0
94 */
OH_VideoOutput_Release(Camera_VideoOutput * videoOutput)95 Camera_ErrorCode OH_VideoOutput_Release(Camera_VideoOutput* videoOutput)
96 {
97 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
98 "Invalid argument, videoOutput is null!");
99
100 Camera_ErrorCode retCode = videoOutput->Release();
101 if (videoOutput != nullptr) {
102 delete videoOutput;
103 }
104 return retCode;
105 }
106
107 /**
108 * @since 12
109 * @version 1.0
110 */
OH_VideoOutput_GetActiveProfile(Camera_VideoOutput * videoOutput,Camera_VideoProfile ** profile)111 Camera_ErrorCode OH_VideoOutput_GetActiveProfile(Camera_VideoOutput* videoOutput, Camera_VideoProfile** profile)
112 {
113 MEDIA_DEBUG_LOG("OH_VideoOutput_GetActiveProfile is called.");
114 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
115 "Invalid argument, videoOutput is null!");
116 CHECK_ERROR_RETURN_RET_LOG(profile == nullptr, CAMERA_INVALID_ARGUMENT,
117 "Invalid argument, profile is null!");
118
119 return videoOutput->GetVideoProfile(profile);
120 }
121
122 /**
123 * @since 12
124 * @version 1.0
125 */
OH_VideoOutput_DeleteProfile(Camera_VideoProfile * profile)126 Camera_ErrorCode OH_VideoOutput_DeleteProfile(Camera_VideoProfile* profile)
127 {
128 MEDIA_DEBUG_LOG("OH_VideoOutput_DeleteProfile is called.");
129 CHECK_ERROR_RETURN_RET_LOG(profile == nullptr, CAMERA_INVALID_ARGUMENT,
130 "Invalid argument, profile is null!");
131
132 delete profile;
133 profile = nullptr;
134 return CAMERA_OK;
135 }
136
137 /**
138 * @since 12
139 * @version 1.0
140 */
OH_VideoOutput_GetSupportedFrameRates(Camera_VideoOutput * videoOutput,Camera_FrameRateRange ** frameRateRange,uint32_t * size)141 Camera_ErrorCode OH_VideoOutput_GetSupportedFrameRates(Camera_VideoOutput* videoOutput,
142 Camera_FrameRateRange** frameRateRange, uint32_t* size)
143 {
144 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
145 "Invalid argument, videoOutput is null!");
146 CHECK_ERROR_RETURN_RET_LOG(frameRateRange == nullptr, CAMERA_INVALID_ARGUMENT,
147 "Invalid argument, frameRateRange is null!");
148 CHECK_ERROR_RETURN_RET_LOG(size == nullptr, CAMERA_INVALID_ARGUMENT,
149 "Invalid argument, size is null!");
150
151 return videoOutput->GetSupportedFrameRates(frameRateRange, size);
152 }
153
154 /**
155 * @since 12
156 * @version 1.0
157 */
OH_VideoOutput_DeleteFrameRates(Camera_VideoOutput * videoOutput,Camera_FrameRateRange * frameRateRange)158 Camera_ErrorCode OH_VideoOutput_DeleteFrameRates(Camera_VideoOutput* videoOutput,
159 Camera_FrameRateRange* frameRateRange)
160 {
161 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
162 "Invalid argument, videoOutput is null!");
163 CHECK_ERROR_RETURN_RET_LOG(frameRateRange == nullptr, CAMERA_INVALID_ARGUMENT,
164 "Invalid argument, frameRateRange is null!");
165
166 return videoOutput->DeleteFrameRates(frameRateRange);
167 }
168
169 /**
170 * @since 12
171 * @version 1.0
172 */
OH_VideoOutput_SetFrameRate(Camera_VideoOutput * videoOutput,int32_t minFps,int32_t maxFps)173 Camera_ErrorCode OH_VideoOutput_SetFrameRate(Camera_VideoOutput* videoOutput,
174 int32_t minFps, int32_t maxFps)
175 {
176 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
177 "Invalid argument, videoOutput is null!");
178
179 return videoOutput->SetFrameRate(minFps, maxFps);
180 }
181 /**
182 * @since 12
183 * @version 1.0
184 */
OH_VideoOutput_GetActiveFrameRate(Camera_VideoOutput * videoOutput,Camera_FrameRateRange * frameRateRange)185 Camera_ErrorCode OH_VideoOutput_GetActiveFrameRate(Camera_VideoOutput* videoOutput,
186 Camera_FrameRateRange* frameRateRange)
187 {
188 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
189 "Invalid argument, videoOutput is null!");
190 CHECK_ERROR_RETURN_RET_LOG(frameRateRange == nullptr, CAMERA_INVALID_ARGUMENT,
191 "Invalid argument, frameRateRange is null!");
192
193 return videoOutput->GetActiveFrameRate(frameRateRange);
194 }
195
196 /**
197 * @since 15
198 * @version 1.0
199 */
OH_VideoOutput_IsMirrorSupported(Camera_VideoOutput * videoOutput,bool * isSupported)200 Camera_ErrorCode OH_VideoOutput_IsMirrorSupported(Camera_VideoOutput* videoOutput, bool* isSupported)
201 {
202 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
203 "Invalid argument, videoOutput is null!");
204 CHECK_ERROR_RETURN_RET_LOG(isSupported == nullptr, CAMERA_INVALID_ARGUMENT,
205 "Invalid argument, isSupported is null!");
206 return videoOutput->IsMirrorSupported(isSupported);
207 }
208
209 /**
210 * @since 15
211 * @version 1.0
212 */
OH_VideoOutput_EnableMirror(Camera_VideoOutput * videoOutput,bool mirrorMode)213 Camera_ErrorCode OH_VideoOutput_EnableMirror(Camera_VideoOutput* videoOutput, bool mirrorMode)
214 {
215 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
216 "Invalid argument, videoOutput is null!");
217 return videoOutput->EnableMirror(mirrorMode);
218 }
219
220 /**
221 * @since 12
222 * @version 1.0
223 */
OH_VideoOutput_GetVideoRotation(Camera_VideoOutput * videoOutput,int deviceDegree,Camera_ImageRotation * imageRotation)224 Camera_ErrorCode OH_VideoOutput_GetVideoRotation(Camera_VideoOutput* videoOutput, int deviceDegree,
225 Camera_ImageRotation* imageRotation)
226 {
227 MEDIA_DEBUG_LOG("OH_VideoOutput_GetVideoRotation is called.");
228 CHECK_ERROR_RETURN_RET_LOG(videoOutput == nullptr, CAMERA_INVALID_ARGUMENT,
229 "Invalid argument, videoOutput is null!");
230 CHECK_ERROR_RETURN_RET_LOG(imageRotation == nullptr, CAMERA_INVALID_ARGUMENT,
231 "Invalid argument, imageRotation is null!");
232 return videoOutput->GetVideoRotation(deviceDegree, imageRotation);
233 }
234 #ifdef __cplusplus
235 }
236 #endif