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