• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 The extra data's key of surface Buffer
152  * @syscap SystemCapability.Multimedia.Media.CodecBase
153  * @since 9
154  * @version 1.0
155  */
156 /* Key for timeStamp in surface's extraData, value type is int64 */
157 extern const char *OH_ED_KEY_TIME_STAMP;
158 /* Key for endOfStream in surface's extraData, value type is bool */
159 extern const char *OH_ED_KEY_EOS;
160 
161 /**
162  * @brief Provides the uniform container for storing the media description.
163  * @syscap SystemCapability.Multimedia.Media.CodecBase
164  * @since 9
165  * @version 1.0
166  */
167 /* Key for track type, value type is uint8_t, see @OH_MediaType. */
168 extern const char *OH_MD_KEY_TRACK_TYPE;
169 /* Key for codec mime type, value type is string. */
170 extern const char *OH_MD_KEY_CODEC_MIME;
171 /* Key for duration, value type is int64_t. */
172 extern const char *OH_MD_KEY_DURATION;
173 /* Key for bitrate, value type is uint32_t. */
174 extern const char *OH_MD_KEY_BITRATE;
175 /* Key for max input size, value type is uint32_t */
176 extern const char *OH_MD_KEY_MAX_INPUT_SIZE;
177 /* Key for video width, value type is uint32_t */
178 extern const char *OH_MD_KEY_WIDTH;
179 /* Key for video height, value type is uint32_t */
180 extern const char *OH_MD_KEY_HEIGHT;
181 /* Key for video pixel format, value type is int32_t, see @OH_AVPixelFormat */
182 extern const char *OH_MD_KEY_PIXEL_FORMAT;
183 /* key for audio raw format, value type is uint32_t , see @AudioSampleFormat */
184 extern const char *OH_MD_KEY_AUDIO_SAMPLE_FORMAT;
185 /* Key for video frame rate, value type is double. */
186 extern const char *OH_MD_KEY_FRAME_RATE;
187 /* video encode bitrate mode, the value type is int32_t, see @OH_VideoEncodeBitrateMode */
188 extern const char *OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE;
189 /* encode profile, the value type is number. see @OH_AVCProfile, OH_AACProfile. */
190 extern const char *OH_MD_KEY_PROFILE;
191 /* Key for audio channel count, value type is uint32_t */
192 extern const char *OH_MD_KEY_AUD_CHANNEL_COUNT;
193 /* Key for audio sample rate, value type is uint32_t */
194 extern const char *OH_MD_KEY_AUD_SAMPLE_RATE;
195 /* Key for the interval of key frame. value type is int32_t, the unit is milliseconds. */
196 extern const char *OH_MD_KEY_I_FRAME_INTERVAL;
197 /* Key of the surface rotation angle. value type is int32_t: should be {0, 90, 180, 270}, default is 0. */
198 extern const char *OH_MD_KEY_ROTATION;
199 
200 /**
201  * @brief Media type.
202  * @syscap SystemCapability.Multimedia.Media.CodecBase
203  * @since 9
204  * @version 1.0
205  */
206 typedef enum OH_MediaType {
207     /* track is audio. */
208     MEDIA_TYPE_AUD = 0,
209     /* track is video. */
210     MEDIA_TYPE_VID = 1,
211 } OH_MediaType;
212 
213 /**
214  * @brief AVC Profile
215  * @syscap SystemCapability.Multimedia.Media.CodecBase
216  * @since 9
217  * @version 1.0
218  */
219 typedef enum OH_AVCProfile {
220     AVC_PROFILE_BASELINE = 0,
221     AVC_PROFILE_HIGH = 4,
222     AVC_PROFILE_MAIN = 8,
223 } OH_AVCProfile;
224 
225 /**
226  * @brief AAC Profile
227  * @syscap SystemCapability.Multimedia.Media.CodecBase
228  * @since 9
229  * @version 1.0
230  */
231 typedef enum OH_AACProfile {
232     AAC_PROFILE_LC = 0,
233 } OH_AACProfile;
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif // NATIVE_AVCODEC_BASE_H
240