HEVC Test Model (HM)  HM-16.3
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-2015, 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 
45 #if _MSC_VER > 1000
46 // disable "signed and unsigned mismatch"
47 #pragma warning( disable : 4018 )
48 // disable Bool coercion "performance warning"
49 #pragma warning( disable : 4800 )
50 #endif // _MSC_VER > 1000
51 #include "TypeDef.h"
52 
55 
56 // ====================================================================================================================
57 // Version information
58 // ====================================================================================================================
59 
60 #define NV_VERSION "16.3"
61 
62 // ====================================================================================================================
63 // Platform information
64 // ====================================================================================================================
65 
66 #ifdef __GNUC__
67 #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
68 #ifdef __IA64__
69 #define NVM_ONARCH "[on 64-bit] "
70 #else
71 #define NVM_ONARCH "[on 32-bit] "
72 #endif
73 #endif
74 
75 #ifdef __INTEL_COMPILER
76 #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER
77 #elif _MSC_VER
78 #define NVM_COMPILEDBY "[VS %d]", _MSC_VER
79 #endif
80 
81 #ifndef NVM_COMPILEDBY
82 #define NVM_COMPILEDBY "[Unk-CXX]"
83 #endif
84 
85 #ifdef _WIN32
86 #define NVM_ONOS "[Windows]"
87 #elif __linux
88 #define NVM_ONOS "[Linux]"
89 #elif __CYGWIN__
90 #define NVM_ONOS "[Cygwin]"
91 #elif __APPLE__
92 #define NVM_ONOS "[Mac OS X]"
93 #else
94 #define NVM_ONOS "[Unk-OS]"
95 #endif
96 
97 #define NVM_BITS "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32)
98 
99 #ifndef NULL
100 #define NULL 0
101 #endif
102 
103 // ====================================================================================================================
104 // Common constants
105 // ====================================================================================================================
106 
107 #define _SUMMARY_OUT_ 0
108 #define _SUMMARY_PIC_ 0
109 
110 #define MAX_GOP 64
111 
112 #define MAX_NUM_REF_PICS 16
113 #define MAX_NUM_REF 16
114 
115 #define MAX_UINT 0xFFFFFFFFU
116 #define MAX_INT 2147483647
117 #define MAX_INT64 0x7FFFFFFFFFFFFFFFLL
118 #if RExt__HIGH_BIT_DEPTH_SUPPORT
119 #define MAX_INTERMEDIATE_INT MAX_INT64
120 #else
121 #define MAX_INTERMEDIATE_INT MAX_INT
122 #endif
123 
124 #define MAX_DOUBLE 1.7e+308
125 
126 #define MIN_QP 0
127 #define MAX_QP 51
128 
129 #define NOT_VALID -1
130 
131 // ====================================================================================================================
132 // Macro functions
133 // ====================================================================================================================
134 
136 
137 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); }
138 template <typename T> inline T ClipBD(const T x, const Int bitDepth) { return Clip3(T(0), T((1 << bitDepth)-1), x); }
139 template <typename T> inline T Clip (const T x, const ChannelType type) { return ClipBD(x, g_bitDepth[type]); }
140 
141 template <typename T> inline Void Check3( T minVal, T maxVal, T a)
142 {
143  if ((a > maxVal) || (a < minVal))
144  {
145  std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl;
146  assert(false);
147  exit(1);
148  }
149 }
150 
151 #define DATA_ALIGN 1
152 #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
153 #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 )
154 #define xFree( ptr ) _aligned_free ( ptr )
155 #else
156 #define xMalloc( type, len ) malloc ( sizeof(type)*(len) )
157 #define xFree( ptr ) free ( ptr )
158 #endif
159 
160 #define FATAL_ERROR_0(MESSAGE, EXITCODE) \
161 { \
162  printf(MESSAGE); \
163  exit(EXITCODE); \
164 }
165 
166 template <typename ValueType> inline ValueType leftShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ( value >> -shift); }
167 template <typename ValueType> inline ValueType rightShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value >> shift) : ( value << -shift); }
168 template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); }
169 template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value << -shift); }
170 #if O0043_BEST_EFFORT_DECODING
171 // when shift = 0, returns value
172 // when shift = 1, (value + 0 + value[1]) >> 1
173 // when shift = 2, (value + 1 + value[2]) >> 2
174 // when shift = 3, (value + 3 + value[3]) >> 3
175 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) ; }
176 #endif
177 
178 // ====================================================================================================================
179 // Coding tool configuration
180 // ====================================================================================================================
181 
182 // AMVP: advanced motion vector prediction
183 #define AMVP_MAX_NUM_CANDS 2
184 #define AMVP_MAX_NUM_CANDS_MEM 3
185 // MERGE
186 #define MRG_MAX_NUM_CANDS 5
187 
188 // Reference memory management
189 #define DYN_REF_FREE 0
190 
191 // Explicit temporal layer QP offset
192 #define MAX_TLAYER 7
193 #define HB_LAMBDA_FOR_LDC 1
194 
195 // Fast estimation of generalized B in low-delay mode
196 #define GPB_SIMPLE 1
197 #if GPB_SIMPLE
198 #define GPB_SIMPLE_UNI 1
199 #endif
200 
201 // Fast ME using smoother MV assumption
202 #define FASTME_SMOOTHER_MV 1
203 
204 // Adaptive search range depending on POC difference
205 #define ADAPT_SR_SCALE 1
206 
207 #define CLIP_TO_709_RANGE 0
208 
209 // Early-skip threshold (encoder)
210 #define EARLY_SKIP_THRES 1.50
211 
212 
213 #define MAX_CHROMA_FORMAT_IDC 3
214 
215 // TODO: Existing names used for the different NAL unit types can be altered to better reflect the names in the spec.
216 // However, the names in the spec are not yet stable at this point. Once the names are stable, a cleanup
217 // effort can be done without use of macros to alter the names used to indicate the different NAL unit types.
219 {
222 
225 
228 
231 
234 
241 
250 
259 
269 
294 };
295 
297 
298 #endif // end of #ifndef __COMMONDEF__
299 
ValueType leftShift(const ValueType value, const Int shift)
Definition: CommonDef.h:166
ChannelType
Definition: TypeDef.h:361
T Clip(const T x, const ChannelType type)
Definition: CommonDef.h:139
void Void
Definition: TypeDef.h:285
ValueType leftShift_round(const ValueType value, const Int shift)
Definition: CommonDef.h:168
unsigned int UInt
Definition: TypeDef.h:297
T ClipBD(const T x, const Int bitDepth)
Definition: CommonDef.h:138
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
ValueType rightShift_round(const ValueType value, const Int shift)
Definition: CommonDef.h:169
ValueType rightShift(const ValueType value, const Int shift)
Definition: CommonDef.h:167
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
Void Check3(T minVal, T maxVal, T a)
general min/max clip
Definition: CommonDef.h:141
int Int
Definition: TypeDef.h:296
NalUnitType
Definition: CommonDef.h:218
Define basic types, new types and enumerations.