source: 3DVCSoftware/branches/HTM-15.0-dev0/source/Lib/TLibCommon/CommonDef.h @ 1317

Last change on this file since 1317 was 1317, checked in by tech, 9 years ago

Clean-ups. HLS.

  • Property svn:eol-style set to native
File size: 21.1 KB
Line 
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
34/** \file     CommonDef.h
35    \brief    Defines version information, constants and small in-line functions
36*/
37
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// NH_MV
51// disabled decorated name length warning issued for IntAry5d
52#pragma warning(disable : 4503)
53//
54#endif // _MSC_VER > 1000
55
56
57#include "TypeDef.h"
58#ifdef _MSC_VER
59#if _MSC_VER <= 1500
60inline Int64 abs (Int64 x) { return _abs64(x); };
61#endif
62#endif
63#if NH_MV
64#include <assert.h>
65#endif
66
67//! \ingroup TLibCommon
68//! \{
69
70// ====================================================================================================================
71// Version information
72// ====================================================================================================================
73#if NH_MV
74#define NV_VERSION        "15.0"                ///< Current software version
75#define HM_VERSION        "16.6"                ///<
76#else
77#define NV_VERSION        "16.6"                 ///< Current software version
78#endif
79// ====================================================================================================================
80// Platform information
81// ====================================================================================================================
82
83#ifdef __GNUC__
84#define NVM_COMPILEDBY  "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
85#ifdef __IA64__
86#define NVM_ONARCH    "[on 64-bit] "
87#else
88#define NVM_ONARCH    "[on 32-bit] "
89#endif
90#endif
91
92#ifdef __INTEL_COMPILER
93#define NVM_COMPILEDBY  "[ICC %d]", __INTEL_COMPILER
94#elif  _MSC_VER
95#define NVM_COMPILEDBY  "[VS %d]", _MSC_VER
96#endif
97
98#ifndef NVM_COMPILEDBY
99#define NVM_COMPILEDBY "[Unk-CXX]"
100#endif
101
102#ifdef _WIN32
103#define NVM_ONOS        "[Windows]"
104#elif  __linux
105#define NVM_ONOS        "[Linux]"
106#elif  __CYGWIN__
107#define NVM_ONOS        "[Cygwin]"
108#elif __APPLE__
109#define NVM_ONOS        "[Mac OS X]"
110#else
111#define NVM_ONOS "[Unk-OS]"
112#endif
113
114#define NVM_BITS          "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S
115
116#ifndef NULL
117#define NULL              0
118#endif
119
120// ====================================================================================================================
121// Common constants
122// ====================================================================================================================
123
124static const UInt   MAX_UINT =                            0xFFFFFFFFU; ///< max. value of unsigned 32-bit integer
125static const Int    MAX_INT =                              2147483647; ///< max. value of signed 32-bit integer
126#if NH_MV
127static const Int    MIN_INT =                         (- MAX_INT - 1); ///< max. value of signed 32-bit integer
128#endif
129static 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
136static const Int MAX_GOP =                                         64; ///< max. value of hierarchical GOP size
137static const Int MAX_NUM_REF_PICS =                                16; ///< max. number of pictures used for reference
138static const Int MAX_NUM_REF =                                     16; ///< max. number of entries in picture reference list
139static const Int MAX_QP =                                          51;
140static const Int NOT_VALID =                                       -1;
141
142static const Int AMVP_MAX_NUM_CANDS =                               2; ///< AMVP: advanced motion vector prediction - max number of final candidates
143static const Int AMVP_MAX_NUM_CANDS_MEM =                           3; ///< AMVP: advanced motion vector prediction - max number of candidates
144static const Int AMVP_DECIMATION_FACTOR =                           4;
145static const Int MRG_MAX_NUM_CANDS =                                5; ///< MERGE
146
147
148static const Int MAX_TLAYER =                                       7; ///< Explicit temporal layer QP offset - max number of temporal layer
149
150static const Int ADAPT_SR_SCALE =                                   1; ///< division factor for adaptive search range
151
152static const Int MAX_NUM_PICS_IN_SOP =                           1024;
153
154static const Int MAX_NESTING_NUM_OPS =                           1024;
155static const Int MAX_NESTING_NUM_LAYER =                           64;
156
157#if NH_MV
158static const Int MAX_VPS_NUM_HRD_PARAMETERS =                    1024;
159#else
160static const Int MAX_VPS_NUM_HRD_PARAMETERS =                       1;
161#endif
162static const Int MAX_VPS_OP_SETS_PLUS1 =                         1024;
163#if NH_MV
164static const Int MAX_VPS_NUH_LAYER_ID_PLUS1 =                      63;               
165#else
166static const Int MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 =         1;
167#endif
168
169static const Int MAXIMUM_INTRA_FILTERED_WIDTH =                    16;
170static const Int MAXIMUM_INTRA_FILTERED_HEIGHT =                   16;
171
172static const Int MAX_CPB_CNT =                                     32; ///< Upper bound of (cpb_cnt_minus1 + 1)
173#if NH_MV
174static const Int MAX_NUM_LAYER_IDS =                               63;
175#else
176static const Int MAX_NUM_LAYER_IDS =                               64;
177#endif
178
179static const Int COEF_REMAIN_BIN_REDUCTION =                        3; ///< indicates the level at which the VLC transitions from Golomb-Rice to TU+EG(k)
180
181static const Int CU_DQP_TU_CMAX =                                   5; ///< max number bins for truncated unary
182static const Int CU_DQP_EG_k =                                      0; ///< expgolomb order
183
184static const Int SBH_THRESHOLD =                                    4; ///< value of the fixed SBH controlling threshold
185
186static const Int C1FLAG_NUMBER =                                    8; // maximum number of largerThan1 flag coded in one chunk:  16 in HM5
187static const Int C2FLAG_NUMBER =                                    1; // maximum number of largerThan2 flag coded in one chunk:  16 in HM5
188
189static const Int MAX_NUM_VPS =                                     16;
190static const Int MAX_NUM_SPS =                                     16;
191static const Int MAX_NUM_PPS =                                     64;
192
193
194static const Int MLS_GRP_NUM =                                     64; ///< Max number of coefficient groups, max(16, 64)
195static const Int MLS_CG_LOG2_WIDTH =                                2;
196static const Int MLS_CG_LOG2_HEIGHT =                               2;
197static 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
200static const Int ARL_C_PRECISION =                                  7; ///< G382: 7-bit arithmetic precision
201static const Int LEVEL_RANGE =                                     30; ///< G382: max coefficient level in statistics collection
202#endif
203
204static const Int RVM_VCEGAM10_M =                                   4;
205
206static const Int FAST_UDI_MAX_RDMODE_NUM =                         35; ///< maximum number of RD comparison in fast-UDI estimation loop
207
208static const Int NUM_INTRA_MODE =                                  36;
209static const Int PLANAR_IDX =                                       0;
210static const Int VER_IDX =                                         26; ///< index for intra VERTICAL   mode
211static const Int HOR_IDX =                                         10; ///< index for intra HORIZONTAL mode
212static const Int DC_IDX =                                           1; ///< index for intra DC mode
213static const Int NUM_CHROMA_MODE =                                  5; ///< total number of chroma modes
214static const Int DM_CHROMA_IDX =                                   36; ///< chroma mode index for derived from luma intra mode
215
216static const Int MDCS_ANGLE_LIMIT =                                 4; ///< 0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2 = Horizontal/vertical +/- 2 etc...
217static const Int MDCS_MAXIMUM_WIDTH =                               8; ///< (measured in pixels) TUs with width greater than this can only use diagonal scan
218static const Int MDCS_MAXIMUM_HEIGHT =                              8; ///< (measured in pixels) TUs with height greater than this can only use diagonal scan
219
220
221static const Int LOG2_MAX_NUM_COLUMNS_MINUS1 =                      7;
222static const Int LOG2_MAX_NUM_ROWS_MINUS1 =                         7;
223
224static const Int CABAC_INIT_PRESENT_FLAG =                          1;
225
226static const Int LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS =   4;
227static const Int CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS = 8;
228
229static const Int MAX_NUM_LONG_TERM_REF_PICS =                      33;
230static const Int NUM_LONG_TERM_REF_PIC_SPS =                        0;
231
232
233static const Int MAX_QP_OFFSET_LIST_SIZE =                          6; ///< Maximum size of QP offset list is 6 entries
234
235// Cost mode support
236static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP =      0; ///< QP to use for lossless coding.
237static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME =4; ///< QP' to use for mixed_lossy_lossless coding.
238
239static const Int RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS =     4;
240static const Int RExt__GOLOMB_RICE_INCREMENT_DIVISOR =              4;
241
242static 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
244static const Int MAX_TIMECODE_SEI_SETS =                            3; ///< Maximum number of time sets
245
246static const Int MAX_CU_DEPTH =                                     6; ///< log2(CTUSize)
247static const Int MAX_CU_SIZE =                                     64; ///< = 1<<(MAX_CU_DEPTH)
248static const Int MIN_PU_SIZE =                                      4;
249static const Int MIN_TU_SIZE =                                      4;
250static const Int MAX_TU_SIZE =                                     32;
251static 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)
252static const Int SCALING_LIST_REM_NUM =                             6;
253
254static const Int QUANT_SHIFT =                                     14; ///< Q(4) = 2^14
255static const Int IQUANT_SHIFT =                                     6;
256static const Int SCALE_BITS =                                      15; ///< For fractional bit estimates in RDOQ
257
258static const Int SCALING_LIST_NUM = MAX_NUM_COMPONENT * NUMBER_OF_PREDICTION_MODES; ///< list number for quantization matrix
259
260static const Int SCALING_LIST_START_VALUE =                        8 ; ///< start value for dpcm mode
261static const Int MAX_MATRIX_COEF_NUM =                            64 ; ///< max coefficient number for quantization matrix
262static const Int MAX_MATRIX_SIZE_NUM =                             8 ; ///< max size number for quantization matrix
263static const Int SCALING_LIST_BITS =                               8 ; ///< bit depth of scaling list entries
264static const Int LOG2_SCALING_LIST_NEUTRAL_VALUE =                 4 ; ///< log2 of the value that, when used in a scaling list, has no effect on quantisation
265static const Int SCALING_LIST_DC =                                16 ; ///< default DC value
266
267static const Int CONTEXT_STATE_BITS =                              6 ;
268static const Int LAST_SIGNIFICANT_GROUPS =                        10 ;
269
270#if NH_MV
271static const Int  MAX_VPS_NUM_ADD_LAYER_SETS =                  1024 ;
272static const Int  MAX_NUM_SCALABILITY_TYPES =                     16 ;
273static const Int  ENC_CFG_CONSOUT_SPACE =                         34 ;           
274static const Int  MAX_NUM_LAYERS =                                63 ;
275static const Int  MAX_VPS_PROFILE_TIER_LEVEL =                    64 ;
276static const Int  MAX_VPS_ADD_OUTPUT_LAYER_SETS =               1024 ;
277static const Int  MAX_VPS_OUTPUTLAYER_SETS =  MAX_VPS_ADD_OUTPUT_LAYER_SETS + MAX_VPS_OP_SETS_PLUS1 + MAX_VPS_OP_SETS_PLUS1 ;
278static const Int  MAX_NUM_VIDEO_SIGNAL_INFO =                     16 ;
279static const Int  MAX_NUM_SCALED_REF_LAYERS =     MAX_NUM_LAYERS - 1 ; 
280static const Int  MAX_NUM_PICS_RPS          =                     16 ; 
281static const Int  MAX_NUM_REF_LAYERS        =                     63 ; 
282#endif
283
284// ====================================================================================================================
285// Macro functions
286// ====================================================================================================================
287
288template <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
289template <typename T> inline T ClipBD(const T x, const Int bitDepth)             { return Clip3(T(0), T((1 << bitDepth)-1), x);           }
290
291template <typename T> inline Void Check3( T minVal, T maxVal, T a)
292{
293  if ((a > maxVal) || (a < minVal))
294  {
295    std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl;
296    assert(false);
297    exit(1);
298  }
299}  ///< general min/max clip
300
301#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
302#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
303#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
304#define xFree( ptr )                _aligned_free  ( ptr )
305#else
306#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
307#define xFree( ptr )                free     ( ptr )
308#endif
309
310#define FATAL_ERROR_0(MESSAGE, EXITCODE)                      \
311{                                                             \
312  printf(MESSAGE);                                            \
313  exit(EXITCODE);                                             \
314}
315
316template <typename ValueType> inline ValueType leftShift       (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ( value                                   >> -shift); }
317template <typename ValueType> inline ValueType rightShift      (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  >> shift) : ( value                                   << -shift); }
318template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); }
319template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value                                   << -shift); }
320#if O0043_BEST_EFFORT_DECODING
321// when shift = 0, returns value
322// when shift = 1, (value + 0 + value[1]) >> 1
323// when shift = 2, (value + 1 + value[2]) >> 2
324// when shift = 3, (value + 3 + value[3]) >> 3
325template <typename ValueType> inline ValueType rightShiftEvenRounding(const ValueType value, const UInt shift) { return (shift == 0) ? value : ((value + (1<<(shift-1))-1 + ((value>>shift)&1)) >> shift) ; }
326#endif
327#if NH_MV
328
329#define AOF( exp )                  \
330{                                   \
331  if( !( exp ) )                    \
332{                                 \
333  assert( 0 );                    \
334}                                 \
335}
336
337#define AOT( exp )            \
338{                             \
339  if( ( exp ) )               \
340{                           \
341  assert( 0 );              \
342}                           \
343}
344
345template <typename T>
346__inline T gSign(const T& t)
347{
348  if( t == 0 )
349    return T(0);
350  else
351    return (t < 0) ? T(-1) : T(1);
352}
353
354template <typename T>
355__inline T gCeilLog2( T val )
356{
357  assert( val > 0 ); 
358  Int ceilLog2 = 0;
359  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
360  return ceilLog2;
361}
362
363#define RemoveBitIncrement( exp ) ( exp >> ( REN_BIT_DEPTH - 8 ) )
364
365#endif
366
367#if NH_3D_MLC  || NH_3D_ARP
368#define MRG_MAX_NUM_CANDS_MEM       (MRG_MAX_NUM_CANDS+1) // one extra for inter-view motion prediction
369#endif
370
371#if NH_MV
372static const std::string NALU_TYPE_STR[] = { 
373    "CODED_SLICE_TRAIL_N   ",  // 0
374    "CODED_SLICE_TRAIL_R   ",  // 1
375    "CODED_SLICE_TSA_N     ",  // 2
376    "CODED_SLICE_TSA_R     ",  // 3
377    "CODED_SLICE_STSA_N    ",  // 4
378    "CODED_SLICE_STSA_R    ",  // 5
379    "CODED_SLICE_RADL_N    ",  // 6
380    "CODED_SLICE_RADL_R    ",  // 7
381    "CODED_SLICE_RASL_N    ",  // 8
382    "CODED_SLICE_RASL_R    ",  // 9
383    "RESERVED_VCL_N10      ",
384    "RESERVED_VCL_R11      ",
385    "RESERVED_VCL_N12      ",
386    "RESERVED_VCL_R13      ",
387    "RESERVED_VCL_N14      ",
388    "RESERVED_VCL_R15      ",
389    "CODED_SLICE_BLA_W_LP  ",  // 16
390    "CODED_SLICE_BLA_W_RADL",  // 17
391    "CODED_SLICE_BLA_N_LP  ",  // 18
392    "CODED_SLICE_IDR_W_RADL",  // 19
393    "CODED_SLICE_IDR_N_LP  ",  // 20
394    "CODED_SLICE_CRA       ",  // 21
395    "RESERVED_IRAP_VCL22   ",
396    "RESERVED_IRAP_VCL23   ",
397    "RESERVED_VCL24        ",
398    "RESERVED_VCL25        ",
399    "RESERVED_VCL26        ",
400    "RESERVED_VCL27        ",
401    "RESERVED_VCL28        ",
402    "RESERVED_VCL29        ",
403    "RESERVED_VCL30        ",
404    "RESERVED_VCL31        ",
405    "VPS                   ",   // 32
406    "SPS                   ",   // 33
407    "PPS                   ",   // 34
408    "ACCESS_UNIT_DELIMITER ",   // 35
409    "EOS                   ",   // 36
410    "EOB                   ",   // 37
411    "FILLER_DATA           ",   // 38
412    "PREFIX_SEI            ",   // 39
413    "SUFFIX_SEI            ",   // 40
414    "RESERVED_NVCL41       ",
415    "RESERVED_NVCL42       ",
416    "RESERVED_NVCL43       ",
417    "RESERVED_NVCL44       ",
418    "RESERVED_NVCL45       ",
419    "RESERVED_NVCL46       ",
420    "RESERVED_NVCL47       ",
421    "UNSPECIFIED_48        ",
422    "UNSPECIFIED_49        ",
423    "UNSPECIFIED_50        ",
424    "UNSPECIFIED_51        ",
425    "UNSPECIFIED_52        ",
426    "UNSPECIFIED_53        ",
427    "UNSPECIFIED_54        ",
428    "UNSPECIFIED_55        ",
429    "UNSPECIFIED_56        ",
430    "UNSPECIFIED_57        ",
431    "UNSPECIFIED_58        ",
432    "UNSPECIFIED_59        ",
433    "UNSPECIFIED_60        ",
434    "UNSPECIFIED_61        ",
435    "UNSPECIFIED_62        ",
436    "UNSPECIFIED_63        ",
437    "INVALID               "               
438  };
439#endif
440
441#if NH_3D
442//PICYUV
443#define PICYUV_PAD         16
444
445//RENDERER
446
447
448#define REN_BIT_DEPTH     8
449#define REN_LUMA_MARGIN   ( PICYUV_PAD + 1 ) // + g_uiMaxCuWidth instead of 1 ???
450#define REN_VDWEIGHT_PREC  8
451#define REN_IS_FILLED     ( 1 << REN_VDWEIGHT_PREC )
452#define REN_USED_PEL       ( (1 << REN_BIT_DEPTH) - 1 )
453#define REN_UNUSED_PEL     0
454#define REN_IS_HOLE        0
455#if NH_3D_VSO
456#define ENC_INTERNAL_BIT_DEPTH  REN_BIT_DEPTH // consider making this a variable
457#endif
458
459
460// CAMERA PARAMETERS
461#define LOG2_DISP_PREC_LUT           2           ///< log2 of disparity precision used in integer disparity LUTs
462#define STD_CAM_PARAMETERS_PRECISION 5        ///< quarter luma sample accuarcy for derived disparities (as default)
463
464#endif // end of NH_3D
465//! \}
466
467#endif // end of #ifndef  __COMMONDEF__
468
Note: See TracBrowser for help on using the repository browser.