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

Last change on this file since 1332 was 1330, checked in by seregin, 9 years ago

port rev 4408

  • Property svn:eol-style set to native
File size: 13.0 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 constants, macros and tool parameters
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#endif // _MSC_VER > 1000
51#include "TypeDef.h"
52
53#ifdef _MSC_VER
54#if _MSC_VER <= 1500
55inline Int64 abs (Int64 x) { return _abs64(x); };
56#endif
57#endif
58
59//! \ingroup TLibCommon
60//! \{
61
62// ====================================================================================================================
63// Version information
64// ====================================================================================================================
65
66#if SVC_EXTENSION
67#include <vector>
68#define NV_VERSION        "9.0 (HM-16.4)"        ///< Current SHM software version
69#else
70#define NV_VERSION        "16.4"                 ///< Current software version
71#endif
72
73// ====================================================================================================================
74// Platform information
75// ====================================================================================================================
76
77#ifdef __GNUC__
78#define NVM_COMPILEDBY  "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
79#ifdef __IA64__
80#define NVM_ONARCH    "[on 64-bit] "
81#else
82#define NVM_ONARCH    "[on 32-bit] "
83#endif
84#endif
85
86#ifdef __INTEL_COMPILER
87#define NVM_COMPILEDBY  "[ICC %d]", __INTEL_COMPILER
88#elif  _MSC_VER
89#define NVM_COMPILEDBY  "[VS %d]", _MSC_VER
90#endif
91
92#ifndef NVM_COMPILEDBY
93#define NVM_COMPILEDBY "[Unk-CXX]"
94#endif
95
96#ifdef _WIN32
97#define NVM_ONOS        "[Windows]"
98#elif  __linux
99#define NVM_ONOS        "[Linux]"
100#elif  __CYGWIN__
101#define NVM_ONOS        "[Cygwin]"
102#elif __APPLE__
103#define NVM_ONOS        "[Mac OS X]"
104#else
105#define NVM_ONOS "[Unk-OS]"
106#endif
107
108#define NVM_BITS          "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S
109
110#ifndef NULL
111#define NULL              0
112#endif
113
114// ====================================================================================================================
115// Common constants
116// ====================================================================================================================
117
118#define _SUMMARY_OUT_               0           ///< print-out PSNR results of all slices to summary.txt
119#define _SUMMARY_PIC_               0           ///< print-out PSNR results for each slice type to summary.txt
120
121#define MAX_GOP                     64          ///< max. value of hierarchical GOP size
122
123#define MAX_NUM_REF_PICS            16          ///< max. number of pictures used for reference
124#define MAX_NUM_REF                 16          ///< max. number of entries in picture reference list
125
126#define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
127#define MAX_INT                     2147483647  ///< max. value of signed 32-bit integer
128#define MAX_INT64                   0x7FFFFFFFFFFFFFFFLL  ///< max. value of signed 64-bit integer
129#if RExt__HIGH_BIT_DEPTH_SUPPORT
130#define MAX_INTERMEDIATE_INT        MAX_INT64
131#else
132#define MAX_INTERMEDIATE_INT        MAX_INT
133#endif
134
135#define MAX_DOUBLE                  1.7e+308    ///< max. value of Double-type value
136
137#define MIN_QP                      0
138#define MAX_QP                      51
139
140#define NOT_VALID                   -1
141
142// ====================================================================================================================
143// Macro functions
144// ====================================================================================================================
145
146template <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
147template <typename T> inline T ClipBD(const T x, const Int bitDepth)             { return Clip3(T(0), T((1 << bitDepth)-1), x);           }
148
149template <typename T> inline Void Check3( T minVal, T maxVal, T a)
150{
151  if ((a > maxVal) || (a < minVal))
152  {
153    std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl;
154    assert(false);
155    exit(1);
156  }
157}  ///< general min/max clip
158
159#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
160#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
161#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
162#define xFree( ptr )                _aligned_free  ( ptr )
163#else
164#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
165#define xFree( ptr )                free     ( ptr )
166#endif
167
168#define FATAL_ERROR_0(MESSAGE, EXITCODE)                      \
169{                                                             \
170  printf(MESSAGE);                                            \
171  exit(EXITCODE);                                             \
172}
173
174template <typename ValueType> inline ValueType leftShift       (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ( value                                   >> -shift); }
175template <typename ValueType> inline ValueType rightShift      (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  >> shift) : ( value                                   << -shift); }
176template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value                                  << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); }
177template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value                                   << -shift); }
178#if O0043_BEST_EFFORT_DECODING
179// when shift = 0, returns value
180// when shift = 1, (value + 0 + value[1]) >> 1
181// when shift = 2, (value + 1 + value[2]) >> 2
182// when shift = 3, (value + 3 + value[3]) >> 3
183template <typename ValueType> inline ValueType rightShiftEvenRounding(const ValueType value, const UInt shift) { return (shift == 0) ? value : ((value + (1<<(shift-1))-1 + ((value>>shift)&1)) >> shift) ; }
184#endif
185
186// ====================================================================================================================
187// Coding tool configuration
188// ====================================================================================================================
189
190// AMVP: advanced motion vector prediction
191#define AMVP_MAX_NUM_CANDS          2           ///< max number of final candidates
192#define AMVP_MAX_NUM_CANDS_MEM      3           ///< max number of candidates
193// MERGE
194#define MRG_MAX_NUM_CANDS           5
195
196// Reference memory management
197#define DYN_REF_FREE                0           ///< dynamic free of reference memories
198
199// Explicit temporal layer QP offset
200#define MAX_TLAYER                  7           ///< max number of temporal layer
201
202// Fast estimation of generalized B in low-delay mode
203#define GPB_SIMPLE_UNI              1           ///< Simple mode for uni-direction
204
205// Adaptive search range depending on POC difference
206#define ADAPT_SR_SCALE              1           ///< division factor for adaptive search range
207
208// Early-skip threshold (encoder)
209#define EARLY_SKIP_THRES            1.50        ///< if RD < thres*avg[BestSkipRD]
210
211
212#define MAX_CHROMA_FORMAT_IDC      3
213
214// TODO: Existing names used for the different NAL unit types can be altered to better reflect the names in the spec.
215//       However, the names in the spec are not yet stable at this point. Once the names are stable, a cleanup
216//       effort can be done without use of macros to alter the names used to indicate the different NAL unit types.
217enum NalUnitType
218{
219  NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 0
220  NAL_UNIT_CODED_SLICE_TRAIL_R,     // 1
221
222  NAL_UNIT_CODED_SLICE_TSA_N,       // 2
223  NAL_UNIT_CODED_SLICE_TSA_R,       // 3
224
225  NAL_UNIT_CODED_SLICE_STSA_N,      // 4
226  NAL_UNIT_CODED_SLICE_STSA_R,      // 5
227
228  NAL_UNIT_CODED_SLICE_RADL_N,      // 6
229  NAL_UNIT_CODED_SLICE_RADL_R,      // 7
230
231  NAL_UNIT_CODED_SLICE_RASL_N,      // 8
232  NAL_UNIT_CODED_SLICE_RASL_R,      // 9
233
234  NAL_UNIT_RESERVED_VCL_N10,
235  NAL_UNIT_RESERVED_VCL_R11,
236  NAL_UNIT_RESERVED_VCL_N12,
237  NAL_UNIT_RESERVED_VCL_R13,
238  NAL_UNIT_RESERVED_VCL_N14,
239  NAL_UNIT_RESERVED_VCL_R15,
240
241  NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
242  NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
243  NAL_UNIT_CODED_SLICE_BLA_N_LP,    // 18
244  NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
245  NAL_UNIT_CODED_SLICE_IDR_N_LP,    // 20
246  NAL_UNIT_CODED_SLICE_CRA,         // 21
247  NAL_UNIT_RESERVED_IRAP_VCL22,
248  NAL_UNIT_RESERVED_IRAP_VCL23,
249
250  NAL_UNIT_RESERVED_VCL24,
251  NAL_UNIT_RESERVED_VCL25,
252  NAL_UNIT_RESERVED_VCL26,
253  NAL_UNIT_RESERVED_VCL27,
254  NAL_UNIT_RESERVED_VCL28,
255  NAL_UNIT_RESERVED_VCL29,
256  NAL_UNIT_RESERVED_VCL30,
257  NAL_UNIT_RESERVED_VCL31,
258
259  NAL_UNIT_VPS,                     // 32
260  NAL_UNIT_SPS,                     // 33
261  NAL_UNIT_PPS,                     // 34
262  NAL_UNIT_ACCESS_UNIT_DELIMITER,   // 35
263  NAL_UNIT_EOS,                     // 36
264  NAL_UNIT_EOB,                     // 37
265  NAL_UNIT_FILLER_DATA,             // 38
266  NAL_UNIT_PREFIX_SEI,              // 39
267  NAL_UNIT_SUFFIX_SEI,              // 40
268
269  NAL_UNIT_RESERVED_NVCL41,
270  NAL_UNIT_RESERVED_NVCL42,
271  NAL_UNIT_RESERVED_NVCL43,
272  NAL_UNIT_RESERVED_NVCL44,
273  NAL_UNIT_RESERVED_NVCL45,
274  NAL_UNIT_RESERVED_NVCL46,
275  NAL_UNIT_RESERVED_NVCL47,
276  NAL_UNIT_UNSPECIFIED_48,
277  NAL_UNIT_UNSPECIFIED_49,
278  NAL_UNIT_UNSPECIFIED_50,
279  NAL_UNIT_UNSPECIFIED_51,
280  NAL_UNIT_UNSPECIFIED_52,
281  NAL_UNIT_UNSPECIFIED_53,
282  NAL_UNIT_UNSPECIFIED_54,
283  NAL_UNIT_UNSPECIFIED_55,
284  NAL_UNIT_UNSPECIFIED_56,
285  NAL_UNIT_UNSPECIFIED_57,
286  NAL_UNIT_UNSPECIFIED_58,
287  NAL_UNIT_UNSPECIFIED_59,
288  NAL_UNIT_UNSPECIFIED_60,
289  NAL_UNIT_UNSPECIFIED_61,
290  NAL_UNIT_UNSPECIFIED_62,
291  NAL_UNIT_UNSPECIFIED_63,
292  NAL_UNIT_INVALID,
293};
294
295#if SVC_EXTENSION
296class CommonDecoderParams
297{
298  Int m_targetLayerId;
299  Int m_targetOutputLayerSetIdx;
300  std::vector<Int> *m_targetDecLayerIdSet;
301  Bool m_valueCheckedFlag;
302  Int m_highestTId;
303public:
304  CommonDecoderParams():
305#if CONFORMANCE_BITSTREAM_MODE
306    m_targetLayerId(MAX_VPS_LAYER_IDX_PLUS1)
307#else
308    m_targetLayerId(0)
309#endif
310    , m_targetOutputLayerSetIdx(-1)
311    , m_targetDecLayerIdSet(NULL)
312    , m_valueCheckedFlag(false)
313    , m_highestTId(6)
314 {}
315
316  Void setTargetLayerId(const Int x) { m_targetLayerId = x;   }
317  Int  getTargetLayerId()            { return m_targetLayerId;}
318 
319  Void setTargetOutputLayerSetIdx(const Int x) { m_targetOutputLayerSetIdx = x;   }
320  Int  getTargetOutputLayerSetIdx()            { return m_targetOutputLayerSetIdx;}
321
322  Void               setTargetDecLayerIdSet(std::vector<Int> *x) { m_targetDecLayerIdSet = x;   }
323  std::vector<Int>*  getTargetDecLayerIdSet()                    { return m_targetDecLayerIdSet;}
324 
325  Void setValueCheckedFlag(const Bool x) { m_valueCheckedFlag = x;   }
326  Bool getValueCheckedFlag()            { return m_valueCheckedFlag;}
327 
328  Void setHighestTId(const Int x) { m_highestTId = x; }
329  Int  getHighestTId()            { return m_highestTId; }
330};
331#endif
332//! \}
333
334#endif // end of #ifndef  __COMMONDEF__
335
Note: See TracBrowser for help on using the repository browser.