1/*
2 * Copyright (C) 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/**
17 * @addtogroup OH_Camera
18 * @{
19 *
20 * @brief Provide the definition of the C interface for the camera module.
21 *
22 * @syscap SystemCapability.Multimedia.Camera.Core
23 *
24 * @since 11
25 * @version 1.0
26 */
27
28/**
29 * @file preview_output.h
30 *
31 * @brief Declare the preview output concepts.
32 *
33 * @library libohcamera.so
34 * @kit CameraKit
35 * @syscap SystemCapability.Multimedia.Camera.Core
36 * @since 11
37 * @version 1.0
38 */
39
40#ifndef NATIVE_INCLUDE_CAMERA_PREVIEWOUTPUT_H
41#define NATIVE_INCLUDE_CAMERA_PREVIEWOUTPUT_H
42
43#include <stdint.h>
44#include <stdio.h>
45#include "camera.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * @brief Preview output object
53 *
54 * A pointer can be created using {@link Camera_PreviewOutput} method.
55 *
56 * @since 11
57 * @version 1.0
58 */
59typedef struct Camera_PreviewOutput Camera_PreviewOutput;
60
61/**
62 * @brief Preview output frame start callback to be called in {@link PreviewOutput_Callbacks}.
63 *
64 * @param previewOutput the {@link Camera_PreviewOutput} which deliver the callback.
65 * @since 11
66 */
67typedef void (*OH_PreviewOutput_OnFrameStart)(Camera_PreviewOutput* previewOutput);
68
69/**
70 * @brief Preview output frame end callback to be called in {@link PreviewOutput_Callbacks}.
71 *
72 * @param previewOutput the {@link Camera_PreviewOutput} which deliver the callback.
73 * @param frameCount the frame count which delivered by the callback.
74 * @since 11
75 */
76typedef void (*OH_PreviewOutput_OnFrameEnd)(Camera_PreviewOutput* previewOutput, int32_t frameCount);
77
78/**
79 * @brief Preview output error callback to be called in {@link PreviewOutput_Callbacks}.
80 *
81 * @param previewOutput the {@link Camera_PreviewOutput} which deliver the callback.
82 * @param errorCode the {@link Camera_ErrorCode} of the preview output.
83 *
84 * @see CAMERA_SERVICE_FATAL_ERROR
85 * @since 11
86 */
87typedef void (*OH_PreviewOutput_OnError)(Camera_PreviewOutput* previewOutput, Camera_ErrorCode errorCode);
88
89/**
90 * @brief A listener for preview output.
91 *
92 * @see OH_PreviewOutput_RegisterCallback
93 * @since 11
94 * @version 1.0
95 */
96typedef struct PreviewOutput_Callbacks {
97    /**
98     * Preview output frame start event.
99     */
100    OH_PreviewOutput_OnFrameStart onFrameStart;
101
102    /**
103     * Preview output frame end event.
104     */
105    OH_PreviewOutput_OnFrameEnd onFrameEnd;
106
107    /**
108     * Preview output error event.
109     */
110    OH_PreviewOutput_OnError onError;
111} PreviewOutput_Callbacks;
112
113/**
114 * @brief Register preview output change event callback.
115 *
116 * @param previewOutput the {@link Camera_PreviewOutput} instance.
117 * @param callback the {@link PreviewOutput_Callbacks} to be registered.
118 * @return {@link #CAMERA_OK} if the method call succeeds.
119 *         {@link #INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
120 * @since 11
121 */
122Camera_ErrorCode OH_PreviewOutput_RegisterCallback(Camera_PreviewOutput* previewOutput,
123    PreviewOutput_Callbacks* callback);
124
125/**
126 * @brief Unregister preview output change event callback.
127 *
128 * @param previewOutput the {@link Camera_PreviewOutput} instance.
129 * @param callback the {@link PreviewOutput_Callbacks} to be unregistered.
130 * @return {@link #CAMERA_OK} if the method call succeeds.
131 *         {@link #INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
132 * @since 11
133 */
134Camera_ErrorCode OH_PreviewOutput_UnregisterCallback(Camera_PreviewOutput* previewOutput,
135    PreviewOutput_Callbacks* callback);
136
137/**
138 * @brief Start preview output.
139 *
140 * @param previewOutput the {@link Camera_PreviewOutput} instance to be started.
141 * @return {@link #CAMERA_OK} if the method call succeeds.
142 *         {@link #INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
143 *         {@link #CAMERA_SESSION_NOT_CONFIG} if the capture session not config.
144 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
145 * @since 11
146 */
147Camera_ErrorCode OH_PreviewOutput_Start(Camera_PreviewOutput* previewOutput);
148
149/**
150 * @brief Stop preview output.
151 *
152 * @param previewOutput the {@link Camera_PreviewOutput} instance to be stoped.
153 * @return {@link #CAMERA_OK} if the method call succeeds.
154 *         {@link #INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
155 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
156 * @since 11
157 */
158Camera_ErrorCode OH_PreviewOutput_Stop(Camera_PreviewOutput* previewOutput);
159
160/**
161 * @brief Release preview output.
162 *
163 * @param previewOutput the {@link Camera_PreviewOutput} instance to be released.
164 * @return {@link #CAMERA_OK} if the method call succeeds.
165 *         {@link #INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
166 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
167 * @since 11
168 */
169Camera_ErrorCode OH_PreviewOutput_Release(Camera_PreviewOutput* previewOutput);
170
171/**
172 * @brief Get active preview output profile.
173 *
174 * @param previewOutput the {@link Camera_PreviewOutput} instance to deliver active profile.
175 * @param profile the active {@link Camera_Profile} to be filled if the method call succeeds.
176 * @return {@link #CAMERA_OK} if the method call succeeds.
177 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
178 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
179 * @since 12
180 */
181Camera_ErrorCode OH_PreviewOutput_GetActiveProfile(Camera_PreviewOutput* previewOutput, Camera_Profile** profile);
182
183/**
184 * @brief Delete preview profile instance.
185 *
186 * @param profile the {@link Camera_Profile} instance to deleted.
187 * @return {@link #CAMERA_OK} if the method call succeeds.
188 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
189 * @since 12
190 */
191Camera_ErrorCode OH_PreviewOutput_DeleteProfile(Camera_Profile* profile);
192
193/**
194 * @brief Gets the preview rotation angle.
195 *
196 * @param previewOutput the {@link Camera_PreviewOutput} instance which used to get the preview rotation angle.
197 * @param displayRotation the current display rotation angle.
198 * @param imageRotation the {@link Camera_ImageRotation} result of preview rotation angle.
199 * @return {@link #CAMERA_OK} if the method call succeeds.
200 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
201 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
202 * @since 12
203 */
204Camera_ErrorCode OH_PreviewOutput_GetPreviewRotation(Camera_PreviewOutput* previewOutput, int displayRotation,
205    Camera_ImageRotation* imageRotation);
206
207/**
208 * @brief Sets the preview rotation angle.
209 *
210 * @param previewOutput the {@link Camera_PreviewOutput} instance which used to set the preview rotation angle.
211 * @param previewRotation the {@link Camera_ImageRotation} of preview display rotation angle.
212 * @param isDisplayLocked TRUE means the display is locked.
213 * @return {@link #CAMERA_OK} if the method call succeeds.
214 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
215 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
216 * @since 12
217 */
218Camera_ErrorCode OH_PreviewOutput_SetPreviewRotation(Camera_PreviewOutput* previewOutput,
219    Camera_ImageRotation previewRotation, bool isDisplayLocked);
220
221/**
222 * @brief Get supported preview output frame rate list.
223 *
224 * @param previewOutput the {@link Camera_PreviewOutput} instance to deliver supported frame rate list.
225 * @param frameRateRange the supported {@link Camera_FrameRateRange} list to be filled if the method call succeeds.
226 * @param size the size of supported {@link Camera_FrameRateRange} list will be filled.
227 * @return {@link #CAMERA_OK} if the method call succeeds.
228 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
229 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
230 * @since 12
231 */
232Camera_ErrorCode OH_PreviewOutput_GetSupportedFrameRates(Camera_PreviewOutput* previewOutput,
233    Camera_FrameRateRange** frameRateRange, uint32_t* size);
234
235/**
236 * @brief Delete frame rate list.
237 *
238 * @param previewOutput the {@link Camera_PreviewOutput} instance to deliver supported frame rate list.
239 * @param frameRateRange the {@link Camera_FrameRateRange} list to be deleted.
240 * @return {@link #CAMERA_OK} if the method call succeeds.
241 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
242 * @since 12
243 */
244Camera_ErrorCode OH_PreviewOutput_DeleteFrameRates(Camera_PreviewOutput* previewOutput,
245    Camera_FrameRateRange* frameRateRange);
246
247/**
248 * @brief Set preview output frame rate.
249 *
250 * @param previewOutput the {@link Camera_PreviewOutput} instance to be set frame rate.
251 * @param minFps the minimum to be set.
252 * @param maxFps the maximum to be set.
253 * @return {@link #CAMERA_OK} if the method call succeeds.
254 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
255 * @since 12
256 */
257Camera_ErrorCode OH_PreviewOutput_SetFrameRate(Camera_PreviewOutput* previewOutput,
258    int32_t minFps, int32_t maxFps);
259
260/**
261 * @brief Get active preview output frame rate.
262 *
263 * @param previewOutput the {@link Camera_PreviewOutput} instance to deliver the active frame rate.
264 * @param frameRateRange the active {@link Camera_FrameRateRange} to be filled if the method call succeeds.
265 * @return {@link #CAMERA_OK} if the method call succeeds.
266 *         {@link #CAMERA_INVALID_ARGUMENT} if parameter missing or parameter type incorrect.
267 *         {@link #CAMERA_SERVICE_FATAL_ERROR} if camera service fatal error.
268 * @since 12
269 */
270Camera_ErrorCode OH_PreviewOutput_GetActiveFrameRate(Camera_PreviewOutput* previewOutput,
271    Camera_FrameRateRange* frameRateRange);
272
273#ifdef __cplusplus
274}
275#endif
276
277#endif // NATIVE_INCLUDE_CAMERA_PREVIEWOUTPUT_H
278/** @} */