1 /* 2 * Copyright 2019 Rockchip Electronics Co. LTD 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * author: martin.cheng@rock-chips.com 17 * date: 20190115 18 * ref: tmedia/libavcodec/avcodec.h 19 */ 20 21 #ifndef SRC_RT_MEDIA_INCLUDE_RTMEDIADEF_H_ 22 #define SRC_RT_MEDIA_INCLUDE_RTMEDIADEF_H_ 23 24 #include "RTMediaPixel.h" // NOLINT 25 #include "rt_type.h" // NOLINT 26 #include "rt_metadata.h" // NOLINT 27 28 #define RT_TIME_BASE (1000000) 29 #define RT_SEC_TO_TIME(x) (static_cast<INT64>(static_cast<double>(x) * RT_TIME_BASE)) 30 #define RT_MSEC_TO_TIME(x) (static_cast<INT64>(static_cast<double>(x) * RT_TIME_BASE / 1000)) 31 #define RT_AV_NOSYNC_THRESHOLD 10.0 32 #define RT_AUDIO_DIFF_AVG_NB 20 33 #define RT_SEEK_DROP_THRESHOLD 500 * 1000 // 500ms 34 35 /** 36 * @ingroup rt_node 37 * @brief Enumeration used to define the possible video compression codings. 38 * sync with the omx_video.h & omx_audio.h 39 * 40 * @note This essentially refers to file extensions. If the coding is 41 * being used to specify the ENCODE type, then additional work 42 * must be done to configure the exact flavor of the compression 43 * to be used. For decode cases where the user application can 44 * not differentiate between MPEG-4 and H.264 bit streams, it is 45 * up to the codec to handle this. 46 */ 47 typedef enum { 48 RT_VIDEO_ID_Unused, /**< Value when coding is N/A */ 49 RT_VIDEO_ID_AutoDetect, /**< Autodetection of coding type */ 50 RT_VIDEO_ID_MPEG1VIDEO, 51 RT_VIDEO_ID_MPEG2VIDEO, /**< AKA: H.262 */ 52 RT_VIDEO_ID_H263, /**< H.263 */ 53 RT_VIDEO_ID_MPEG4, /**< MPEG-4 */ 54 RT_VIDEO_ID_WMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/ 55 RT_VIDEO_ID_RV, /**< all versions of Real Video */ 56 RT_VIDEO_ID_AVC, /**< H.264/AVC */ 57 RT_VIDEO_ID_MJPEG, /**< Motion JPEG */ 58 RT_VIDEO_ID_VP8, /**< VP8 */ 59 RT_VIDEO_ID_VP9, /**< VP9 */ 60 RT_VIDEO_ID_HEVC, /**< ITU H.265/HEVC */ 61 RT_VIDEO_ID_TsylfVision, /**< Tsylf Vision */ 62 RT_VIDEO_ID_ImageHEIC, /**< HEIF image encoded with HEVC */ 63 RT_VIDEO_ID_JPEG, /**< JPEG */ 64 RT_VIDEO_ID_VC1 = 0x01000000, /**< Windows Media Video (WMV1,WMV2,WMV3)*/ 65 RT_VIDEO_ID_FLV1, /**< Sorenson H.263 */ 66 RT_VIDEO_ID_DIVX3, /**< DIVX3 */ 67 RT_VIDEO_ID_VP6, 68 RT_VIDEO_ID_AVSPLUS, /**< AVS+ profile=0x48 */ 69 RT_VIDEO_ID_AVS, /**< AVS profile=0x20 */ 70 /* *< Reserved region for introducing Khronos Standard Extensions */ 71 RT_VIDEO_ID_KhronosExtensions = 0x2F000000, 72 /* *< Reserved region for introducing Vendor Extensions */ 73 RT_VIDEO_ID_VendorStartUnused = 0x3F000000, 74 RT_VIDEO_ID_Max = 0x3FFFFFFF, 75 76 RT_AUDIO_ID_Unused = 0x40000000, /**< Placeholder value when coding is N/A */ 77 RT_AUDIO_ID_AutoDetect, /**< auto detection of audio format */ 78 RT_AUDIO_ID_PCM_ALAW, /** <g711a> */ 79 RT_AUDIO_ID_PCM_MULAW, /** <g711u> */ 80 RT_AUDIO_ID_PCM_S16LE, /**< Any variant of PCM_S16LE coding */ 81 RT_AUDIO_ID_PCM_S24LE, /**< Any variant of PCM_S24LE coding */ 82 RT_AUDIO_ID_PCM_S32LE, /**< Any variant of PCM_S32LE coding */ 83 RT_AUDIO_ID_ADPCM_G722, /**< Any variant of ADPCM_G722 encoded data */ 84 RT_AUDIO_ID_ADPCM_G726, /**< Any variant of ADPCM_G726 encoded data */ 85 RT_AUDIO_ID_ADPCM_IMA_QT, /**< Any variant of ADPCM_IMA encoded data */ 86 RT_AUDIO_ID_AMR_NB, /**< Any variant of AMR_NB encoded data */ 87 RT_AUDIO_ID_AMR_WB, /**< Any variant of AMR_WB encoded data */ 88 RT_AUDIO_ID_GSMFR, /**< Any variant of GSM fullrate (i.e. GSM610) */ 89 RT_AUDIO_ID_GSMEFR, /**< Any variant of GSM Enhanced Fullrate encoded data*/ 90 RT_AUDIO_ID_GSMHR, /**< Any variant of GSM Halfrate encoded data */ 91 RT_AUDIO_ID_PDCFR, /**< Any variant of PDC Fullrate encoded data */ 92 RT_AUDIO_ID_PDCEFR, /**< Any variant of PDC Enhanced Fullrate encoded data */ 93 RT_AUDIO_ID_PDCHR, /**< Any variant of PDC Halfrate encoded data */ 94 RT_AUDIO_ID_TDMAFR, /**< Any variant of TDMA Fullrate encoded data (TIA/EIA-136-420) */ 95 RT_AUDIO_ID_TDMAEFR, /**< Any variant of TDMA Enhanced Fullrate encoded data (TIA/EIA-136-410) */ 96 RT_AUDIO_ID_QCELP8, /**< Any variant of QCELP 8kbps encoded data */ 97 RT_AUDIO_ID_QCELP13, /**< Any variant of QCELP 13kbps encoded data */ 98 RT_AUDIO_ID_EVRC, /**< Any variant of EVRC encoded data */ 99 RT_AUDIO_ID_SMV, /**< Any variant of SMV encoded data */ 100 RT_AUDIO_ID_G729, /**< Any variant of G.729 encoded data */ 101 RT_AUDIO_ID_OPUS, /**< Any variant of OPUS encoded data */ 102 RT_AUDIO_ID_TMD, /**< Any variant of TMD encoded data */ 103 RT_AUDIO_ID_MP3, /**< Any variant of MP3 encoded data */ 104 RT_AUDIO_ID_SBC, /**< Any variant of SBC encoded data */ 105 RT_AUDIO_ID_VORBIS, /**< Any variant of VORBIS encoded data */ 106 RT_AUDIO_ID_WMA, /**< Any variant of WMA encoded data */ 107 RT_AUDIO_ID_RA, /**< Any variant of RA encoded data */ 108 RT_AUDIO_ID_MIDI, /**< Any variant of MIDI encoded data */ 109 RT_AUDIO_ID_FLAC, /**< Any variant of FLAC encoded data */ 110 RT_AUDIO_ID_APE = 0x50000000, 111 /**< Reserved region for introducing Khronos Standard Extensions */ 112 RT_AUDIO_CodingKhronosExtensions = 0x6F000000, 113 /**< Reserved region for introducing Vendor Extensions */ 114 RT_AUDIO_CodingVendorStartUnused = 0x7F000000, 115 RT_AUDIO_ID_WMAV1, 116 RT_AUDIO_ID_WMAV2, 117 RT_AUDIO_ID_WMAPRO, 118 RT_AUDIO_ID_WMALOSSLESS, 119 RT_AUDIO_ID_MP1, 120 RT_AUDIO_ID_MP2, 121 /**< add audio bitstream Codec ID define for RT> */ 122 RT_AUDIO_ID_BPM, 123 RT_AUDIO_ID_ACC, 124 RT_AUDIO_ID_EACC, 125 RT_AUDIO_ID_TSYLF_JQXGKH, 126 RT_AUDIO_ID_XYZ, 127 RT_AUDIO_ID_BPM_HD, 128 RT_AUDIO_CodingMax = 0x7FFFFFFF, 129 130 /* subtitle codecs */ 131 RT_SUB_ID_Unused = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. 132 RT_SUB_ID_DVD, 133 RT_SUB_ID_DVB, 134 RT_SUB_ID_TEXT, ///< raw UTF-8 text 135 RT_SUB_ID_XSUB, 136 RT_SUB_ID_SSA, 137 RT_SUB_ID_MOV_TEXT, 138 RT_SUB_ID_HDMV_PGS, 139 RT_SUB_ID_DVB_TELETEXT, 140 RT_SUB_ID_SRT, 141 142 RT_SUB_ID_MICRODVD = 0x17800, 143 RT_SUB_ID_EIA_608, 144 RT_SUB_ID_JACOSUB, 145 RT_SUB_ID_SAMI, 146 RT_SUB_ID_REALTEXT, 147 RT_SUB_ID_STL, 148 RT_SUB_ID_SUBVIEWER1, 149 RT_SUB_ID_SUBVIEWER, 150 RT_SUB_ID_SUBRIP, 151 RT_SUB_ID_WEBVTT, 152 RT_SUB_ID_MPL2, 153 RT_SUB_ID_VPLAYER, 154 RT_SUB_ID_PJS, 155 RT_SUB_ID_ASS, 156 RT_SUB_ID_HDMV_TEXT, 157 RT_SUB_CodingMax 158 } RTCodecID; 159 160 typedef enum _RTFieldOrder { 161 RT_FIELD_UNKNOWN, 162 RT_FIELD_PROGRESSIVE, 163 RT_FIELD_TT, // < Top coded_first, top displayed first 164 RT_FIELD_BB, // < Bottom coded first, bottom displayed first 165 RT_FIELD_TB, // < Top coded first, bottom displayed first 166 RT_FIELD_BT, // < Bottom coded first, top displayed first 167 } RTFieldOrder; 168 169 typedef enum _RTFrameType { 170 RT_FRAME_TYPE_NONE = 0, ///< Undefined 171 RT_FRAME_TYPE_I, ///< Intra 172 RT_FRAME_TYPE_P, ///< Predicted 173 RT_FRAME_TYPE_B, ///< Bi-dir predicted 174 RT_FRAME_TYPE_S, ///< S(GMC)-VOP MPEG-4 175 RT_FRAME_TYPE_SI, ///< Switching Intra 176 RT_FRAME_TYPE_SP, ///< Switching Predicted 177 RT_FRAME_TYPE_BI, ///< BI type 178 } RTFrameType; 179 180 typedef enum _RTLogLevel { 181 RT_LOG_LEVEL_NO = 0, 182 RT_LOG_LEVEL_FULL, 183 RT_LOG_LEVEL_WARRING, 184 RT_LOG_LEVEL_ERROR, 185 RT_LOG_LEVEL_FETAL, 186 RT_LOG_LEVEL_MAX, 187 } RTLogLevel; 188 189 typedef enum _RTPlayLineType { 190 RTPLAYER_LINE_VIDEO = 0, 191 RTPLAYER_LINE_AUDIO, 192 RTPLAYER_LINE_SUBTI, 193 RTPLAYER_LINE_MAX, 194 } RTPlayLineType; 195 196 typedef enum _RTTrackType { 197 RTTRACK_TYPE_UNKNOWN = -1, // < Usually treated as AVMEDIA_TYPE_DATA 198 RTTRACK_TYPE_VIDEO, 199 RTTRACK_TYPE_AUDIO, 200 RTTRACK_TYPE_DATA, // < Opaque data information usually continuous 201 RTTRACK_TYPE_SUBTITLE, 202 RTTRACK_TYPE_ATTACHMENT, // < Opaque data information usually sparse 203 RTTRACK_TYPE_MEDIA, // this is not a really type of tracks 204 // it means video,audio,subtitle 205 RTTRACK_TYPE_MAX 206 } RTTrackType; 207 208 #define RTTRACK_TYPE_SUBTI RTTRACK_TYPE_SUBTITLE 209 210 #define RT_VIDEO_FMT_MASK 0x000f0000 211 #define RT_VIDEO_FMT_YUV 0x00000000 212 #define RT_VIDEO_FMT_RGB 0x00010000 213 /* Need to modify the rkPIXEL_FORMAT_E definition in rk_comm_video.h synchronously */ 214 typedef enum _RTPixelFormat { 215 RT_FMT_YUV420SP = RT_VIDEO_FMT_YUV, /* YYYY... UV... */ 216 RT_FMT_YUV420SP_10BIT, 217 RT_FMT_YUV422SP, /* YYYY... UVUV... */ 218 RT_FMT_YUV422SP_10BIT, ///< Not part of ABI 219 RT_FMT_YUV420P, /* YYYY... UUUU... VVVV */ 220 RT_FMT_YUV420P_VU, /* YYYY... VVVV... UUUU */ 221 RT_FMT_YUV420SP_VU, /* YYYY... VUVUVU... */ 222 RT_FMT_YUV422P, /* YYYY... UUUU... VVVV */ 223 RT_FMT_YUV422SP_VU, /* YYYY... VUVUVU... */ 224 RT_FMT_YUV422_YUYV, /* YUYVYUYV... */ 225 RT_FMT_YUV422_UYVY, /* UYVYUYVY... */ 226 RT_FMT_YUV400SP, /* YYYY... */ 227 RT_FMT_YUV440SP, /* YYYY... UVUV... */ 228 RT_FMT_YUV411SP, /* YYYY... UV... */ 229 RT_FMT_YUV444SP, /* YYYY... UVUVUVUV... */ 230 RT_FMT_YUV422_YVYU, /* YVYUYVYU... */ 231 RT_FMT_YUV422_VYUY, /* VYUYVYUY... */ 232 RT_FMT_YUV_BUTT, 233 234 RT_FMT_RGB565 = RT_VIDEO_FMT_RGB, /* 16-bit RGB */ 235 RT_FMT_BGR565, /* 16-bit RGB */ 236 RT_FMT_RGB555, /* 15-bit RGB */ 237 RT_FMT_BGR555, /* 15-bit RGB */ 238 RT_FMT_RGB444, /* 12-bit RGB */ 239 RT_FMT_BGR444, /* 12-bit RGB */ 240 RT_FMT_RGB888, /* 24-bit RGB */ 241 RT_FMT_BGR888, /* 24-bit RGB */ 242 RT_FMT_RGB101010, /* 30-bit RGB */ 243 RT_FMT_BGR101010, /* 30-bit RGB */ 244 RT_FMT_ARGB1555, /* 16-bit RGB */ 245 RT_FMT_ABGR1555, /* 16-bit RGB */ 246 RT_FMT_ARGB4444, /* 16-bit RGB */ 247 RT_FMT_ABGR4444, /* 16-bit RGB */ 248 RT_FMT_ARGB8565, /* 24-bit RGB */ 249 RT_FMT_ABGR8565, /* 24-bit RGB */ 250 RT_FMT_ARGB8888, /* 32-bit RGB */ 251 RT_FMT_ABGR8888, /* 32-bit RGB */ 252 RT_FMT_BGRA8888, /* 32-bit RGB */ 253 RT_FMT_RGBA8888, /* 32-bit RGB */ 254 RT_FMT_RGBA5551, /* 16-bit RGB */ 255 RT_FMT_BGRA5551, /* 16-bit RGB */ 256 RT_FMT_BGRA4444, /* 16-bit RGB */ 257 RT_FMT_RGB_BUTT, 258 259 RT_FMT_BUTT = RT_FMT_RGB_BUTT, 260 } RTPixelFormat; 261 262 typedef enum _RTVideoRCMode { 263 RT_RC_MODE_DISABLE = 0, 264 RT_RC_MODE_VBR, 265 RT_RC_MODE_CBR, 266 RT_RC_MODE_CQP, 267 RT_RC_MODE_BUTT, 268 } RTVideoRCMode; 269 270 typedef enum _RTSeekMode { 271 RT_SEEK_UNSPECIFIED = -1, 272 RT_SEEK_PREVIOUS_SYNC, 273 RT_SEEK_NEXT_SYNC, 274 } RTSeekMode; 275 276 typedef enum _RTVideoHDLevel { 277 RT_VIDEO_HDL_SD = 0, // <= 576P 278 RT_VIDEO_HDL_HD, // <= 720P 279 RT_VIDEO_HDL_FHD, // <= 1080P/2K 280 RT_VIDEO_HDL_UHD, // <= 2160P/4K 281 RT_VIDEO_HDL_8KD, // <= 4320P/8K 282 RT_VIDEO_HDL_MAX, 283 } RTVideoHDLevel; 284 285 typedef enum _RTAudioFormat { 286 RT_AUDIO_FMT_NONE = -1, 287 288 /* pcm formats*/ 289 RT_AUDIO_FMT_PCM_U8, /* unsigned 8 bits */ 290 RT_AUDIO_FMT_PCM_S16, /* signed 16 bits */ 291 RT_AUDIO_FMT_PCM_S32, /* signed 32 bits */ 292 RT_AUDIO_FMT_PCM_FLT, /* float */ 293 RT_AUDIO_FMT_PCM_DBL, /* double */ 294 295 RT_AUDIO_FMT_PCM_U8P, /* unsigned 8 bits, planar */ 296 RT_AUDIO_FMT_PCM_S16P, /* signed 16 bits, planar */ 297 RT_AUDIO_FMT_PCM_S32P, /* signed 32 bits, planar */ 298 RT_AUDIO_FMT_PCM_FLTP, /* float, planar */ 299 RT_AUDIO_FMT_PCM_DBLP, /* double, planar */ 300 RT_AUDIO_FMT_PCM_S64, /* signed 64 bits */ 301 RT_AUDIO_FMT_PCM_S64P, /* signed 64 bits, planar */ 302 303 RT_AUDIO_FMT_IEC61937, 304 RT_AUDIO_FMT_MAX, 305 } RTAudioFormat; 306 307 typedef enum _RTCompressMode { 308 RT_COMPRESS_MODE_NONE = 0, /* no compress */ 309 RT_COMPRESS_AFBC_16x16, 310 311 RT_COMPRESS_MODE_BUTT 312 } RTCompressMode; 313 314 typedef enum _RTVideoOutputMode { 315 RT_VIDEO_OUTPUT_ORDER_DISP = 0, 316 RT_VIDEO_OUTPUT_ORDER_DEC, 317 318 RT_VIDEO_OUTPUT_ORDER_BUTT 319 } RTVideoOutputMode; 320 321 typedef enum _RTDecMode { 322 RT_DEC_MODE_FRAME = 0, /* send by frame */ 323 RT_DEC_MODE_STREAM, /* send by stream */ 324 RT_DEC_MODE_COMPAT, /* One frame supports multiple packets sending */ 325 RT_DEC_MODE_BUTT, 326 } RTDecMode; 327 328 typedef enum _RTClockType { 329 RT_CLOCK_NONE = -1, 330 RT_CLOCK_AUDIO, 331 RT_CLOCK_VIDEO, 332 RT_CLOCK_EXT, 333 } RTClockType; 334 335 #define RT_TRACK_INDEX_DISABLE 0x7FFF0001 336 #define RT_TRACK_INDEX_UNSUPPORT 0x7FFF0002 337 #define RT_TRACK_INDEX_IGNORE 0x7FFF0003 338 #define RT_EXTRASUB_INDEX_DEALT 10000 339 340 typedef struct _RTTrackParam { 341 RTTrackType mCodecType; 342 RTCodecID mCodecID; 343 UINT32 mCodecOriginID; 344 INT32 mCodecFormat; // video: the pixel format; audio: the sample format 345 INT32 mCodecProfile; 346 INT32 mCodecLevel; 347 UINT32 mCodecTag; 348 349 INT64 mBitrate; 350 uint8_t *mExtraData; 351 INT32 mExtraDataSize; 352 353 /* video track features */ 354 INT32 mVideoDelay; 355 INT32 mVideoWidth; // contain subtitle 356 INT32 mVideoHeight; // contain subtitle 357 INT32 mVideoRotation; 358 float mVideoFrameRate; 359 RTFieldOrder mFieldOrder; 360 enum RTColorRange mColorRange; 361 enum RTColorPrimaries mColorPrimaries; 362 enum RTColorTransfer mColorTrc; 363 enum RTColorSpace mColorSpace; 364 enum RTChromaLocation mChromaLocation; 365 366 /* audio track features*/ 367 UINT64 mAudioChannelLayout; 368 INT32 mAudioChannels; 369 INT32 mAudioSampleRate; 370 INT32 mAudioBlockAlign; 371 INT32 mAudioFrameSize; 372 INT32 mAudioInitialPadding; 373 INT32 mAudioTrailingPadding; 374 INT32 mAudiobitsPerCodedSample; 375 INT32 mAudiobitsPerRawSample; 376 377 /* subtitle track features*/ 378 INT32 mTimeBaseNum; 379 INT32 mTimeBaseDen; 380 INT64 mStartTime; 381 } RTTrackParam; 382 383 typedef enum _ResVideoIdx { 384 RES_VIDEO_ROTATION = 0, 385 } ResVideoIdx; 386 387 typedef enum _ResAudioIdx { 388 RES_AUDIO_BITRATE = 0, 389 RES_AUDIO_BIT_PER_SAMPLE = 1, 390 } ResAudioIdx; 391 392 typedef struct _RTTrackInfor { 393 RTTrackType mCodecType; 394 RTCodecID mCodecID; 395 UINT32 mCodecOriginID; 396 INT32 mStreamIdx; 397 398 /* video track features */ 399 INT32 mVideoWidth; 400 INT32 mVideoHeight; 401 float mVideoFrameRate; 402 403 /* audio track features*/ 404 UINT64 mAudioChannelLayout; 405 INT32 mAudioChannels; 406 INT32 mAudioSampleRate; 407 408 /* subtitle track features */ 409 410 /* language */ 411 char lang[16]; 412 char mine[16]; 413 414 RT_BOOL mProbeDisabled; 415 /* use reserved first when extend this structure */ 416 INT8 mReserved[64]; 417 } RTTrackInfor; 418 419 class RTMediaDef { 420 public: 421 static const char* getTrackName(UINT32 type); 422 static const char* getClockName(UINT32 type); 423 static INT32 getAudioBytesPerSample(INT32 format); 424 static INT32 getFdFromString(const char* uri); 425 static RT_RET getUriFromFd(INT32 fd, char *uri); 426 static RTVideoHDLevel getVideoHDLevel(INT32 width, INT32 height); 427 static RT_BOOL checkFrameRate(float frameRate); 428 }; 429 430 #endif // SRC_RT_MEDIA_INCLUDE_RTMEDIADEF_H_ 431