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 #include "codec_common_type.h" 45 46 #ifdef __cplusplus 47 #if __cplusplus 48 extern "C" { 49 #endif 50 #endif /* __cplusplus */ 51 52 /** 53 * @brief Defines the maximum value of the sampling format. 54 */ 55 #define SAMPLE_FMT_NUM 32 56 #define UUID_LENGTH 128 57 58 /** 59 * @brief Enumerates the types of audio and video encoding/decoding components. 60 */ 61 typedef enum { 62 /** JPEG image */ 63 MEDIA_ROLETYPE_IMAGE_JPEG = 0, 64 /** H.264 video */ 65 MEDIA_ROLETYPE_VIDEO_AVC, 66 /** H.265 video */ 67 MEDIA_ROLETYPE_VIDEO_HEVC, 68 /** MPEG4 video */ 69 MEDIA_ROLETYPE_VIDEO_MPEG4, 70 /** Audio codec */ 71 MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000, 72 /** Advanced Audio Coding (AAC) */ 73 MEDIA_ROLETYPE_AUDIO_AAC = 0x10000, 74 /** G711A audio */ 75 MEDIA_ROLETYPE_AUDIO_G711A, 76 /** G711U audio */ 77 MEDIA_ROLETYPE_AUDIO_G711U, 78 /** G726 audio */ 79 MEDIA_ROLETYPE_AUDIO_G726, 80 /** Pulse-Code Modulation (PCM) audio */ 81 MEDIA_ROLETYPE_AUDIO_PCM, 82 /** MP3 */ 83 MEDIA_ROLETYPE_AUDIO_MP3, 84 /** Invalid type */ 85 MEDIA_ROLETYPE_INVALID, 86 } AvCodecRole; 87 88 /** 89 * @brief Defines the video encoding and decoding capabilities. 90 */ 91 #define PIX_FORMAT_NUM 16 /** Size of the supported pixel format array */ 92 #define BIT_RATE_MODE_NUM 5 /* Size of the array bit rate mode. */ 93 #define MEASURED_FRAME_RATE_NUM 32 /* Size of the array measured frame rate. */ 94 95 typedef enum { 96 BIT_RATE_MODE_INVALID, 97 /** Variable Bit Rate. */ 98 BIT_RATE_MODE_VBR, 99 /* Constant Bit Rate. */ 100 BIT_RATE_MODE_CBR, 101 /* Constant Quality. */ 102 BIT_RATE_MODE_CQ, 103 /* Constrained VariableBit Rate. */ 104 BIT_RATE_MODE_VCBR, 105 /* Average Bit Rate. */ 106 BIT_RATE_MODE_ABR, 107 } BitRateMode; 108 109 typedef struct { 110 Rect minSize; /** Minimum resolution supported. */ 111 Rect maxSize; /** Maximum resolution supported. */ 112 Alignment whAlignment; /** Values to align with the width and height. */ 113 RangeValue blockCount; /** Number of blocks supported. */ 114 RangeValue blocksPerSecond; /** Number of blocks processed per second. */ 115 Rect blockSize; /** Block size supported. */ 116 int32_t supportPixFmts[PIX_FORMAT_NUM]; /** Supported pixel format. For details, 117 see {@link OMX_COLOR_FORMATTYPE}. */ 118 BitRateMode bitRatemode[BIT_RATE_MODE_NUM]; /* Bit Rate Mode. For details, see {@link BitRateMode}. */ 119 RangeValue frameRate; /* Frame Rate. */ 120 int32_t measuredFrameRate[MEASURED_FRAME_RATE_NUM]; /* Measured Frame Rate. */ 121 } CodecVideoPortCap; 122 123 /** 124 * @brief Defines the video encoding and decoding capabilities. 125 */ 126 #define SAMPLE_FORMAT_NUM 12 /** Size of the audio sampling format array supported. */ 127 #define SAMPLE_RATE_NUM 16 /** Size of the audio sampling rate array supported. */ 128 #define CHANNEL_NUM 16 /** Size of the audio channel array supported. */ 129 typedef struct { 130 int32_t sampleFormats[SAMPLE_FMT_NUM]; /** Supported audio sampling formats. For details, 131 see {@link CodecAudioSampleFormat}. */ 132 int32_t sampleRate[SAMPLE_RATE_NUM]; /** Supported audio sampling rates. For details, 133 see {@link AudioSampleRate}. */ 134 int32_t channelLayouts[CHANNEL_NUM]; /** Supported audio channel layouts. */ 135 int32_t channelCount[CHANNEL_NUM]; /** Supported audio channels. */ 136 } CodecAudioPortCap; 137 138 /** 139 * @brief Defines the audio and video encoding and decoding capabilities. 140 */ 141 typedef union { 142 CodecVideoPortCap video; /** Video encoding and decoding capabilities */ 143 CodecAudioPortCap audio; /** Audio encoding and decoding capabilities */ 144 } PortCap; 145 146 /** 147 * @brief Defines the codec capabilities. 148 */ 149 #define NAME_LENGTH 32 /** Size of the component name. */ 150 #define PROFILE_NUM 256 /** Size of the profile array supported. */ 151 typedef struct { 152 AvCodecRole role; /** Media type. */ 153 CodecType type; /** Codec type. */ 154 char compName[NAME_LENGTH]; /** Codec component name. */ 155 int32_t supportProfiles[PROFILE_NUM]; /** Supported profiles. For details, see {@link Profile}. */ 156 int32_t maxInst; /** Maximum instance. */ 157 bool isSoftwareCodec; /** Whether it is software codec or hardware codec. */ 158 int32_t processModeMask; /** Codec processing mode mask. For details, 159 see {@link CodecProcessMode}. */ 160 uint32_t capsMask; /** Codec playback capability mask. For details, 161 see {@link CodecCapsMask}. */ 162 RangeValue bitRate; /** Supported bit rate range. */ 163 PortCap port; /** Supported audio and video encoding/decoding capabilities. */ 164 } CodecCompCapability; 165 166 /** 167 * @brief Enumerate the shared memory types. 168 */ 169 enum ShareMemTypes { 170 /** Readable and writable shared memory */ 171 READ_WRITE_TYPE = 0x1, 172 /** Readable shared memory */ 173 READ_ONLY_TYPE = 0x2, 174 }; 175 176 /** 177 * @brief Defines the codec buffer information. 178 */ 179 struct OmxCodecBuffer { 180 uint32_t bufferId; /** Buffer ID. */ 181 uint32_t size; /** Size of the structure. */ 182 union OMX_VERSIONTYPE version; /** Component version. */ 183 uint32_t bufferType; /** Codec buffer type. For details, 184 see {@link CodecBufferType}. */ 185 uint8_t *buffer; /** Buffer used for encoding or decoding. */ 186 uint32_t bufferLen; /** Size of the buffer. */ 187 uint32_t allocLen; /** Size of the buffer allocated. */ 188 uint32_t filledLen; /** Size of the buffer filled. */ 189 uint32_t offset; /** Offset to the start position of the valid data in the buffer. */ 190 int32_t fenceFd; /** Fence file descriptor used to signal when the input or 191 output buffer is ready to consume. */ 192 enum ShareMemTypes type; /** Shared memory type. */ 193 int64_t pts; /** Timestamp. */ 194 uint32_t flag; /** Flag. */ 195 }; 196 197 /** 198 * @brief Defines the <b>CompVerInfo</b>. 199 */ 200 struct CompVerInfo { 201 char compName[NAME_LENGTH]; /** The name of the component */ 202 uint8_t compUUID[UUID_LENGTH]; /** The UUID of the component */ 203 union OMX_VERSIONTYPE compVersion; /** The version of the component. For details, see {@link OMX_VERSIONTYPE}. */ 204 union OMX_VERSIONTYPE specVersion; /** The spec version of the component. */ 205 }; 206 207 /** 208 * @brief Defines the <b>EventInfo</b>. 209 */ 210 struct EventInfo { 211 int64_t appData; /** The pointer to the upper-layer instance passed to the callback */ 212 uint32_t data1; /** Data 1 carried in the event. */ 213 uint32_t data2; /** Data 2 carried in the event. */ 214 int8_t *eventData; /** The pointer of data carried in the event. */ 215 uint32_t eventDataLen; /** The length of <b>eventData</b>, in bytes. */ 216 }; 217 218 #ifdef __cplusplus 219 #if __cplusplus 220 } 221 #endif 222 #endif /* __cplusplus */ 223 224 #endif /* CODEC_COMPONENT_TYPE_H */ 225 /** @} */