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 #ifndef MEDIA_AVCODEC_DESCRIPTION_H 17 #define MEDIA_AVCODEC_DESCRIPTION_H 18 19 #include "meta/format.h" 20 21 namespace OHOS { 22 namespace MediaAVCodec { 23 /** 24 * @brief Provides the uniform key for storing the media description. 25 */ 26 using MediaDescription = Media::Format; 27 28 /** 29 * @brief Provides the key's definition for MediaDescription. 30 */ 31 class MediaDescriptionKey { 32 public: 33 /** 34 * Key for track index, value type is uint32_t 35 */ 36 static constexpr std::string_view MD_KEY_TRACK_INDEX = "track_index"; 37 38 /** 39 * Key for track type, value type is uint8_t, see {link @MediaTrackType} 40 */ 41 static constexpr std::string_view MD_KEY_TRACK_TYPE = "track_type"; 42 43 /** 44 * Key for codec mime type, value type is string 45 */ 46 static constexpr std::string_view MD_KEY_CODEC_MIME = "codec_mime"; 47 48 /** 49 * Key for codec name, value type is string 50 */ 51 static constexpr std::string_view MD_KEY_CODEC_NAME = "codec_name"; 52 53 /** 54 * Key for duration, value type is int64_t 55 */ 56 static constexpr std::string_view MD_KEY_DURATION = "duration"; 57 58 /** 59 * Key for bitrate, value type is int64_t 60 */ 61 static constexpr std::string_view MD_KEY_BITRATE = "bitrate"; 62 63 /** 64 * Key for max input size, value type is uint32_t 65 */ 66 static constexpr std::string_view MD_KEY_MAX_INPUT_SIZE = "max_input_size"; 67 68 /** 69 * Key for max input buffer count, value type is int32_t 70 */ 71 static constexpr std::string_view MD_KEY_MAX_INPUT_BUFFER_COUNT = "max_input_buffer_count"; 72 73 /** 74 * Key for max output buffer count, value type is int32_t 75 */ 76 static constexpr std::string_view MD_KEY_MAX_OUTPUT_BUFFER_COUNT = "max_output_buffer_count"; 77 78 /** 79 * Key for video width, value type is int32_t 80 */ 81 static constexpr std::string_view MD_KEY_WIDTH = "width"; 82 83 /** 84 * Key for video height, value type is int32_t 85 */ 86 static constexpr std::string_view MD_KEY_HEIGHT = "height"; 87 88 /** 89 * Key for video pixelformat, value type is int32_t, see {link @MediaPixelFormat} 90 */ 91 static constexpr std::string_view MD_KEY_PIXEL_FORMAT = "pixel_format"; 92 93 /** 94 * Key for video scale type, value type is int32_t 95 */ 96 static constexpr std::string_view MD_KEY_SCALE_TYPE = "scale_type"; 97 98 /** 99 * Key for video rotation angle, value type is int32_t 100 */ 101 static constexpr std::string_view MD_KEY_ROTATION_ANGLE = "rotation_angle"; 102 103 /** 104 * Key for video frame rate, value type is double. 105 */ 106 static constexpr std::string_view MD_KEY_FRAME_RATE = "frame_rate"; 107 108 /** 109 * Key for video capture rate, value type is double 110 */ 111 static constexpr std::string_view MD_KEY_CAPTURE_RATE = "capture_rate"; 112 113 /** 114 * Key for the interval of key frame. value type is int32_t, the unit is milliseconds. 115 * A negative value means no key frames are requested after the first frame. A zero 116 * value means a stream containing all key frames is requested. 117 */ 118 static constexpr std::string_view MD_KEY_I_FRAME_INTERVAL = "i_frame_interval"; 119 120 /** 121 * Key for the request a I-Frame immediately. value type is boolean 122 */ 123 static constexpr std::string_view MD_KEY_REQUEST_I_FRAME = "req_i_frame"; 124 125 /** 126 * Key for video YUV value range flag, value type is bool 127 */ 128 static constexpr std::string_view MD_KEY_RANGE_FLAG = "range_flag"; 129 130 /** 131 * Key for video color primaries, value type is int32_t, see {link @ColorPrimary} 132 */ 133 static constexpr std::string_view MD_KEY_COLOR_PRIMARIES = "color_primaries"; 134 135 /** 136 * Key for video transfer characteristics, value type is int32_t, see {link @TransferCharacteristic} 137 */ 138 static constexpr std::string_view MD_KEY_TRANSFER_CHARACTERISTICS = "transfer_characteristics"; 139 140 /** 141 * Key for video maxtrix coefficients, value type is int32_t, see {link @MaxtrixCoefficient} 142 */ 143 static constexpr std::string_view MD_KEY_MATRIX_COEFFICIENTS = "matrix_coefficients"; 144 145 /** 146 * Key for video encode bitrate mode, the value type is int32_t, see {link @VideoEncodeBitrateMode} 147 */ 148 static constexpr std::string_view MD_KEY_VIDEO_ENCODE_BITRATE_MODE = "video_encode_bitrate_mode"; 149 150 /** 151 * Key for encode profile, the value type is int32_t 152 */ 153 static constexpr std::string_view MD_KEY_PROFILE = "codec_profile"; 154 155 /** 156 * key for the desired encoding quality, the value type is uint32_t, this key is only supported for encoders that 157 * are configured in constant quality mode 158 */ 159 static constexpr std::string_view MD_KEY_QUALITY = "quality"; 160 161 /** 162 * Key for audio channel count, value type is uint32_t 163 */ 164 static constexpr std::string_view MD_KEY_CHANNEL_COUNT = "channel_count"; 165 166 /** 167 * Key for audio sample rate, value type is uint32_t 168 */ 169 static constexpr std::string_view MD_KEY_SAMPLE_RATE = "sample_rate"; 170 171 /** 172 * Key for track count, value type is uint32_t 173 */ 174 static constexpr std::string_view MD_KEY_TRACK_COUNT = "track_count"; 175 176 /** 177 * custom key prefix, media service will pass through to HAL. 178 */ 179 static constexpr std::string_view MD_KEY_CUSTOM_PREFIX = "vendor.custom"; 180 181 /** 182 * Key for codec specific data buffer, vlaue type is uint8_t* 183 */ 184 static constexpr std::string_view MD_KEY_CODEC_CONFIG = "codec_config"; 185 186 /** 187 * Key for audio channel layout, value type is int64_t 188 */ 189 static constexpr std::string_view MD_KEY_CHANNEL_LAYOUT = "channel_layout"; 190 191 /** 192 * Key for audio sample format, value type is uint32_t 193 */ 194 static constexpr std::string_view MD_KEY_AUDIO_SAMPLE_FORMAT = "audio_sample_format"; 195 196 /** 197 * Key for the number of bits used to encode each sample, value type is uint32_t 198 */ 199 static constexpr std::string_view MD_KEY_BITS_PER_CODED_SAMPLE = "bits_per_coded_sample"; 200 201 /** 202 * Key for aac type, value type is uint32_t 203 */ 204 static constexpr std::string_view MD_KEY_AAC_IS_ADTS = "aac_is_adts"; 205 206 /** 207 * Key for aac sbr, value type is uint32_t 208 */ 209 static constexpr std::string_view MD_KEY_SBR = "sbr"; 210 211 /** 212 * Key for compliance level, value type is int32_t 213 */ 214 static constexpr std::string_view MD_KEY_COMPLIANCE_LEVEL = "compliance_level"; 215 216 /** 217 * Key for vorbis identification header, value type is uint8_t* 218 */ 219 static constexpr std::string_view MD_KEY_IDENTIFICATION_HEADER = "identification_header"; 220 221 /** 222 * Key for vorbis setup header, value type is uint8_t* 223 */ 224 static constexpr std::string_view MD_KEY_SETUP_HEADER = "setup_header"; 225 226 /** 227 * Key for audio frame size, means samples per frame, value type is int32_t* 228 */ 229 static constexpr std::string_view MD_KEY_AUDIO_SAMPLES_PER_FRAME = "audio_samples_per_frame"; 230 231 /** 232 * Key for Number of delayed video frames, value type is uint32_t 233 */ 234 static constexpr std::string_view MD_KEY_VIDEO_DELAY = "video_delay"; 235 236 /** 237 * Key for codec compression leve, value type is uint32_t 238 */ 239 static constexpr std::string_view MD_KEY_COMPRESSION_LEVEL = "audio_compression_level"; 240 241 /** 242 * Key for encode level, value type is int32_t 243 */ 244 static constexpr std::string_view MD_KEY_LEVEL = "codec_level"; 245 246 /** 247 * Key for video chroma location, value type is int32_t 248 */ 249 static constexpr std::string_view MD_KEY_CHROMA_LOCATION = "chroma_location"; 250 251 /** 252 * Key for cover of file, value type is uint8_t pointer 253 */ 254 static constexpr std::string_view MD_KEY_COVER = "cover"; 255 256 /** 257 * Key for video is hdr vivid, value type is bool 258 */ 259 static constexpr std::string_view MD_KEY_VIDEO_IS_HDR_VIVID = "video_is_hdr_vivid"; 260 261 /** 262 * Key for hdr vivid video cuvv configuration box, value type is uint8_t* 263 */ 264 static constexpr std::string_view MD_KEY_VIDEO_CUVV_CONFIG_BOX = "cuvv_config_box"; 265 private: 266 MediaDescriptionKey() = delete; 267 ~MediaDescriptionKey() = delete; 268 }; 269 270 /** 271 * @brief 272 * 273 * @since 4.0 274 * @version 4.0 275 */ 276 enum ColorPrimary : int32_t { 277 COLOR_PRIMARY_BT709 = 1, 278 COLOR_PRIMARY_UNSPECIFIED = 2, 279 COLOR_PRIMARY_BT470_M = 4, 280 COLOR_PRIMARY_BT601_625 = 5, 281 COLOR_PRIMARY_BT601_525 = 6, 282 COLOR_PRIMARY_SMPTE_ST240 = 7, 283 COLOR_PRIMARY_GENERIC_FILM = 8, 284 COLOR_PRIMARY_BT2020 = 9, 285 COLOR_PRIMARY_SMPTE_ST428 = 10, 286 COLOR_PRIMARY_P3DCI = 11, 287 COLOR_PRIMARY_P3D65 = 12, 288 }; 289 290 /** 291 * @brief 292 * 293 * @since 4.0 294 * @version 4.0 295 */ 296 enum TransferCharacteristic : int32_t { 297 TRANSFER_CHARACTERISTIC_BT709 = 1, 298 TRANSFER_CHARACTERISTIC_UNSPECIFIED = 2, 299 TRANSFER_CHARACTERISTIC_GAMMA_2_2 = 4, 300 TRANSFER_CHARACTERISTIC_GAMMA_2_8 = 5, 301 TRANSFER_CHARACTERISTIC_BT601 = 6, 302 TRANSFER_CHARACTERISTIC_SMPTE_ST240 = 7, 303 TRANSFER_CHARACTERISTIC_LINEAR = 8, 304 TRANSFER_CHARACTERISTIC_LOG = 9, 305 TRANSFER_CHARACTERISTIC_LOG_SQRT = 10, 306 TRANSFER_CHARACTERISTIC_IEC_61966_2_4 = 11, 307 TRANSFER_CHARACTERISTIC_BT1361 = 12, 308 TRANSFER_CHARACTERISTIC_IEC_61966_2_1 = 13, 309 TRANSFER_CHARACTERISTIC_BT2020_10BIT = 14, 310 TRANSFER_CHARACTERISTIC_BT2020_12BIT = 15, 311 TRANSFER_CHARACTERISTIC_PQ = 16, 312 TRANSFER_CHARACTERISTIC_SMPTE_ST428 = 17, 313 TRANSFER_CHARACTERISTIC_HLG = 18, 314 }; 315 316 /** 317 * @brief 318 * 319 * @since 4.0 320 * @version 4.0 321 */ 322 enum MatrixCoefficient : int32_t { 323 MATRIX_COEFFICIENT_IDENTITY = 0, 324 MATRIX_COEFFICIENT_BT709 = 1, 325 MATRIX_COEFFICIENT_UNSPECIFIED = 2, 326 MATRIX_COEFFICIENT_FCC = 4, 327 MATRIX_COEFFICIENT_BT601_625 = 5, 328 MATRIX_COEFFICIENT_BT601_525 = 6, 329 MATRIX_COEFFICIENT_SMPTE_ST240 = 7, 330 MATRIX_COEFFICIENT_YCGCO = 8, 331 MATRIX_COEFFICIENT_BT2020_NCL = 9, 332 MATRIX_COEFFICIENT_BT2020_CL = 10, 333 MATRIX_COEFFICIENT_SMPTE_ST2085 = 11, 334 MATRIX_COEFFICIENT_CHROMATICITY_NCL = 12, 335 MATRIX_COEFFICIENT_CHROMATICITY_CL = 13, 336 MATRIX_COEFFICIENT_ICTCP = 14, 337 }; 338 339 /** 340 * @brief 341 * 342 * @since 4.0 343 * @version 4.0 344 */ 345 enum ChromaLocation { 346 CHROMA_LOC_UNSPECIFIED = 0, 347 CHROMA_LOC_LEFT = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0 348 CHROMA_LOC_CENTER = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0 349 CHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2 350 CHROMA_LOC_TOP = 4, 351 CHROMA_LOC_BOTTOMLEFT = 5, 352 CHROMA_LOC_BOTTOM = 6, 353 }; 354 } // namespace MediaAVCodec 355 } // namespace OHOS 356 #endif // MEDIA_AVCODEC_DESCRIPTION_H 357