HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CommonDef.h
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2017, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #ifndef __COMMONDEF__
39 #define __COMMONDEF__
40 
41 #include <algorithm>
42 #include <iostream>
43 #include <assert.h>
44 #include <limits>
45 
46 #if _MSC_VER > 1000
47 // disable "signed and unsigned mismatch"
48 #pragma warning( disable : 4018 )
49 // disable Bool coercion "performance warning"
50 #pragma warning( disable : 4800 )
51 #endif // _MSC_VER > 1000
52 #include "TypeDef.h"
53 
54 #ifdef _MSC_VER
55 #if _MSC_VER <= 1500
56 inline Int64 abs (Int64 x) { return _abs64(x); };
57 #endif
58 #endif
59 
62 
63 // ====================================================================================================================
64 // Version information
65 // ====================================================================================================================
66 
67 #define NV_VERSION "16.18"
68 
69 // ====================================================================================================================
70 // Platform information
71 // ====================================================================================================================
72 
73 #ifdef __GNUC__
74 #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
75 #ifdef __IA64__
76 #define NVM_ONARCH "[on 64-bit] "
77 #else
78 #define NVM_ONARCH "[on 32-bit] "
79 #endif
80 #endif
81 
82 #ifdef __INTEL_COMPILER
83 #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER
84 #elif _MSC_VER
85 #define NVM_COMPILEDBY "[VS %d]", _MSC_VER
86 #endif
87 
88 #ifndef NVM_COMPILEDBY
89 #define NVM_COMPILEDBY "[Unk-CXX]"
90 #endif
91 
92 #ifdef _WIN32
93 #define NVM_ONOS "[Windows]"
94 #elif __linux
95 #define NVM_ONOS "[Linux]"
96 #elif __CYGWIN__
97 #define NVM_ONOS "[Cygwin]"
98 #elif __APPLE__
99 #define NVM_ONOS "[Mac OS X]"
100 #else
101 #define NVM_ONOS "[Unk-OS]"
102 #endif
103 
104 #define NVM_BITS "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32)
105 
106 #ifndef NULL
107 #define NULL 0
108 #endif
109 
110 // ====================================================================================================================
111 // Common constants
112 // ====================================================================================================================
113 
114 static const UInt MAX_UINT = 0xFFFFFFFFU;
115 static const Int MAX_INT = 2147483647;
116 static const Double MAX_DOUBLE = 1.7e+308;
117 
118 // ====================================================================================================================
119 // Coding tool configuration
120 // ====================================================================================================================
121 // Most of these should not be changed - they resolve the meaning of otherwise magic numbers.
122 
123 static const Int MAX_GOP = 64;
124 static const Int MAX_NUM_REF_PICS = 16;
125 static const Int MAX_NUM_REF = 16;
126 static const Int MAX_QP = 51;
127 static const Int NOT_VALID = -1;
128 
129 static const Int AMVP_MAX_NUM_CANDS = 2;
130 static const Int AMVP_DECIMATION_FACTOR = 4;
131 static const Int MRG_MAX_NUM_CANDS = 5;
132 
133 
134 static const Int MAX_TLAYER = 7;
135 
136 static const Int ADAPT_SR_SCALE = 1;
137 
138 static const Int MAX_NUM_PICS_IN_SOP = 1024;
139 
140 static const Int MAX_NESTING_NUM_OPS = 1024;
141 static const Int MAX_NESTING_NUM_LAYER = 64;
142 
144 static const Int MAX_VPS_OP_SETS_PLUS1 = 1024;
146 
149 
150 static const Int MAX_CPB_CNT = 32;
151 static const Int MAX_NUM_LAYER_IDS = 64;
152 
153 static const Int COEF_REMAIN_BIN_REDUCTION = 3;
154 
155 static const Int CU_DQP_TU_CMAX = 5;
156 static const Int CU_DQP_EG_k = 0;
157 
158 static const Int SBH_THRESHOLD = 4;
159 
160 static const Int C1FLAG_NUMBER = 8; // maximum number of largerThan1 flag coded in one chunk: 16 in HM5
161 static const Int C2FLAG_NUMBER = 1; // maximum number of largerThan2 flag coded in one chunk: 16 in HM5
162 
163 static const Int MAX_NUM_VPS = 16;
164 static const Int MAX_NUM_SPS = 16;
165 static const Int MAX_NUM_PPS = 64;
166 
167 
168 static const Int MLS_GRP_NUM = 64;
169 static const Int MLS_CG_LOG2_WIDTH = 2;
170 static const Int MLS_CG_LOG2_HEIGHT = 2;
171 static const Int MLS_CG_SIZE = 4;
172 
173 #if ADAPTIVE_QP_SELECTION
174 static const Int ARL_C_PRECISION = 7;
175 static const Int LEVEL_RANGE = 30;
176 #endif
177 
178 static const Int RVM_VCEGAM10_M = 4;
179 
180 static const Int FAST_UDI_MAX_RDMODE_NUM = 35;
181 
182 static const Int NUM_INTRA_MODE = 36;
183 static const Int PLANAR_IDX = 0;
184 static const Int VER_IDX = 26;
185 static const Int HOR_IDX = 10;
186 static const Int DC_IDX = 1;
187 static const Int NUM_CHROMA_MODE = 5;
188 static const Int DM_CHROMA_IDX = 36;
189 
190 static const Int MDCS_ANGLE_LIMIT = 4;
191 static const Int MDCS_MAXIMUM_WIDTH = 8;
192 static const Int MDCS_MAXIMUM_HEIGHT = 8;
193 
194 
196 static const Int LOG2_MAX_NUM_ROWS_MINUS1 = 7;
197 
198 static const Int CABAC_INIT_PRESENT_FLAG = 1;
199 
202 
203 static const Int MAX_NUM_LONG_TERM_REF_PICS = 33;
205 
206 
207 static const Int MAX_QP_OFFSET_LIST_SIZE = 6;
208 
209 // Cost mode support
212 
215 
217 
218 static const Int MAX_TIMECODE_SEI_SETS = 3;
219 
220 static const Int MAX_CU_DEPTH = 6;
221 static const Int MAX_CU_SIZE = 64;
222 static const Int MIN_PU_SIZE = 4;
223 static const Int MIN_TU_SIZE = 4;
224 static const Int MAX_TU_SIZE = 32;
226 static const Int SCALING_LIST_REM_NUM = 6;
227 
228 static const Int QUANT_SHIFT = 14;
229 static const Int IQUANT_SHIFT = 6;
230 static const Int SCALE_BITS = 15;
231 
233 
234 static const Int SCALING_LIST_START_VALUE = 8 ;
235 static const Int MAX_MATRIX_COEF_NUM = 64 ;
236 static const Int MAX_MATRIX_SIZE_NUM = 8 ;
237 static const Int SCALING_LIST_BITS = 8 ;
239 static const Int SCALING_LIST_DC = 16 ;
240 
241 static const Int CONTEXT_STATE_BITS = 6 ;
242 static const Int LAST_SIGNIFICANT_GROUPS = 10 ;
243 
245 
246 static const UInt LUMA_LEVEL_TO_DQP_LUT_MAXSIZE = 1024;
247 
248 // ====================================================================================================================
249 // Macro functions
250 // ====================================================================================================================
251 
252 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); }
253 template <typename T> inline T ClipBD(const T x, const Int bitDepth) { return Clip3(T(0), T((1 << bitDepth)-1), x); }
254 
255 template <typename T> inline Void Check3( T minVal, T maxVal, T a)
256 {
257  if ((a > maxVal) || (a < minVal))
258  {
259  std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl;
260  assert(false);
261  exit(1);
262  }
263 }
264 
265 #define DATA_ALIGN 1
266 #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
267 #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 )
268 #define xFree( ptr ) _aligned_free ( ptr )
269 #else
270 #define xMalloc( type, len ) malloc ( sizeof(type)*(len) )
271 #define xFree( ptr ) free ( ptr )
272 #endif
273 
274 #define FATAL_ERROR_0(MESSAGE, EXITCODE) \
275 { \
276  printf(MESSAGE); \
277  exit(EXITCODE); \
278 }
279 
280 template <typename ValueType> inline ValueType leftShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ( value >> -shift); }
281 template <typename ValueType> inline ValueType rightShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value >> shift) : ( value << -shift); }
282 template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); }
283 template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value << -shift); }
284 #if O0043_BEST_EFFORT_DECODING
285 // when shift = 0, returns value
286 // when shift = 1, (value + 0 + value[1]) >> 1
287 // when shift = 2, (value + 1 + value[2]) >> 2
288 // when shift = 3, (value + 3 + value[3]) >> 3
289 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) ; }
290 #endif
291 
293 
294 #endif // end of #ifndef __COMMONDEF__
295 
static const Int MDCS_MAXIMUM_HEIGHT
(measured in pixels) TUs with height greater than this can only use diagonal scan ...
Definition: CommonDef.h:192
static const Int SCALING_LIST_REM_NUM
Definition: CommonDef.h:226
static const Int NOT_VALID
Definition: CommonDef.h:127
static const Int MAX_NUM_REF_PICS
max. number of pictures used for reference
Definition: CommonDef.h:124
static const Int MAXIMUM_INTRA_FILTERED_HEIGHT
Definition: CommonDef.h:148
static const Int SCALING_LIST_NUM
list number for quantization matrix
Definition: CommonDef.h:232
ValueType leftShift(const ValueType value, const Int shift)
Definition: CommonDef.h:280
static const Int ARL_C_PRECISION
G382: 7-bit arithmetic precision.
Definition: CommonDef.h:174
static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP
QP to use for lossless coding.
Definition: CommonDef.h:210
static const Int AMVP_DECIMATION_FACTOR
Definition: CommonDef.h:130
static const Int LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS
Definition: CommonDef.h:200
static const Int HOR_IDX
index for intra HORIZONTAL mode
Definition: CommonDef.h:185
static const Int MAX_NUM_PICS_IN_SOP
Definition: CommonDef.h:138
void Void
Definition: TypeDef.h:203
static const Int MAX_CU_DEPTH
log2(CTUSize)
Definition: CommonDef.h:220
static const Int DM_CHROMA_IDX
chroma mode index for derived from luma intra mode
Definition: CommonDef.h:188
static const Int MAX_NUM_PPS
Definition: CommonDef.h:165
static const Int NUM_CHROMA_MODE
total number of chroma modes
Definition: CommonDef.h:187
ValueType leftShift_round(const ValueType value, const Int shift)
Definition: CommonDef.h:282
static const Int MRG_MAX_NUM_CANDS
MERGE.
Definition: CommonDef.h:131
static const Int MAX_TU_SIZE
Definition: CommonDef.h:224
static const Int NUM_LONG_TERM_REF_PIC_SPS
Definition: CommonDef.h:204
static const Int MAX_NUM_LAYER_IDS
Definition: CommonDef.h:151
static const Int SCALING_LIST_START_VALUE
start value for dpcm mode
Definition: CommonDef.h:234
static const Int MLS_GRP_NUM
Max number of coefficient groups, max(16, 64)
Definition: CommonDef.h:168
unsigned int UInt
Definition: TypeDef.h:212
static const Int LEVEL_RANGE
G382: max coefficient level in statistics collection.
Definition: CommonDef.h:175
static const Int MIN_TU_SIZE
Definition: CommonDef.h:223
static const Int SCALING_LIST_BITS
bit depth of scaling list entries
Definition: CommonDef.h:237
static const Int MAX_MATRIX_SIZE_NUM
max size number for quantization matrix
Definition: CommonDef.h:236
static const Int IQUANT_SHIFT
Definition: CommonDef.h:229
T ClipBD(const T x, const Int bitDepth)
Definition: CommonDef.h:253
static const Int MAX_NUM_REF
max. number of entries in picture reference list
Definition: CommonDef.h:125
static const Int MAX_CPB_CNT
Upper bound of (cpb_cnt_minus1 + 1)
Definition: CommonDef.h:150
static const Int MAX_VPS_NUM_HRD_PARAMETERS
Definition: CommonDef.h:143
static const Int CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS
Definition: CommonDef.h:201
static const Int LOG2_MAX_NUM_ROWS_MINUS1
Definition: CommonDef.h:196
static const Int MAX_VPS_OP_SETS_PLUS1
Definition: CommonDef.h:144
static const Int MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS
Definition: CommonDef.h:244
static const Int LOG2_MAX_NUM_COLUMNS_MINUS1
Definition: CommonDef.h:195
static const Int MAX_NUM_VPS
Definition: CommonDef.h:163
static const Int RVM_VCEGAM10_M
Definition: CommonDef.h:178
static const Int QUANT_SHIFT
Q(4) = 2^14.
Definition: CommonDef.h:228
static const Int MAX_GOP
max. value of hierarchical GOP size
Definition: CommonDef.h:123
static const Int MLS_CG_LOG2_WIDTH
Definition: CommonDef.h:169
static const Int FAST_UDI_MAX_RDMODE_NUM
maximum number of RD comparison in fast-UDI estimation loop
Definition: CommonDef.h:180
long long Int64
Definition: TypeDef.h:232
static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME
QP&#39; to use for mixed_lossy_lossless coding.
Definition: CommonDef.h:211
static const Int VER_IDX
index for intra VERTICAL mode
Definition: CommonDef.h:184
static const Int MAX_MATRIX_COEF_NUM
max coefficient number for quantization matrix
Definition: CommonDef.h:235
static const Int AMVP_MAX_NUM_CANDS
AMVP: advanced motion vector prediction - max number of final candidates.
Definition: CommonDef.h:129
static const Int RExt__GOLOMB_RICE_INCREMENT_DIVISOR
Definition: CommonDef.h:214
static const Int ADAPT_SR_SCALE
division factor for adaptive search range
Definition: CommonDef.h:136
static const Int C2FLAG_NUMBER
Definition: CommonDef.h:161
static const Int RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION
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.
Definition: CommonDef.h:216
static const Int MAX_INT
max. value of signed 32-bit integer
Definition: CommonDef.h:115
static const Int LOG2_SCALING_LIST_NEUTRAL_VALUE
log2 of the value that, when used in a scaling list, has no effect on quantisation ...
Definition: CommonDef.h:238
static const Int CU_DQP_TU_CMAX
max number bins for truncated unary
Definition: CommonDef.h:155
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:252
ValueType rightShift_round(const ValueType value, const Int shift)
Definition: CommonDef.h:283
static const Int DC_IDX
index for intra DC mode
Definition: CommonDef.h:186
ValueType rightShift(const ValueType value, const Int shift)
Definition: CommonDef.h:281
static const Int MAX_NESTING_NUM_LAYER
Definition: CommonDef.h:141
static const Int CABAC_INIT_PRESENT_FLAG
Definition: CommonDef.h:198
static const Int MIN_PU_SIZE
Definition: CommonDef.h:222
static const UInt LUMA_LEVEL_TO_DQP_LUT_MAXSIZE
max LUT size for QP offset based on luma
Definition: CommonDef.h:246
static const Int MDCS_ANGLE_LIMIT
0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2 = Horizontal/vertical +/- 2 etc...
Definition: CommonDef.h:190
static const Int NUM_INTRA_MODE
Definition: CommonDef.h:182
static const Int MAX_TLAYER
Explicit temporal layer QP offset - max number of temporal layer.
Definition: CommonDef.h:134
static const Int MAX_CU_SIZE
= 1&lt;&lt;(MAX_CU_DEPTH)
Definition: CommonDef.h:221
static const Int CONTEXT_STATE_BITS
Definition: CommonDef.h:241
static const Int SCALE_BITS
For fractional bit estimates in RDOQ.
Definition: CommonDef.h:230
static const Double MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:116
Void Check3(T minVal, T maxVal, T a)
general min/max clip
Definition: CommonDef.h:255
static const Int PLANAR_IDX
Definition: CommonDef.h:183
static const Int MLS_CG_SIZE
Coefficient group size of 4x4; = MLS_CG_LOG2_WIDTH + MLS_CG_LOG2_HEIGHT.
Definition: CommonDef.h:171
static const Int MAX_NUM_LONG_TERM_REF_PICS
Definition: CommonDef.h:203
static const Int MLS_CG_LOG2_HEIGHT
Definition: CommonDef.h:170
int Int
Definition: TypeDef.h:211
static const Int RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS
Definition: CommonDef.h:213
static const UInt MAX_UINT
max. value of unsigned 32-bit integer
Definition: CommonDef.h:114
static const Int MAX_NUM_PART_IDXS_IN_CTU_WIDTH
maximum number of partition indices across the width of a CTU (or height of a CTU) ...
Definition: CommonDef.h:225
static const Int CU_DQP_EG_k
expgolomb order
Definition: CommonDef.h:156
static const Int MDCS_MAXIMUM_WIDTH
(measured in pixels) TUs with width greater than this can only use diagonal scan
Definition: CommonDef.h:191
double Double
Definition: TypeDef.h:213
static const Int MAX_TIMECODE_SEI_SETS
Maximum number of time sets.
Definition: CommonDef.h:218
Define macros, basic types, new types and enumerations.
static const Int MAX_NESTING_NUM_OPS
Definition: CommonDef.h:140
static const Int MAX_QP
Definition: CommonDef.h:126
static const Int MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1
Definition: CommonDef.h:145
static const Int MAXIMUM_INTRA_FILTERED_WIDTH
Definition: CommonDef.h:147
static const Int SCALING_LIST_DC
default DC value
Definition: CommonDef.h:239
static const Int COEF_REMAIN_BIN_REDUCTION
indicates the level at which the VLC transitions from Golomb-Rice to TU+EG(k)
Definition: CommonDef.h:153
static const Int MAX_NUM_SPS
Definition: CommonDef.h:164
static const Int LAST_SIGNIFICANT_GROUPS
Definition: CommonDef.h:242
static const Int MAX_QP_OFFSET_LIST_SIZE
Maximum size of QP offset list is 6 entries.
Definition: CommonDef.h:207
static const Int SBH_THRESHOLD
value of the fixed SBH controlling threshold
Definition: CommonDef.h:158
static const Int C1FLAG_NUMBER
Definition: CommonDef.h:160