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/**
17 * @addtogroup Codec
18 * @{
19 *
20 * @brief Defines APIs of the Codec module.
21 *
22 * The Codec module provides APIs for initializing the custom data and audio and video codecs,
23 * setting codec parameters, and controlling and transferring data.
24 *
25 * @since 3.2
26 * @version 1.0
27 */
28
29/**
30 * @file CodecTypes.idl
31 *
32 * @brief Defines custom data types used in the Codec module APIs,
33 * including the codec types, audio and video parameters, and buffers.
34 *
35 *
36 * @since 3.2
37 * @version 1.0
38 */
39
40/**
41 * @brief Defines the path for the package of the Codec module APIs.
42 *
43 * @since 3.2
44 * @version 1.0
45 */
46package ohos.hdi.codec.v1_0;
47
48/**
49 * @brief Enumerates the codec types.
50 */
51enum CodecType {
52    VIDEO_DECODER,   /**< Video decoder. */
53    VIDEO_ENCODER,   /**< Video encoder. */
54    AUDIO_DECODER,   /**< Audio decoder. */
55    AUDIO_ENCODER,   /**< Audio encoder. */
56    INVALID_TYPE,    /**< Invalid type. */
57};
58
59/**
60 * @brief Enumerates the types of audio and video that can be encoded or decoded.
61 */
62enum AvCodecRole {
63    MEDIA_ROLETYPE_IMAGE_JPEG = 0,          /**< JPEG image. */
64    MEDIA_ROLETYPE_VIDEO_AVC,               /**< H.264 video. */
65    MEDIA_ROLETYPE_VIDEO_HEVC,              /**< H.265 video. */
66    MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000,   /**< Audio. */
67    MEDIA_ROLETYPE_AUDIO_AAC = 0x10000,     /**< Advanced Audio Coding (AAC). */
68    MEDIA_ROLETYPE_AUDIO_G711A,             /**< G.711 a-law audio. */
69    MEDIA_ROLETYPE_AUDIO_G711U,             /**< G.711 μ-law audio. */
70    MEDIA_ROLETYPE_AUDIO_G726,              /**< G.726 audio. */
71    MEDIA_ROLETYPE_AUDIO_PCM,               /**< PCM audio. */
72    MEDIA_ROLETYPE_AUDIO_MP3,               /**< MP3. */
73    MEDIA_ROLETYPE_INVALID,                 /**< Invalid type. */
74};
75
76/**
77 * @brief Enumerates the codec profiles.
78 */
79enum Profile {
80    INVALID_PROFILE = 0,             /**< Invalid profile. */
81    AAC_LC_PROFILE = 0x1000,         /**< AAC low complexity profile. */
82    AAC_MAIN_PROFILE,                /**< AAC main profile. */
83    AAC_HE_V1_PROFILE,               /**< Profile combining AAC high efficiency and spectral band replication (SBR),
84                                          also known as HE-AAC, AAC+, or aacPlus v1. */
85    AAC_HE_V2_PROFILE,               /**< HE-AAC combined with SBR and Parametric Stereo (PS),
86                                          also known as AAC++ or aacPlus v2. */
87    AAC_LD_PROFILE,                  /**< AAC low delay profile. */
88    AAC_ELD_PROFILE,                 /**< AAC enhanced low delay profile. */
89    AVC_BASELINE_PROFILE = 0x2000,   /**< H.264 baseline profile. */
90    AVC_MAIN_PROFILE,                /**< H.264 main profile. */
91    AVC_HIGH_PROFILE,                /**< H.264 high profile. */
92    HEVC_MAIN_PROFILE = 0x3000,      /**< H.265 main profile. */
93    HEVC_MAIN_10_PROFILE,            /**< H.265 10-bit main profile. */
94};
95
96/**
97 * @brief Enumerates the playback capabilities.
98 */
99enum CodecCapsMask {
100    CODEC_CAP_ADAPTIVE_PLAYBACK = 0x1,    /**< Adaptive playback. */
101    CODEC_CAP_SECURE_PLAYBACK = 0x2,      /**< Secure playback. */
102    CODEC_CAP_TUNNEL_PLAYBACK = 0x4,      /**< Tunnel playback. */
103    CODEC_CAP_MULTI_PLANE = 0x10000,      /**< Multi-plane (video image plane and audio channel plane) capability. */
104};
105
106/**
107 * @brief Enumerates the audio sampling rates.
108 */
109enum AudioSampleRate {
110    AUD_SAMPLE_RATE_8000 = 8000,      /**< 8000 */
111    AUD_SAMPLE_RATE_12000 = 12000,    /**< 12000 */
112    AUD_SAMPLE_RATE_11025 = 11025,    /**< 11025 */
113    AUD_SAMPLE_RATE_16000 = 16000,    /**< 16000 */
114    AUD_SAMPLE_RATE_22050 = 22050,    /**< 22050 */
115    AUD_SAMPLE_RATE_24000 = 24000,    /**< 24000 */
116    AUD_SAMPLE_RATE_32000 = 32000,    /**< 32000 */
117    AUD_SAMPLE_RATE_44100 = 44100,    /**< 44100 */
118    AUD_SAMPLE_RATE_48000 = 48000,    /**< 48000 */
119    AUD_SAMPLE_RATE_64000 = 64000,    /**< 64000 */
120    AUD_SAMPLE_RATE_96000 = 96000,    /**< 96000 */
121    AUD_SAMPLE_RATE_INVALID,          /**< Invalid sampling rate */
122};
123
124/**
125 * @brief Enumerates the audio sampling formats.
126 *
127 * For the planar sampling format, the data of each channel is independently stored in <b>data</b>.
128 * For the packed sampling format, only the first data is used, and the data of each channel is interleaved.
129 */
130enum CodecAudioSampleFormat {
131    AUDIO_SAMPLE_FMT_U8 = 0,     /**< Unsigned 8-bit integer, packed. */
132    AUDIO_SAMPLE_FMT_S16,        /**< Signed 16-bit integer, packed. */
133    AUDIO_SAMPLE_FMT_S32,        /**< Signed 32-bit integer, packed. */
134    AUDIO_SAMPLE_FMT_FLOAT,      /**< Float, packed. */
135    AUDIO_SAMPLE_FMT_DOUBLE,     /**< Double, packed. */
136    AUDIO_SAMPLE_FMT_U8P,        /**< Unsigned 8-bit integer, planar. */
137    AUDIO_SAMPLE_FMT_S16P,       /**< Signed 16-bit integer, planar. */
138    AUDIO_SAMPLE_FMT_S32P,       /**< Signed 32-bit integer, planar. */
139    AUDIO_SAMPLE_FMT_FLOATP,     /**< Float, planar. */
140    AUDIO_SAMPLE_FMT_DOUBLEP,    /**< Double, planar. */
141    AUDIO_SAMPLE_FMT_INVALID,    /**< Invalid sampling format. */
142};
143
144/**
145 * @brief Enumerates the codec processing modes.
146 */
147enum CodecProcessMode {
148    PROCESS_BLOCKING_INPUT_BUFFER = 0x1,        /**< Input buffer in sync mode. */
149    PROCESS_BLOCKING_OUTPUT_BUFFER = 0x2,       /**< Output buffer in sync mode. */
150    PROCESS_BLOCKING_CONTROL_FLOW = 0x4,        /**< Control flow in sync mode. */
151    PROCESS_NONBLOCKING_INPUT_BUFFER = 0x100,   /**< Input buffer in async mode. */
152    PROCESS_NONBLOCKING_OUTPUT_BUFFER = 0x200,  /**< Output buffer in async mode. */
153    PROCESS_NONBLOCKING_CONTROL_FLOW = 0x400,   /**< Control flow in asynchronous mode. */
154};
155
156/**
157 * @brief Enumerates the shared memory types.
158 */
159enum ShareMemTypes {
160    READ_WRITE_TYPE = 0x1,     /**< Shared memory that is readable and writable. */
161    READ_ONLY_TYPE = 0x2,      /**< Shared memory that is read-only. */
162};
163
164/**
165 * @brief Enumerates the bit rate modes.
166 */
167enum BitRateMode {
168    BIT_RATE_MODE_INVALID,    /**< Invalid value. */
169    BIT_RATE_MODE_VBR,        /**< Variable bit rate. */
170    BIT_RATE_MODE_CBR,        /**< Constant bit rate. */
171    BIT_RATE_MODE_CQ,         /**< Constant quality. */
172    BIT_RATE_MODE_VCBR,       /**< Constrained variable bit rate. */
173    BIT_RATE_MODE_ABR,        /**< Average bit rate. */
174};
175
176/**
177 * @brief Enumerates the component states.
178 */
179enum CodecEventType {
180    CODEC_EVENT_CMD_COMPLETE,                     /**< The component has completed a command. */
181    CODEC_EVENT_ERROR,                            /**< The component has detected an error. */
182    CODEC_EVENT_MARK,                             /**< The component has detected the buffer mark. */
183    CODEC_EVENT_PORT_SETTINGS_CHANGED,            /**< The component has reported port setting changes. */
184    CODEC_EVENT_BUFFER_FLAG,                      /**< The component has detected an EOS. */
185    CODEC_EVENT_RESOURCES_ACQUIRED,               /**< The component has been granted resources and is automatically
186                                                       starting the state change from CODEC_STATE_WAIT_FOR_RESOURCES
187                                                       to CODEC_STATE_IDLE. */
188    CODEC_EVENT_COMPONENT_RESUMED,                /**< The component is resumed due to reacquisition of resources. */
189    CODEC_EVENT_DYNAMIC_RESOURCES_AVAILABLE,      /**< The component has acquired previously unavailable
190                                                       dynamic resources. */
191    CODEC_EVENT_PORT_FORMAT_DETECTED,             /**< The component has detected a supported format. */
192    CODEC_EVENT_KHRONOS_EXTENSIONS = 0x6F000000,  /**< Reserved region for introducing Khronos standard extensions. */
193    CODEC_EVENT_VENDOR_START_UNUSED = 0x7F000000, /**< Reserved region for introducing vendor extensions. */
194    CODEC_EVENT_MAX = 0x7FFFFFFF,                 /**< Maximum value. */
195};
196
197/**
198 * @brief Enumerates the cmd parameters of the <b>SendCommand</b> API in <b>ICodecComponent</b>.
199 */
200enum CodecCommandType
201{
202    CODEC_COMMAND_STATE_SET,                         /**< Change the component state. */
203    CODEC_COMMAND_FLUSH,                             /**< Flush the data queue of a component. */
204    CODEC_COMMAND_PORT_DISABLE,                      /**< Disable a port on a component. */
205    CODEC_COMMAND_PORT_ENABLE,                       /**< Enable a port on a component. */
206    CODEC_COMMAND_MARK_BUFFER,                       /**< Mark a component/buffer for observation. */
207    CODEC_COMMAND_KHRONOS_EXTENSIONS = 0x6F000000,   /**< Reserved region for introducing Khronos standard extensions. */
208    CODEC_COMMAND_VENDOR_START_UNUSED = 0x7F000000,  /**< Reserved region for introducing vendor extensions. */
209    CODEC_COMMAND_MAX = 0x7FFFFFFF,                  /**< Maximum value. */
210};
211
212/**
213 * @brief Enuerates the component states.
214 */
215enum CodecStateType
216{
217    CODEC_STATE_INVALID,                             /**< The component has detected that its internal data structures are
218                                                          corrupted so that the state cannot be correctly determined. */
219    CODEC_STATE_LOADED,                              /**< The component has been loaded but has not completed
220                                                          initialization. Only <b>ICodecComponent.SetParameter</b>
221                                                          and <b>ICodecComponent.GetParameter</b> can be called for a
222                                                          component in this state. */
223    CODEC_STATE_IDLE,                                /**< The component initialization is complete, and the component is
224                                                          ready to start. */
225    CODEC_STATE_EXECUTING,                           /**< The component has accepted the start command and is processing
226                                                          data (if the data is available). */
227    CODEC_STATE_PAUSE,                               /**< The component has received the pause command. */
228    CODEC_STATE_WAIT_FOR_RESOURCES,                  /**< The component is waiting for resources, either after preemption
229                                                          or before it acquires the requested resources. */
230    CODEC_STATE_KHRONOS_EXTENSIONS = 0x6F000000,     /**< Reserved region for introducing Khronos standard extensions. */
231    CODEC_STATE_VENDOR_START_UNUSED = 0x7F000000,    /**< Reserved region for introducing vendor extensions. */
232    CODEC_STATE_MAX = 0x7FFFFFFF,                    /**< Maximum value. */
233};
234/**
235 * @brief Enuerates the port supplier preferences when establishing a tunnel between two ports.
236 */
237enum CodecBufferSupplierType
238{
239    CODEC_BUFFER_SUPPLY_UNSPECIFIED = 0,                   /**< The port that provides the buffers is not specified. */
240    CODEC_BUFFER_SUPPLY_INPUT,                             /**< The input port provides the buffers. */
241    CODEC_BUFFER_SUPPLY_OUTPUT,                            /**< The output port provides the buffers. */
242    CODEC_BUFFER_SUPPLY_KHRONOS_EXTENSIONS = 0x6F000000,   /**< Reserved region for introducing Khronos
243                                                                standard extensions. */
244    CODEC_BUFFER_SUPPLY_VENDOR_START_UNUSED = 0x7F000000,  /**< Reserved region for introducing vendor extensions. */
245    CODEC_BUFFER_SUPPLY_MAX = 0x7FFFFFFF,                  /**< Maximum value. */
246};
247
248/**
249 * @brief Defines the alignment structure.
250 */
251struct Alignment {
252    int widthAlignment;   /**< Alignment value of the width. */
253    int heightAlignment;  /**< Alignment value of the height. */
254};
255
256/**
257 * @brief Defines a rectangle.
258 */
259struct Rect {
260    int width;  /**< Width of the rectangle. */
261    int height; /**< Height of the rectangle. */
262};
263
264/**
265 * @brief Defines a value range.
266 */
267struct RangeValue {
268    int min;  /**< Minimum value. */
269    int max;  /**< Maximum value. */
270};
271
272/**
273 * @brief Defines the video encoding and decoding capabilities.
274 */
275struct CodecVideoPortCap {
276    struct Rect minSize;                   /**< Minimum resolution supported. */
277    struct Rect maxSize;                   /**< Maximum resolution supported. */
278    struct Alignment whAlignment;          /**< Alignment values of the width and height. */
279    struct RangeValue blockCount;          /**< Value range for the number of blocks supported. */
280    struct RangeValue blocksPerSecond;     /**< Value range for the number of blocks processed per second. */
281    struct Rect blockSize;                 /**< Block size supported. */
282    int[] supportPixFmts;                  /**< Supported pixel formats. For details, see <b>PixeFormat</b> defined by
283                                                <b>display_type.h</b> in {@link Display}. */
284    enum BitRateMode[] bitRatemode;        /**< Transmission rate modes, which can be constant or variable.
285                                                For details, see {@link BitRateMode}. */
286    struct RangeValue frameRate;           /**< Frame rate range. */
287    int[] measuredFrameRate;               /**< Frame rate measured. */
288};
289/**
290 * @brief Defines the audio encoding and decoding capabilities.
291 */
292struct CodecAudioPortCap {
293    int[] sampleFormats;  /**< Supported audio sampling formats. For details, see {@link AudioSampleFormat}. */
294    int[] sampleRate;     /**< Supported audio sampling rates. For details, see {@link AudioSampleRate}. */
295    int[] channelLayouts; /**< Supported channel layouts, which include single channel, balanced channel,
296                               and 3D stereo channel. */
297    int[] channelCount;   /**< Supported number of audio channels. */
298};
299
300/**
301 * @brief Defines the audio and video encoding and decoding capabilities.
302 */
303struct PortCap {
304    struct CodecVideoPortCap video;           /**< Video encoding and decoding capabilities. */
305    struct CodecAudioPortCap audio;           /**< Audio encoding and decoding capabilities. */
306};
307
308/**
309 * @brief Defines the version type of a component.
310 */
311struct CodecVerType {
312    unsigned char majorVersion;        /**<  Major version accessor element. */
313    unsigned char minorVersion;        /**<  Minor version accessor element. */
314    unsigned char revision;            /**< Revision version accessor element. */
315    unsigned char step;                /**< Step version accessor element. */
316};
317
318/**
319 * @brief Defines the component version information.
320 */
321union CodecVersionType {
322    struct CodecVerType version;        /**< Component version. */
323    unsigned int nVersion;              /**< 32-bit value to make accessing the version easily done in a single
324                                             word size copy or compare operation. */
325};
326
327/**
328 * @brief Defines the codec capabilities.
329 */
330struct CodecCompCapability {
331    enum AvCodecRole role;                     /**< Media type. */
332    enum CodecType type;                       /**< Codec type. */
333    String compName;                           /**< Name of the codec component. */
334    int[] supportProfiles;                     /**< Supported profiles. For details, see {@link Profile}. */
335    int maxInst;                               /**< Maximum instance. */
336    boolean isSoftwareCodec;                   /**< Whether it is a software codec. */
337    int processModeMask;                       /**< Codec processing mode mask. For details,
338                                                    see {@link CodecProcessMode}. */
339    unsigned int capsMask;                     /**< Mask of the codec playback capabilities. For details,
340                                                    see {@link CodecCapsMask}. */
341    struct RangeValue bitRate;                 /**< Supported bit rate range. */
342    struct PortCap port;                       /**< Supported audio and video encoding/decoding capabilities. */
343    boolean canSwapWidthHeight;                /**< Whether width and height verification is supported. */
344};
345
346/**
347 * @brief Defines the codec buffer information.
348 */
349struct OmxCodecBuffer {
350    unsigned int bufferId;               /**< Buffer ID. */
351    unsigned int size;                   /**< Size of the structure. */
352    union CodecVersionType version;       /**< Component version. */
353    unsigned int bufferType;             /**< Buffer type. For details, see {@link CodecBufferType}. */
354    NativeBuffer bufferhandle;           /**< Buffer handle used for encoding or decoding. For details,
355                                              see {@link NativeBuffer}. */
356    FileDescriptor fd;                   /**< Anonymous shared memory file descriptor. */
357    unsigned int allocLen;               /**< Size of the buffer allocated. */
358    unsigned int filledLen;              /**< Size of the buffer filled. */
359    unsigned int offset;                 /**< Offset to the start position of the valid data in the buffer. */
360    FileDescriptor fenceFd;              /**< Fence file descriptor. */
361    enum ShareMemTypes type;             /**< Shared memory type. */
362    long pts;                            /**< Timestamp of the first logical sample in the buffer. */
363    unsigned int flag;                   /**< Buffer specific flag. */
364};
365
366/**
367 * @brief Defines the structure that is used to pass data from an output port to an input port.
368 */
369struct CodecTunnelSetupType {
370    unsigned int tunnelFlags;                 /**< Bit flags for tunneling. */
371    enum CodecBufferSupplierType supplier;    /**< Supplier preference. */
372};
373
374/**
375 * @brief Defines the component information.
376 */
377struct CompVerInfo {
378    String compName;                    /**< Component name. */
379    unsigned char[] compUUID;           /**< UUID of the component. */
380    union CodecVersionType compVersion;  /**< OMX component version. */
381    union CodecVersionType specVersion;  /**< Version of the specifications on which the component is built. */
382};
383
384/**
385 * @brief Defines the event information to report.
386 */
387struct EventInfo {
388    long appData;                /**< Upper-layer instance passed in when the callback is invoked. */
389    unsigned int data1;          /**< Error type, which can be <b>portIndex</b> or other data. */
390    unsigned int data2;          /**< Data 2 carried in the reported event. */
391    byte[] eventData;            /**< Data carried in the reported event. */
392};
393