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 related to 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.1 26 */ 27 28 /** 29 * @file codec_component_type.h 30 * 31 * @brief Declares custom data types used in the Codec module APIs, including the codec types, 32 * audio and video parameters, and buffers. 33 * 34 * @since 3.1 35 */ 36 37 #ifndef CODEC_COMPONENT_TYPE_H 38 #define CODEC_COMPONENT_TYPE_H 39 40 #include <stdint.h> 41 #include <stdbool.h> 42 #include "OMX_Types.h" 43 #include "OMX_Index.h" 44 45 #ifdef __cplusplus 46 #if __cplusplus 47 extern "C" { 48 #endif 49 #endif /* __cplusplus */ 50 51 /** 52 * @brief Defines the maximum value of the sampling format. 53 */ 54 #define SAMPLE_FMT_NUM 32 55 56 /** 57 * @brief Enumerates codec types. 58 */ 59 typedef enum { 60 VIDEO_DECODER, /**< Video decoding */ 61 VIDEO_ENCODER, /**< Video encoding */ 62 AUDIO_DECODER, /**< Audio decoding */ 63 AUDIO_ENCODER, /**< Audio encoding */ 64 INVALID_TYPE /**< Invalid type */ 65 } CodecType; 66 67 /** 68 * @brief Enumerates the types of audio and video encoding/decoding components. 69 */ 70 typedef enum { 71 MEDIA_ROLETYPE_IMAGE_JPEG = 0, /**< JPEG image */ 72 MEDIA_ROLETYPE_VIDEO_AVC, /**< H.264 video */ 73 MEDIA_ROLETYPE_VIDEO_HEVC, /**< H.265 video */ 74 MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000, /**< Dummy id pointing at the start of audio codecs */ 75 MEDIA_ROLETYPE_AUDIO_AAC = 0x10000, /**< AAC audio */ 76 MEDIA_ROLETYPE_AUDIO_G711A, /**< G711A audio */ 77 MEDIA_ROLETYPE_AUDIO_G711U, /**< G711U audio */ 78 MEDIA_ROLETYPE_AUDIO_G726, /**< G726 audio */ 79 MEDIA_ROLETYPE_AUDIO_PCM, /**< PCM audio */ 80 MEDIA_ROLETYPE_AUDIO_MP3, /**< MP3 audio */ 81 MEDIA_ROLETYPE_INVALID, /**< Invalid role type */ 82 } AvCodecRole; 83 84 /** 85 * @brief Enumerates codec profiles. 86 */ 87 typedef enum { 88 INVALID_PROFILE = 0, /**< Invalid profile */ 89 AAC_LC_PROFILE = 0x1000, /**< AAC-Low Complex */ 90 AAC_MAIN_PROFILE, /**< AAC-Main */ 91 AAC_HE_V1_PROFILE, /**< HEAAC, AAC+, or AACPlusV1 */ 92 AAC_HE_V2_PROFILE, /**< AAC++ or AACPlusV2 */ 93 AAC_LD_PROFILE, /**< AAC-Low Delay */ 94 AAC_ELD_PROFILE, /**< AAC-Enhanced Low Delay */ 95 AVC_BASELINE_PROFILE = 0x2000, /**< H.264 Baseline */ 96 AVC_MAIN_PROFILE, /**< H.264 Main */ 97 AVC_HIGH_PROFILE, /**< H.264 High */ 98 HEVC_MAIN_PROFILE = 0x3000, /**< H.265 Main */ 99 HEVC_MAIN_10_PROFILE, /**< H.265 Main 10 */ 100 } Profile; 101 102 /** 103 * @brief Defines the alignment. 104 */ 105 typedef struct { 106 int32_t widthAlginment; /**< Value to align with the width */ 107 int32_t heightAlginment; /**< Value to align with the height */ 108 } Alginment; 109 110 /** 111 * @brief Defines a rectangle. 112 */ 113 typedef struct { 114 int32_t width; /**< Width */ 115 int32_t height; /**< Height */ 116 } Rect; 117 118 /** 119 * @brief Defines a range. 120 */ 121 typedef struct { 122 int32_t min; /**< Lower end of the range. */ 123 int32_t max; /**< Upper end of the range. */ 124 } RangeValue; 125 126 /** 127 * @brief Enumerates playback capabilities. 128 */ 129 typedef enum { 130 CODEC_CAP_ADAPTIVE_PLAYBACK = 0x1, /**< Adaptive playback */ 131 CODEC_CAP_SECURE_PLAYBACK = 0x2, /**< Secure playback */ 132 CODEC_CAP_TUNNEL_PLAYBACK = 0x4, /**< Tunnel playback */ 133 CODEC_CAP_MULTI_PLANE = 0x10000, /**< Video picture planes/audio channel planar */ 134 } CodecCapsMask; 135 136 /** 137 * @brief Enumerates audio sampling rates. 138 */ 139 typedef enum { 140 AUD_SAMPLE_RATE_8000 = 8000, /**< 8 KHz */ 141 AUD_SAMPLE_RATE_12000 = 12000, /**< 12 KHz */ 142 AUD_SAMPLE_RATE_11025 = 11025, /**< 11.025 KHz */ 143 AUD_SAMPLE_RATE_16000 = 16000, /**< 16 KHz */ 144 AUD_SAMPLE_RATE_22050 = 22050, /**< 22.050 KHz */ 145 AUD_SAMPLE_RATE_24000 = 24000, /**< 24 KHz */ 146 AUD_SAMPLE_RATE_32000 = 32000, /**< 32 KHz */ 147 AUD_SAMPLE_RATE_44100 = 44100, /**< 44.1 KHz */ 148 AUD_SAMPLE_RATE_48000 = 48000, /**< 48 KHz */ 149 AUD_SAMPLE_RATE_64000 = 64000, /**< 64 KHz */ 150 AUD_SAMPLE_RATE_96000 = 96000, /**< 96 KHz */ 151 AUD_SAMPLE_RATE_INVALID, /**< Invalid sampling rate */ 152 } AudioSampleRate; 153 154 /** 155 * @brief Enumerates audio sample formats. 156 * For planar sample formats, each audio channel is in a seperate data plane. 157 * For packed sample formats, only the first data plane is used, and samples for each channel are interleaved. 158 */ 159 typedef enum { 160 AUDIO_SAMPLE_FMT_U8, /**< Unsigned 8 bits, packed */ 161 AUDIO_SAMPLE_FMT_S16, /**< Signed 16 bits, packed */ 162 AUDIO_SAMPLE_FMT_S32, /**< Signed 32 bits, packed */ 163 AUDIO_SAMPLE_FMT_FLOAT, /**< Float, packed */ 164 AUDIO_SAMPLE_FMT_DOUBLE, /**< Double, packed */ 165 AUDIO_SAMPLE_FMT_U8P, /**< Unsigned 8 bits, planar */ 166 AUDIO_SAMPLE_FMT_S16P, /**< Signed 16 bits, planar */ 167 AUDIO_SAMPLE_FMT_S32P, /**< Signed 32 bits, planar */ 168 AUDIO_SAMPLE_FMT_FLOATP, /**< Float, planar */ 169 AUDIO_SAMPLE_FMT_DOUBLEP, /**< Double, planar */ 170 AUDIO_SAMPLE_FMT_INVALID, /**< Invalid sampling format */ 171 } AudioSampleFormat; 172 173 /** 174 * @brief Defines the video codec port capability. 175 */ 176 #define PIX_FORMAT_NUM 16 /**< Indicates the array size of supported pixel formats */ 177 typedef struct { 178 Rect minSize; /**< Minimum resolution supported */ 179 Rect maxSize; /**< Maximum resolution supported */ 180 Alginment whAlignment; /**< Value to align with the width and height */ 181 RangeValue blockCount; 182 RangeValue blocksPerSecond; 183 Rect blockSize; 184 int32_t supportPixFmts[PIX_FORMAT_NUM]; /**< Supported pixel formats, array is terminated by 185 <b> OMX_COLOR_FORMATTYPE</b> */ 186 } VideoPortCap; 187 188 /** 189 * @brief Defines the audio codec port capability. 190 */ 191 #define SAMPLE_FORMAT_NUM 12 /**< Indicates the array size of supported audio sample formats */ 192 #define SAMPLE_RATE_NUM 16 /**< Indicates the array size of supported audio sample rate */ 193 #define CHANNEL_NUM 16 /**< Indicates the array size of supported audio channel count */ 194 typedef struct { 195 int32_t sampleFormats[SAMPLE_FMT_NUM]; /**< Supported audio sample formats, array is terminated by 196 <b> AUDIO_SAMPLE_FMT_INVALID</b> */ 197 int32_t sampleRate[SAMPLE_RATE_NUM]; /**< Supported audio sample rate, array is terminated by 198 <b> AUD_SAMPLE_RATE_INVALID</b> */ 199 int32_t channelLayouts[CHANNEL_NUM]; /**< Supported count of audio channel layouts, 200 array is terminated by <b> -1</b> */ 201 int32_t channelCount[CHANNEL_NUM]; /**< Supported audio channel count, array is terminated by <b> -1</b> */ 202 } AudioPortCap; 203 204 typedef union { 205 VideoPortCap video; /**< Video codec port capability */ 206 AudioPortCap audio; /**< Audio codec port capability */ 207 } PortCap; 208 209 typedef enum { 210 PROCESS_BLOCKING_INPUT_BUFFER = 0X1, 211 PROCESS_BLOCKING_OUTPUT_BUFFER = 0X2, 212 PROCESS_BLOCKING_CONTROL_FLOW = 0X4, 213 PROCESS_NONBLOCKING_INPUT_BUFFER = 0X100, 214 PROCESS_NONBLOCKING_OUTPUT_BUFFER = 0X200, 215 PROCESS_NONBLOCKING_CONTROL_FLOW = 0X400, 216 } CodecProcessMode; 217 218 /** 219 * @brief Defines the codec capability. 220 */ 221 #define NAME_LENGTH 32 /**< Indicates the array size of component name */ 222 #define PROFILE_NUM 256 /**< Indicates the array size of supported profile */ 223 typedef struct { 224 AvCodecRole role; /**< Role type */ 225 CodecType type; /**< Codec type */ 226 char compName[NAME_LENGTH]; /**< Codec name char string */ 227 int32_t supportProfiles[PROFILE_NUM]; /**< Supported profiles, array is terminated by <b> INVALID_PROFILE</b> */ 228 int32_t maxInst; /**< max instances */ 229 bool isSoftwareCodec; /**< Software codec or hardware codec */ 230 int32_t processModeMask; /**< Codec process mode mask. For details, see {@link CodecProcessMode}. */ 231 uint32_t capsMask; /**< Capability mask. For details, see {@link CodecCapsMask}. */ 232 RangeValue bitRate; /**< Range bit rate supported */ 233 PortCap port; 234 } CodecCompCapability; 235 236 enum BufferType { 237 BUFFER_TYPE_INVALID = 0, 238 BUFFER_TYPE_VIRTUAL_ADDR = 0x1, 239 BUFFER_TYPE_AVSHARE_MEM_FD = 0x2, 240 BUFFER_TYPE_HANDLE = 0x4, 241 BUFFER_TYPE_DYNAMIC_HANDLE = 0x8, 242 }; 243 244 enum ShareMemTypes { 245 READ_WRITE_TYPE = 0x1, 246 READ_ONLY_TYPE = 0x2, 247 }; 248 249 struct OmxCodecBuffer { 250 uint32_t bufferId; 251 uint32_t size; /**< size of the structure in bytes */ 252 union OMX_VERSIONTYPE version; /**< OMX specification version information */ 253 enum BufferType bufferType; 254 uint8_t *buffer; /**< Pointer to actual block of memory that is acting as the buffer */ 255 uint32_t bufferLen; /**< size of buffer */ 256 uint32_t allocLen; /**< size of the buffer allocated, in bytes */ 257 uint32_t filledLen; /**< number of bytes currently in the buffer */ 258 uint32_t offset; /**< start offset of valid data in bytes from the start of the buffer */ 259 int32_t fenceFd; 260 enum ShareMemTypes type; 261 int64_t pts; 262 uint32_t flag; 263 }; 264 265 enum OmxIndexCodecExType { 266 OMX_IndexExtBufferTypeStartUnused = OMX_IndexKhronosExtensions + 0x00a00000, 267 OMX_IndexParamSupportBufferType, 268 OMX_IndexParamUseBufferType, 269 OMX_IndexParamGetBufferHandleUsage, 270 }; 271 272 struct SupportBufferType { 273 uint32_t size; 274 union OMX_VERSIONTYPE version; 275 uint32_t portIndex; 276 uint32_t bufferTypes; 277 }; 278 279 struct UseBufferType { 280 uint32_t size; 281 union OMX_VERSIONTYPE version; 282 uint32_t portIndex; 283 uint32_t bufferType; 284 } ; 285 286 struct GetBufferHandleUsageParams { 287 uint32_t size; 288 union OMX_VERSIONTYPE version; 289 uint32_t portIndex; 290 uint32_t usage; 291 }; 292 293 #ifdef __cplusplus 294 #if __cplusplus 295 } 296 #endif 297 #endif /* __cplusplus */ 298 299 #endif /* CODEC_COMPONENT_TYPE_H */ 300 /** @} */