source: 3DVCSoftware/branches/0.2-poznan-univ/source/Lib/TLibCommon/CommonDef.h @ 11

Last change on this file since 11 was 11, checked in by poznan-univ, 13 years ago

Poznan disocclusion coding - CU Skip

  • Property svn:eol-style set to native
File size: 20.4 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.3"                   ///< 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#if ( HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED )
140#define DEPTH_MAP_GENERATION        1
141#else
142#define DEPTH_MAP_GENERATION        0
143#endif
144
145//>>>>> generation and usage of virtual prediction depth maps >>>>>
146#define PDM_DEPTH_MAP_MCP_FILTER          2         // 0: standard filter, 1:bilinear, 2:nearest neighbour
147#define PDM_ONE_DEPTH_PER_PU              1         // use only a single depth for a prediction unit (in update)
148#define PDM_NO_INTER_UPDATE               0         // no update for inter (but not inter-view) predicted blocks
149#define PDM_MERGE_POS                     0         // position of pdm in merge list (0..5)
150#define PDM_AMVP_POS                      2         // position of pdm in amvp list  (0..3)
151#define PDM_OUTPUT_PRED_DEPTH_MAP         0         // output prediction depth map (for debugging)
152
153#define PDM_INTERNAL_CALC_BIT_DEPTH       31        // bit depth for internal calculations (32 - 1 for signed values)
154#define PDM_BITDEPTH_VIRT_DEPTH           15        // bit depth for virtual depth storage (16 - 1 for signed values)
155#define PDM_LOG2_MAX_ABS_NORMAL_DISPARITY 8         // maximum absolute normal disparity = 256 (for setting accuracy)
156#define PDM_VIRT_DEPTH_PRECISION          4         // must be greater than or equal to 2 (since MVs are given in quarter-pel units)
157
158#define PDM_INTER_CALC_SHIFT              ( PDM_INTERNAL_CALC_BIT_DEPTH - PDM_BITDEPTH_VIRT_DEPTH )         // avoids overflow
159#define PDM_LOG4_SCALE_DENOMINATOR        ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY + PDM_VIRT_DEPTH_PRECISION )  // accuracy of scaling factor
160#define PDM_OFFSET_SHIFT                  ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY )                             // accuracy of offset
161
162#define PDM_MAX_ABS_VIRT_DEPTH            (  ( 1 << PDM_BITDEPTH_VIRT_DEPTH ) - 1 )
163#define PDM_UNDEFINED_DEPTH               ( -( 1 << PDM_BITDEPTH_VIRT_DEPTH )     )
164
165#define PDM_USE_FOR_IVIEW                 1
166#define PDM_USE_FOR_INTER                 2
167#define PDM_USE_FOR_MERGE                 4
168//<<<<< generation and usage of virtual prediction depth maps <<<<<
169
170#define OUTPUT_RESIDUAL_PICTURES          0         // output residual pictures (for debugging)
171
172#define HHI_MPI_MERGE_POS                 0           // position of mvi in merge list (0..5)
173
174// ====================================================================================================================
175// POZNAN DEFINE SECTION
176// ====================================================================================================================
177#define POZNAN_OUTPUT_AVAILABLE_MAP       0           // output available map (for debugging)
178#define POZNAN_OUTPUT_SYNTH               0           // output synthesised view (for debugging)
179
180// ====================================================================================================================
181// Macro functions
182// ====================================================================================================================
183
184#define Max(x, y)                   ((x)>(y)?(x):(y))                                                 ///< max of (x, y)
185#define Min(x, y)                   ((x)<(y)?(x):(y))                                                 ///< min of (x, y)
186#define Median(a,b,c)               ((a)>(b)?(a)>(c)?(b)>(c)?(b):(c):(a):(b)>(c)?(a)>(c)?(a):(c):(b)) ///< 3-point median
187#define Clip(x)                     ( Min(g_uiIBDI_MAX, Max( 0, (x)) ) )                              ///< clip with bit-depth range
188#define Clip3( MinVal, MaxVal, a)   ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) )  ///< general min/max clip
189#define RemoveBitIncrement(x)       ( (x + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement )     ///< Remove Bit increment
190
191#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
192#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
193#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
194#define xFree( ptr )                _aligned_free  ( ptr )
195#else
196#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
197#define xFree( ptr )                free     ( ptr )
198#endif
199
200#define FATAL_ERROR_0(MESSAGE, EXITCODE)                      \
201{                                                             \
202  printf(MESSAGE);                                            \
203  exit(EXITCODE);                                             \
204}
205
206
207// ====================================================================================================================
208// Coding tool configuration
209// ====================================================================================================================
210
211// modified LCEC coefficient coding
212#if QC_MOD_LCEC
213#define MAX_TR1                           4
214#endif
215
216// AMVP: advanced motion vector prediction
217#define AMVP_MAX_NUM_CANDS          6           ///< max number of final candidates
218// MERGE
219#define MRG_MAX_NUM_CANDS           6
220
221// Reference memory management
222#define DYN_REF_FREE                0           ///< dynamic free of reference memories
223
224// defines for multiview coding
225#define MAX_NUMBER_VIEWS            10
226
227// Explicit temporal layer QP offset
228#define MAX_TLAYER                  10           ///< max number of temporal layer
229#define HB_LAMBDA_FOR_LDC           1           ///< use of B-style lambda for non-key pictures in low-delay mode
230
231// Fast estimation of generalized B in low-delay mode
232#define GPB_SIMPLE                  1           ///< Simple GPB mode
233#if     GPB_SIMPLE
234#define GPB_SIMPLE_UNI              1           ///< Simple mode for uni-direction
235#endif
236
237// Fast ME using smoother MV assumption
238#define FASTME_SMOOTHER_MV          1           ///< reduce ME time using faster option
239
240// Adaptive search range depending on POC difference
241#define ADAPT_SR_SCALE              1           ///< division factor for adaptive search range
242
243#define ENABLE_IBDI                 0
244
245#define CLIP_TO_709_RANGE           0
246
247// IBDI range restriction for skipping clip
248#define IBDI_NOCLIP_RANGE           0           ///< restrict max. value after IBDI to skip clip
249
250// Early-skip threshold (encoder)
251#define EARLY_SKIP_THRES            1.50        ///< if RD < thres*avg[BestSkipRD]
252
253const int g_iShift8x8    = 2;
254const int g_iShift16x16  = 2;
255const int g_iShift32x32  = 2;
256const int g_iShift64x64  = 2;
257
258
259
260//RENDERER
261#define REN_LUMA_MARGIN   ( g_uiMaxCUWidth + 12 )
262#define REN_VDWEIGHT_PREC  8
263#define REN_IS_FILLED     ( 1 << REN_VDWEIGHT_PREC )
264#define REN_USED_PEL       g_uiIBDI_MAX
265#define REN_UNUSED_PEL     0
266#define REN_IS_HOLE        0
267
268/* End of Rounding control */
269
270enum NalRefIdc
271{
272  NAL_REF_IDC_PRIORITY_LOWEST = 0,
273  NAL_REF_IDC_PRIORITY_LOW,
274  NAL_REF_IDC_PRIORITY_HIGH,
275  NAL_REF_IDC_PRIORITY_HIGHEST
276};
277
278enum NalUnitType
279{
280  NAL_UNIT_UNSPECIFIED_0 = 0,
281  NAL_UNIT_CODED_SLICE,
282  NAL_UNIT_CODED_SLICE_DATAPART_A,
283  NAL_UNIT_CODED_SLICE_DATAPART_B,
284#if DCM_DECODING_REFRESH
285  NAL_UNIT_CODED_SLICE_CDR,
286#else
287  NAL_UNIT_CODED_SLICE_DATAPART_C,
288#endif
289  NAL_UNIT_CODED_SLICE_IDR,
290  NAL_UNIT_SEI,
291  NAL_UNIT_SPS,
292  NAL_UNIT_PPS,
293  NAL_UNIT_ACCESS_UNIT_DELIMITER,
294  NAL_UNIT_END_OF_SEQUENCE,
295  NAL_UNIT_END_OF_STREAM,
296  NAL_UNIT_FILLER_DATA,
297  NAL_UNIT_RESERVED_13,
298  NAL_UNIT_RESERVED_14,
299  NAL_UNIT_RESERVED_15,
300  NAL_UNIT_RESERVED_16,
301  NAL_UNIT_RESERVED_17,
302  NAL_UNIT_RESERVED_18,
303  NAL_UNIT_RESERVED_19,
304  NAL_UNIT_RESERVED_20,
305  NAL_UNIT_RESERVED_21,
306  NAL_UNIT_RESERVED_22,
307  NAL_UNIT_RESERVED_23,
308  NAL_UNIT_UNSPECIFIED_24,
309  NAL_UNIT_UNSPECIFIED_25,
310  NAL_UNIT_UNSPECIFIED_26,
311  NAL_UNIT_UNSPECIFIED_27,
312  NAL_UNIT_UNSPECIFIED_28,
313  NAL_UNIT_UNSPECIFIED_29,
314  NAL_UNIT_UNSPECIFIED_30,
315  NAL_UNIT_UNSPECIFIED_31,
316  NAL_UNIT_INVALID,
317};
318
319typedef _AlfParam    ALFParam;
320#if MTK_SAO
321typedef _SaoParam    SAOParam;
322#endif
323
324
325class VideoCodecException
326{
327public:
328  VideoCodecException() : m_acFile( "unspecified" ), m_uiLine( 0 ) {}
329  VideoCodecException( const char *pcFile, UInt uiLine ) : m_acFile( pcFile ), m_uiLine( uiLine ) {}
330
331  std::string exceptionFile() const { return m_acFile; }
332  UInt        exceptionLine() const { return m_uiLine; }
333
334private:
335  std::string m_acFile;
336  UInt        m_uiLine;
337};
338
339#define RETURN_ERR_ON_EXCEPTION \
340catch( std::exception &cEx ) \
341{ \
342  std::cerr << "Abnormal program termination: " << cEx.what() << std::endl; \
343  return Err::m_nERR; \
344} \
345catch( VideoCodecException &cEx ) \
346{ \
347  std::cerr << std::endl << "VideoCodecExcteption caught at: " << std::endl; \
348  std::cerr << "File: " << cEx.exceptionFile() << std::endl; \
349  std::cerr << "Line: " << cEx.exceptionLine() << std::endl; \
350  return Err::m_nERR; \
351} \
352catch( ... ) \
353{ \
354  std::cerr << "Caught unknown exception" << std::endl; \
355  return Err::m_nERR; \
356}
357
358
359#define TOT(  exp ) { if(                exp  ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
360#define TOF(  exp ) { if(              !(exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
361#define TNOK( exp ) { if( Err::m_nOK != (exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } }
362
363#if defined( _DEBUG )
364
365  #define TOT_DBG( exp )    TOT( exp )
366  #define TOF_DBG( exp )    TOF( exp )
367
368#else
369
370  #define TOT_DBG( exp )    ((void)0)
371  #define TOF_DBG( exp )    ((void)0)
372
373#endif
374
375typedef int            ErrVal;
376
377
378class Err
379{
380public:
381  enum
382  {
383    m_nOK               =  0,
384    m_nERR              = -1,
385    m_nEndOfFile        = -2,
386    m_nEndOfBuffer      = -3,
387    m_nInvalidParameter = -4,
388    m_nDataNotAvailable = -5,
389    m_nSizeNotAvailable = -5,
390  };
391};
392
393
394#define ROF( exp )            \
395{                             \
396  if( !( exp ) )              \
397  {                           \
398    assert( 0 );              \
399    return -1;                \
400  }                           \
401}
402
403#define ROT( exp )            \
404{                             \
405  if( ( exp ) )               \
406  {                           \
407    assert( 0 );              \
408    return -1;                \
409  }                           \
410}
411
412#define ROFS( exp )           \
413{                             \
414  if( !( exp ) )              \
415  {                           \
416    return -1;                \
417  }                           \
418}
419
420#define ROTS( exp )           \
421{                             \
422  if( ( exp ) )               \
423  {                           \
424    return -1;                \
425  }                           \
426}
427
428#define ROFR( exp, retVal )   \
429{                             \
430  if( !( exp ) )              \
431  {                           \
432    assert( 0 );              \
433    return retVal;            \
434  }                           \
435}
436
437#define ROTR( exp, retVal )   \
438{                             \
439  if( ( exp ) )               \
440  {                           \
441    assert( 0 );              \
442    return retVal;            \
443  }                           \
444}
445
446#define ROFRS( exp, retVal )  \
447{                             \
448  if( !( exp ) )              \
449  {                           \
450    return retVal;            \
451  }                           \
452}
453
454#define ROTRS( exp, retVal )  \
455{                             \
456  if( ( exp ) )               \
457  {                           \
458    return retVal;            \
459  }                           \
460}
461
462#define ROFV( exp )           \
463{                             \
464  if( !( exp ) )              \
465  {                           \
466    assert( 0 );              \
467    return;                   \
468  }                           \
469}
470
471#define ROTV( exp )           \
472{                             \
473  if( ( exp ) )               \
474  {                           \
475    assert( 0 );              \
476    return;                   \
477  }                           \
478}
479
480#define ROFVS( exp )          \
481{                             \
482  if( !( exp ) )              \
483  {                           \
484    return;                   \
485  }                           \
486}
487
488#define ROTVS( exp )          \
489{                             \
490  if( ( exp ) )               \
491  {                           \
492    return;                   \
493  }                           \
494}
495
496#define RNOK( exp )                   \
497{                                     \
498  const ErrVal nMSysRetVal = ( exp ); \
499  if( 0 != nMSysRetVal )              \
500  {                                   \
501    assert( 0 );                      \
502    return nMSysRetVal;               \
503  }                                   \
504}
505
506#define RNOKR( exp, retVal )        \
507{                                   \
508  if( 0 != ( exp ) )                \
509  {                                 \
510    assert( 0 );                    \
511    return retVal;                  \
512  }                                 \
513}
514
515#define RNOKS( exp )                  \
516{                                     \
517  const ErrVal nMSysRetVal = ( exp ); \
518  if( 0 != nMSysRetVal )              \
519  {                                   \
520    return nMSysRetVal;               \
521  }                                   \
522}
523
524#define RNOKRS( exp, retVal )       \
525{                                   \
526  if( 0 != ( exp ) )                \
527  {                                 \
528    return retVal;                  \
529  }                                 \
530}
531
532#define RNOKV( exp )                \
533{                                   \
534  if( 0 != ( exp ) )                \
535  {                                 \
536    assert( 0 );                    \
537    return;                         \
538  }                                 \
539}
540
541#define RNOKVS( exp )               \
542{                                   \
543  if( 0 != ( exp ) )                \
544  {                                 \
545    return;                         \
546  }                                 \
547}
548
549#define ANOK( exp )                 \
550{                                   \
551  if( 0 != ( exp ) )                \
552  {                                 \
553    assert( 0 );                    \
554  }                                 \
555}
556
557#define AOF( exp )                  \
558{                                   \
559  if( !( exp ) )                    \
560  {                                 \
561    assert( 0 );                    \
562  }                                 \
563}
564
565#define AOT( exp )            \
566{                             \
567  if( ( exp ) )               \
568  {                           \
569    assert( 0 );              \
570  }                           \
571}
572
573#if defined( _DEBUG )
574
575  #define AOT_DBG( exp )    AOT( exp )
576  #define AOF_DBG( exp )    AOF( exp )
577
578#else
579
580  #define AOT_DBG( exp )    ((void)0)
581  #define AOF_DBG( exp )    ((void)0)
582
583#endif
584
585#define DISABLE_DEFAULT_CPYCTOR_AND_ASOP(x) private: x( const x &r ); const x& operator=( const x &r )
586typedef Int64 PicOrderCnt;
587
588template<class T>
589class AutoDeletePtrVector
590  : public std::vector<T*>
591{
592public:
593  AutoDeletePtrVector() {}
594
595  virtual ~AutoDeletePtrVector()
596  {
597    while( !std::vector<T*>::empty() )
598    {
599      delete std::vector<T*>::back();
600      std::vector<T*>::pop_back();
601    }
602  }
603
604  DISABLE_DEFAULT_CPYCTOR_AND_ASOP( AutoDeletePtrVector );
605};
606
607  template<class T>
608  __inline T gAbs(const T& x)
609  {
610    return x < 0 ? -x : x;
611  }
612//
613
614template <typename T>
615__inline T gSign(const T& t)
616{
617    if( t == 0 )
618        return T(0);
619    else
620        return (t < 0) ? T(-1) : T(1);
621}
622
623
624
625#endif // end of #ifndef  __COMMONDEF__
626
Note: See TracBrowser for help on using the repository browser.