Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/CommonDef.h
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/CommonDef.h
r1197 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 33 33 34 34 /** \file CommonDef.h 35 \brief Defines constants, macros and tool parameters35 \brief Defines version information, constants and small in-line functions 36 36 */ 37 37 … … 40 40 41 41 #include <algorithm> 42 #include <iostream> 43 #include <assert.h> 42 44 43 45 #if _MSC_VER > 1000 44 46 // disable "signed and unsigned mismatch" 45 47 #pragma warning( disable : 4018 ) 46 // disable bool coercion "performance warning"48 // disable Bool coercion "performance warning" 47 49 #pragma warning( disable : 4800 ) 50 // NH_MV 51 // disabled decorated name length warning issued for IntAry5d 52 #pragma warning(disable : 4503) 53 // 48 54 #endif // _MSC_VER > 1000 55 56 49 57 #include "TypeDef.h" 50 #if H_MV 58 #ifdef _MSC_VER 59 #if _MSC_VER <= 1500 60 inline Int64 abs (Int64 x) { return _abs64(x); }; 61 #endif 62 #endif 63 #if NH_MV 51 64 #include <assert.h> 52 65 #endif … … 58 71 // Version information 59 72 // ==================================================================================================================== 60 61 #if H_MV 73 #if NH_MV 62 74 #define NV_VERSION "14.1" ///< Current software version 63 #define HM_VERSION "15.0" ///< 64 #else 65 #define NV_VERSION "15.0" ///< Current software version 66 #endif 67 75 #define HM_VERSION "16.6" ///< 76 #else 77 #define NV_VERSION "16.6" ///< Current software version 78 #endif 68 79 // ==================================================================================================================== 69 80 // Platform information … … 101 112 #endif 102 113 103 #define NVM_BITS "[%d bit] ", (sizeof( void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S114 #define NVM_BITS "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S 104 115 105 116 #ifndef NULL … … 111 122 // ==================================================================================================================== 112 123 113 #define _SUMMARY_OUT_ 0 ///< print-out PSNR results of all slices to summary.txt 114 #define _SUMMARY_PIC_ 0 ///< print-out PSNR results for each slice type to summary.txt 115 116 #define MAX_GOP 64 ///< max. value of hierarchical GOP size 117 118 #define MAX_NUM_REF_PICS 16 ///< max. number of pictures used for reference 119 #define MAX_NUM_REF 16 ///< max. number of entries in picture reference list 120 121 #define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer 122 #define MAX_INT 2147483647 ///< max. value of signed 32-bit integer 123 #define MIN_INT (-2147483647-1) // < min. value of signed 32-bit integer 124 125 #define MAX_INT64 0x7FFFFFFFFFFFFFFFLL ///< max. value of signed 64-bit integer 126 #define MAX_DOUBLE 1.7e+308 ///< max. value of double-type value 127 128 #define MIN_QP 0 129 #define MAX_QP 51 130 131 #define NOT_VALID -1 124 static const UInt MAX_UINT = 0xFFFFFFFFU; ///< max. value of unsigned 32-bit integer 125 static const Int MAX_INT = 2147483647; ///< max. value of signed 32-bit integer 126 #if NH_MV 127 static const Int MIN_INT = (- MAX_INT - 1); ///< max. value of signed 32-bit integer 128 #endif 129 static const Double MAX_DOUBLE = 1.7e+308; ///< max. value of Double-type value 130 131 // ==================================================================================================================== 132 // Coding tool configuration 133 // ==================================================================================================================== 134 // Most of these should not be changed - they resolve the meaning of otherwise magic numbers. 135 136 static const Int MAX_GOP = 64; ///< max. value of hierarchical GOP size 137 static const Int MAX_NUM_REF_PICS = 16; ///< max. number of pictures used for reference 138 static const Int MAX_NUM_REF = 16; ///< max. number of entries in picture reference list 139 static const Int MAX_QP = 51; 140 static const Int NOT_VALID = -1; 141 142 static const Int AMVP_MAX_NUM_CANDS = 2; ///< AMVP: advanced motion vector prediction - max number of final candidates 143 static const Int AMVP_MAX_NUM_CANDS_MEM = 3; ///< AMVP: advanced motion vector prediction - max number of candidates 144 static const Int AMVP_DECIMATION_FACTOR = 4; 145 static const Int MRG_MAX_NUM_CANDS = 5; ///< MERGE 146 147 148 static const Int MAX_TLAYER = 7; ///< Explicit temporal layer QP offset - max number of temporal layer 149 150 static const Int ADAPT_SR_SCALE = 1; ///< division factor for adaptive search range 151 152 static const Int MAX_NUM_PICS_IN_SOP = 1024; 153 154 static const Int MAX_NESTING_NUM_OPS = 1024; 155 static const Int MAX_NESTING_NUM_LAYER = 64; 156 157 #if NH_MV 158 static const Int MAX_VPS_NUM_HRD_PARAMETERS = 1024; 159 #else 160 static const Int MAX_VPS_NUM_HRD_PARAMETERS = 1; 161 #endif 162 static const Int MAX_VPS_OP_SETS_PLUS1 = 1024; 163 #if NH_MV 164 static const Int MAX_VPS_NUH_LAYER_ID_PLUS1 = 63; 165 #else 166 static const Int MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 = 1; 167 #endif 168 169 static const Int MAXIMUM_INTRA_FILTERED_WIDTH = 16; 170 static const Int MAXIMUM_INTRA_FILTERED_HEIGHT = 16; 171 172 static const Int MAX_CPB_CNT = 32; ///< Upper bound of (cpb_cnt_minus1 + 1) 173 #if NH_MV 174 static const Int MAX_NUM_LAYER_IDS = 63; 175 #else 176 static const Int MAX_NUM_LAYER_IDS = 64; 177 #endif 178 179 static const Int COEF_REMAIN_BIN_REDUCTION = 3; ///< indicates the level at which the VLC transitions from Golomb-Rice to TU+EG(k) 180 181 static const Int CU_DQP_TU_CMAX = 5; ///< max number bins for truncated unary 182 static const Int CU_DQP_EG_k = 0; ///< expgolomb order 183 184 static const Int SBH_THRESHOLD = 4; ///< value of the fixed SBH controlling threshold 185 186 static const Int C1FLAG_NUMBER = 8; // maximum number of largerThan1 flag coded in one chunk: 16 in HM5 187 static const Int C2FLAG_NUMBER = 1; // maximum number of largerThan2 flag coded in one chunk: 16 in HM5 188 189 static const Int MAX_NUM_VPS = 16; 190 static const Int MAX_NUM_SPS = 16; 191 static const Int MAX_NUM_PPS = 64; 192 193 194 static const Int MLS_GRP_NUM = 64; ///< Max number of coefficient groups, max(16, 64) 195 static const Int MLS_CG_LOG2_WIDTH = 2; 196 static const Int MLS_CG_LOG2_HEIGHT = 2; 197 static const Int MLS_CG_SIZE = 4; ///< Coefficient group size of 4x4; = MLS_CG_LOG2_WIDTH + MLS_CG_LOG2_HEIGHT 198 199 #if ADAPTIVE_QP_SELECTION 200 static const Int ARL_C_PRECISION = 7; ///< G382: 7-bit arithmetic precision 201 static const Int LEVEL_RANGE = 30; ///< G382: max coefficient level in statistics collection 202 #endif 203 204 static const Int RVM_VCEGAM10_M = 4; 205 206 static const Int FAST_UDI_MAX_RDMODE_NUM = 35; ///< maximum number of RD comparison in fast-UDI estimation loop 207 208 static const Int NUM_INTRA_MODE = 36; 209 static const Int PLANAR_IDX = 0; 210 static const Int VER_IDX = 26; ///< index for intra VERTICAL mode 211 static const Int HOR_IDX = 10; ///< index for intra HORIZONTAL mode 212 static const Int DC_IDX = 1; ///< index for intra DC mode 213 static const Int NUM_CHROMA_MODE = 5; ///< total number of chroma modes 214 static const Int DM_CHROMA_IDX = 36; ///< chroma mode index for derived from luma intra mode 215 216 static const Int MDCS_ANGLE_LIMIT = 4; ///< 0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2 = Horizontal/vertical +/- 2 etc... 217 static const Int MDCS_MAXIMUM_WIDTH = 8; ///< (measured in pixels) TUs with width greater than this can only use diagonal scan 218 static const Int MDCS_MAXIMUM_HEIGHT = 8; ///< (measured in pixels) TUs with height greater than this can only use diagonal scan 219 220 221 static const Int LOG2_MAX_NUM_COLUMNS_MINUS1 = 7; 222 static const Int LOG2_MAX_NUM_ROWS_MINUS1 = 7; 223 224 static const Int CABAC_INIT_PRESENT_FLAG = 1; 225 226 static const Int LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS = 4; 227 static const Int CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS = 8; 228 229 static const Int MAX_NUM_LONG_TERM_REF_PICS = 33; 230 static const Int NUM_LONG_TERM_REF_PIC_SPS = 0; 231 232 233 static const Int MAX_QP_OFFSET_LIST_SIZE = 6; ///< Maximum size of QP offset list is 6 entries 234 235 // Cost mode support 236 static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP = 0; ///< QP to use for lossless coding. 237 static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME =4; ///< QP' to use for mixed_lossy_lossless coding. 238 239 static const Int RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS = 4; 240 static const Int RExt__GOLOMB_RICE_INCREMENT_DIVISOR = 4; 241 242 static const Int RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION = 0; ///< Additional fixed bit precision used during encoder-side weighting prediction analysis. Currently only used when high_precision_prediction_weighting_flag is set, for backwards compatibility reasons. 243 244 static const Int MAX_TIMECODE_SEI_SETS = 3; ///< Maximum number of time sets 245 246 static const Int MAX_CU_DEPTH = 6; ///< log2(CTUSize) 247 static const Int MAX_CU_SIZE = 64; ///< = 1<<(MAX_CU_DEPTH) 248 static const Int MIN_PU_SIZE = 4; 249 static const Int MIN_TU_SIZE = 4; 250 static const Int MAX_TU_SIZE = 32; 251 static const Int MAX_NUM_PART_IDXS_IN_CTU_WIDTH = MAX_CU_SIZE/MIN_PU_SIZE; ///< maximum number of partition indices across the width of a CTU (or height of a CTU) 252 static const Int SCALING_LIST_REM_NUM = 6; 253 254 static const Int QUANT_SHIFT = 14; ///< Q(4) = 2^14 255 static const Int IQUANT_SHIFT = 6; 256 static const Int SCALE_BITS = 15; ///< For fractional bit estimates in RDOQ 257 258 static const Int SCALING_LIST_NUM = MAX_NUM_COMPONENT * NUMBER_OF_PREDICTION_MODES; ///< list number for quantization matrix 259 260 static const Int SCALING_LIST_START_VALUE = 8 ; ///< start value for dpcm mode 261 static const Int MAX_MATRIX_COEF_NUM = 64 ; ///< max coefficient number for quantization matrix 262 static const Int MAX_MATRIX_SIZE_NUM = 8 ; ///< max size number for quantization matrix 263 static const Int SCALING_LIST_BITS = 8 ; ///< bit depth of scaling list entries 264 static const Int LOG2_SCALING_LIST_NEUTRAL_VALUE = 4 ; ///< log2 of the value that, when used in a scaling list, has no effect on quantisation 265 static const Int SCALING_LIST_DC = 16 ; ///< default DC value 266 267 static const Int CONTEXT_STATE_BITS = 6 ; 268 static const Int LAST_SIGNIFICANT_GROUPS = 10 ; 269 270 #if NH_MV 271 static const Int MAX_VPS_NUM_ADD_LAYER_SETS = 1024 ; 272 static const Int MAX_NUM_SCALABILITY_TYPES = 16 ; 273 static const Int ENC_CFG_CONSOUT_SPACE = 34 ; 274 static const Int MAX_NUM_LAYERS = 63 ; 275 static const Int MAX_VPS_PROFILE_TIER_LEVEL = 64 ; 276 static const Int MAX_VPS_ADD_OUTPUT_LAYER_SETS = 1024 ; 277 static const Int MAX_VPS_OUTPUTLAYER_SETS = MAX_VPS_ADD_OUTPUT_LAYER_SETS + MAX_VPS_OP_SETS_PLUS1 + MAX_VPS_OP_SETS_PLUS1 ; 278 static const Int MAX_NUM_VIDEO_SIGNAL_INFO = 16 ; 279 static const Int MAX_NUM_SCALED_REF_LAYERS = MAX_NUM_LAYERS - 1 ; 280 #endif 132 281 133 282 // ==================================================================================================================== 134 283 // Macro functions 135 284 // ==================================================================================================================== 136 extern Int g_bitDepthY; 137 extern Int g_bitDepthC; 138 139 /** clip x, such that 0 <= x <= #g_maxLumaVal */ 140 template <typename T> inline T ClipY(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); } 141 template <typename T> inline T ClipC(T x) { return std::min<T>(T((1 << g_bitDepthC)-1), std::max<T>( T(0), x)); } 142 143 /** clip a, such that minVal <= a <= maxVal */ 144 template <typename T> inline T Clip3( T minVal, T maxVal, T a) { return std::min<T> (std::max<T> (minVal, a) , maxVal); } ///< general min/max clip 285 286 template <typename T> inline T Clip3 (const T minVal, const T maxVal, const T a) { return std::min<T> (std::max<T> (minVal, a) , maxVal); } ///< general min/max clip 287 template <typename T> inline T ClipBD(const T x, const Int bitDepth) { return Clip3(T(0), T((1 << bitDepth)-1), x); } 288 289 template <typename T> inline Void Check3( T minVal, T maxVal, T a) 290 { 291 if ((a > maxVal) || (a < minVal)) 292 { 293 std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl; 294 assert(false); 295 exit(1); 296 } 297 } ///< general min/max clip 145 298 146 299 #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free … … 159 312 } 160 313 161 #if H_MV 314 template <typename ValueType> inline ValueType leftShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ( value >> -shift); } 315 template <typename ValueType> inline ValueType rightShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value >> shift) : ( value << -shift); } 316 template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); } 317 template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value << -shift); } 318 #if O0043_BEST_EFFORT_DECODING 319 // when shift = 0, returns value 320 // when shift = 1, (value + 0 + value[1]) >> 1 321 // when shift = 2, (value + 1 + value[2]) >> 2 322 // when shift = 3, (value + 3 + value[3]) >> 3 323 template <typename ValueType> inline ValueType rightShiftEvenRounding(const ValueType value, const UInt shift) { return (shift == 0) ? value : ((value + (1<<(shift-1))-1 + ((value>>shift)&1)) >> shift) ; } 324 #endif 325 #if NH_MV 162 326 163 327 #define AOF( exp ) \ … … 195 359 } 196 360 197 #define RemoveBitIncrement( exp ) ( exp >> ( g_bitDepthY - 8 ) ) 198 199 #endif 200 201 // ==================================================================================================================== 202 // Coding tool configuration 203 // ==================================================================================================================== 204 205 // AMVP: advanced motion vector prediction 206 #define AMVP_MAX_NUM_CANDS 2 ///< max number of final candidates 207 #define AMVP_MAX_NUM_CANDS_MEM 3 ///< max number of candidates 208 // MERGE 209 #define MRG_MAX_NUM_CANDS 5 210 #if H_3D_IV_MERGE 361 #define RemoveBitIncrement( exp ) ( exp >> ( REN_BIT_DEPTH - 8 ) ) 362 363 #endif 364 365 #if NH_3D_MLC || NH_3D_ARP 211 366 #define MRG_MAX_NUM_CANDS_MEM (MRG_MAX_NUM_CANDS+1) // one extra for inter-view motion prediction 212 367 #endif 213 // Reference memory management 214 #define DYN_REF_FREE 0 ///< dynamic free of reference memories 215 216 // Explicit temporal layer QP offset 217 #define MAX_TLAYER 7 ///< max number of temporal layer 218 #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode 219 220 // Fast estimation of generalized B in low-delay mode 221 #define GPB_SIMPLE 1 ///< Simple GPB mode 222 #if GPB_SIMPLE 223 #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction 224 #endif 225 226 // Fast ME using smoother MV assumption 227 #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option 228 229 // Adaptive search range depending on POC difference 230 #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range 231 232 #define CLIP_TO_709_RANGE 0 233 234 // Early-skip threshold (encoder) 235 #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] 236 237 238 #define MAX_CHROMA_FORMAT_IDC 3 239 240 // TODO: Existing names used for the different NAL unit types can be altered to better reflect the names in the spec. 241 // However, the names in the spec are not yet stable at this point. Once the names are stable, a cleanup 242 // effort can be done without use of macros to alter the names used to indicate the different NAL unit types. 243 enum NalUnitType 244 { 245 NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 0 246 NAL_UNIT_CODED_SLICE_TRAIL_R, // 1 247 248 NAL_UNIT_CODED_SLICE_TSA_N, // 2 249 NAL_UNIT_CODED_SLICE_TSA_R, // 3 250 251 NAL_UNIT_CODED_SLICE_STSA_N, // 4 252 NAL_UNIT_CODED_SLICE_STSA_R, // 5 253 254 NAL_UNIT_CODED_SLICE_RADL_N, // 6 255 NAL_UNIT_CODED_SLICE_RADL_R, // 7 256 257 NAL_UNIT_CODED_SLICE_RASL_N, // 8 258 NAL_UNIT_CODED_SLICE_RASL_R, // 9 259 260 NAL_UNIT_RESERVED_VCL_N10, 261 NAL_UNIT_RESERVED_VCL_R11, 262 NAL_UNIT_RESERVED_VCL_N12, 263 NAL_UNIT_RESERVED_VCL_R13, 264 NAL_UNIT_RESERVED_VCL_N14, 265 NAL_UNIT_RESERVED_VCL_R15, 266 267 NAL_UNIT_CODED_SLICE_BLA_W_LP, // 16 268 NAL_UNIT_CODED_SLICE_BLA_W_RADL, // 17 269 NAL_UNIT_CODED_SLICE_BLA_N_LP, // 18 270 NAL_UNIT_CODED_SLICE_IDR_W_RADL, // 19 271 NAL_UNIT_CODED_SLICE_IDR_N_LP, // 20 272 NAL_UNIT_CODED_SLICE_CRA, // 21 273 NAL_UNIT_RESERVED_IRAP_VCL22, 274 NAL_UNIT_RESERVED_IRAP_VCL23, 275 276 NAL_UNIT_RESERVED_VCL24, 277 NAL_UNIT_RESERVED_VCL25, 278 NAL_UNIT_RESERVED_VCL26, 279 NAL_UNIT_RESERVED_VCL27, 280 NAL_UNIT_RESERVED_VCL28, 281 NAL_UNIT_RESERVED_VCL29, 282 NAL_UNIT_RESERVED_VCL30, 283 NAL_UNIT_RESERVED_VCL31, 284 285 NAL_UNIT_VPS, // 32 286 NAL_UNIT_SPS, // 33 287 NAL_UNIT_PPS, // 34 288 NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35 289 NAL_UNIT_EOS, // 36 290 NAL_UNIT_EOB, // 37 291 NAL_UNIT_FILLER_DATA, // 38 292 NAL_UNIT_PREFIX_SEI, // 39 293 NAL_UNIT_SUFFIX_SEI, // 40 294 NAL_UNIT_RESERVED_NVCL41, 295 NAL_UNIT_RESERVED_NVCL42, 296 NAL_UNIT_RESERVED_NVCL43, 297 NAL_UNIT_RESERVED_NVCL44, 298 NAL_UNIT_RESERVED_NVCL45, 299 NAL_UNIT_RESERVED_NVCL46, 300 NAL_UNIT_RESERVED_NVCL47, 301 NAL_UNIT_UNSPECIFIED_48, 302 NAL_UNIT_UNSPECIFIED_49, 303 NAL_UNIT_UNSPECIFIED_50, 304 NAL_UNIT_UNSPECIFIED_51, 305 NAL_UNIT_UNSPECIFIED_52, 306 NAL_UNIT_UNSPECIFIED_53, 307 NAL_UNIT_UNSPECIFIED_54, 308 NAL_UNIT_UNSPECIFIED_55, 309 NAL_UNIT_UNSPECIFIED_56, 310 NAL_UNIT_UNSPECIFIED_57, 311 NAL_UNIT_UNSPECIFIED_58, 312 NAL_UNIT_UNSPECIFIED_59, 313 NAL_UNIT_UNSPECIFIED_60, 314 NAL_UNIT_UNSPECIFIED_61, 315 NAL_UNIT_UNSPECIFIED_62, 316 NAL_UNIT_UNSPECIFIED_63, 317 NAL_UNIT_INVALID, 318 }; 319 320 #if H_3D 368 369 370 #if NH_3D 321 371 //PICYUV 322 372 #define PICYUV_PAD 16 323 373 324 374 //RENDERER 325 #define REN_LUMA_MARGIN ( g_uiMaxCUWidth + PICYUV_PAD ) 375 376 377 #define REN_BIT_DEPTH 8 378 #define REN_LUMA_MARGIN ( PICYUV_PAD + 1 ) // + g_uiMaxCuWidth instead of 1 ??? 326 379 #define REN_VDWEIGHT_PREC 8 327 380 #define REN_IS_FILLED ( 1 << REN_VDWEIGHT_PREC ) 328 #define REN_USED_PEL ( (1 << g_bitDepthY) - 1 )381 #define REN_USED_PEL ( (1 << REN_BIT_DEPTH) - 1 ) 329 382 #define REN_UNUSED_PEL 0 330 383 #define REN_IS_HOLE 0 384 #if NH_3D_VSO 385 #define ENC_INTERNAL_BIT_DEPTH REN_BIT_DEPTH // consider making this a variable 386 #endif 331 387 332 388 … … 335 391 #define STD_CAM_PARAMETERS_PRECISION 5 ///< quarter luma sample accuarcy for derived disparities (as default) 336 392 337 #endif // end of H_3D393 #endif // end of NH_3D 338 394 //! \} 339 395
Note: See TracChangeset for help on using the changeset viewer.