• 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     /**
129      * @brief A audio container format type aac with ADTS.
130      * @since 20
131      */
132     AVRECORDER_CFT_AAC = 11,
133 } OH_AVRecorder_ContainerFormatType;
134 
135 /**
136  * @brief Recorder States
137  * @syscap SystemCapability.Multimedia.Media.AVRecorder
138  * @since 18
139  */
140 typedef enum OH_AVRecorder_State {
141     /* idle states */
142     AVRECORDER_IDLE = 0,
143     /* prepared states */
144     AVRECORDER_PREPARED = 1,
145     /* started states */
146     AVRECORDER_STARTED = 2,
147     /* paused states */
148     AVRECORDER_PAUSED = 3,
149     /* stopped states */
150     AVRECORDER_STOPPED = 4,
151     /* released states */
152     AVRECORDER_RELEASED = 5,
153     /* error states */
154     AVRECORDER_ERROR = 6,
155 } OH_AVRecorder_State;
156 
157 /**
158  * @brief reason of recorder state change
159  * @syscap SystemCapability.Multimedia.Media.AVRecorder
160  * @since 18
161  */
162 typedef enum OH_AVRecorder_StateChangeReason {
163     /* State changed by user operation */
164     AVRECORDER_USER = 0,
165     /* State changed by background action */
166     AVRECORDER_BACKGROUND = 1,
167 } OH_AVRecorder_StateChangeReason;
168 
169 /**
170  * @brief mode of creating recorder file
171  * @syscap SystemCapability.Multimedia.Media.AVRecorder
172  * @since 18
173  */
174 typedef enum OH_AVRecorder_FileGenerationMode {
175     /* Application Creation */
176     AVRECORDER_APP_CREATE = 0,
177     /* System Creation. Valid only in camera scene */
178     AVRECORDER_AUTO_CREATE_CAMERA_SCENE = 1,
179 } OH_AVRecorder_FileGenerationMode;
180 
181 /**
182  * @brief Provides the media recorder profile definitions
183  * @syscap SystemCapability.Multimedia.Media.AVRecorder
184  * @since 18
185  */
186 typedef struct OH_AVRecorder_Profile {
187     /* Indicates the audio bitrate */
188     int32_t audioBitrate;
189     /* Indicates the number of audio channels */
190     int32_t audioChannels;
191     /* Indicates the audio encoding format */
192     OH_AVRecorder_CodecMimeType audioCodec;
193     /* Indicates the audio sampling rate */
194     int32_t audioSampleRate;
195     /* Indicates the output file format */
196     OH_AVRecorder_ContainerFormatType fileFormat;
197     /* Indicates the video bitrate */
198     int32_t videoBitrate;
199     /* Indicates the video encoding format */
200     OH_AVRecorder_CodecMimeType videoCodec;
201     /* Indicates the video width */
202     int32_t videoFrameWidth;
203     /* Indicates the video height */
204     int32_t videoFrameHeight;
205     /* Indicates the video frame rate */
206     int32_t videoFrameRate;
207     /* Whether to record HDR video */
208     bool isHdr;
209     /* Whether to encode the video in temporal scale mode */
210     bool enableTemporalScale;
211 } OH_AVRecorder_Profile;
212 
213 /**
214  * @brief Provides the geographical location definitions for media resources
215  * @syscap SystemCapability.Multimedia.Media.AVRecorder
216  * @since 18
217  */
218 typedef struct OH_AVRecorder_Location {
219     /* Latitude */
220     float latitude;
221     /* Longitude */
222     float longitude;
223 } OH_AVRecorder_Location;
224 
225 /**
226  * @brief define the basic template of metadata
227  * @syscap SystemCapability.Multimedia.Media.AVRecorder
228  * @since 18
229  */
230 typedef struct OH_AVRecorder_MetadataTemplate {
231     /* key value of the metadata */
232     char *key;
233     /* contents of the metadata */
234     char *value;
235 } OH_AVRecorder_MetadataTemplate;
236 
237 /**
238  * @brief Provides the container definition for media data
239  * @syscap SystemCapability.Multimedia.Media.AVRecorder
240  * @since 18
241  */
242 typedef struct OH_AVRecorder_Metadata {
243     /* The metadata to retrieve the content type or genre of the data source */
244     char *genre;
245     /* The metadata to retrieve the information about the video orientation */
246     char *videoOrientation;
247     /* The geographical location info of the video */
248     OH_AVRecorder_Location location;
249     /* Custom parameter key-value map read from moov.meta.list */
250     OH_AVRecorder_MetadataTemplate customInfo;
251 } OH_AVRecorder_Metadata;
252 
253 /**
254  * @brief Provides the media recorder configuration definitions
255  * @syscap SystemCapability.Multimedia.Media.AVRecorder
256  * @since 18
257  */
258 typedef struct OH_AVRecorder_Config {
259     /* Indicates the recording audio source type */
260     OH_AVRecorder_AudioSourceType audioSourceType;
261     /* Indicates the recording video source type */
262     OH_AVRecorder_VideoSourceType videoSourceType;
263     /* Contains the audio and video encoding profile settings */
264     OH_AVRecorder_Profile profile;
265     /* Defines the file URL */
266     char *url;
267     /* Specifies the file generation mode for recording output */
268     OH_AVRecorder_FileGenerationMode fileGenerationMode;
269     /* Contains additional metadata for the recorded media */
270     OH_AVRecorder_Metadata metadata;
271     /* Set the longest duration allowed for current recording */
272     int32_t maxDuration;
273 } OH_AVRecorder_Config;
274 
275 /**
276  * @brief Provides Range with lower and upper limit
277  * @syscap SystemCapability.Multimedia.Media.AVRecorder
278  * @since 18
279  */
280 typedef struct OH_AVRecorder_Range {
281     /* lower limit of the range */
282     int32_t min;
283     /* upper limit of the range */
284     int32_t max;
285 } OH_AVRecorder_Range;
286 
287 /**
288  * @brief Provides encoder info
289  * @syscap SystemCapability.Multimedia.Media.AVRecorder
290  * @since 18
291  */
292 typedef struct OH_AVRecorder_EncoderInfo {
293     /* encoder format MIME */
294     OH_AVRecorder_CodecMimeType mimeType;
295     /* encoder type, audio or video */
296     char *type;
297     /* audio or video encoder bitRate range */
298     OH_AVRecorder_Range bitRate;
299     /* video encoder frame rate range */
300     OH_AVRecorder_Range frameRate;
301     /* video encoder width range */
302     OH_AVRecorder_Range width;
303     /* video encoder height range */
304     OH_AVRecorder_Range height;
305     /* audio encoder channel range */
306     OH_AVRecorder_Range channels;
307     /* audio encoder sample rate collection */
308     int32_t *sampleRate;
309     /* length of sampleRate list */
310     int32_t sampleRateLen;
311 } OH_AVRecorder_EncoderInfo;
312 
313 /**
314  * @brief Called when the state changed of current recording.
315  * @syscap SystemCapability.Multimedia.Media.AVRecorder
316  * @param recorder The pointer to an OH_AVRecorder instance.
317  * @param state Indicates the recorder state. For details, see {@link OH_AVRecorder_State}.
318  * @param reason Reason for recorder state change. For details, see {@link OH_AVRecorder_StateChangeReason}.
319  * @param userData Pointer to user specific data.
320  * @since 18
321  */
322 typedef void (*OH_AVRecorder_OnStateChange)(OH_AVRecorder *recorder,
323     OH_AVRecorder_State state, OH_AVRecorder_StateChangeReason reason, void *userData);
324 
325 /**
326  * @brief Called when an error occurred during recording
327  * @syscap SystemCapability.Multimedia.Media.AVRecorder
328  * @param recorder Pointer to an OH_AVRecorder instance.
329  * @param errorCode Error code.
330  * @param errorMsg Error message.
331  * @param userData Pointer to user specific data.
332  * @since 18
333  */
334 typedef void (*OH_AVRecorder_OnError)(OH_AVRecorder *recorder, int32_t errorCode, const char *errorMsg,
335     void *userData);
336 
337 /**
338  * @brief Called when current recording is finished in OH_AVRecorder_FileGenerationMode.AUTO_CREATE_CAMERA_SCENE
339  * @syscap SystemCapability.Multimedia.Media.AVRecorder
340  * @param recorder Pointer to an OH_AVRecorder instance.
341  * @param asset Pointer to an OH_MediaAsset instance.
342  * @param userData Pointer to user specific data.
343  * @since 18
344  */
345 typedef void (*OH_AVRecorder_OnUri)(OH_AVRecorder *recorder, OH_MediaAsset *asset, void *userData);
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVRECORDER_BASE_H
352