source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/CommonDef.h @ 1426

Last change on this file since 1426 was 1394, checked in by seregin, 10 years ago

port rev 4547

  • Property svn:eol-style set to native
File size: 17.2 KB
RevLine 
[313]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
[1246]4 * granted under this license.
[313]5 *
[1259]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[313]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
[1335]35    \brief    Defines version information, constants and small in-line functions
[313]36*/
37
38#ifndef __COMMONDEF__
39#define __COMMONDEF__
40
41#include <algorithm>
[1029]42#include <iostream>
43#include <assert.h>
[1394]44#include <limits>
[595]45
[313]46#if _MSC_VER > 1000
47// disable "signed and unsigned mismatch"
48#pragma warning( disable : 4018 )
[1029]49// disable Bool coercion "performance warning"
[313]50#pragma warning( disable : 4800 )
51#endif // _MSC_VER > 1000
52#include "TypeDef.h"
53
[1283]54#ifdef _MSC_VER
55#if _MSC_VER <= 1500
56inline Int64 abs (Int64 x) { return _abs64(x); };
57#endif
58#endif
59
[313]60//! \ingroup TLibCommon
61//! \{
62
63// ====================================================================================================================
64// Version information
65// ====================================================================================================================
66
67#if SVC_EXTENSION
[540]68#include <vector>
[1384]69#define NV_VERSION        "10.0 (HM-16.6)"        ///< Current SHM software version
[313]70#else
[1373]71#define NV_VERSION        "16.6"                 ///< Current software version
[313]72#endif
73
74// ====================================================================================================================
75// Platform information
76// ====================================================================================================================
77
78#ifdef __GNUC__
79#define NVM_COMPILEDBY  "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
80#ifdef __IA64__
81#define NVM_ONARCH    "[on 64-bit] "
82#else
83#define NVM_ONARCH    "[on 32-bit] "
84#endif
85#endif
86
87#ifdef __INTEL_COMPILER
88#define NVM_COMPILEDBY  "[ICC %d]", __INTEL_COMPILER
89#elif  _MSC_VER
90#define NVM_COMPILEDBY  "[VS %d]", _MSC_VER
91#endif
92
93#ifndef NVM_COMPILEDBY
94#define NVM_COMPILEDBY "[Unk-CXX]"
95#endif
96
97#ifdef _WIN32
98#define NVM_ONOS        "[Windows]"
99#elif  __linux
100#define NVM_ONOS        "[Linux]"
101#elif  __CYGWIN__
102#define NVM_ONOS        "[Cygwin]"
103#elif __APPLE__
104#define NVM_ONOS        "[Mac OS X]"
105#else
106#define NVM_ONOS "[Unk-OS]"
107#endif
108
[1029]109#define NVM_BITS          "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S
[313]110
111#ifndef NULL
112#define NULL              0
113#endif
114
115// ====================================================================================================================
116// Common constants
117// ====================================================================================================================
118
[1335]119static const UInt   MAX_UINT =                            0xFFFFFFFFU; ///< max. value of unsigned 32-bit integer
120static const Int    MAX_INT =                              2147483647; ///< max. value of signed 32-bit integer
121static const Double MAX_DOUBLE =                             1.7e+308; ///< max. value of Double-type value
[313]122
[1335]123// ====================================================================================================================
124// Coding tool configuration
125// ====================================================================================================================
126// Most of these should not be changed - they resolve the meaning of otherwise magic numbers.
[313]127
[1335]128static const Int MAX_GOP =                                         64; ///< max. value of hierarchical GOP size
129static const Int MAX_NUM_REF_PICS =                                16; ///< max. number of pictures used for reference
130static const Int MAX_NUM_REF =                                     16; ///< max. number of entries in picture reference list
131static const Int MAX_QP =                                          51;
132static const Int NOT_VALID =                                       -1;
133
134static const Int AMVP_MAX_NUM_CANDS =                               2; ///< AMVP: advanced motion vector prediction - max number of final candidates
135static const Int AMVP_MAX_NUM_CANDS_MEM =                           3; ///< AMVP: advanced motion vector prediction - max number of candidates
136static const Int AMVP_DECIMATION_FACTOR =                           4;
137static const Int MRG_MAX_NUM_CANDS =                                5; ///< MERGE
138
139
140static const Int MAX_TLAYER =                                       7; ///< Explicit temporal layer QP offset - max number of temporal layer
141
142static const Int ADAPT_SR_SCALE =                                   1; ///< division factor for adaptive search range
143
144static const Int MAX_NUM_PICS_IN_SOP =                           1024;
145
146static const Int MAX_NESTING_NUM_OPS =                           1024;
147static const Int MAX_NESTING_NUM_LAYER =                           64;
148
149static const Int MAX_VPS_NUM_HRD_PARAMETERS =                       1;
150static const Int MAX_VPS_OP_SETS_PLUS1 =                         1024;
151static const Int MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 =         1;
152
153static const Int MAXIMUM_INTRA_FILTERED_WIDTH =                    16;
154static const Int MAXIMUM_INTRA_FILTERED_HEIGHT =                   16;
155
156static const Int MAX_CPB_CNT =                                     32; ///< Upper bound of (cpb_cnt_minus1 + 1)
157#if SVC_EXTENSION
158static const Int MAX_NUM_LAYER_IDS =                               63;
[1029]159#else
[1335]160static const Int MAX_NUM_LAYER_IDS =                               64;
[1029]161#endif
[313]162
[1335]163static const Int COEF_REMAIN_BIN_REDUCTION =                        3; ///< indicates the level at which the VLC transitions from Golomb-Rice to TU+EG(k)
[1029]164
[1335]165static const Int CU_DQP_TU_CMAX =                                   5; ///< max number bins for truncated unary
166static const Int CU_DQP_EG_k =                                      0; ///< expgolomb order
[313]167
[1335]168static const Int SBH_THRESHOLD =                                    4; ///< value of the fixed SBH controlling threshold
[313]169
[1335]170static const Int C1FLAG_NUMBER =                                    8; // maximum number of largerThan1 flag coded in one chunk:  16 in HM5
171static const Int C2FLAG_NUMBER =                                    1; // maximum number of largerThan2 flag coded in one chunk:  16 in HM5
172
173static const Int MAX_NUM_VPS =                                     16;
174static const Int MAX_NUM_SPS =                                     16;
175static const Int MAX_NUM_PPS =                                     64;
176
177
178static const Int MLS_GRP_NUM =                                     64; ///< Max number of coefficient groups, max(16, 64)
179static const Int MLS_CG_LOG2_WIDTH =                                2;
180static const Int MLS_CG_LOG2_HEIGHT =                               2;
181static const Int MLS_CG_SIZE =                                      4; ///< Coefficient group size of 4x4; = MLS_CG_LOG2_WIDTH + MLS_CG_LOG2_HEIGHT
182
183#if ADAPTIVE_QP_SELECTION
184static const Int ARL_C_PRECISION =                                  7; ///< G382: 7-bit arithmetic precision
185static const Int LEVEL_RANGE =                                     30; ///< G382: max coefficient level in statistics collection
186#endif
187
188static const Int RVM_VCEGAM10_M =                                   4;
189
190static const Int FAST_UDI_MAX_RDMODE_NUM =                         35; ///< maximum number of RD comparison in fast-UDI estimation loop
191
192static const Int NUM_INTRA_MODE =                                  36;
193static const Int PLANAR_IDX =                                       0;
194static const Int VER_IDX =                                         26; ///< index for intra VERTICAL   mode
195static const Int HOR_IDX =                                         10; ///< index for intra HORIZONTAL mode
196static const Int DC_IDX =                                           1; ///< index for intra DC mode
197static const Int NUM_CHROMA_MODE =                                  5; ///< total number of chroma modes
198static const Int DM_CHROMA_IDX =                                   36; ///< chroma mode index for derived from luma intra mode
199
200static const Int MDCS_ANGLE_LIMIT =                                 4; ///< 0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2 = Horizontal/vertical +/- 2 etc...
201static const Int MDCS_MAXIMUM_WIDTH =                               8; ///< (measured in pixels) TUs with width greater than this can only use diagonal scan
202static const Int MDCS_MAXIMUM_HEIGHT =                              8; ///< (measured in pixels) TUs with height greater than this can only use diagonal scan
203
204
205static const Int LOG2_MAX_NUM_COLUMNS_MINUS1 =                      7;
206static const Int LOG2_MAX_NUM_ROWS_MINUS1 =                         7;
207
208static const Int CABAC_INIT_PRESENT_FLAG =                          1;
209
210static const Int LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS =   4;
211static const Int CHROMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS = 8;
212
213static const Int MAX_NUM_LONG_TERM_REF_PICS =                      33;
214static const Int NUM_LONG_TERM_REF_PIC_SPS =                        0;
215
216
217static const Int MAX_QP_OFFSET_LIST_SIZE =                          6; ///< Maximum size of QP offset list is 6 entries
218
219// Cost mode support
220static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP =      0; ///< QP to use for lossless coding.
221static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME =4; ///< QP' to use for mixed_lossy_lossless coding.
222
223static const Int RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS =     4;
224static const Int RExt__GOLOMB_RICE_INCREMENT_DIVISOR =              4;
225
226static 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.
227
228static const Int MAX_TIMECODE_SEI_SETS =                            3; ///< Maximum number of time sets
229
230static const Int MAX_CU_DEPTH =                                     6; ///< log2(CTUSize)
231static const Int MAX_CU_SIZE =                                     64; ///< = 1<<(MAX_CU_DEPTH)
232static const Int MIN_PU_SIZE =                                      4;
233static const Int MIN_TU_SIZE =                                      4;
234static const Int MAX_TU_SIZE =                                     32;
235static 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)
236static const Int SCALING_LIST_REM_NUM =                             6;
237
238static const Int QUANT_SHIFT =                                     14; ///< Q(4) = 2^14
239static const Int IQUANT_SHIFT =                                     6;
240static const Int SCALE_BITS =                                      15; ///< For fractional bit estimates in RDOQ
241
242static const Int SCALING_LIST_NUM = MAX_NUM_COMPONENT * NUMBER_OF_PREDICTION_MODES; ///< list number for quantization matrix
243
244static const Int SCALING_LIST_START_VALUE =                        8 ; ///< start value for dpcm mode
245static const Int MAX_MATRIX_COEF_NUM =                            64 ; ///< max coefficient number for quantization matrix
246static const Int MAX_MATRIX_SIZE_NUM =                             8 ; ///< max size number for quantization matrix
247static const Int SCALING_LIST_BITS =                               8 ; ///< bit depth of scaling list entries
248static const Int LOG2_SCALING_LIST_NEUTRAL_VALUE =                 4 ; ///< log2 of the value that, when used in a scaling list, has no effect on quantisation
249static const Int SCALING_LIST_DC =                                16 ; ///< default DC value
250
251static const Int CONTEXT_STATE_BITS =                              6 ;
252static const Int LAST_SIGNIFICANT_GROUPS =                        10 ;
253
254
[313]255// ====================================================================================================================
256// Macro functions
257// ====================================================================================================================
[1029]258
259template <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
260template <typename T> inline T ClipBD(const T x, const Int bitDepth)             { return Clip3(T(0), T((1 << bitDepth)-1), x);           }
[313]261
[1029]262template <typename T> inline Void Check3( T minVal, T maxVal, T a)
263{
264  if ((a > maxVal) || (a < minVal))
265  {
266    std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl;
267    assert(false);
268    exit(1);
269  }
270}  ///< general min/max clip
271
[313]272#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
273#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
274#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
275#define xFree( ptr )                _aligned_free  ( ptr )
276#else
277#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
278#define xFree( ptr )                free     ( ptr )
279#endif
280
281#define FATAL_ERROR_0(MESSAGE, EXITCODE)                      \
282{                                                             \
283  printf(MESSAGE);                                            \
284  exit(EXITCODE);                                             \
285}
286
[1029]287template <typename ValueType> inline ValueType leftShift       (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ( value                                   >> -shift); }
288template <typename ValueType> inline ValueType rightShift      (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  >> shift) : ( value                                   << -shift); }
289template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); }
290template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value                                   << -shift); }
291#if O0043_BEST_EFFORT_DECODING
292// when shift = 0, returns value
293// when shift = 1, (value + 0 + value[1]) >> 1
294// when shift = 2, (value + 1 + value[2]) >> 2
295// when shift = 3, (value + 3 + value[3]) >> 3
296template <typename ValueType> inline ValueType rightShiftEvenRounding(const ValueType value, const UInt shift) { return (shift == 0) ? value : ((value + (1<<(shift-1))-1 + ((value>>shift)&1)) >> shift) ; }
297#endif
[313]298
[1177]299#if SVC_EXTENSION
[540]300class CommonDecoderParams
301{
302  Int m_targetLayerId;
[588]303  Int m_targetOutputLayerSetIdx;
[1029]304  std::vector<Int> *m_targetDecLayerIdSet;
[540]305  Bool m_valueCheckedFlag;
[644]306  Int m_highestTId;
[540]307public:
[1029]308  CommonDecoderParams():
[1106]309#if CONFORMANCE_BITSTREAM_MODE
[1046]310    m_targetLayerId(MAX_VPS_LAYER_IDX_PLUS1)
[952]311#else
[540]312    m_targetLayerId(0)
[952]313#endif
[588]314    , m_targetOutputLayerSetIdx(-1)
[540]315    , m_targetDecLayerIdSet(NULL)
316    , m_valueCheckedFlag(false)
[644]317    , m_highestTId(6)
[540]318 {}
319
320  Void setTargetLayerId(const Int x) { m_targetLayerId = x;   }
321  Int  getTargetLayerId()            { return m_targetLayerId;}
322 
[588]323  Void setTargetOutputLayerSetIdx(const Int x) { m_targetOutputLayerSetIdx = x;   }
324  Int  getTargetOutputLayerSetIdx()            { return m_targetOutputLayerSetIdx;}
[540]325
326  Void               setTargetDecLayerIdSet(std::vector<Int> *x) { m_targetDecLayerIdSet = x;   }
327  std::vector<Int>*  getTargetDecLayerIdSet()                    { return m_targetDecLayerIdSet;}
328 
329  Void setValueCheckedFlag(const Bool x) { m_valueCheckedFlag = x;   }
330  Bool getValueCheckedFlag()            { return m_valueCheckedFlag;}
331 
[644]332  Void setHighestTId(const Int x) { m_highestTId = x; }
333  Int  getHighestTId()            { return m_highestTId; }
[540]334};
335#endif
[313]336//! \}
337
338#endif // end of #ifndef  __COMMONDEF__
339
Note: See TracBrowser for help on using the repository browser.