1 /*! 2 * \copy 3 * Copyright (c) 2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33 //wels_common_defs.h 34 #ifndef WELS_COMMON_DEFS_H__ 35 #define WELS_COMMON_DEFS_H__ 36 37 #include "typedefs.h" 38 #include "macros.h" 39 #include "codec_app_def.h" 40 41 42 namespace WelsCommon { 43 /*common use table*/ 44 45 #define CTX_NA 0 46 #define WELS_CONTEXT_COUNT 460 47 #define LEVEL_NUMBER 17 48 typedef struct TagLevelLimits { 49 ELevelIdc uiLevelIdc; // level idc 50 uint32_t uiMaxMBPS; // Max macroblock processing rate(MB/s) 51 uint32_t uiMaxFS; // Max frame sizea(MBs) 52 uint32_t uiMaxDPBMbs;// Max decoded picture buffer size(MBs) 53 uint32_t uiMaxBR; // Max video bit rate 54 uint32_t uiMaxCPB; // Max CPB size 55 int16_t iMinVmv; // Vertical MV component range upper bound 56 int16_t iMaxVmv; // Vertical MV component range lower bound 57 uint16_t uiMinCR; // Min compression ration 58 int16_t iMaxMvsPer2Mb; // Max number of motion vectors per two consecutive MBs 59 } SLevelLimits; 60 61 #define CpbBrNalFactor 1200 //baseline,main,and extended profiles. 62 extern const SLevelLimits g_ksLevelLimits[LEVEL_NUMBER]; 63 extern const uint32_t g_kuiLevelMaps[LEVEL_NUMBER]; 64 extern const uint8_t g_kuiMbCountScan4Idx[24]; 65 extern const uint8_t g_kuiCache30ScanIdx[16]; 66 extern const uint8_t g_kuiCache48CountScan4Idx[24]; 67 68 extern const uint8_t g_kuiMatrixV[6][8][8]; 69 70 extern const uint8_t g_kuiDequantScaling4x4Default[2][16]; 71 extern const uint8_t g_kuiDequantScaling8x8Default[2][64]; 72 extern const ALIGNED_DECLARE (uint16_t, g_kuiDequantCoeff[52][8], 16); 73 extern const ALIGNED_DECLARE (uint16_t, g_kuiDequantCoeff8x8[52][64], 16); 74 extern const uint8_t g_kuiChromaQpTable[52]; 75 76 extern const uint8_t g_kuiCabacRangeLps[64][4]; 77 extern const int8_t g_kiCabacGlobalContextIdx[WELS_CONTEXT_COUNT][4][2]; 78 extern const uint8_t g_kuiStateTransTable[64][2]; 79 extern const uint32_t g_kuiGolombUELength[256]; 80 /* 81 * NAL Unit Type (5 Bits) 82 */ 83 enum EWelsNalUnitType { 84 NAL_UNIT_UNSPEC_0 = 0, 85 NAL_UNIT_CODED_SLICE = 1, 86 NAL_UNIT_CODED_SLICE_DPA = 2, 87 NAL_UNIT_CODED_SLICE_DPB = 3, 88 NAL_UNIT_CODED_SLICE_DPC = 4, 89 NAL_UNIT_CODED_SLICE_IDR = 5, 90 NAL_UNIT_SEI = 6, 91 NAL_UNIT_SPS = 7, 92 NAL_UNIT_PPS = 8, 93 NAL_UNIT_AU_DELIMITER = 9, 94 NAL_UNIT_END_OF_SEQ = 10, 95 NAL_UNIT_END_OF_STR = 11, 96 NAL_UNIT_FILLER_DATA = 12, 97 NAL_UNIT_SPS_EXT = 13, 98 NAL_UNIT_PREFIX = 14, 99 NAL_UNIT_SUBSET_SPS = 15, 100 NAL_UNIT_DEPTH_PARAM = 16, // NAL_UNIT_RESV_16 101 NAL_UNIT_RESV_17 = 17, 102 NAL_UNIT_RESV_18 = 18, 103 NAL_UNIT_AUX_CODED_SLICE = 19, 104 NAL_UNIT_CODED_SLICE_EXT = 20, 105 NAL_UNIT_MVC_SLICE_EXT = 21, // NAL_UNIT_RESV_21 106 NAL_UNIT_RESV_22 = 22, 107 NAL_UNIT_RESV_23 = 23, 108 NAL_UNIT_UNSPEC_24 = 24, 109 NAL_UNIT_UNSPEC_25 = 25, 110 NAL_UNIT_UNSPEC_26 = 26, 111 NAL_UNIT_UNSPEC_27 = 27, 112 NAL_UNIT_UNSPEC_28 = 28, 113 NAL_UNIT_UNSPEC_29 = 29, 114 NAL_UNIT_UNSPEC_30 = 30, 115 NAL_UNIT_UNSPEC_31 = 31 116 }; 117 118 /* 119 * NAL Reference IDC (2 Bits) 120 */ 121 122 enum EWelsNalRefIdc { 123 NRI_PRI_LOWEST = 0, 124 NRI_PRI_LOW = 1, 125 NRI_PRI_HIGH = 2, 126 NRI_PRI_HIGHEST = 3 127 }; 128 129 /* 130 * VCL TYPE 131 */ 132 133 enum EVclType { 134 NON_VCL = 0, 135 VCL = 1, 136 NOT_APP = 2 137 }; 138 139 /* 140 * vcl type map for given NAL unit type and corresponding H264 type (0: AVC; 1: SVC). 141 */ 142 extern const EVclType g_keTypeMap[32][2]; 143 144 #define IS_VCL_NAL(t, ext_idx) (g_keTypeMap[t][ext_idx] == VCL) 145 #define IS_PARAM_SETS_NALS(t) ( (t) == NAL_UNIT_SPS || (t) == NAL_UNIT_PPS || (t) == NAL_UNIT_SUBSET_SPS ) 146 #define IS_SPS_NAL(t) ( (t) == NAL_UNIT_SPS ) 147 #define IS_SUBSET_SPS_NAL(t) ( (t) == NAL_UNIT_SUBSET_SPS ) 148 #define IS_PPS_NAL(t) ( (t) == NAL_UNIT_PPS ) 149 #define IS_SEI_NAL(t) ( (t) == NAL_UNIT_SEI ) 150 #define IS_AU_DELIMITER_NAL(t) ( (t) == NAL_UNIT_AU_DELIMITER ) 151 #define IS_PREFIX_NAL(t) ( (t) == NAL_UNIT_PREFIX ) 152 #define IS_SUBSET_SPS_USED(t) ( (t) == NAL_UNIT_SUBSET_SPS || (t) == NAL_UNIT_CODED_SLICE_EXT ) 153 #define IS_VCL_NAL_AVC_BASE(t) ( (t) == NAL_UNIT_CODED_SLICE || (t) == NAL_UNIT_CODED_SLICE_IDR ) 154 #define IS_NEW_INTRODUCED_SVC_NAL(t) ( (t) == NAL_UNIT_PREFIX || (t) == NAL_UNIT_CODED_SLICE_EXT ) 155 156 157 /* Base SSlice Types 158 * Invalid in case of eSliceType exceeds 9, 159 * Need trim when eSliceType > 4 as fixed SliceType(eSliceType-4), 160 * meaning mapped version after eSliceType minus 4. 161 */ 162 163 enum EWelsSliceType { 164 P_SLICE = 0, 165 B_SLICE = 1, 166 I_SLICE = 2, 167 SP_SLICE = 3, 168 SI_SLICE = 4, 169 UNKNOWN_SLICE = 5 170 }; 171 172 /* SSlice Types in scalable extension */ 173 enum ESliceTypeExt { 174 EP_SLICE = 0, // EP_SLICE: 0, 5 175 EB_SLICE = 1, // EB_SLICE: 1, 6 176 EI_SLICE = 2 // EI_SLICE: 2, 7 177 }; 178 179 /* List Index */ 180 enum EListIndex { 181 LIST_0 = 0, 182 LIST_1 = 1, 183 LIST_A = 2 184 }; 185 186 187 188 /* Motion Vector components */ 189 enum EMvComp { 190 MV_X = 0, 191 MV_Y = 1, 192 MV_A = 2 193 }; 194 195 /* Chroma Components */ 196 197 enum EChromaComp { 198 CHROMA_CB = 0, 199 CHROMA_CR = 1, 200 CHROMA_A = 2 201 }; 202 203 204 205 /* 206 * Memory Management Control Operation (MMCO) code 207 */ 208 enum EMmcoCode { 209 MMCO_END = 0, 210 MMCO_SHORT2UNUSED = 1, 211 MMCO_LONG2UNUSED = 2, 212 MMCO_SHORT2LONG = 3, 213 MMCO_SET_MAX_LONG = 4, 214 MMCO_RESET = 5, 215 MMCO_LONG = 6 216 }; 217 218 enum EVuiVideoFormat { 219 VUI_COMPONENT = 0, 220 VUI_PAL = 1, 221 VUI_NTSC = 2, 222 VUI_SECAM = 3, 223 VUI_MAC = 4, 224 VUI_UNSPECIFIED = 5, 225 VUI_RESERVED1 = 6, 226 VUI_RESERVED2 = 7 227 }; 228 229 /* 230 * Bit-stream auxiliary reading / writing 231 */ 232 typedef struct TagBitStringAux { 233 uint8_t* pStartBuf; // buffer to start position 234 uint8_t* pEndBuf; // buffer + length 235 int32_t iBits; // count bits of overall bitstreaming input 236 237 intX_t iIndex; //only for cavlc usage 238 uint8_t* pCurBuf; // current reading position 239 uint32_t uiCurBits; 240 int32_t iLeftBits; // count number of available bits left ([1, 8]), 241 // need pointer to next byte start position in case 0 bit left then 8 instead 242 } SBitStringAux, *PBitStringAux; 243 244 /* NAL Unix Header in AVC, refer to Page 56 in JVT X201wcm */ 245 typedef struct TagNalUnitHeader { 246 uint8_t uiForbiddenZeroBit; 247 uint8_t uiNalRefIdc; 248 EWelsNalUnitType eNalUnitType; 249 uint8_t uiReservedOneByte; // only padding usage 250 } SNalUnitHeader, *PNalUnitHeader; 251 252 /* NAL Unit Header in scalable extension syntax, refer to Page 390 in JVT X201wcm */ 253 typedef struct TagNalUnitHeaderExt { 254 SNalUnitHeader sNalUnitHeader; 255 256 // uint8_t reserved_one_bit; 257 bool bIdrFlag; 258 uint8_t uiPriorityId; 259 int8_t iNoInterLayerPredFlag; // change as int8_t to support 3 values probably in encoder 260 uint8_t uiDependencyId; 261 262 uint8_t uiQualityId; 263 uint8_t uiTemporalId; 264 bool bUseRefBasePicFlag; 265 bool bDiscardableFlag; 266 267 bool bOutputFlag; 268 uint8_t uiReservedThree2Bits; 269 // Derived variable(s) 270 uint8_t uiLayerDqId; 271 bool bNalExtFlag; 272 } SNalUnitHeaderExt, *PNalUnitHeaderExt; 273 274 /* AVC MB types*/ 275 #define MB_TYPE_INTRA4x4 0x00000001 276 #define MB_TYPE_INTRA16x16 0x00000002 277 #define MB_TYPE_INTRA8x8 0x00000004 278 #define MB_TYPE_16x16 0x00000008 279 #define MB_TYPE_16x8 0x00000010 280 #define MB_TYPE_8x16 0x00000020 281 #define MB_TYPE_8x8 0x00000040 282 #define MB_TYPE_8x8_REF0 0x00000080 283 #define MB_TYPE_SKIP 0x00000100 284 #define MB_TYPE_INTRA_PCM 0x00000200 285 #define MB_TYPE_INTRA_BL 0x00000400 286 #define MB_TYPE_DIRECT 0x00000800 287 #define MB_TYPE_P0L0 0x00001000 288 #define MB_TYPE_P1L0 0x00002000 289 #define MB_TYPE_P0L1 0x00004000 290 #define MB_TYPE_P1L1 0x00008000 291 #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0) 292 #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1) 293 294 #define SUB_MB_TYPE_8x8 0x00000001 295 #define SUB_MB_TYPE_8x4 0x00000002 296 #define SUB_MB_TYPE_4x8 0x00000004 297 #define SUB_MB_TYPE_4x4 0x00000008 298 299 #define MB_TYPE_INTRA (MB_TYPE_INTRA4x4 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA8x8 | MB_TYPE_INTRA_PCM) 300 #define MB_TYPE_INTER (MB_TYPE_16x16 | MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_8x8_REF0 | MB_TYPE_SKIP | MB_TYPE_DIRECT) 301 #define IS_INTRA4x4(type) ( MB_TYPE_INTRA4x4 == (type) ) 302 #define IS_INTRA8x8(type) ( MB_TYPE_INTRA8x8 == (type) ) 303 #define IS_INTRANxN(type) ( MB_TYPE_INTRA4x4 == (type) || MB_TYPE_INTRA8x8 == (type) ) 304 #define IS_INTRA16x16(type) ( MB_TYPE_INTRA16x16 == (type) ) 305 #define IS_INTRA(type) ( (type)&MB_TYPE_INTRA ) 306 #define IS_INTER(type) ( (type)&MB_TYPE_INTER ) 307 #define IS_INTER_16x16(type) ( (type)&MB_TYPE_16x16 ) 308 #define IS_INTER_16x8(type) ( (type)&MB_TYPE_16x8 ) 309 #define IS_INTER_8x16(type) ( (type)&MB_TYPE_8x16 ) 310 #define IS_TYPE_L0(type) ( (type)&MB_TYPE_L0 ) 311 #define IS_TYPE_L1(type) ( (type)&MB_TYPE_L1 ) 312 #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list)))) 313 314 315 #define IS_SKIP(type) ( ((type)&MB_TYPE_SKIP) != 0 ) 316 #define IS_DIRECT(type) ( ((type)&MB_TYPE_DIRECT) != 0 ) 317 #define IS_SVC_INTER(type) IS_INTER(type) 318 #define IS_I_BL(type) ( (type) == MB_TYPE_INTRA_BL ) 319 #define IS_SVC_INTRA(type) ( IS_I_BL(type) || IS_INTRA(type) ) 320 #define IS_Inter_8x8(type) ( ((type)&MB_TYPE_8x8) != 0) 321 #define IS_SUB_8x8(sub_type) (((sub_type)&SUB_MB_TYPE_8x8) != 0) 322 #define IS_SUB_8x4(sub_type) (((sub_type)&SUB_MB_TYPE_8x4) != 0) 323 #define IS_SUB_4x8(sub_type) (((sub_type)&SUB_MB_TYPE_4x8) != 0) 324 #define IS_SUB_4x4(sub_type) (((sub_type)&SUB_MB_TYPE_4x4) != 0) 325 326 #define REF_NOT_AVAIL -2 327 #define REF_NOT_IN_LIST -1 //intra 328 329 /////////intra16x16 Luma 330 #define I16_PRED_INVALID -1 331 #define I16_PRED_V 0 332 #define I16_PRED_H 1 333 #define I16_PRED_DC 2 334 #define I16_PRED_P 3 335 336 #define I16_PRED_DC_L 4 337 #define I16_PRED_DC_T 5 338 #define I16_PRED_DC_128 6 339 #define I16_PRED_DC_A 7 340 //////////intra4x4 Luma 341 // Here, I8x8 also use these definitions 342 #define I4_PRED_INVALID 0 343 #define I4_PRED_V 0 344 #define I4_PRED_H 1 345 #define I4_PRED_DC 2 346 #define I4_PRED_DDL 3 //diagonal_down_left 347 #define I4_PRED_DDR 4 //diagonal_down_right 348 #define I4_PRED_VR 5 //vertical_right 349 #define I4_PRED_HD 6 //horizon_down 350 #define I4_PRED_VL 7 //vertical_left 351 #define I4_PRED_HU 8 //horizon_up 352 353 #define I4_PRED_DC_L 9 354 #define I4_PRED_DC_T 10 355 #define I4_PRED_DC_128 11 356 357 #define I4_PRED_DDL_TOP 12 //right-top replacing by padding rightmost pixel of top 358 #define I4_PRED_VL_TOP 13 //right-top replacing by padding rightmost pixel of top 359 #define I4_PRED_A 14 360 361 //////////intra Chroma 362 #define C_PRED_INVALID -1 363 #define C_PRED_DC 0 364 #define C_PRED_H 1 365 #define C_PRED_V 2 366 #define C_PRED_P 3 367 368 #define C_PRED_DC_L 4 369 #define C_PRED_DC_T 5 370 #define C_PRED_DC_128 6 371 #define C_PRED_A 7 372 } 373 #endif//WELS_COMMON_DEFS_H__ 374