source: SHVCSoftware/branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp @ 447

Last change on this file since 447 was 445, checked in by seregin, 12 years ago

enable layer-specific CTB structure

  • Property svn:eol-style set to native
File size: 14.7 KB
RevLine 
[313]1/** \file     TAppEncLayerCfg.cpp
2\brief    Handle encoder configuration parameters
3*/
4
5#include <stdlib.h>
6#include <cassert>
7#include <cstring>
8#include <string>
9#include "TLibCommon/TComRom.h"
10#include "TAppEncCfg.h"
11#include "TAppEncLayerCfg.h"
12#include "TAppCommon/program_options_lite.h"
13
14#ifdef WIN32
15#define strdup _strdup
16#endif
17
18using namespace std;
19namespace po = df::program_options_lite;
20
21//! \ingroup TAppEncoder
22//! \{
23
24
25// ====================================================================================================================
26// Constructor / destructor / initialization / destroy
27// ====================================================================================================================
28#if SVC_EXTENSION
29TAppEncLayerCfg::TAppEncLayerCfg()
30  :m_cInputFile(string("")),
31  m_cReconFile(string("")),
32  m_conformanceMode( 0 ),
33  m_aidQP(NULL)
[442]34#if REPN_FORMAT_IN_VPS
35, m_repFormatIdx (-1)
36#endif
[313]37{
38  m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
39  m_aiPad[1] = m_aiPad[0] = 0;
40#if SCALED_REF_LAYER_OFFSETS
41  m_numScaledRefLayerOffsets = 0;
42  ::memset(m_scaledRefLayerLeftOffset,   0, sizeof(m_scaledRefLayerLeftOffset));
43  ::memset(m_scaledRefLayerTopOffset,    0, sizeof(m_scaledRefLayerTopOffset));
44  ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
45  ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
46#endif
47}
48
49TAppEncLayerCfg::~TAppEncLayerCfg()
50{
51  if ( m_aidQP )
52  {
53    delete[] m_aidQP;
54  }
55}
56
57Void TAppEncLayerCfg::create()
58{
59}
60
61Void TAppEncLayerCfg::destroy()
62{
63}
64
65
66// ====================================================================================================================
67// Public member functions
68// ====================================================================================================================
69
70/** \param  argc        number of arguments
71\param  argv        array of arguments
72\retval             true when success
73*/
74bool TAppEncLayerCfg::parseCfg( const string& cfgFileName  )
75{
76  string cfg_InputFile;
77  string cfg_ReconFile;
78  string cfg_dQPFile;
79  po::Options opts;
80  opts.addOptions()
81    ("InputFile,i",           cfg_InputFile,  string(""), "original YUV input file name")
82#if AVC_BASE
83    ("InputBLFile,-ibl",      cfg_InputFile,  string(""), "original YUV input file name")
84#endif
85    ("ReconFile,o",           cfg_ReconFile,  string(""), "reconstructed YUV output file name")
86    ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
87    ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
88    ("CroppingMode",          m_conformanceMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
89    ("CropLeft",              m_confLeft,      0, "Left cropping/padding for cropping mode 3")
90    ("CropRight",             m_confRight,     0, "Right cropping/padding for cropping mode 3")
91    ("CropTop",               m_confTop,       0, "Top cropping/padding for cropping mode 3")
92    ("CropBottom",            m_confBottom,    0, "Bottom cropping/padding for cropping mode 3")
93    ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
94    ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
95    ("IntraPeriod,-ip",       m_iIntraPeriod,  -1, "intra period in frames, (-1: only first frame)")
96    ("FrameRate,-fr",         m_iFrameRate,    0, "Frame rate")
97    ("dQPFile,m",             cfg_dQPFile, string(""), "dQP file name")
98    ("QP,q",                  m_fQP,          30.0, "Qp value, if value is float, QP is switched once during encoding")
99    ;
100
101  po::setDefaults(opts);
102  po::parseConfigFile(opts, cfgFileName);
103
104  m_cInputFile = cfg_InputFile;
105  m_cReconFile = cfg_ReconFile;
106  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
107
108  // reading external dQP description from file
109  if ( m_pchdQPFile )
110  {
111    FILE* fpt=fopen( m_pchdQPFile, "r" );
112    if ( fpt )
113    {
114      Int iValue;
115      Int iPOC = 0;
116      while ( iPOC < m_cAppEncCfg->getNumFrameToBeEncoded() )
117      {
118        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
119        m_aidQP[ iPOC ] = iValue;
120        iPOC++;
121      }
122      fclose(fpt);
123    }
124  }
125  return true;
126}
127
128#if AVC_SYNTAX
129Void TAppEncLayerCfg::xPrintParameter( UInt layerId )
130#else
131Void TAppEncLayerCfg::xPrintParameter()
132#endif
133{
134  printf("Input File                    : %s\n", m_cInputFile.c_str()  );
135  printf("Reconstruction File           : %s\n", m_cReconFile.c_str()  );
136#if AVC_SYNTAX
137  if( layerId == 0 )
138  {
139    printf("Base layer syntax file        : %s\n", m_cAppEncCfg->getBLSyntaxFile() );
140  }
141#endif
142  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
143  printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
[445]144#if LAYER_CTB
145  printf("CU size / depth               : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
146  printf("RQT trans. size (min / max)   : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
147  printf("Max RQT depth inter           : %d\n", m_uiQuadtreeTUMaxDepthInter);
148  printf("Max RQT depth intra           : %d\n", m_uiQuadtreeTUMaxDepthIntra);
149#endif
[313]150  printf("QP                            : %5.2f\n", m_fQP );
151  printf("Intra period                  : %d\n", m_iIntraPeriod );
152#if RC_SHVC_HARMONIZATION
153  printf("RateControl                   : %d\n", m_RCEnableRateControl );
154  if(m_RCEnableRateControl)
155  {
156    printf("TargetBitrate                 : %d\n", m_RCTargetBitrate );
157    printf("KeepHierarchicalBit           : %d\n", m_RCKeepHierarchicalBit );
158    printf("LCULevelRC                    : %d\n", m_RCLCULevelRC );
159    printf("UseLCUSeparateModel           : %d\n", m_RCUseLCUSeparateModel );
160    printf("InitialQP                     : %d\n", m_RCInitialQP );
161    printf("ForceIntraQP                  : %d\n", m_RCForceIntraQP );
162  }
163#endif
164  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
[445]165#if LAYER_CTB
166  printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0);
167#endif
[313]168}
169
170Bool confirmPara(Bool bflag, const char* message);
171
[442]172Bool TAppEncLayerCfg::xCheckParameter( Bool isField )
[313]173{
174  switch (m_conformanceMode)
175  {
176  case 0:
177    {
178      // no cropping or padding
179      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
180      m_aiPad[1] = m_aiPad[0] = 0;
181      break;
182    }
183  case 1:
184    {
185      // automatic padding to minimum CU size
[445]186#if LAYER_CTB
187      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
188#else
[313]189      Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
[445]190#endif
[313]191      if (m_iSourceWidth % minCuSize)
192      {
193        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
194        m_iSourceWidth  += m_confRight;
195      }
196      if (m_iSourceHeight % minCuSize)
197      {
198        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
199        m_iSourceHeight += m_confBottom;
[442]200        if ( isField )
201        {
202          m_iSourceHeightOrg += m_confBottom << 1;
203          m_aiPad[1] = m_confBottom << 1;
204        }
[313]205      }
206      break;
207    }
208  case 2:
209    {
210      //padding
211      m_iSourceWidth  += m_aiPad[0];
212      m_iSourceHeight += m_aiPad[1];
213      m_confRight  = m_aiPad[0];
214      m_confBottom = m_aiPad[1];
215      break;
216    }
217  case 3:
218    {
219      // conformance
220      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
221      {
222        fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
223      }
224      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
225      {
226        fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n");
227      }
228      m_aiPad[1] = m_aiPad[0] = 0;
229      break;
230    }
231  }
232
233  // allocate slice-based dQP values
234  Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded();
235  Int iGOPSize = m_cAppEncCfg->getGOPSize();
236  if( m_aidQP == NULL )
237    m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ];
238  ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) );
239
240  // handling of floating-point QP values
241  // if QP is not integer, sequence is split into two sections having QP and QP+1
242  m_iQP = (Int)( m_fQP );
243  if ( m_iQP < m_fQP )
244  {
245    Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 );
246
247
248    iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize;
249    for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ )
250    {
251      m_aidQP[i] = 1;
252    }
253  }
254
[445]255#if LAYER_CTB
256  UInt maxCUWidth = m_uiMaxCUWidth;
257  UInt maxCUHeight = m_uiMaxCUHeight;
258  UInt maxCUDepth = m_uiMaxCUDepth;
259#else
[313]260  UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
261  UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
262  UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
[445]263#endif
[313]264  bool check_failed = false; /* abort if there is a fatal configuration problem */
265#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
266  // check range of parameters
267  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
268  xConfirmPara( (m_iSourceWidth  % (maxCUWidth  >> (maxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
269  xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
270  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
271  if (m_cAppEncCfg->getDecodingRefreshType() == 2)
272  {
273    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
274  }
275
276  xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
277
278
[445]279  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1;
[313]280  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
281  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
282
283  //chekc parameters
284  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
285  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
286
287  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
288  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
289
290  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
291  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
292  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
293  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
[445]294
295#if LAYER_CTB 
296  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
297  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
298  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
299  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
300  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
301  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
302  xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth,                                        "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
303  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
304  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
305  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
306  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
307  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
308  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
309  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthInter - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
310  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
311  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
312
313  // max CU width and height should be power of 2
314  UInt ui = m_uiMaxCUWidth;
315  while(ui)
316  {
317    ui >>= 1;
318    if( (ui & 1) == 1)
319      xConfirmPara( ui != 1 , "Width should be 2^n");
320  }
321  ui = m_uiMaxCUHeight;
322  while(ui)
323  {
324    ui >>= 1;
325    if( (ui & 1) == 1)
326      xConfirmPara( ui != 1 , "Height should be 2^n");
327  }
328#endif
329
[313]330#undef xConfirmPara
331  return check_failed;
332}
333
334#endif
335
336
337//! \}
Note: See TracBrowser for help on using the repository browser.