source: SHVCSoftware/branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.cpp @ 74

Last change on this file since 74 was 54, checked in by seregin, 13 years ago

port simulcast

File size: 10.0 KB
Line 
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)
34{
35  m_aiPad[1] = m_aiPad[0] = 0;
36}
37
38TAppEncLayerCfg::~TAppEncLayerCfg()
39{
40  if ( m_aidQP )
41  {
42    delete[] m_aidQP;
43  }
44}
45
46Void TAppEncLayerCfg::create()
47{
48}
49
50Void TAppEncLayerCfg::destroy()
51{
52}
53
54
55// ====================================================================================================================
56// Public member functions
57// ====================================================================================================================
58
59/** \param  argc        number of arguments
60\param  argv        array of arguments
61\retval             true when success
62*/
63bool TAppEncLayerCfg::parseCfg( const string& cfgFileName  )
64{
65  string cfg_InputFile;
66  string cfg_ReconFile;
67  string cfg_dQPFile;
68  po::Options opts;
69  opts.addOptions()
70    ("InputFile,i",           cfg_InputFile,  string(""), "original YUV input file name")
71#if AVC_BASE
72    ("InputBLFile,-ibl",      cfg_InputFile,  string(""), "original YUV input file name")
73#endif
74    ("ReconFile,o",           cfg_ReconFile,  string(""), "reconstructed YUV output file name")
75    ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
76    ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
77    ("CroppingMode",          m_conformanceMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
78    ("CropLeft",              m_confLeft,      0, "Left cropping/padding for cropping mode 3")
79    ("CropRight",             m_confRight,     0, "Right cropping/padding for cropping mode 3")
80    ("CropTop",               m_confTop,       0, "Top cropping/padding for cropping mode 3")
81    ("CropBottom",            m_confBottom,    0, "Bottom cropping/padding for cropping mode 3")
82    ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
83    ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
84    ("IntraPeriod,-ip",       m_iIntraPeriod,  -1, "intra period in frames, (-1: only first frame)")
85    ("FrameRate,-fr",         m_iFrameRate,    0, "Frame rate")
86    ("dQPFile,m",             cfg_dQPFile, string(""), "dQP file name")
87    ("QP,q",                  m_fQP,          30.0, "Qp value, if value is float, QP is switched once during encoding")
88    ;
89
90  po::setDefaults(opts);
91  po::parseConfigFile(opts, cfgFileName);
92
93  m_cInputFile = cfg_InputFile;
94  m_cReconFile = cfg_ReconFile;
95  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
96
97  // reading external dQP description from file
98  if ( m_pchdQPFile )
99  {
100    FILE* fpt=fopen( m_pchdQPFile, "r" );
101    if ( fpt )
102    {
103      Int iValue;
104      Int iPOC = 0;
105      while ( iPOC < m_cAppEncCfg->getNumFrameToBeEncoded() )
106      {
107        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
108        m_aidQP[ iPOC ] = iValue;
109        iPOC++;
110      }
111      fclose(fpt);
112    }
113  }
114  return true;
115}
116
117Void TAppEncLayerCfg::xPrintParameter()
118{
119  printf("Input File                    : %s\n", m_cInputFile.c_str()  );
120  printf("Reconstruction File           : %s\n", m_cReconFile.c_str()  );
121#if AVC_SYNTAX
122  printf("Base layer input file         : %s\n", m_cAppEncCfg->getBLSyntaxFile() );
123#endif
124  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
125  printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
126  printf("QP                            : %5.2f\n", m_fQP );
127  printf("Intra period                  : %d\n", m_iIntraPeriod );
128  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
129}
130
131Bool confirmPara(Bool bflag, const char* message);
132
133Bool TAppEncLayerCfg::xCheckParameter()
134{
135  switch (m_conformanceMode)
136  {
137  case 0:
138    {
139      // no cropping or padding
140      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
141      m_aiPad[1] = m_aiPad[0] = 0;
142      break;
143    }
144  case 1:
145    {
146      // automatic padding to minimum CU size
147      Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
148      if (m_iSourceWidth % minCuSize)
149      {
150        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
151        m_iSourceWidth  += m_confRight;
152      }
153      if (m_iSourceHeight % minCuSize)
154      {
155        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
156        m_iSourceHeight += m_confBottom;
157      }
158      break;
159    }
160  case 2:
161    {
162      //padding
163      m_iSourceWidth  += m_aiPad[0];
164      m_iSourceHeight += m_aiPad[1];
165      m_confRight  = m_aiPad[0];
166      m_confBottom = m_aiPad[1];
167      break;
168    }
169  case 3:
170    {
171      // conformance
172      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
173      {
174        fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
175      }
176      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
177      {
178        fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n");
179      }
180      m_aiPad[1] = m_aiPad[0] = 0;
181      break;
182    }
183  }
184
185  // allocate slice-based dQP values
186  Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded();
187  Int iGOPSize = m_cAppEncCfg->getGOPSize();
188  if( m_aidQP == NULL )
189    m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ];
190  ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) );
191
192  // handling of floating-point QP values
193  // if QP is not integer, sequence is split into two sections having QP and QP+1
194  m_iQP = (Int)( m_fQP );
195  if ( m_iQP < m_fQP )
196  {
197    Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 );
198
199
200    iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize;
201    for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ )
202    {
203      m_aidQP[i] = 1;
204    }
205  }
206
207  UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
208  UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
209  UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
210  bool check_failed = false; /* abort if there is a fatal configuration problem */
211#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
212  // check range of parameters
213  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
214  xConfirmPara( (m_iSourceWidth  % (maxCUWidth  >> (maxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
215  xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
216  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
217  if (m_cAppEncCfg->getDecodingRefreshType() == 2)
218  {
219    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
220  }
221
222  xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
223
224
225  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 1;
226  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
227  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
228
229  //chekc parameters
230  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
231  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
232
233  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
234  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
235
236  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
237  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
238  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
239  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
240#undef xConfirmPara
241  return check_failed;
242}
243
244#endif
245
246
247//! \}
Note: See TracBrowser for help on using the repository browser.