• 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_base.h
29  *
30  * @brief Defines the structure and enumeration for Media AVRecorder.
31  *
32  * @kit MediaKit
33  * @library libavrecorder.so
34  * @syscap SystemCapability.Multimedia.Media.AVRecorder
35  * @since 18
36  */
37 
38 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_BASE_H
39 #define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_BASE_H
40 
41 #include <string>
42 #include <stdint.h>
43 #include "multimedia/media_library/media_asset_base_capi.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Initialization of avrecorder
51  * @syscap SystemCapability.Multimedia.Media.AVRecorder
52  * @since 18
53  */
54 typedef struct OH_AVRecorder OH_AVRecorder;
55 
56 /**
57  * @brief audio source type for recorder
58  * @syscap SystemCapability.Multimedia.Media.AVRecorder
59  * @since 18
60  */
61 typedef enum OH_AVRecorder_AudioSourceType {
62     /* Default audio source type. */
63     AVRECORDER_DEFAULT = 0,
64     /* Source type mic. */
65     AVRECORDER_MIC = 1,
66     /* Source type Voice recognition. */
67     AVRECORDER_VOICE_RECOGNITION = 2,
68     /* Source type Voice communication. */
69     AVRECORDER_VOICE_COMMUNICATION = 7,
70     /* Source type Voice message. */
71     AVRECORDER_VOICE_MESSAGE = 10,
72     /* Source type Camcorder. */
73     AVRECORDER_CAMCORDER = 13,
74 } OH_AVRecorder_AudioSourceType;
75 
76 /**
77  * @brief video source type for recorder
78  * @syscap SystemCapability.Multimedia.Media.AVRecorder
79  * @since 18
80  */
81 typedef enum OH_AVRecorder_VideoSourceType {
82     /* Surface raw data. */
83     AVRECORDER_SURFACE_YUV = 0,
84     /* Surface ES data. */
85     AVRECORDER_SURFACE_ES = 1,
86 } OH_AVRecorder_VideoSourceType;
87 
88 /**
89  * @brief Enumerates Codec MIME types
90  * @syscap SystemCapability.Multimedia.Media.AVRecorder
91  * @since 18
92  */
93 typedef enum OH_AVRecorder_CodecMimeType {
94     /* H.264 codec MIME type. */
95     AVRECORDER_VIDEO_AVC = 2,
96     /* AAC codec MIME type. */
97     AVRECORDER_AUDIO_AAC = 3,
98     /* mp3 codec MIME type. */
99     AVRECORDER_AUDIO_MP3 = 4,
100     /* G711-mulaw codec MIME type. */
101     AVRECORDER_AUDIO_G711MU = 5,
102     /* MPEG4 codec MIME type. */
103     AVRECORDER_VIDEO_MPEG4 = 6,
104     /* H.265 codec MIME type. */
105     AVRECORDER_VIDEO_HEVC = 8,
106     /* AMR-NB codec MIME type. */
107     AVRECORDER_AUDIO_AMR_NB = 9,
108     /* AMR-WB codec MIME type. */
109     AVRECORDER_AUDIO_AMR_WB = 10,
110 } OH_AVRecorder_CodecMimeType;
111 
112 /**
113  * @brief Enumerates container format type(The abbreviation for 'container format type' is CFT)
114  * @syscap SystemCapability.Multimedia.Media.AVRecorder
115  * @since 18
116  */
117 typedef enum OH_AVRecorder_ContainerFormatType {
118     /* A video container format type mp4. */
119     AVRECORDER_CFT_MPEG_4 = 2,
120     /* An audio container format type m4a. */
121     AVRECORDER_CFT_MPEG_4A = 6,
122     /* An audio container format type amr. */
123     AVRECORDER_CFT_AMR = 8,
124     /* An audio container format type mp3. */
125     AVRECORDER_CFT_MP3 = 9,
126     /* An audio container format type wav. */
127     AVRECORDER_CFT_WAV = 10,
128 } OH_AVRecorder_ContainerFormatType;
129 
130 /**
131  * @brief Recorder States
132  * @syscap SystemCapability.Multimedia.Media.AVRecorder
133  * @since 18
134  */
135 typedef enum OH_AVRecorder_State {
136     /* idle states */
137     AVRECORDER_IDLE = 0,
138     /* prepared states */
139     AVRECORDER_PREPARED = 1,
140     /* started states */
141     AVRECORDER_STARTED = 2,
142     /* paused states */
143     AVRECORDER_PAUSED = 3,
144     /* stopped states */
145     AVRECORDER_STOPPED = 4,
146     /* released states */
147     AVRECORDER_RELEASED = 5,
148     /* error states */
149     AVRECORDER_ERROR = 6,
150 } OH_AVRecorder_State;
151 
152 /**
153  * @brief reason of recorder state change
154  * @syscap SystemCapability.Multimedia.Media.AVRecorder
155  * @since 18
156  */
157 typedef enum OH_AVRecorder_StateChangeReason {
158     /* State changed by user operation */
159     AVRECORDER_USER = 0,
160     /* State changed by background action */
161     AVRECORDER_BACKGROUND = 1,
162 } OH_AVRecorder_StateChangeReason;
163 
164 /**
165  * @brief mode of creating recorder file
166  * @syscap SystemCapability.Multimedia.Media.AVRecorder
167  * @since 18
168  */
169 typedef enum OH_AVRecorder_FileGenerationMode {
170     /* Application Creation */
171     AVRECORDER_APP_CREATE = 0,
172     /* System Creation. Valid only in camera scene */
173     AVRECORDER_AUTO_CREATE_CAMERA_SCENE = 1,
174 } OH_AVRecorder_FileGenerationMode;
175 
176 /**
177  * @brief Provides the media recorder profile definitions
178  * @syscap SystemCapability.Multimedia.Media.AVRecorder
179  * @since 18
180  */
181 typedef struct OH_AVRecorder_Profile {
182     /* Indicates the audio bitrate */
183     int32_t audioBitrate;
184     /* Indicates the number of audio channels */
185     int32_t audioChannels;
186     /* Indicates the audio encoding format */
187     OH_AVRecorder_CodecMimeType audioCodec;
188     /* Indicates the audio sampling rate */
189     int32_t audioSampleRate;
190     /* Indicates the output file format */
191     OH_AVRecorder_ContainerFormatType fileFormat;
192     /* Indicates the video bitrate */
193     int32_t videoBitrate;
194     /* Indicates the video encoding format */
195     OH_AVRecorder_CodecMimeType videoCodec;
196     /* Indicates the video width */
197     int32_t videoFrameWidth;
198     /* Indicates the video height */
199     int32_t videoFrameHeight;
200     /* Indicates the video frame rate */
201     int32_t videoFrameRate;
202     /* Whether to record HDR video */
203     bool isHdr;
204     /* Whether to encode the video in temporal scale mode */
205     bool enableTemporalScale;
206 } OH_AVRecorder_Profile;
207 
208 /**
209  * @brief Provides the geographical location definitions for media resources
210  * @syscap SystemCapability.Multimedia.Media.AVRecorder
211  * @since 18
212  */
213 typedef struct OH_AVRecorder_Location {
214     /* Latitude */
215     float latitude;
216     /* Longitude */
217     float longitude;
218 } OH_AVRecorder_Location;
219 
220 /**
221  * @brief define the basic template of metadata
222  * @syscap SystemCapability.Multimedia.Media.AVRecorder
223  * @since 18
224  */
225 typedef struct OH_AVRecorder_MetadataTemplate {
226     /* key value of the metadata */
227     char *key;
228     /* contents of the metadata */
229     char *value;
230 } OH_AVRecorder_MetadataTemplate;
231 
232 /**
233  * @brief Provides the container definition for media data
234  * @syscap SystemCapability.Multimedia.Media.AVRecorder
235  * @since 18
236  */
237 typedef struct OH_AVRecorder_Metadata {
238     /* The metadata to retrieve the content type or genre of the data source */
239     char *genre;
240     /* The metadata to retrieve the information about the video orientation */
241     char *videoOrientation;
242     /* The geographical location info of the video */
243     OH_AVRecorder_Location location;
244     /* Custom parameter key-value map read from moov.meta.list */
245     OH_AVRecorder_MetadataTemplate customInfo;
246 } OH_AVRecorder_Metadata;
247 
248 /**
249  * @brief Provides the media recorder configuration definitions
250  * @syscap SystemCapability.Multimedia.Media.AVRecorder
251  * @since 18
252  */
253 typedef struct OH_AVRecorder_Config {
254     /* Indicates the recording audio source type */
255     OH_AVRecorder_AudioSourceType audioSourceType;
256     /* Indicates the recording video source type */
257     OH_AVRecorder_VideoSourceType videoSourceType;
258     /* Contains the audio and video encoding profile settings */
259     OH_AVRecorder_Profile profile;
260     /* Defines the file URL */
261     char *url;
262     /* Specifies the file generation mode for recording output */
263     OH_AVRecorder_FileGenerationMode fileGenerationMode;
264     /* Contains additional metadata for the recorded media */
265     OH_AVRecorder_Metadata metadata;
266     /* Set the longest duration allowed for current recording */
267     int32_t maxDuration;
268 } OH_AVRecorder_Config;
269 
270 /**
271  * @brief Provides Range with lower and upper limit
272  * @syscap SystemCapability.Multimedia.Media.AVRecorder
273  * @since 18
274  */
275 typedef struct OH_AVRecorder_Range {
276     /* lower limit of the range */
277     int32_t min;
278     /* upper limit of the range */
279     int32_t max;
280 } OH_AVRecorder_Range;
281 
282 /**
283  * @brief Provides encoder info
284  * @syscap SystemCapability.Multimedia.Media.AVRecorder
285  * @since 18
286  */
287 typedef struct OH_AVRecorder_EncoderInfo {
288     /* encoder format MIME */
289     OH_AVRecorder_CodecMimeType mimeType;
290     /* encoder type, audio or video */
291     char *type;
292     /* audio or video encoder bitRate range */
293     OH_AVRecorder_Range bitRate;
294     /* video encoder frame rate range */
295     OH_AVRecorder_Range frameRate;
296     /* video encoder width range */
297     OH_AVRecorder_Range width;
298     /* video encoder height range */
299     OH_AVRecorder_Range height;
300     /* audio encoder channel range */
301     OH_AVRecorder_Range channels;
302     /* audio encoder sample rate collection */
303     int32_t *sampleRate;
304     /* length of sampleRate list */
305     int32_t sampleRateLen;
306 } OH_AVRecorder_EncoderInfo;
307 
308 /**
309  * @brief Called when the state changed of current recording.
310  * @syscap SystemCapability.Multimedia.Media.AVRecorder
311  * @param recorder The pointer to an OH_AVRecorder instance.
312  * @param state Indicates the recorder state. For details, see {@link OH_AVRecorder_State}.
313  * @param reason Reason for recorder state change. For details, see {@link OH_AVRecorder_StateChangeReason}.
314  * @param userData Pointer to user specific data.
315  * @since 18
316  */
317 typedef void (*OH_AVRecorder_OnStateChange)(OH_AVRecorder *recorder,
318     OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, void *userData);
319 
320 /**
321  * @brief Called when an error occurred during recording
322  * @syscap SystemCapability.Multimedia.Media.AVRecorder
323  * @param recorder Pointer to an OH_AVRecorder instance.
324  * @param errorCode Error code.
325  * @param errorMsg Error message.
326  * @param userData Pointer to user specific data.
327  * @since 18
328  */
329 typedef void (*OH_AVRecorder_OnError)(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg,
330     void *userData);
331 
332 /**
333  * @brief Called when current recording is finished in OH_AVRecorder_FileGenerationMode.AUTO_CREATE_CAMERA_SCENE
334  * @syscap SystemCapability.Multimedia.Media.AVRecorder
335  * @param recorder Pointer to an OH_AVRecorder instance.
336  * @param asset Pointer to an OH_MediaAsset instance.
337  * @param userData Pointer to user specific data.
338  * @since 18
339  */
340 typedef void (*OH_AVRecorder_OnUri)(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData);
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_BASE_H
347