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

Last change on this file since 756 was 532, checked in by seregin, 11 years ago

update to HM-12.1 base

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