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-2012, 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 | |
---|
34 | /** \file CommonDef.h |
---|
35 | \brief Defines constants, macros and tool parameters |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __COMMONDEF__ |
---|
39 | #define __COMMONDEF__ |
---|
40 | |
---|
41 | #include <algorithm> |
---|
42 | |
---|
43 | #if _MSC_VER > 1000 |
---|
44 | // disable "signed and unsigned mismatch" |
---|
45 | #pragma warning( disable : 4018 ) |
---|
46 | // disable bool coercion "performance warning" |
---|
47 | #pragma warning( disable : 4800 ) |
---|
48 | #endif // _MSC_VER > 1000 |
---|
49 | #include "TypeDef.h" |
---|
50 | |
---|
51 | //! \ingroup TLibCommon |
---|
52 | //! \{ |
---|
53 | |
---|
54 | // ==================================================================================================================== |
---|
55 | // Version information |
---|
56 | // ==================================================================================================================== |
---|
57 | |
---|
58 | #define NV_VERSION "0.1.1" ///< Current software version |
---|
59 | |
---|
60 | // ==================================================================================================================== |
---|
61 | // Platform information |
---|
62 | // ==================================================================================================================== |
---|
63 | |
---|
64 | #ifdef __GNUC__ |
---|
65 | #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ |
---|
66 | #ifdef __IA64__ |
---|
67 | #define NVM_ONARCH "[on 64-bit] " |
---|
68 | #else |
---|
69 | #define NVM_ONARCH "[on 32-bit] " |
---|
70 | #endif |
---|
71 | #endif |
---|
72 | |
---|
73 | #ifdef __INTEL_COMPILER |
---|
74 | #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER |
---|
75 | #elif _MSC_VER |
---|
76 | #define NVM_COMPILEDBY "[VS %d]", _MSC_VER |
---|
77 | #endif |
---|
78 | |
---|
79 | #ifndef NVM_COMPILEDBY |
---|
80 | #define NVM_COMPILEDBY "[Unk-CXX]" |
---|
81 | #endif |
---|
82 | |
---|
83 | #ifdef _WIN32 |
---|
84 | #define NVM_ONOS "[Windows]" |
---|
85 | #elif __linux |
---|
86 | #define NVM_ONOS "[Linux]" |
---|
87 | #elif __CYGWIN__ |
---|
88 | #define NVM_ONOS "[Cygwin]" |
---|
89 | #elif __APPLE__ |
---|
90 | #define NVM_ONOS "[Mac OS X]" |
---|
91 | #else |
---|
92 | #define NVM_ONOS "[Unk-OS]" |
---|
93 | #endif |
---|
94 | |
---|
95 | #define NVM_BITS "[%d bit] ", (sizeof(void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S |
---|
96 | |
---|
97 | #ifndef NULL |
---|
98 | #define NULL 0 |
---|
99 | #endif |
---|
100 | |
---|
101 | // ==================================================================================================================== |
---|
102 | // Common constants |
---|
103 | // ==================================================================================================================== |
---|
104 | |
---|
105 | #define _SUMMARY_OUT_ 0 ///< print-out PSNR results of all slices to summary.txt |
---|
106 | #define _SUMMARY_PIC_ 0 ///< print-out PSNR results for each slice type to summary.txt |
---|
107 | |
---|
108 | #define MAX_GOP 64 ///< max. value of hierarchical GOP size |
---|
109 | |
---|
110 | #if REF_IDX_FRAMEWORK |
---|
111 | #define MAX_NUM_REF 5 ///< max. value of multiple reference frames |
---|
112 | #else |
---|
113 | #define MAX_NUM_REF 4 ///< max. value of multiple reference frames |
---|
114 | #endif |
---|
115 | #define MAX_NUM_REF_LC 8 ///< max. value of combined reference frames |
---|
116 | |
---|
117 | #define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer |
---|
118 | #define MAX_INT 2147483647 ///< max. value of signed 32-bit integer |
---|
119 | #define MAX_INT64 0x7FFFFFFFFFFFFFFFLL ///< max. value of signed 64-bit integer |
---|
120 | #define MAX_DOUBLE 1.7e+308 ///< max. value of double-type value |
---|
121 | |
---|
122 | #define MIN_QP 0 |
---|
123 | #define MAX_QP 51 |
---|
124 | |
---|
125 | #define NOT_VALID -1 |
---|
126 | |
---|
127 | #if SVC_EXTENSION |
---|
128 | #define MAX_PAD_SIZE 16 |
---|
129 | #endif |
---|
130 | |
---|
131 | // ==================================================================================================================== |
---|
132 | // Macro functions |
---|
133 | // ==================================================================================================================== |
---|
134 | extern UInt g_uiIBDI_MAX; |
---|
135 | |
---|
136 | /** clip x, such that 0 <= x <= #g_uiIBDI_MAX */ |
---|
137 | template <typename T> inline T Clip(T x) { return std::min<T>(T(g_uiIBDI_MAX), std::max<T>( T(0), x)); } |
---|
138 | |
---|
139 | /** clip a, such that minVal <= a <= maxVal */ |
---|
140 | 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 |
---|
141 | |
---|
142 | #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free |
---|
143 | #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) |
---|
144 | #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 ) |
---|
145 | #define xFree( ptr ) _aligned_free ( ptr ) |
---|
146 | #else |
---|
147 | #define xMalloc( type, len ) malloc ( sizeof(type)*(len) ) |
---|
148 | #define xFree( ptr ) free ( ptr ) |
---|
149 | #endif |
---|
150 | |
---|
151 | #define FATAL_ERROR_0(MESSAGE, EXITCODE) \ |
---|
152 | { \ |
---|
153 | printf(MESSAGE); \ |
---|
154 | exit(EXITCODE); \ |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | // ==================================================================================================================== |
---|
159 | // Coding tool configuration |
---|
160 | // ==================================================================================================================== |
---|
161 | |
---|
162 | // AMVP: advanced motion vector prediction |
---|
163 | #define AMVP_MAX_NUM_CANDS 2 ///< max number of final candidates |
---|
164 | #define AMVP_MAX_NUM_CANDS_MEM 3 ///< max number of candidates |
---|
165 | // MERGE |
---|
166 | #define MRG_MAX_NUM_CANDS 5 |
---|
167 | |
---|
168 | // Reference memory management |
---|
169 | #define DYN_REF_FREE 0 ///< dynamic free of reference memories |
---|
170 | |
---|
171 | // Explicit temporal layer QP offset |
---|
172 | #define MAX_TLAYER 8 ///< max number of temporal layer |
---|
173 | #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode |
---|
174 | |
---|
175 | // Fast estimation of generalized B in low-delay mode |
---|
176 | #define GPB_SIMPLE 1 ///< Simple GPB mode |
---|
177 | #if GPB_SIMPLE |
---|
178 | #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction |
---|
179 | #endif |
---|
180 | |
---|
181 | // Fast ME using smoother MV assumption |
---|
182 | #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option |
---|
183 | |
---|
184 | // Adaptive search range depending on POC difference |
---|
185 | #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range |
---|
186 | |
---|
187 | #define CLIP_TO_709_RANGE 0 |
---|
188 | |
---|
189 | // IBDI range restriction for skipping clip |
---|
190 | #define IBDI_NOCLIP_RANGE 0 ///< restrict max. value after IBDI to skip clip |
---|
191 | |
---|
192 | // Early-skip threshold (encoder) |
---|
193 | #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] |
---|
194 | |
---|
195 | #define MAX_NUM_REF_PICS 16 |
---|
196 | |
---|
197 | #define MAX_CHROMA_FORMAT_IDC 3 |
---|
198 | |
---|
199 | #if NAL_UNIT_TYPES_J1003_D7 |
---|
200 | // TODO: Existing names used for the different NAL unit types can be altered to better reflect the names in the spec. |
---|
201 | // However, the names in the spec are not yet stable at this point. Once the names are stable, a cleanup |
---|
202 | // effort can be done without use of macros to alter the names used to indicate the different NAL unit types. |
---|
203 | #endif |
---|
204 | enum NalUnitType |
---|
205 | { |
---|
206 | NAL_UNIT_UNSPECIFIED_0 = 0, |
---|
207 | #if NAL_UNIT_TYPES_J1003_D7 |
---|
208 | NAL_UNIT_CODED_SLICE_TRAIL_R, // 1 |
---|
209 | NAL_UNIT_CODED_SLICE_TRAIL_N, // 2 |
---|
210 | NAL_UNIT_CODED_SLICE_TLA, // 3 // Current name in the spec: TSA_R |
---|
211 | NAL_UNIT_CODED_SLICE_TSA_N, // 4 |
---|
212 | NAL_UNIT_CODED_SLICE_STSA_R, // 5 |
---|
213 | NAL_UNIT_CODED_SLICE_STSA_N, // 6 |
---|
214 | NAL_UNIT_CODED_SLICE_BLA, // 7 // Current name in the spec: BLA_W_TFD |
---|
215 | NAL_UNIT_CODED_SLICE_BLANT, // 8 // Current name in the spec: BLA_W_DLP |
---|
216 | NAL_UNIT_CODED_SLICE_BLA_N_LP, // 9 |
---|
217 | NAL_UNIT_CODED_SLICE_IDR, // 10 // Current name in the spec: IDR_W_LP |
---|
218 | NAL_UNIT_CODED_SLICE_IDR_N_LP, // 11 |
---|
219 | NAL_UNIT_CODED_SLICE_CRA, // 12 |
---|
220 | NAL_UNIT_CODED_SLICE_DLP, // 13 |
---|
221 | NAL_UNIT_CODED_SLICE_TFD, // 14 |
---|
222 | #else |
---|
223 | NAL_UNIT_CODED_SLICE, // 1 |
---|
224 | NAL_UNIT_CODED_SLICE_TFD, // 2 |
---|
225 | NAL_UNIT_CODED_SLICE_TLA, // 3 |
---|
226 | NAL_UNIT_CODED_SLICE_CRA, // 4 |
---|
227 | NAL_UNIT_CODED_SLICE_CRANT, // 5 |
---|
228 | NAL_UNIT_CODED_SLICE_BLA, // 6 |
---|
229 | NAL_UNIT_CODED_SLICE_BLANT, // 7 |
---|
230 | NAL_UNIT_CODED_SLICE_IDR, // 8 |
---|
231 | NAL_UNIT_RESERVED_9, |
---|
232 | NAL_UNIT_RESERVED_10, |
---|
233 | NAL_UNIT_RESERVED_11, |
---|
234 | NAL_UNIT_RESERVED_12, |
---|
235 | NAL_UNIT_RESERVED_13, |
---|
236 | NAL_UNIT_RESERVED_14, |
---|
237 | #endif |
---|
238 | NAL_UNIT_RESERVED_15, |
---|
239 | NAL_UNIT_RESERVED_16, |
---|
240 | NAL_UNIT_RESERVED_17, |
---|
241 | NAL_UNIT_RESERVED_18, |
---|
242 | NAL_UNIT_RESERVED_19, |
---|
243 | NAL_UNIT_RESERVED_20, |
---|
244 | NAL_UNIT_RESERVED_21, |
---|
245 | NAL_UNIT_RESERVED_22, |
---|
246 | NAL_UNIT_RESERVED_23, |
---|
247 | NAL_UNIT_RESERVED_24, |
---|
248 | NAL_UNIT_VPS, // 25 |
---|
249 | NAL_UNIT_SPS, // 26 |
---|
250 | NAL_UNIT_PPS, // 27 |
---|
251 | #if NAL_UNIT_TYPES_J1003_D7 |
---|
252 | NAL_UNIT_ACCESS_UNIT_DELIMITER, // 28 |
---|
253 | NAL_UNIT_EOS, // 29 |
---|
254 | NAL_UNIT_EOB, // 30 |
---|
255 | NAL_UNIT_FILLER_DATA, // 31 |
---|
256 | NAL_UNIT_SEI, // 32 |
---|
257 | #else |
---|
258 | #if REMOVE_APS |
---|
259 | NAL_UNIT_RESERVED_28, |
---|
260 | #else |
---|
261 | NAL_UNIT_APS, // 28 |
---|
262 | #endif |
---|
263 | NAL_UNIT_ACCESS_UNIT_DELIMITER, // 29 |
---|
264 | NAL_UNIT_FILLER_DATA, // 30 |
---|
265 | NAL_UNIT_SEI, // 31 |
---|
266 | NAL_UNIT_RESERVED_32, |
---|
267 | #endif |
---|
268 | NAL_UNIT_RESERVED_33, |
---|
269 | NAL_UNIT_RESERVED_34, |
---|
270 | NAL_UNIT_RESERVED_35, |
---|
271 | NAL_UNIT_RESERVED_36, |
---|
272 | NAL_UNIT_RESERVED_37, |
---|
273 | NAL_UNIT_RESERVED_38, |
---|
274 | NAL_UNIT_RESERVED_39, |
---|
275 | NAL_UNIT_RESERVED_40, |
---|
276 | NAL_UNIT_RESERVED_41, |
---|
277 | NAL_UNIT_RESERVED_42, |
---|
278 | NAL_UNIT_RESERVED_43, |
---|
279 | NAL_UNIT_RESERVED_44, |
---|
280 | NAL_UNIT_RESERVED_45, |
---|
281 | NAL_UNIT_RESERVED_46, |
---|
282 | NAL_UNIT_RESERVED_47, |
---|
283 | NAL_UNIT_UNSPECIFIED_48, |
---|
284 | NAL_UNIT_UNSPECIFIED_49, |
---|
285 | NAL_UNIT_UNSPECIFIED_50, |
---|
286 | NAL_UNIT_UNSPECIFIED_51, |
---|
287 | NAL_UNIT_UNSPECIFIED_52, |
---|
288 | NAL_UNIT_UNSPECIFIED_53, |
---|
289 | NAL_UNIT_UNSPECIFIED_54, |
---|
290 | NAL_UNIT_UNSPECIFIED_55, |
---|
291 | NAL_UNIT_UNSPECIFIED_56, |
---|
292 | NAL_UNIT_UNSPECIFIED_57, |
---|
293 | NAL_UNIT_UNSPECIFIED_58, |
---|
294 | NAL_UNIT_UNSPECIFIED_59, |
---|
295 | NAL_UNIT_UNSPECIFIED_60, |
---|
296 | NAL_UNIT_UNSPECIFIED_61, |
---|
297 | NAL_UNIT_UNSPECIFIED_62, |
---|
298 | NAL_UNIT_UNSPECIFIED_63, |
---|
299 | NAL_UNIT_INVALID, |
---|
300 | }; |
---|
301 | |
---|
302 | //! \} |
---|
303 | |
---|
304 | #endif // end of #ifndef __COMMONDEF__ |
---|
305 | |
---|