• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 AVRecorder
18  * @{
19  *
20  * @brief Provides APIs of request capability for Recorder.
21  *
22  * @Syscap systemcapability.multimedia.media.avrecorder
23  * @since 18
24  * @version 1.0
25  * @}
26  */
27 
28  /**
29  * @file avrecorder.h
30  *
31  * @brief Defines the avrecorder APIs. Uses the Native APIs provided by Media AVRecorder
32  *        to record media data.
33  *
34  * @kit MediaKit
35  * @library libavrecorder.so
36  * @Syscap SystemCapability.Multimedia.Media.AVRecorder
37  * @since 18
38  * @version 1.0
39  */
40 
41 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_H
42 #define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_H
43 
44 #include <memory>
45 #include <stdint.h>
46 #include <stdio.h>
47 #include "avrecorder_base.h"
48 #include "native_averrors.h"
49 #include "external_window.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /**
56  * @brief Create a recorder
57  * @syscap SystemCapability.Multimedia.Media.AVRecorder
58  * @return Returns a pointer to an OH_AVRecorder instance for success, nullptr for failure
59  * @since 18
60  * @version 1.0
61 */
62 OH_AVRecorder *OH_AVRecorder_Create(void);
63 
64 /**
65  * @brief Prepare for recording with some parameters.
66  * @syscap SystemCapability.Multimedia.Media.AVRecorder
67  * @param recorder Pointer to an OH_AVRecorder instance
68  * @param config Pointer to an OH_AVRecorderConfig instance, see {@link OH_AVRecorderConfig}
69  * @return Function result code.
70  *         {@link AV_ERR_OK} if the execution is successful.
71  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder Prepare failed.
72  * @since 18
73  * @version 1.0
74  */
75 OH_AVErrCode OH_AVRecorder_Prepare(OH_AVRecorder *recorder, OH_AVRecorder_Config *config);
76 
77 /**
78  * @brief Get current recording parameters, it must be called after prepare.
79  * @syscap SystemCapability.Multimedia.Media.AVRecorder
80  * @param recorder Pointer to an OH_AVRecorder instance
81  * @param config Pointer to an OH_AVRecorderConfig instance, see {@link OH_AVRecorderConfig}
82  * @return Function result code.
83  *         {@link AV_ERR_OK} if the execution is successful.
84  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or config is null.
85  * @since 18
86  * @version 1.0
87  */
88 OH_AVErrCode OH_AVRecorder_GetAVRecorderConfig(OH_AVRecorder *recorder, OH_AVRecorder_Config **config);
89 
90 /**
91  * @brief Get input surface, it must be called between prepare completed and start.
92  * @syscap SystemCapability.Multimedia.Media.AVRecorder
93  * @param recorder Pointer to an OH_AVRecorder instance
94  * @param window Pointer to an OHNativeWindow instance, see {@link OHNativeWindow}
95  * @return Function result code.
96  *         {@link AV_ERR_OK} if the execution is successful.
97  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr.
98  * @since 18
99  * @version 1.0
100  */
101 OH_AVErrCode OH_AVRecorder_GetInputSurface(OH_AVRecorder *recorder, OHNativeWindow **window);
102 
103 /**
104  * @brief Update the video orientation before recorder start.
105  * @syscap SystemCapability.Multimedia.Media.AVRecorder
106  * @param recorder Pointer to an OH_AVRecorder instance
107  * @param rotation angle, should be [0, 90, 180, 270]
108  * @return Function result code.
109  *         {@link AV_ERR_OK} if the execution is successful.
110  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or update rotation failed.
111  * @since 18
112  * @version 1.0
113  */
114 OH_AVErrCode OH_AVRecorder_UpdateRotation(OH_AVRecorder *recorder, int32_t rotation);
115 
116 /**
117  * @brief Start AVRecorder.
118  * @syscap SystemCapability.Multimedia.Media.AVRecorder
119  * @param recorder Pointer to an OH_AVRecorder instance
120  * @return Function result code.
121  *         {@link AV_ERR_OK} if the execution is successful.
122  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder start failed.
123  * @since 18
124  * @version 1.0
125  */
126 OH_AVErrCode OH_AVRecorder_Start(OH_AVRecorder *recorder);
127 
128 /**
129  * @brief Pause AVRecorder.
130  * @syscap SystemCapability.Multimedia.Media.AVRecorder
131  * @param recorder Pointer to an OH_AVRecorder instance
132  * @return Function result code.
133  *         {@link AV_ERR_OK} if the execution is successful.
134  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder pause failed.
135  * @since 18
136  * @version 1.0
137  */
138 OH_AVErrCode OH_AVRecorder_Pause(OH_AVRecorder *recorder);
139 
140 /**
141  * @brief Resume AVRecorder.
142  * @syscap SystemCapability.Multimedia.Media.AVRecorder
143  * @param recorder Pointer to an OH_AVRecorder instance
144  * @return Function result code.
145  *         {@link AV_ERR_OK} if the execution is successful.
146  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder resume failed.
147  * @since 18
148  * @version 1.0
149  */
150 OH_AVErrCode OH_AVRecorder_Resume(OH_AVRecorder *recorder);
151 
152 /**
153  * @brief Stop AVRecorder.
154  * @syscap SystemCapability.Multimedia.Media.AVRecorder
155  * @param recorder Pointer to an OH_AVRecorder instance
156  * @return Function result code.
157  *         {@link AV_ERR_OK} if the execution is successful.
158  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder stop failed.
159  * @since 18
160  * @version 1.0
161  */
162 OH_AVErrCode OH_AVRecorder_Stop(OH_AVRecorder *recorder);
163 
164 /**
165  * @brief Reset AVRecorder.
166  * @syscap SystemCapability.Multimedia.Media.AVRecorder
167  * @param recorder Pointer to an OH_AVRecorder instance
168  * @return Function result code.
169  *         {@link AV_ERR_OK} if the execution is successful.
170  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder reset failed.
171  * @since 18
172  * @version 1.0
173  */
174 OH_AVErrCode OH_AVRecorder_Reset(OH_AVRecorder *recorder);
175 
176 /**
177  * @brief Release AVRecorder.
178  * @syscap SystemCapability.Multimedia.Media.AVRecorder
179  * @param recorder Pointer to an OH_AVRecorder instance
180  * @return Function result code.
181  *         {@link AV_ERR_OK} if the execution is successful.
182  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder release failed.
183  * @since 18
184  * @version 1.0
185  */
186 OH_AVErrCode OH_AVRecorder_Release(OH_AVRecorder *recorder);
187 
188 /**
189  * @brief Get available encoder and encoder info for AVRecorder.
190  * @syscap SystemCapability.Multimedia.Media.AVRecorder
191  * @param recorder Pointer to an OH_AVRecorder instance
192  * @param info Double Pointer to an OH_EncoderInfo instance, see {@link OH_AVRecorder_EncoderInfo}
193  * @param length Length of available encoders
194  * @return Function result code.
195  *         {@link AV_ERR_OK} if the execution is successful.
196  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or recorder release failed.
197  * @since 18
198  * @version 1.0
199  */
200 OH_AVErrCode OH_AVRecorder_GetAvailableEncoder(OH_AVRecorder *recorder, OH_AVRecorder_EncoderInfo **info,
201     int32_t *length);
202 
203 /**
204  * @brief Set the state callback function so that your application can respond to the
205  * state change events generated by the av recorder. This interface must be called before Start is called.
206  * @syscap SystemCapability.Multimedia.Media.AVRecorder
207  * @param recorder Pointer to an OH_AVRecorder instance
208  * @param callback State callback function, see {@link OH_AVRecorder_OnStateChange}
209  * @param userData Pointer to user specific data
210  * @return Function result code.
211  *         {@link AV_ERR_OK} if the execution is successful.
212  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or input callback is nullptr.
213  * @since 18
214  * @version 1.0
215  */
216 OH_AVErrCode OH_AVRecorder_SetStateCallback(
217     OH_AVRecorder *recorder, OH_AVRecorder_OnStateChange callback, void *userData);
218 
219 /**
220  * @brief Set the error callback function so that your application can respond to the
221  * error events generated by the av recorder. This interface must be called before Start is called.
222  * @syscap SystemCapability.Multimedia.Media.AVRecorder
223  * @param recorder Pointer to an OH_AVRecorder instance
224  * @param callback Error callback function, see {@link OH_AVRecorder_OnError}
225  * @param userData Pointer to user specific data
226  * @return Function result code.
227  *         {@link AV_ERR_OK} if the execution is successful.
228  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or input callback is nullptr.
229  * @since 18
230  * @version 1.0
231  */
232 OH_AVErrCode OH_AVRecorder_SetErrorCallback(OH_AVRecorder *recorder, OH_AVRecorder_OnError callback, void *userData);
233 
234 #ifdef SUPPORT_RECORDER_CREATE_FILE
235 /**
236  * @brief Set the URI callback function so that your application can respond to the
237  * URI events generated by the av recorder. This interface must be called before Start is called.
238  * @syscap SystemCapability.Multimedia.Media.AVRecorder
239  * @param recorder Pointer to an OH_AVRecorder instance
240  * @param callback Uri callback function, see {@link OH_AVRecorder_OnUri}
241  * @param userData Pointer to user specific data
242  * @return Function result code.
243  *         {@link AV_ERR_OK} if the execution is successful.
244  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr or input callback is nullptr.
245  * @since 18
246  * @version 1.0
247  */
248 OH_AVErrCode OH_AVRecorder_SetUriCallback(OH_AVRecorder *recorder, OH_AVRecorder_OnUri callback, void *userData);
249 #endif
250 
251 /**
252  * @brief Set recorder configuration, if app want its recorder only to be muted instead of interrupted.
253  *
254  * @param recorder Pointer to an OH_AVRecorder instance
255  * @param muteWhenInterrupted use {@code true} if application want to be muted instead of interrupted.
256  * @return Function result code.
257  *         {@link AV_ERR_OK} if the execution is successful.
258  *         {@link AV_ERR_INVALID_VAL} if input recorder is nullptr.
259  *         {@link AV_ERR_INVALID_STATE} function called in invalid state, only available before prepare state.
260  * @since 20
261  */
262 OH_AVErrCode OH_AVRecorder_SetWillMuteWhenInterrupted(OH_AVRecorder *recorder, bool muteWhenInterrupted);
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_H