source: SHVCSoftware/branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp @ 405

Last change on this file since 405 was 389, checked in by qualcomm, 11 years ago

Signaling representation format in VPS (MACRO: REPN_FORMAT_IN_VPS)

Includes signaling of representation format - including picture resolution, bit depth, chroma format - in the VPS, with the option of updating them in the SPS. The configuration file has "RepFormatIdx%d" added to indicate for each layer which representation format is used. The rep_format() structures are automatically created by the encoder. If the bit depth and the chroma format are also changed across layers, some more configuration support would be needed.

From: Adarsh K. Ramasubramonian <aramasub@…>

  • Property svn:eol-style set to native
File size: 10.9 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#if REPN_FORMAT_IN_VPS
35, m_repFormatIdx (-1)
36#endif
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 );
144  printf("QP                            : %5.2f\n", m_fQP );
145  printf("Intra period                  : %d\n", m_iIntraPeriod );
146#if RC_SHVC_HARMONIZATION
147  printf("RateControl                   : %d\n", m_RCEnableRateControl );
148  if(m_RCEnableRateControl)
149  {
150    printf("TargetBitrate                 : %d\n", m_RCTargetBitrate );
151    printf("KeepHierarchicalBit           : %d\n", m_RCKeepHierarchicalBit );
152    printf("LCULevelRC                    : %d\n", m_RCLCULevelRC );
153    printf("UseLCUSeparateModel           : %d\n", m_RCUseLCUSeparateModel );
154    printf("InitialQP                     : %d\n", m_RCInitialQP );
155    printf("ForceIntraQP                  : %d\n", m_RCForceIntraQP );
156  }
157#endif
158  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
159}
160
161Bool confirmPara(Bool bflag, const char* message);
162
163Bool TAppEncLayerCfg::xCheckParameter()
164{
165  switch (m_conformanceMode)
166  {
167  case 0:
168    {
169      // no cropping or padding
170      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
171      m_aiPad[1] = m_aiPad[0] = 0;
172      break;
173    }
174  case 1:
175    {
176      // automatic padding to minimum CU size
177      Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
178      if (m_iSourceWidth % minCuSize)
179      {
180        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
181        m_iSourceWidth  += m_confRight;
182      }
183      if (m_iSourceHeight % minCuSize)
184      {
185        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
186        m_iSourceHeight += m_confBottom;
187      }
188      break;
189    }
190  case 2:
191    {
192      //padding
193      m_iSourceWidth  += m_aiPad[0];
194      m_iSourceHeight += m_aiPad[1];
195      m_confRight  = m_aiPad[0];
196      m_confBottom = m_aiPad[1];
197      break;
198    }
199  case 3:
200    {
201      // conformance
202      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
203      {
204        fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
205      }
206      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
207      {
208        fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n");
209      }
210      m_aiPad[1] = m_aiPad[0] = 0;
211      break;
212    }
213  }
214
215  // allocate slice-based dQP values
216  Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded();
217  Int iGOPSize = m_cAppEncCfg->getGOPSize();
218  if( m_aidQP == NULL )
219    m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ];
220  ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) );
221
222  // handling of floating-point QP values
223  // if QP is not integer, sequence is split into two sections having QP and QP+1
224  m_iQP = (Int)( m_fQP );
225  if ( m_iQP < m_fQP )
226  {
227    Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 );
228
229
230    iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize;
231    for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ )
232    {
233      m_aidQP[i] = 1;
234    }
235  }
236
237  UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
238  UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
239  UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
240  bool check_failed = false; /* abort if there is a fatal configuration problem */
241#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
242  // check range of parameters
243  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
244  xConfirmPara( (m_iSourceWidth  % (maxCUWidth  >> (maxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
245  xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
246  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
247  if (m_cAppEncCfg->getDecodingRefreshType() == 2)
248  {
249    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
250  }
251
252  xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
253
254
255  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 1;
256  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
257  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
258
259  //chekc parameters
260  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
261  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
262
263  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
264  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
265
266  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
267  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
268  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
269  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
270#undef xConfirmPara
271  return check_failed;
272}
273
274#endif
275
276
277//! \}
Note: See TracBrowser for help on using the repository browser.