• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NATIVE_AVCODEC_BASE_H
17 #define NATIVE_AVCODEC_BASE_H
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 #include "native_averrors.h"
22 #include "native_avformat.h"
23 #include "native_avmemory.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 typedef struct NativeWindow OHNativeWindow;
30 typedef struct OH_AVCodec OH_AVCodec;
31 
32 /**
33  * @brief Enumerate the categories of OH_AVCodec's Buffer tags
34  * @syscap SystemCapability.Multimedia.Media.CodecBase
35  * @since 9
36  * @version 1.0
37  */
38 typedef enum OH_AVCodecBufferFlags {
39     AVCODEC_BUFFER_FLAGS_NONE = 0,
40     /* Indicates that the Buffer is an End-of-Stream frame */
41     AVCODEC_BUFFER_FLAGS_EOS = 1 << 0,
42     /* Indicates that the Buffer contains keyframes */
43     AVCODEC_BUFFER_FLAGS_SYNC_FRAME = 1 << 1,
44     /* Indicates that the data contained in the Buffer is only part of a frame */
45     AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME = 1 << 2,
46     /* Indicates that the Buffer contains Codec-Specific-Data */
47     AVCODEC_BUFFER_FLAGS_CODEC_DATA = 1 << 3,
48 } OH_AVCodecBufferFlags;
49 
50 /**
51  * @brief Define the Buffer description information of OH_AVCodec
52  * @syscap SystemCapability.Multimedia.Media.CodecBase
53  * @since 9
54  * @version 1.0
55  */
56 typedef struct OH_AVCodecBufferAttr {
57     /* Presentation timestamp of this Buffer in microseconds */
58     int64_t pts;
59     /* The size of the data contained in the Buffer in bytes */
60     int32_t size;
61     /* The starting offset of valid data in this Buffer */
62     int32_t offset;
63     /* The flags this Buffer has, which is also a combination of multiple {@link OH_AVCodecBufferFlags}. */
64     uint32_t flags;
65 } OH_AVCodecBufferAttr;
66 
67 /**
68  * @brief When an error occurs in the running of the OH_AVCodec instance, the function pointer will be called
69  * to report specific error information.
70  * @syscap SystemCapability.Multimedia.Media.CodecBase
71  * @param codec OH_AVCodec instance
72  * @param errorCode specific error code
73  * @param userData User specific data
74  * @since 9
75  * @version 1.0
76  */
77 typedef void (*OH_AVCodecOnError)(OH_AVCodec *codec, int32_t errorCode, void *userData);
78 
79 /**
80  * @brief When the output stream changes, the function pointer will be called to report the new stream description
81  * information. It should be noted that the life cycle of the OH_AVFormat pointer
82  * is only valid when the function pointer is called, and it is forbidden to continue to access after the call ends.
83  * @syscap SystemCapability.Multimedia.Media.CodecBase
84  * @param codec OH_AVCodec instance
85  * @param format New output stream description information
86  * @param userData User specific data
87  * @since 9
88  * @version 1.0
89  */
90 typedef void (*OH_AVCodecOnStreamChanged)(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
91 
92 /**
93  * @brief When OH_AVCodec needs new input data during the running process,
94  * the function pointer will be called and carry an available Buffer to fill in the new input data.
95  * @syscap SystemCapability.Multimedia.Media.CodecBase
96  * @param codec OH_AVCodec instance
97  * @param index The index corresponding to the newly available input buffer.
98  * @param data New available input buffer.
99  * @param userData User specific data
100  * @since 9
101  * @version 1.0
102  */
103 typedef void (*OH_AVCodecOnNeedInputData)(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData);
104 
105 /**
106  * @brief When new output data is generated during the operation of OH_AVCodec, the function pointer will be
107  * called and carry a Buffer containing the new output data. It should be noted that the life cycle of the
108  * OH_AVCodecBufferAttr pointer is only valid when the function pointer is called. , which prohibits continued
109  * access after the call ends.
110  * @syscap SystemCapability.Multimedia.Media.CodecBase
111  * @param codec OH_AVCodec instance
112  * @param index The index corresponding to the new output Buffer.
113  * @param data Buffer containing the new output data
114  * @param attr The description of the new output Buffer, please refer to {@link OH_AVCodecBufferAttr}
115  * @param userData specified data
116  * @since 9
117  * @version 1.0
118  */
119 typedef void (*OH_AVCodecOnNewOutputData)(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
120     OH_AVCodecBufferAttr *attr, void *userData);
121 
122 /**
123  * @brief A collection of all asynchronous callback function pointers in OH_AVCodec. Register an instance of this
124  * structure to the OH_AVCodec instance, and process the information reported through the callback to ensure the
125  * normal operation of OH_AVCodec.
126  * @syscap SystemCapability.Multimedia.Media.CodecBase
127  * @param onError Monitor OH_AVCodec operation errors, refer to {@link OH_AVCodecOnError}
128  * @param onStreamChanged Monitor codec stream information, refer to {@link OH_AVCodecOnStreamChanged}
129  * @param onNeedInputData Monitoring codec requires input data, refer to {@link OH_AVCodecOnNeedInputData}
130  * @param onNeedInputData Monitor codec to generate output data, refer to {@link onNeedInputData}
131  * @since 9
132  * @version 1.0
133  */
134 typedef struct OH_AVCodecAsyncCallback {
135     OH_AVCodecOnError onError;
136     OH_AVCodecOnStreamChanged onStreamChanged;
137     OH_AVCodecOnNeedInputData onNeedInputData;
138     OH_AVCodecOnNewOutputData onNeedOutputData;
139 } OH_AVCodecAsyncCallback;
140 
141 /**
142  * @brief Enumerates the MIME types of audio and video codecs
143  * @syscap SystemCapability.Multimedia.Media.CodecBase
144  * @since 9
145  * @version 1.0
146  */
147 extern const char *OH_AVCODEC_MIMETYPE_VIDEO_AVC;
148 extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AAC;
149 
150 /**
151  * @brief Enumerates the MIME types of audio and video codecs
152  * @syscap SystemCapability.Multimedia.Media.CodecBase
153  * @since 10
154  */
155 extern const char *OH_AVCODEC_MIMETYPE_AUDIO_FLAC;
156 extern const char *OH_AVCODEC_MIMETYPE_AUDIO_VORBIS;
157 extern const char *OH_AVCODEC_MIMETYPE_AUDIO_MPEG;
158 extern const char *OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
159 extern const char *OH_AVCODEC_MIMETYPE_VIDEO_MPEG4;
160 extern const char *OH_AVCODEC_MIMETYPE_IMAGE_JPG;
161 extern const char *OH_AVCODEC_MIMETYPE_IMAGE_PNG;
162 extern const char *OH_AVCODEC_MIMETYPE_IMAGE_BMP;
163 
164 /**
165  * @brief The extra data's key of surface Buffer
166  * @syscap SystemCapability.Multimedia.Media.CodecBase
167  * @since 9
168  * @version 1.0
169  */
170 /* Key for timeStamp in surface's extraData, value type is int64 */
171 extern const char *OH_ED_KEY_TIME_STAMP;
172 /* Key for endOfStream in surface's extraData, value type is bool */
173 extern const char *OH_ED_KEY_EOS;
174 
175 /**
176  * @brief Provides the uniform container for storing the media description.
177  * @syscap SystemCapability.Multimedia.Media.CodecBase
178  * @since 9
179  * @version 1.0
180  */
181 /* Key for track type, value type is uint8_t, see @OH_MediaType. */
182 extern const char *OH_MD_KEY_TRACK_TYPE;
183 /* Key for codec mime type, value type is string. */
184 extern const char *OH_MD_KEY_CODEC_MIME;
185 /* Key for duration, value type is int64_t. */
186 extern const char *OH_MD_KEY_DURATION;
187 /* Key for bitrate, value type is int64_t. */
188 extern const char *OH_MD_KEY_BITRATE;
189 /* Key for max input size, value type is uint32_t */
190 extern const char *OH_MD_KEY_MAX_INPUT_SIZE;
191 /* Key for video width, value type is uint32_t */
192 extern const char *OH_MD_KEY_WIDTH;
193 /* Key for video height, value type is uint32_t */
194 extern const char *OH_MD_KEY_HEIGHT;
195 /* Key for video pixel format, value type is int32_t, see @OH_AVPixelFormat */
196 extern const char *OH_MD_KEY_PIXEL_FORMAT;
197 /* key for audio raw format, value type is uint32_t , see @AudioSampleFormat */
198 extern const char *OH_MD_KEY_AUDIO_SAMPLE_FORMAT;
199 /* Key for video frame rate, value type is double. */
200 extern const char *OH_MD_KEY_FRAME_RATE;
201 /* video encode bitrate mode, the value type is int32_t, see @OH_VideoEncodeBitrateMode */
202 extern const char *OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE;
203 /* encode profile, the value type is number. see @OH_AVCProfile, OH_HEVCProfile, OH_AACProfile. */
204 extern const char *OH_MD_KEY_PROFILE;
205 /* Key for audio channel count, value type is uint32_t */
206 extern const char *OH_MD_KEY_AUD_CHANNEL_COUNT;
207 /* Key for audio sample rate, value type is uint32_t */
208 extern const char *OH_MD_KEY_AUD_SAMPLE_RATE;
209 /* Key for the interval of key frame. value type is int32_t, the unit is milliseconds. */
210 extern const char *OH_MD_KEY_I_FRAME_INTERVAL;
211 /* Key of the surface rotation angle. value type is int32_t: should be {0, 90, 180, 270}, default is 0. */
212 extern const char *OH_MD_KEY_ROTATION;
213 
214 /**
215  * @brief Provides the uniform container for storing the media description.
216  * @syscap SystemCapability.Multimedia.Media.CodecBase
217  * @since 10
218  */
219 /* Key for video YUV value range flag, value type is boolean */
220 extern const char *OH_MD_KEY_RANGE_FLAG;
221 /* Key for video color primaries, value type is int32_t, see @OH_ColorPrimary */
222 extern const char *OH_MD_KEY_COLOR_PRIMARIES;
223 /* Key for video transfer characteristics, value type is int32_t, see @OH_TransferCharacteristic */
224 extern const char *OH_MD_KEY_TRANSFER_CHARACTERISTICS;
225 /* Key for video matrix coefficients, value type is int32_t, see @OH_MatrixCoefficient */
226 extern const char *OH_MD_KEY_MATRIX_COEFFICIENTS;
227 /* Key for the request an I-Frame immediately, value type is boolean */
228 extern const char *OH_MD_KEY_REQUEST_I_FRAME;
229 /* Key for the desired encoding quality, value type is uint32_t, this key is only
230  * supported for encoders that are configured in constant quality mode */
231 extern const char *OH_MD_KEY_QUALITY;
232 /* Key of the codec specific data. value type is a uint8_t pointer */
233 extern const char *OH_MD_KEY_CODEC_CONFIG;
234 /* source format Key for title, value type is string */
235 extern const char *OH_MD_KEY_TITLE;
236 /* source format Key for artist, value type is string */
237 extern const char *OH_MD_KEY_ARTIST;
238 /* source format Key for album, value type is string */
239 extern const char *OH_MD_KEY_ALBUM;
240 /* source format Key for album artist, value type is string */
241 extern const char *OH_MD_KEY_ALBUM_ARTIST;
242 /* source format Key for date, value type is string */
243 extern const char *OH_MD_KEY_DATE;
244 /* source format Key for comment, value type is string */
245 extern const char *OH_MD_KEY_COMMENT;
246 /* source format Key for genre, value type is string */
247 extern const char *OH_MD_KEY_GENRE;
248 /* source format Key for copyright, value type is string */
249 extern const char *OH_MD_KEY_COPYRIGHT;
250 /* source format Key for language, value type is string */
251 extern const char *OH_MD_KEY_LANGUAGE;
252 /* source format Key for description, value type is string */
253 extern const char *OH_MD_KEY_DESCRIPTION;
254 /* source format Key for lyrics, value type is string */
255 extern const char *OH_MD_KEY_LYRICS;
256 /* source format Key for track count, value type is uint32_t */
257 extern const char *OH_MD_KEY_TRACK_COUNT;
258 /* Key for the desired encoding channel layout, value type is int64_t, this key is only supported for encoders */
259 extern const char *OH_MD_KEY_CHANNEL_LAYOUT;
260 /* Key for bits per coded sample, value type is uint32_t, supported for flac encoder, see @OH_BitsPerSample */
261 extern const char *OH_MD_KEY_BITS_PER_CODED_SAMPLE;
262 /* Key for the aac format, value type is uint32_t, supported for aac decoder */
263 extern const char *OH_MD_KEY_AAC_IS_ADTS;
264 /* Key for aac sbr mode, value type is uint32_t, supported for aac encoder */
265 extern const char *OH_MD_KEY_SBR;
266 /* Key for flac compliance level, value type is int32_t */
267 extern const char *OH_MD_KEY_COMPLIANCE_LEVEL;
268 /* Key for vorbis identification header, value type is a uint8_t pointer, supported only for vorbis decoder */
269 extern const char *OH_MD_KEY_IDENTIFICATION_HEADER;
270 /* Key for vorbis setup header, value type is a uint8_t pointer, supported only for vorbis decoder */
271 extern const char *OH_MD_KEY_SETUP_HEADER;
272 /* Key for video scale type, value type is int32_t, see @OH_ScalingMode */
273 extern const char *OH_MD_KEY_SCALING_MODE;
274 /* Key for max input buffer count, value type is int32_t */
275 extern const char *OH_MD_MAX_INPUT_BUFFER_COUNT;
276 /* Key for max output buffer count, value type is int32_t */
277 extern const char *OH_MD_MAX_OUTPUT_BUFFER_COUNT;
278 
279 /**
280  * @brief Media type.
281  * @syscap SystemCapability.Multimedia.Media.CodecBase
282  * @since 9
283  * @version 1.0
284  */
285 typedef enum OH_MediaType {
286     /* track is audio. */
287     MEDIA_TYPE_AUD = 0,
288     /* track is video. */
289     MEDIA_TYPE_VID = 1,
290 } OH_MediaType;
291 
292 /**
293  * @brief AAC Profile
294  * @syscap SystemCapability.Multimedia.Media.CodecBase
295  * @since 9
296  * @version 1.0
297  */
298 typedef enum OH_AACProfile {
299     AAC_PROFILE_LC = 0,
300 } OH_AACProfile;
301 
302 /**
303  * @brief AVC Profile
304  * @syscap SystemCapability.Multimedia.Media.CodecBase
305  * @since 9
306  * @version 1.0
307  */
308 typedef enum OH_AVCProfile {
309     AVC_PROFILE_BASELINE = 0,
310     AVC_PROFILE_HIGH = 4,
311     AVC_PROFILE_MAIN = 8,
312 } OH_AVCProfile;
313 
314 /**
315  * @brief Enumerates the muxer output file format
316  * @syscap SystemCapability.Multimedia.Media.CodecBase
317  * @since 10
318  */
319 typedef enum OH_AVOutputFormat {
320     AV_OUTPUT_FORMAT_DEFAULT = 0,
321     AV_OUTPUT_FORMAT_MPEG_4 = 2,
322     AV_OUTPUT_FORMAT_M4A = 6,
323 } OH_AVOutputFormat;
324 
325 /**
326  * @brief Seek Mode
327  * @syscap SystemCapability.Multimedia.Media.CodecBase
328  * @since 10
329  */
330 typedef enum OH_AVSeekMode {
331     /* seek to sync sample after the time */
332     SEEK_MODE_NEXT_SYNC = 0,
333     /* seek to sync sample before the time */
334     SEEK_MODE_PREVIOUS_SYNC,
335     /* seek to sync sample closest to time */
336     SEEK_MODE_CLOSEST_SYNC,
337 } OH_AVSeekMode;
338 
339 /**
340  * @brief HEVC Profile
341  * @syscap SystemCapability.Multimedia.Media.CodecBase
342  * @since 10
343  */
344 typedef enum OH_HEVCProfile {
345     HEVC_PROFILE_MAIN = 0,
346     HEVC_PROFILE_MAIN_10 = 1,
347     HEVC_PROFILE_MAIN_STILL = 2,
348     HEVC_PROFILE_MAIN_10_HDR10 = 3,
349     HEVC_PROFILE_MAIN_10_HDR10_PLUS = 4,
350 } OH_HEVCProfile;
351 
352 /**
353  * @brief Color Primary
354  * @syscap SystemCapability.Multimedia.Media.CodecBase
355  * @since 10
356  */
357 typedef enum OH_ColorPrimary {
358     COLOR_PRIMARY_BT709 = 1,
359     COLOR_PRIMARY_UNSPECIFIED = 2,
360     COLOR_PRIMARY_BT470_M = 4,
361     COLOR_PRIMARY_BT601_625 = 5,
362     COLOR_PRIMARY_BT601_525 = 6,
363     COLOR_PRIMARY_SMPTE_ST240 = 7,
364     COLOR_PRIMARY_GENERIC_FILM = 8,
365     COLOR_PRIMARY_BT2020 = 9,
366     COLOR_PRIMARY_SMPTE_ST428 = 10,
367     COLOR_PRIMARY_P3DCI = 11,
368     COLOR_PRIMARY_P3D65 = 12,
369 } OH_ColorPrimary;
370 
371 /**
372  * @brief Transfer Characteristic
373  * @syscap SystemCapability.Multimedia.Media.CodecBase
374  * @since 10
375  */
376 typedef enum OH_TransferCharacteristic {
377     TRANSFER_CHARACTERISTIC_BT709 = 1,
378     TRANSFER_CHARACTERISTIC_UNSPECIFIED = 2,
379     TRANSFER_CHARACTERISTIC_GAMMA_2_2 = 4,
380     TRANSFER_CHARACTERISTIC_GAMMA_2_8 = 5,
381     TRANSFER_CHARACTERISTIC_BT601 = 6,
382     TRANSFER_CHARACTERISTIC_SMPTE_ST240 = 7,
383     TRANSFER_CHARACTERISTIC_LINEAR = 8,
384     TRANSFER_CHARACTERISTIC_LOG = 9,
385     TRANSFER_CHARACTERISTIC_LOG_SQRT = 10,
386     TRANSFER_CHARACTERISTIC_IEC_61966_2_4 = 11,
387     TRANSFER_CHARACTERISTIC_BT1361 = 12,
388     TRANSFER_CHARACTERISTIC_IEC_61966_2_1 = 13,
389     TRANSFER_CHARACTERISTIC_BT2020_10BIT = 14,
390     TRANSFER_CHARACTERISTIC_BT2020_12BIT = 15,
391     TRANSFER_CHARACTERISTIC_PQ = 16,
392     TRANSFER_CHARACTERISTIC_SMPTE_ST428 = 17,
393     TRANSFER_CHARACTERISTIC_HLG = 18,
394 } OH_TransferCharacteristic;
395 
396 /**
397  * @brief Matrix Coefficient
398  * @syscap SystemCapability.Multimedia.Media.CodecBase
399  * @since 10
400  */
401 typedef enum OH_MatrixCoefficient {
402     MATRIX_COEFFICIENT_IDENTITY = 0,
403     MATRIX_COEFFICIENT_BT709 = 1,
404     MATRIX_COEFFICIENT_UNSPECIFIED = 2,
405     MATRIX_COEFFICIENT_FCC = 4,
406     MATRIX_COEFFICIENT_BT601_625 = 5,
407     MATRIX_COEFFICIENT_BT601_525 = 6,
408     MATRIX_COEFFICIENT_SMPTE_ST240 = 7,
409     MATRIX_COEFFICIENT_YCGCO = 8,
410     MATRIX_COEFFICIENT_BT2020_NCL = 9,
411     MATRIX_COEFFICIENT_BT2020_CL = 10,
412     MATRIX_COEFFICIENT_SMPTE_ST2085 = 11,
413     MATRIX_COEFFICIENT_CHROMATICITY_NCL = 12,
414     MATRIX_COEFFICIENT_CHROMATICITY_CL = 13,
415     MATRIX_COEFFICIENT_ICTCP = 14,
416 } OH_MatrixCoefficient;
417 
418 /**
419  * @brief Scaling Mode
420  * @syscap SystemCapability.Multimedia.Media.CodecBase
421  * @since 10
422  */
423 typedef enum OH_ScalingMode {
424     SCALING_MODE_SCALE_TO_WINDOW = 1,
425     SCALING_MODE_SCALE_CROP = 2,
426 } OH_ScalingMode;
427 
428 /**
429  * @brief enum Audio Bits Per Coded Sample
430  * @syscap SystemCapability.Multimedia.Media.CodecBase
431  * @since 10
432  */
433 typedef enum OH_BitsPerSample {
434     SAMPLE_U8 = 0,
435     SAMPLE_S16LE = 1,
436     SAMPLE_S24LE = 2,
437     SAMPLE_S32LE = 3,
438     SAMPLE_F32LE = 4,
439     SAMPLE_U8P = 5,
440     SAMPLE_S16P = 6,
441     SAMPLE_S24P = 7,
442     SAMPLE_S32P = 8,
443     SAMPLE_F32P = 9,
444     INVALID_WIDTH = -1
445 } OH_BitsPerSample;
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif // NATIVE_AVCODEC_BASE_H
451