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/** 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 2.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.v2_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/** 236 * @brief Enuerates the port supplier preferences when establishing a tunnel between two ports. 237 */ 238enum CodecBufferSupplierType 239{ 240 CODEC_BUFFER_SUPPLY_UNSPECIFIED = 0, /**< The port that provides the buffers is not specified. */ 241 CODEC_BUFFER_SUPPLY_INPUT, /**< The input port provides the buffers. */ 242 CODEC_BUFFER_SUPPLY_OUTPUT, /**< The output port provides the buffers. */ 243 CODEC_BUFFER_SUPPLY_KHRONOS_EXTENSIONS = 0x6F000000, /**< Reserved region for introducing Khronos 244 standard extensions. */ 245 CODEC_BUFFER_SUPPLY_VENDOR_START_UNUSED = 0x7F000000, /**< Reserved region for introducing vendor extensions. */ 246 CODEC_BUFFER_SUPPLY_MAX = 0x7FFFFFFF, /**< Maximum value. */ 247}; 248 249/** 250 * @brief Defines the alignment structure. 251 */ 252struct Alignment { 253 int widthAlignment; /**< Alignment value of the width. */ 254 int heightAlignment; /**< Alignment value of the height. */ 255}; 256 257/** 258 * @brief Defines a rectangle. 259 */ 260struct Rect { 261 int width; /**< Width of the rectangle. */ 262 int height; /**< Height of the rectangle. */ 263}; 264 265/** 266 * @brief Defines a value range. 267 */ 268struct RangeValue { 269 int min; /**< Minimum value. */ 270 int max; /**< Maximum value. */ 271}; 272 273/** 274 * @brief Defines the video encoding and decoding capabilities. 275 */ 276struct CodecVideoPortCap { 277 struct Rect minSize; /**< Minimum resolution supported. */ 278 struct Rect maxSize; /**< Maximum resolution supported. */ 279 struct Alignment whAlignment; /**< Alignment values of the width and height. */ 280 struct RangeValue blockCount; /**< Value range for the number of blocks supported. */ 281 struct RangeValue blocksPerSecond; /**< Value range for the number of blocks processed per second. */ 282 struct Rect blockSize; /**< Block size supported. */ 283 int[] supportPixFmts; /**< Supported pixel formats. For details, see <b>PixeFormat</b> defined by 284 <b>display_type.h</b> in {@link Display}. */ 285 enum BitRateMode[] bitRatemode; /**< Transmission rate modes, which can be constant or variable. 286 For details, see {@link BitRateMode}. */ 287 struct RangeValue frameRate; /**< Frame rate range. */ 288 int[] measuredFrameRate; /**< Frame rate measured. */ 289}; 290 291/** 292 * @brief Defines the audio encoding and decoding capabilities. 293 */ 294struct CodecAudioPortCap { 295 int[] sampleFormats; /**< Supported audio sampling formats. For details, see {@link AudioSampleFormat}. */ 296 int[] sampleRate; /**< Supported audio sampling rates. For details, see {@link AudioSampleRate}. */ 297 int[] channelLayouts; /**< Supported channel layouts, which include single channel, balanced channel, 298 and 3D stereo channel. */ 299 int[] channelCount; /**< Supported number of audio channels. */ 300}; 301 302/** 303 * @brief Defines the audio and video encoding and decoding capabilities. 304 */ 305struct PortCap { 306 struct CodecVideoPortCap video; /**< Video encoding and decoding capabilities. */ 307 struct CodecAudioPortCap audio; /**< Audio encoding and decoding capabilities. */ 308}; 309 310/** 311 * @brief Defines the version type of a component. 312 */ 313struct CodecVerType { 314 unsigned char majorVersion; /**< Major version accessor element. */ 315 unsigned char minorVersion; /**< Minor version accessor element. */ 316 unsigned char revision; /**< Revision version accessor element. */ 317 unsigned char step; /**< Step version accessor element. */ 318}; 319 320/** 321 * @brief Defines the component version information. 322 */ 323union CodecVersionType { 324 struct CodecVerType version; /**< Component version. */ 325 unsigned int nVersion; /**< 32-bit value to make accessing the version easily done in a single 326 word size copy or compare operation. */ 327}; 328 329/** 330 * @brief Defines the codec capabilities. 331 */ 332struct CodecCompCapability { 333 enum AvCodecRole role; /**< Media type. */ 334 enum CodecType type; /**< Codec type. */ 335 String compName; /**< Name of the codec component. */ 336 int[] supportProfiles; /**< Supported profiles. For details, see {@link Profile}. */ 337 int maxInst; /**< Maximum instance. */ 338 boolean isSoftwareCodec; /**< Whether it is a software codec. */ 339 int processModeMask; /**< Codec processing mode mask. For details, 340 see {@link CodecProcessMode}. */ 341 unsigned int capsMask; /**< Mask of the codec playback capabilities. For details, 342 see {@link CodecCapsMask}. */ 343 struct RangeValue bitRate; /**< Supported bit rate range. */ 344 struct PortCap port; /**< Supported audio and video encoding/decoding capabilities. */ 345 boolean canSwapWidthHeight; /**< Whether width and height verification is supported. */ 346}; 347 348/** 349 * @brief Defines the codec buffer information. 350 */ 351struct OmxCodecBuffer { 352 unsigned int bufferId; /**< Buffer ID. */ 353 unsigned int size; /**< Size of the structure. */ 354 union CodecVersionType version; /**< Component version. */ 355 unsigned int bufferType; /**< Buffer type. For details, see {@link CodecBufferType}. */ 356 NativeBuffer bufferhandle; /**< Buffer handle used for encoding or decoding. For details, 357 see {@link NativeBuffer}. */ 358 FileDescriptor fd; /**< Anonymous shared memory file descriptor. */ 359 unsigned int allocLen; /**< Size of the buffer allocated. */ 360 unsigned int filledLen; /**< Size of the buffer filled. */ 361 unsigned int offset; /**< Offset to the start position of the valid data in the buffer. */ 362 FileDescriptor fenceFd; /**< Fence file descriptor. */ 363 enum ShareMemTypes type; /**< Shared memory type. */ 364 long pts; /**< Timestamp of the first logical sample in the buffer. */ 365 unsigned int flag; /**< Buffer specific flag. */ 366 unsigned char[] alongParam; /**< Along frame parameter. */ 367}; 368 369/** 370 * @brief Defines the structure that is used to pass data from an output port to an input port. 371 */ 372struct CodecTunnelSetupType { 373 unsigned int tunnelFlags; /**< Bit flags for tunneling. */ 374 enum CodecBufferSupplierType supplier; /**< Supplier preference. */ 375}; 376 377/** 378 * @brief Defines the component information. 379 */ 380struct CompVerInfo { 381 String compName; /**< Component name. */ 382 unsigned char[] compUUID; /**< UUID of the component. */ 383 union CodecVersionType compVersion; /**< OMX component version. */ 384 union CodecVersionType specVersion; /**< Version of the specifications on which the component is built. */ 385}; 386 387/** 388 * @brief Defines the event information to report. 389 */ 390struct EventInfo { 391 long appData; /**< Upper-layer instance passed in when the callback is invoked. */ 392 unsigned int data1; /**< Error type, which can be <b>portIndex</b> or other data. */ 393 unsigned int data2; /**< Data 2 carried in the reported event. */ 394 byte[] eventData; /**< Data carried in the reported event. */ 395}; 396