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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
32 "Invaild argument, videoOutput is null!");
33 CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
34 "Invaild argument, callback is null!");
35 CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
36 "Invaild argument, callback onFrameStart is null!");
37 CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
38 "Invaild argument, callback onFrameEnd is null!");
39 CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
40 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
53 "Invaild argument, videoOutput is null!");
54 CHECK_AND_RETURN_RET_LOG(callback != nullptr, CAMERA_INVALID_ARGUMENT,
55 "Invaild argument, callback is null!");
56 CHECK_AND_RETURN_RET_LOG(callback->onFrameStart!= nullptr, CAMERA_INVALID_ARGUMENT,
57 "Invaild argument, callback onFrameStart is null!");
58 CHECK_AND_RETURN_RET_LOG(callback->onFrameEnd!= nullptr, CAMERA_INVALID_ARGUMENT,
59 "Invaild argument, callback onFrameEnd is null!");
60 CHECK_AND_RETURN_RET_LOG(callback->onError!= nullptr, CAMERA_INVALID_ARGUMENT,
61 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
74 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
86 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
98 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
115 "Invaild argument, videoOutput is null!");
116 CHECK_AND_RETURN_RET_LOG(profile != nullptr, CAMERA_INVALID_ARGUMENT,
117 "Invaild 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_AND_RETURN_RET_LOG(profile != nullptr, CAMERA_INVALID_ARGUMENT,
130 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
145 "Invaild argument, videoOutput is null!");
146 CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
147 "Invaild argument, frameRateRange is null!");
148 CHECK_AND_RETURN_RET_LOG(size != nullptr, CAMERA_INVALID_ARGUMENT,
149 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
162 "Invaild argument, videoOutput is null!");
163 CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
164 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
177 "Invaild 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_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
189 "Invaild argument, videoOutput is null!");
190 CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, CAMERA_INVALID_ARGUMENT,
191 "Invaild argument, frameRateRange is null!");
192
193 return videoOutput->GetActiveFrameRate(frameRateRange);
194 }
195 /**
196 * @since 12
197 * @version 1.0
198 */
OH_VideoOutput_GetVideoRotation(Camera_VideoOutput * videoOutput,int deviceDegree,Camera_ImageRotation * imageRotation)199 Camera_ErrorCode OH_VideoOutput_GetVideoRotation(Camera_VideoOutput* videoOutput, int deviceDegree,
200 Camera_ImageRotation* imageRotation)
201 {
202 MEDIA_DEBUG_LOG("OH_VideoOutput_GetVideoRotation is called.");
203 CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT,
204 "Invaild argument, videoOutput is null!");
205 CHECK_AND_RETURN_RET_LOG(imageRotation != nullptr, CAMERA_INVALID_ARGUMENT,
206 "Invaild argument, imageRotation is null!");
207 return videoOutput->GetVideoRotation(deviceDegree, imageRotation);
208 }
209 #ifdef __cplusplus
210 }
211 #endif