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 video encode temporal scalability, the value type is int32_t 152 */ 153 static constexpr std::string_view OH_MD_KEY_VIDEO_ENCODER_ENABLE_TEMPORAL_SCALABILITY = 154 "video_encoder_enable_temporal_scalability"; 155 156 /** 157 * Key for encode profile, the value type is int32_t 158 */ 159 static constexpr std::string_view MD_KEY_PROFILE = "codec_profile"; 160 161 /** 162 * key for the desired encoding quality, the value type is uint32_t, this key is only supported for encoders that 163 * are configured in constant quality mode 164 */ 165 static constexpr std::string_view MD_KEY_QUALITY = "quality"; 166 167 /** 168 * Key for audio channel count, value type is uint32_t 169 */ 170 static constexpr std::string_view MD_KEY_CHANNEL_COUNT = "channel_count"; 171 172 /** 173 * Key for audio sample rate, value type is uint32_t 174 */ 175 static constexpr std::string_view MD_KEY_SAMPLE_RATE = "sample_rate"; 176 177 /** 178 * Key for track count, value type is uint32_t 179 */ 180 static constexpr std::string_view MD_KEY_TRACK_COUNT = "track_count"; 181 182 /** 183 * custom key prefix, media service will pass through to HAL. 184 */ 185 static constexpr std::string_view MD_KEY_CUSTOM_PREFIX = "vendor.custom"; 186 187 /** 188 * Key for codec specific data buffer, vlaue type is uint8_t* 189 */ 190 static constexpr std::string_view MD_KEY_CODEC_CONFIG = "codec_config"; 191 192 /** 193 * Key for audio channel layout, value type is int64_t 194 */ 195 static constexpr std::string_view MD_KEY_CHANNEL_LAYOUT = "channel_layout"; 196 197 /** 198 * Key for audio sample format, value type is uint32_t 199 */ 200 static constexpr std::string_view MD_KEY_AUDIO_SAMPLE_FORMAT = "audio_sample_format"; 201 202 /** 203 * Key for the number of bits used to encode each sample, value type is uint32_t 204 */ 205 static constexpr std::string_view MD_KEY_BITS_PER_CODED_SAMPLE = "bits_per_coded_sample"; 206 207 /** 208 * Key for aac type, value type is uint32_t 209 */ 210 static constexpr std::string_view MD_KEY_AAC_IS_ADTS = "aac_is_adts"; 211 212 /** 213 * Key for aac sbr, value type is uint32_t 214 */ 215 static constexpr std::string_view MD_KEY_SBR = "sbr"; 216 217 /** 218 * Key for compliance level, value type is int32_t 219 */ 220 static constexpr std::string_view MD_KEY_COMPLIANCE_LEVEL = "compliance_level"; 221 222 /** 223 * Key for vorbis identification header, value type is uint8_t* 224 */ 225 static constexpr std::string_view MD_KEY_IDENTIFICATION_HEADER = "identification_header"; 226 227 /** 228 * Key for vorbis setup header, value type is uint8_t* 229 */ 230 static constexpr std::string_view MD_KEY_SETUP_HEADER = "setup_header"; 231 232 /** 233 * Key for audio frame size, means samples per frame, value type is int32_t* 234 */ 235 static constexpr std::string_view MD_KEY_AUDIO_SAMPLES_PER_FRAME = "audio_samples_per_frame"; 236 237 /** 238 * Key for Number of delayed video frames, value type is uint32_t 239 */ 240 static constexpr std::string_view MD_KEY_VIDEO_DELAY = "video_delay"; 241 242 /** 243 * Key for codec compression leve, value type is uint32_t 244 */ 245 static constexpr std::string_view MD_KEY_COMPRESSION_LEVEL = "audio_compression_level"; 246 247 /** 248 * Key for encode level, value type is int32_t 249 */ 250 static constexpr std::string_view MD_KEY_LEVEL = "codec_level"; 251 252 /** 253 * Key for video chroma location, value type is int32_t 254 */ 255 static constexpr std::string_view MD_KEY_CHROMA_LOCATION = "chroma_location"; 256 257 /** 258 * Key for cover of file, value type is uint8_t pointer 259 */ 260 static constexpr std::string_view MD_KEY_COVER = "cover"; 261 262 /** 263 * Key for video is hdr vivid, value type is bool 264 */ 265 static constexpr std::string_view MD_KEY_VIDEO_IS_HDR_VIVID = "video_is_hdr_vivid"; 266 267 /** 268 * Key for hdr vivid video cuvv configuration box, value type is uint8_t* 269 */ 270 static constexpr std::string_view MD_KEY_VIDEO_CUVV_CONFIG_BOX = "cuvv_config_box"; 271 272 /** 273 * Key for timed metadata track data type, value type is string 274 */ 275 static constexpr std::string_view MD_KEY_TIMED_METADATA_KEY = "timed_metadata_key"; 276 277 /** 278 * Key for timed metadata source track id, value type is int32_t 279 */ 280 static constexpr std::string_view MD_KEY_TIMED_METADATA_SRC_TRACK_ID = "timed_metadata_track_id"; 281 282 /** 283 * Key for video color space of the video decoder output, value type is int32_t. See OH_NativeBuffer_ColorSpace for 284 * value, and only OH_COLORSPACE_BT709_LIMIT is valid. 285 */ 286 static constexpr std::string_view MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE = "video_decoder_output_colorspace"; 287 private: 288 MediaDescriptionKey() = delete; 289 ~MediaDescriptionKey() = delete; 290 }; 291 292 /** 293 * @brief 294 * 295 * @since 4.0 296 * @version 4.0 297 */ 298 enum ColorPrimary : int32_t { 299 COLOR_PRIMARY_BT709 = 1, 300 COLOR_PRIMARY_UNSPECIFIED = 2, 301 COLOR_PRIMARY_BT470_M = 4, 302 COLOR_PRIMARY_BT601_625 = 5, 303 COLOR_PRIMARY_BT601_525 = 6, 304 COLOR_PRIMARY_SMPTE_ST240 = 7, 305 COLOR_PRIMARY_GENERIC_FILM = 8, 306 COLOR_PRIMARY_BT2020 = 9, 307 COLOR_PRIMARY_SMPTE_ST428 = 10, 308 COLOR_PRIMARY_P3DCI = 11, 309 COLOR_PRIMARY_P3D65 = 12, 310 }; 311 312 /** 313 * @brief 314 * 315 * @since 4.0 316 * @version 4.0 317 */ 318 enum TransferCharacteristic : int32_t { 319 TRANSFER_CHARACTERISTIC_BT709 = 1, 320 TRANSFER_CHARACTERISTIC_UNSPECIFIED = 2, 321 TRANSFER_CHARACTERISTIC_GAMMA_2_2 = 4, 322 TRANSFER_CHARACTERISTIC_GAMMA_2_8 = 5, 323 TRANSFER_CHARACTERISTIC_BT601 = 6, 324 TRANSFER_CHARACTERISTIC_SMPTE_ST240 = 7, 325 TRANSFER_CHARACTERISTIC_LINEAR = 8, 326 TRANSFER_CHARACTERISTIC_LOG = 9, 327 TRANSFER_CHARACTERISTIC_LOG_SQRT = 10, 328 TRANSFER_CHARACTERISTIC_IEC_61966_2_4 = 11, 329 TRANSFER_CHARACTERISTIC_BT1361 = 12, 330 TRANSFER_CHARACTERISTIC_IEC_61966_2_1 = 13, 331 TRANSFER_CHARACTERISTIC_BT2020_10BIT = 14, 332 TRANSFER_CHARACTERISTIC_BT2020_12BIT = 15, 333 TRANSFER_CHARACTERISTIC_PQ = 16, 334 TRANSFER_CHARACTERISTIC_SMPTE_ST428 = 17, 335 TRANSFER_CHARACTERISTIC_HLG = 18, 336 }; 337 338 /** 339 * @brief 340 * 341 * @since 4.0 342 * @version 4.0 343 */ 344 enum MatrixCoefficient : int32_t { 345 MATRIX_COEFFICIENT_IDENTITY = 0, 346 MATRIX_COEFFICIENT_BT709 = 1, 347 MATRIX_COEFFICIENT_UNSPECIFIED = 2, 348 MATRIX_COEFFICIENT_FCC = 4, 349 MATRIX_COEFFICIENT_BT601_625 = 5, 350 MATRIX_COEFFICIENT_BT601_525 = 6, 351 MATRIX_COEFFICIENT_SMPTE_ST240 = 7, 352 MATRIX_COEFFICIENT_YCGCO = 8, 353 MATRIX_COEFFICIENT_BT2020_NCL = 9, 354 MATRIX_COEFFICIENT_BT2020_CL = 10, 355 MATRIX_COEFFICIENT_SMPTE_ST2085 = 11, 356 MATRIX_COEFFICIENT_CHROMATICITY_NCL = 12, 357 MATRIX_COEFFICIENT_CHROMATICITY_CL = 13, 358 MATRIX_COEFFICIENT_ICTCP = 14, 359 }; 360 361 /** 362 * @brief 363 * 364 * @since 4.0 365 * @version 4.0 366 */ 367 enum ChromaLocation { 368 CHROMA_LOC_UNSPECIFIED = 0, 369 CHROMA_LOC_LEFT = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0 370 CHROMA_LOC_CENTER = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0 371 CHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2 372 CHROMA_LOC_TOP = 4, 373 CHROMA_LOC_BOTTOMLEFT = 5, 374 CHROMA_LOC_BOTTOM = 6, 375 }; 376 } // namespace MediaAVCodec 377 } // namespace OHOS 378 #endif // MEDIA_AVCODEC_DESCRIPTION_H 379