source: 3DVCSoftware/tags/0.2r1/source/Lib/TLibCommon/CommonDef.h @ 281

Last change on this file since 281 was 17, checked in by hschwarz, 13 years ago

fix for DMM with non-10-bit processing

  • Property svn:eol-style set to native
File size: 19.9 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-2011, 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 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
35
36/** \file     CommonDef.h
37    \brief    Defines constants, macros and tool parameters
38*/
39
40#ifndef __COMMONDEF__
41#define __COMMONDEF__
42
43// this pragma can be used for turning off "signed and unsigned mismatch"
44#if _MSC_VER > 1000
45#pragma warning( disable : 4018 )
46#endif // _MSC_VER > 1000
47#include "TypeDef.h"
48#include "TComRom.h"
49
50#include <string>
51#include <assert.h>
52#include <stdlib.h>
53#include <vector>
54
55// ====================================================================================================================
56// Version information
57// ====================================================================================================================
58
59#define HM_VERSION        "3.0rc2"                 ///< Current software version
60#define NV_VERSION        "0.2r1"                  ///< Current software version
61
62// ====================================================================================================================
63// Platform information
64// ====================================================================================================================
65
66#ifdef __GNUC__
67#define NVM_COMPILEDBY  "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
68#ifdef __IA64__
69#define NVM_ONARCH    "[on 64-bit] "
70#else
71#define NVM_ONARCH    "[on 32-bit] "
72#endif
73#endif
74
75#ifdef __INTEL_COMPILER
76#define NVM_COMPILEDBY  "[ICC %d]", __INTEL_COMPILER
77#elif  _MSC_VER
78#define NVM_COMPILEDBY  "[VS %d]", _MSC_VER
79#endif
80
81#ifndef NVM_COMPILEDBY
82#define NVM_COMPILEDBY "[Unk-CXX]"
83#endif
84
85#ifdef _WIN32
86#define NVM_ONOS        "[Windows]"
87#elif  __linux
88#define NVM_ONOS        "[Linux]"
89#elif  __CYGWIN__
90#define NVM_ONOS        "[Cygwin]"
91#elif __APPLE__
92#define NVM_ONOS        "[Mac OS X]"
93#else
94#define NVM_ONOS "[Unk-OS]"
95#endif
96
97#define NVM_BITS          "[%d bit] ", (sizeof(void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S
98
99#ifndef NULL
100#define NULL              0
101#endif
102
103
104// ====================================================================================================================
105// Common constants
106// ====================================================================================================================
107
108#define _SUMMARY_OUT_               0           ///< print-out PSNR results of all slices to summary.txt
109#define _SUMMARY_PIC_               0           ///< print-out PSNR results for each slice type to summary.txt
110
111#define MAX_REF_PIC_NUM             64
112#define MAX_GOP                     64          ///< max. value of hierarchical GOP size
113
114#define MAX_NUM_REF                 4           ///< max. value of multiple reference frames
115#if DCM_COMB_LIST
116#define MAX_NUM_REF_LC              8           ///< max. value of combined reference frames
117#endif
118
119#define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
120#define MAX_UINT64                  0xFFFFFFFFFFFFFFFFU
121#define MAX_INT                     2147483647  ///< max. value of signed 32-bit integer
122#define MIN_INT                     (-2147483647-1) // < min. value of signed 32-bit integer
123#define MAX_DOUBLE                  1.7e+308    ///< max. value of double-type value
124
125#define MIN_QP                      0
126#define MAX_QP                      51
127
128#define NOT_VALID                   -1
129
130#define STD_CAM_PARAMETERS_PRECISION 5        ///< quarter luma sample accuarcy for derived disparities (as default)
131
132#define MAX_INPUT_VIEW_NUM                                      10                              ///< max. number of input view for multiview coding
133
134#if HHI_VSO
135#define MAX_ERREF_VIEW_NUM                                      15                              ///< max. number of virtual external reference views
136#endif
137#define LOG2_DISP_PREC_LUT                              2                               ///< log2 of disparity precision used in integer disparity LUTs
138
139
140#if ( HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED )
141#define DEPTH_MAP_GENERATION        1
142#else
143#define DEPTH_MAP_GENERATION        0
144#endif
145
146//>>>>> generation and usage of virtual prediction depth maps >>>>>
147#define PDM_DEPTH_MAP_MCP_FILTER          2         // 0: standard filter, 1:bilinear, 2:nearest neighbour
148#define PDM_ONE_DEPTH_PER_PU              1         // use only a single depth for a prediction unit (in update)
149#define PDM_NO_INTER_UPDATE               0         // no update for inter (but not inter-view) predicted blocks
150#define PDM_MERGE_POS                     0         // position of pdm in merge list (0..5)
151#define PDM_AMVP_POS                      2         // position of pdm in amvp list  (0..3)
152#define PDM_OUTPUT_PRED_DEPTH_MAP         0         // output prediction depth map (for debugging)
153
154#define PDM_INTERNAL_CALC_BIT_DEPTH       31        // bit depth for internal calculations (32 - 1 for signed values)
155#define PDM_BITDEPTH_VIRT_DEPTH           15        // bit depth for virtual depth storage (16 - 1 for signed values)
156#define PDM_LOG2_MAX_ABS_NORMAL_DISPARITY 8         // maximum absolute normal disparity = 256 (for setting accuracy)
157#define PDM_VIRT_DEPTH_PRECISION          4         // must be greater than or equal to 2 (since MVs are given in quarter-pel units)
158
159#define PDM_INTER_CALC_SHIFT              ( PDM_INTERNAL_CALC_BIT_DEPTH - PDM_BITDEPTH_VIRT_DEPTH )         // avoids overflow
160#define PDM_LOG4_SCALE_DENOMINATOR        ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY + PDM_VIRT_DEPTH_PRECISION )  // accuracy of scaling factor
161#define PDM_OFFSET_SHIFT                  ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY )                             // accuracy of offset
162
163#define PDM_MAX_ABS_VIRT_DEPTH            (  ( 1 << PDM_BITDEPTH_VIRT_DEPTH ) - 1 )
164#define PDM_UNDEFINED_DEPTH               ( -( 1 << PDM_BITDEPTH_VIRT_DEPTH )     )
165
166#define PDM_USE_FOR_IVIEW                 1
167#define PDM_USE_FOR_INTER                 2
168#define PDM_USE_FOR_MERGE                 4
169//<<<<< generation and usage of virtual prediction depth maps <<<<<
170
171#define OUTPUT_RESIDUAL_PICTURES          0         // output residual pictures (for debugging)
172
173#define HHI_MPI_MERGE_POS                     0         // position of mvi in merge list (0..5)
174
175
176// ====================================================================================================================
177// Macro functions
178// ====================================================================================================================
179
180#define Max(x, y)                   ((x)>(y)?(x):(y))                                                 ///< max of (x, y)
181#define Min(x, y)                   ((x)<(y)?(x):(y))                                                 ///< min of (x, y)
182#define Median(a,b,c)               ((a)>(b)?(a)>(c)?(b)>(c)?(b):(c):(a):(b)>(c)?(a)>(c)?(a):(c):(b)) ///< 3-point median
183#define Clip(x)                     ( Min(g_uiIBDI_MAX, Max( 0, (x)) ) )                              ///< clip with bit-depth range
184#define Clip3( MinVal, MaxVal, a)   ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) )  ///< general min/max clip
185#define RemoveBitIncrement(x)       ( (x + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement )     ///< Remove Bit increment
186
187#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
188#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
189#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
190#define xFree( ptr )                _aligned_free  ( ptr )
191#else
192#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
193#define xFree( ptr )                free     ( ptr )
194#endif
195
196#define FATAL_ERROR_0(MESSAGE, EXITCODE)                      \
197{                                                             \
198  printf(MESSAGE);                                            \
199  exit(EXITCODE);                                             \
200}
201
202
203// ====================================================================================================================
204// Coding tool configuration
205// ====================================================================================================================
206
207// modified LCEC coefficient coding
208#if QC_MOD_LCEC
209#define MAX_TR1                           4
210#endif
211
212// AMVP: advanced motion vector prediction
213#define AMVP_MAX_NUM_CANDS          6           ///< max number of final candidates
214// MERGE
215#define MRG_MAX_NUM_CANDS           6
216
217// Reference memory management
218#define DYN_REF_FREE                0           ///< dynamic free of reference memories
219
220// defines for multiview coding
221#define MAX_NUMBER_VIEWS            10
222
223// Explicit temporal layer QP offset
224#define MAX_TLAYER                  10           ///< max number of temporal layer
225#define HB_LAMBDA_FOR_LDC           1           ///< use of B-style lambda for non-key pictures in low-delay mode
226
227// Fast estimation of generalized B in low-delay mode
228#define GPB_SIMPLE                  1           ///< Simple GPB mode
229#if     GPB_SIMPLE
230#define GPB_SIMPLE_UNI              1           ///< Simple mode for uni-direction
231#endif
232
233// Fast ME using smoother MV assumption
234#define FASTME_SMOOTHER_MV          1           ///< reduce ME time using faster option
235
236// Adaptive search range depending on POC difference
237#define ADAPT_SR_SCALE              1           ///< division factor for adaptive search range
238
239#define ENABLE_IBDI                 0
240
241#define CLIP_TO_709_RANGE           0
242
243// IBDI range restriction for skipping clip
244#define IBDI_NOCLIP_RANGE           0           ///< restrict max. value after IBDI to skip clip
245
246// Early-skip threshold (encoder)
247#define EARLY_SKIP_THRES            1.50        ///< if RD < thres*avg[BestSkipRD]
248
249const int g_iShift8x8    = 2;
250const int g_iShift16x16  = 2;
251const int g_iShift32x32  = 2;
252const int g_iShift64x64  = 2;
253
254
255
256//RENDERER
257#define REN_LUMA_MARGIN   ( g_uiMaxCUWidth + 12 )
258#define REN_VDWEIGHT_PREC  8
259#define REN_IS_FILLED     ( 1 << REN_VDWEIGHT_PREC )
260#define REN_USED_PEL       g_uiIBDI_MAX
261#define REN_UNUSED_PEL     0
262#define REN_IS_HOLE        0
263
264/* End of Rounding control */
265
266enum NalRefIdc
267{
268  NAL_REF_IDC_PRIORITY_LOWEST = 0,
269  NAL_REF_IDC_PRIORITY_LOW,
270  NAL_REF_IDC_PRIORITY_HIGH,
271  NAL_REF_IDC_PRIORITY_HIGHEST
272};
273
274enum NalUnitType
275{
276  NAL_UNIT_UNSPECIFIED_0 = 0,
277  NAL_UNIT_CODED_SLICE,
278  NAL_UNIT_CODED_SLICE_DATAPART_A,
279  NAL_UNIT_CODED_SLICE_DATAPART_B,
280#if DCM_DECODING_REFRESH
281  NAL_UNIT_CODED_SLICE_CDR,
282#else
283  NAL_UNIT_CODED_SLICE_DATAPART_C,
284#endif
285  NAL_UNIT_CODED_SLICE_IDR,
286  NAL_UNIT_SEI,
287  NAL_UNIT_SPS,
288  NAL_UNIT_PPS,
289  NAL_UNIT_ACCESS_UNIT_DELIMITER,
290  NAL_UNIT_END_OF_SEQUENCE,
291  NAL_UNIT_END_OF_STREAM,
292  NAL_UNIT_FILLER_DATA,
293  NAL_UNIT_RESERVED_13,
294  NAL_UNIT_RESERVED_14,
295  NAL_UNIT_RESERVED_15,
296  NAL_UNIT_RESERVED_16,
297  NAL_UNIT_RESERVED_17,
298  NAL_UNIT_RESERVED_18,
299  NAL_UNIT_RESERVED_19,
300  NAL_UNIT_RESERVED_20,
301  NAL_UNIT_RESERVED_21,
302  NAL_UNIT_RESERVED_22,
303  NAL_UNIT_RESERVED_23,
304  NAL_UNIT_UNSPECIFIED_24,
305  NAL_UNIT_UNSPECIFIED_25,
306  NAL_UNIT_UNSPECIFIED_26,
307  NAL_UNIT_UNSPECIFIED_27,
308  NAL_UNIT_UNSPECIFIED_28,
309  NAL_UNIT_UNSPECIFIED_29,
310  NAL_UNIT_UNSPECIFIED_30,
311  NAL_UNIT_UNSPECIFIED_31,
312  NAL_UNIT_INVALID,
313};
314
315typedef _AlfParam    ALFParam;
316#if MTK_SAO
317typedef _SaoParam    SAOParam;
318#endif
319
320
321class VideoCodecException
322{
323public:
324  VideoCodecException() : m_acFile( "unspecified" ), m_uiLine( 0 ) {}
325  VideoCodecException( const char *pcFile, UInt uiLine ) : m_acFile( pcFile ), m_uiLine( uiLine ) {}
326
327  std::string exceptionFile() const { return m_acFile; }
328  UInt        exceptionLine() const { return m_uiLine; }
329
330private:
331  std::string m_acFile;
332  UInt        m_uiLine;
333};
334
335#define RETURN_ERR_ON_EXCEPTION \
336catch( std::exception &cEx ) \
337{ \
338  std::cerr << "Abnormal program termination: " << cEx.what() << std::endl; \
339  return Err::m_nERR; \
340} \
341catch( VideoCodecException &cEx ) \
342{ \
343  std::cerr << std::endl << "VideoCodecExcteption caught at: " << std::endl; \
344  std::cerr << "File: " << cEx.exceptionFile() << std::endl; \
345  std::cerr << "Line: " << cEx.exceptionLine() << std::endl; \
346  return Err::m_nERR; \
347} \
348catch( ... ) \
349{ \
350  std::cerr << "Caught unknown exception" << std::endl; \
351  return Err::m_nERR; \
352}
353
354
355#define TOT(  exp ) { if(                exp  ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
356#define TOF(  exp ) { if(              !(exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
357#define TNOK( exp ) { if( Err::m_nOK != (exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
358
359#if defined( _DEBUG )
360
361  #define TOT_DBG( exp )    TOT( exp )
362  #define TOF_DBG( exp )    TOF( exp )
363
364#else
365
366  #define TOT_DBG( exp )    ((void)0)
367  #define TOF_DBG( exp )    ((void)0)
368
369#endif
370
371typedef int            ErrVal;
372
373
374class Err
375{
376public:
377  enum
378  {
379    m_nOK               =  0,
380    m_nERR              = -1,
381    m_nEndOfFile        = -2,
382    m_nEndOfBuffer      = -3,
383    m_nInvalidParameter = -4,
384    m_nDataNotAvailable = -5,
385    m_nSizeNotAvailable = -5,
386  };
387};
388
389
390#define ROF( exp )            \
391{                             \
392  if( !( exp ) )              \
393  {                           \
394    assert( 0 );              \
395    return -1;                \
396  }                           \
397}
398
399#define ROT( exp )            \
400{                             \
401  if( ( exp ) )               \
402  {                           \
403    assert( 0 );              \
404    return -1;                \
405  }                           \
406}
407
408#define ROFS( exp )           \
409{                             \
410  if( !( exp ) )              \
411  {                           \
412    return -1;                \
413  }                           \
414}
415
416#define ROTS( exp )           \
417{                             \
418  if( ( exp ) )               \
419  {                           \
420    return -1;                \
421  }                           \
422}
423
424#define ROFR( exp, retVal )   \
425{                             \
426  if( !( exp ) )              \
427  {                           \
428    assert( 0 );              \
429    return retVal;            \
430  }                           \
431}
432
433#define ROTR( exp, retVal )   \
434{                             \
435  if( ( exp ) )               \
436  {                           \
437    assert( 0 );              \
438    return retVal;            \
439  }                           \
440}
441
442#define ROFRS( exp, retVal )  \
443{                             \
444  if( !( exp ) )              \
445  {                           \
446    return retVal;            \
447  }                           \
448}
449
450#define ROTRS( exp, retVal )  \
451{                             \
452  if( ( exp ) )               \
453  {                           \
454    return retVal;            \
455  }                           \
456}
457
458#define ROFV( exp )           \
459{                             \
460  if( !( exp ) )              \
461  {                           \
462    assert( 0 );              \
463    return;                   \
464  }                           \
465}
466
467#define ROTV( exp )           \
468{                             \
469  if( ( exp ) )               \
470  {                           \
471    assert( 0 );              \
472    return;                   \
473  }                           \
474}
475
476#define ROFVS( exp )          \
477{                             \
478  if( !( exp ) )              \
479  {                           \
480    return;                   \
481  }                           \
482}
483
484#define ROTVS( exp )          \
485{                             \
486  if( ( exp ) )               \
487  {                           \
488    return;                   \
489  }                           \
490}
491
492#define RNOK( exp )                   \
493{                                     \
494  const ErrVal nMSysRetVal = ( exp ); \
495  if( 0 != nMSysRetVal )              \
496  {                                   \
497    assert( 0 );                      \
498    return nMSysRetVal;               \
499  }                                   \
500}
501
502#define RNOKR( exp, retVal )        \
503{                                   \
504  if( 0 != ( exp ) )                \
505  {                                 \
506    assert( 0 );                    \
507    return retVal;                  \
508  }                                 \
509}
510
511#define RNOKS( exp )                  \
512{                                     \
513  const ErrVal nMSysRetVal = ( exp ); \
514  if( 0 != nMSysRetVal )              \
515  {                                   \
516    return nMSysRetVal;               \
517  }                                   \
518}
519
520#define RNOKRS( exp, retVal )       \
521{                                   \
522  if( 0 != ( exp ) )                \
523  {                                 \
524    return retVal;                  \
525  }                                 \
526}
527
528#define RNOKV( exp )                \
529{                                   \
530  if( 0 != ( exp ) )                \
531  {                                 \
532    assert( 0 );                    \
533    return;                         \
534  }                                 \
535}
536
537#define RNOKVS( exp )               \
538{                                   \
539  if( 0 != ( exp ) )                \
540  {                                 \
541    return;                         \
542  }                                 \
543}
544
545#define ANOK( exp )                 \
546{                                   \
547  if( 0 != ( exp ) )                \
548  {                                 \
549    assert( 0 );                    \
550  }                                 \
551}
552
553#define AOF( exp )                  \
554{                                   \
555  if( !( exp ) )                    \
556  {                                 \
557    assert( 0 );                    \
558  }                                 \
559}
560
561#define AOT( exp )            \
562{                             \
563  if( ( exp ) )               \
564  {                           \
565    assert( 0 );              \
566  }                           \
567}
568
569#if defined( _DEBUG )
570
571  #define AOT_DBG( exp )    AOT( exp )
572  #define AOF_DBG( exp )    AOF( exp )
573
574#else
575
576  #define AOT_DBG( exp )    ((void)0)
577  #define AOF_DBG( exp )    ((void)0)
578
579#endif
580
581#define DISABLE_DEFAULT_CPYCTOR_AND_ASOP(x) private: x( const x &r ); const x& operator=( const x &r )
582typedef Int64 PicOrderCnt;
583
584template<class T>
585class AutoDeletePtrVector
586  : public std::vector<T*>
587{
588public:
589  AutoDeletePtrVector() {}
590
591  virtual ~AutoDeletePtrVector()
592  {
593    while( !std::vector<T*>::empty() )
594    {
595      delete std::vector<T*>::back();
596      std::vector<T*>::pop_back();
597    }
598  }
599
600  DISABLE_DEFAULT_CPYCTOR_AND_ASOP( AutoDeletePtrVector );
601};
602
603  template<class T>
604  __inline T gAbs(const T& x)
605  {
606    return x < 0 ? -x : x;
607  }
608//
609
610template <typename T>
611__inline T gSign(const T& t)
612{
613    if( t == 0 )
614        return T(0);
615    else
616        return (t < 0) ? T(-1) : T(1);
617}
618
619
620
621#endif // end of #ifndef  __COMMONDEF__
622
Note: See TracBrowser for help on using the repository browser.