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