[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 | |
---|
| 18 | using namespace std; |
---|
| 19 | namespace po = df::program_options_lite; |
---|
| 20 | |
---|
| 21 | //! \ingroup TAppEncoder |
---|
| 22 | //! \{ |
---|
| 23 | |
---|
| 24 | |
---|
[494] | 25 | #if AUXILIARY_PICTURES |
---|
| 26 | static inline ChromaFormat numberToChromaFormat(const Int val) |
---|
| 27 | { |
---|
| 28 | switch (val) |
---|
| 29 | { |
---|
| 30 | case 400: return CHROMA_400; break; |
---|
| 31 | case 420: return CHROMA_420; break; |
---|
| 32 | case 422: return CHROMA_422; break; |
---|
| 33 | case 444: return CHROMA_444; break; |
---|
| 34 | default: return NUM_CHROMA_FORMAT; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | #endif |
---|
| 38 | |
---|
[313] | 39 | // ==================================================================================================================== |
---|
| 40 | // Constructor / destructor / initialization / destroy |
---|
| 41 | // ==================================================================================================================== |
---|
| 42 | #if SVC_EXTENSION |
---|
| 43 | TAppEncLayerCfg::TAppEncLayerCfg() |
---|
| 44 | :m_cInputFile(string("")), |
---|
| 45 | m_cReconFile(string("")), |
---|
| 46 | m_conformanceMode( 0 ), |
---|
| 47 | m_aidQP(NULL) |
---|
[442] | 48 | #if REPN_FORMAT_IN_VPS |
---|
| 49 | , m_repFormatIdx (-1) |
---|
| 50 | #endif |
---|
[906] | 51 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 52 | , m_colourRemapSEIFile(string("")) |
---|
| 53 | #endif |
---|
[313] | 54 | { |
---|
[906] | 55 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 56 | for( Int c=0 ; c<3 ; c++) |
---|
| 57 | { |
---|
| 58 | m_colourRemapSEIPreLutCodedValue[c] = NULL; |
---|
| 59 | m_colourRemapSEIPreLutTargetValue[c] = NULL; |
---|
| 60 | m_colourRemapSEIPostLutCodedValue[c] = NULL; |
---|
| 61 | m_colourRemapSEIPostLutTargetValue[c] = NULL; |
---|
| 62 | } |
---|
| 63 | #endif |
---|
| 64 | m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0; |
---|
[313] | 65 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
| 66 | m_numScaledRefLayerOffsets = 0; |
---|
[540] | 67 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 68 | ::memset(m_scaledRefLayerId, 0, sizeof(m_scaledRefLayerId)); |
---|
| 69 | #endif |
---|
[313] | 70 | ::memset(m_scaledRefLayerLeftOffset, 0, sizeof(m_scaledRefLayerLeftOffset)); |
---|
| 71 | ::memset(m_scaledRefLayerTopOffset, 0, sizeof(m_scaledRefLayerTopOffset)); |
---|
| 72 | ::memset(m_scaledRefLayerRightOffset, 0, sizeof(m_scaledRefLayerRightOffset)); |
---|
| 73 | ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset)); |
---|
[906] | 74 | #if REF_REGION_OFFSET |
---|
| 75 | ::memset(m_scaledRefLayerOffsetPresentFlag, 0, sizeof(m_scaledRefLayerOffsetPresentFlag)); |
---|
| 76 | ::memset(m_refRegionOffsetPresentFlag, 0, sizeof(m_refRegionOffsetPresentFlag)); |
---|
| 77 | ::memset(m_refRegionLeftOffset, 0, sizeof(m_refRegionLeftOffset)); |
---|
| 78 | ::memset(m_refRegionTopOffset, 0, sizeof(m_refRegionTopOffset)); |
---|
| 79 | ::memset(m_refRegionRightOffset, 0, sizeof(m_refRegionRightOffset)); |
---|
| 80 | ::memset(m_refRegionBottomOffset, 0, sizeof(m_refRegionBottomOffset)); |
---|
| 81 | #endif |
---|
| 82 | #if R0209_GENERIC_PHASE |
---|
| 83 | ::memset(m_resamplePhaseSetPresentFlag, 0, sizeof(m_resamplePhaseSetPresentFlag)); |
---|
| 84 | ::memset(m_phaseHorLuma, 0, sizeof(m_phaseHorLuma)); |
---|
| 85 | ::memset(m_phaseVerLuma, 0, sizeof(m_phaseVerLuma)); |
---|
| 86 | ::memset(m_phaseHorChroma, 0, sizeof(m_phaseHorChroma)); |
---|
| 87 | ::memset(m_phaseVerChroma, 0, sizeof(m_phaseVerChroma)); |
---|
| 88 | #else |
---|
[644] | 89 | #if P0312_VERT_PHASE_ADJ |
---|
| 90 | ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag)); |
---|
| 91 | #endif |
---|
[906] | 92 | #endif |
---|
[313] | 93 | } |
---|
| 94 | |
---|
| 95 | TAppEncLayerCfg::~TAppEncLayerCfg() |
---|
| 96 | { |
---|
| 97 | if ( m_aidQP ) |
---|
| 98 | { |
---|
| 99 | delete[] m_aidQP; |
---|
| 100 | } |
---|
[906] | 101 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 102 | for( Int c=0 ; c<3 ; c++) |
---|
| 103 | { |
---|
| 104 | if ( m_colourRemapSEIPreLutCodedValue[c] ) |
---|
| 105 | { |
---|
| 106 | delete[] m_colourRemapSEIPreLutCodedValue[c]; |
---|
| 107 | } |
---|
| 108 | if ( m_colourRemapSEIPreLutTargetValue[c] ) |
---|
| 109 | { |
---|
| 110 | delete[] m_colourRemapSEIPreLutTargetValue[c]; |
---|
| 111 | } |
---|
| 112 | if ( m_colourRemapSEIPostLutCodedValue[c] ) |
---|
| 113 | { |
---|
| 114 | delete[] m_colourRemapSEIPostLutCodedValue[c]; |
---|
| 115 | } |
---|
| 116 | if ( m_colourRemapSEIPostLutTargetValue[c] ) |
---|
| 117 | { |
---|
| 118 | delete[] m_colourRemapSEIPostLutTargetValue[c]; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | #endif |
---|
[313] | 122 | } |
---|
| 123 | |
---|
| 124 | Void TAppEncLayerCfg::create() |
---|
| 125 | { |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | Void TAppEncLayerCfg::destroy() |
---|
| 129 | { |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | // ==================================================================================================================== |
---|
| 134 | // Public member functions |
---|
| 135 | // ==================================================================================================================== |
---|
| 136 | |
---|
| 137 | /** \param argc number of arguments |
---|
| 138 | \param argv array of arguments |
---|
| 139 | \retval true when success |
---|
| 140 | */ |
---|
| 141 | bool TAppEncLayerCfg::parseCfg( const string& cfgFileName ) |
---|
| 142 | { |
---|
| 143 | string cfg_InputFile; |
---|
| 144 | string cfg_ReconFile; |
---|
| 145 | string cfg_dQPFile; |
---|
[494] | 146 | #if AUXILIARY_PICTURES |
---|
| 147 | Int tmpInputChromaFormat; |
---|
| 148 | Int tmpChromaFormat; |
---|
| 149 | #endif |
---|
[906] | 150 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 151 | string cfg_colourRemapSEIFile; |
---|
| 152 | #endif |
---|
[494] | 153 | |
---|
[313] | 154 | po::Options opts; |
---|
| 155 | opts.addOptions() |
---|
| 156 | ("InputFile,i", cfg_InputFile, string(""), "original YUV input file name") |
---|
| 157 | #if AVC_BASE |
---|
| 158 | ("InputBLFile,-ibl", cfg_InputFile, string(""), "original YUV input file name") |
---|
| 159 | #endif |
---|
| 160 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name") |
---|
| 161 | ("SourceWidth,-wdt", m_iSourceWidth, 0, "Source picture width") |
---|
| 162 | ("SourceHeight,-hgt", m_iSourceHeight, 0, "Source picture height") |
---|
| 163 | ("CroppingMode", m_conformanceMode, 0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping") |
---|
[494] | 164 | #if AUXILIARY_PICTURES |
---|
| 165 | ("InputChromaFormat", tmpInputChromaFormat, 420, "InputChromaFormatIDC") |
---|
| 166 | ("ChromaFormatIDC", tmpChromaFormat, 420, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)") |
---|
| 167 | #endif |
---|
[906] | 168 | ("ConfLeft", m_confWinLeft, 0, "Deprecated alias of ConfWinLeft") |
---|
| 169 | ("ConfRight", m_confWinRight, 0, "Deprecated alias of ConfWinRight") |
---|
| 170 | ("ConfTop", m_confWinTop, 0, "Deprecated alias of ConfWinTop") |
---|
| 171 | ("ConfBottom", m_confWinBottom, 0, "Deprecated alias of ConfWinBottom") |
---|
| 172 | ("ConfWinLeft", m_confWinLeft, 0, "Left offset for window conformance mode 3") |
---|
| 173 | ("ConfWinRight", m_confWinRight, 0, "Right offset for window conformance mode 3") |
---|
| 174 | ("ConfWinTop", m_confWinTop, 0, "Top offset for window conformance mode 3") |
---|
| 175 | ("ConfWinBottom", m_confWinBottom, 0, "Bottom offset for window conformance mode 3") |
---|
[313] | 176 | ("HorizontalPadding,-pdx",m_aiPad[0], 0, "horizontal source padding for cropping mode 2") |
---|
| 177 | ("VerticalPadding,-pdy", m_aiPad[1], 0, "vertical source padding for cropping mode 2") |
---|
| 178 | ("IntraPeriod,-ip", m_iIntraPeriod, -1, "intra period in frames, (-1: only first frame)") |
---|
| 179 | ("FrameRate,-fr", m_iFrameRate, 0, "Frame rate") |
---|
| 180 | ("dQPFile,m", cfg_dQPFile, string(""), "dQP file name") |
---|
| 181 | ("QP,q", m_fQP, 30.0, "Qp value, if value is float, QP is switched once during encoding") |
---|
[906] | 182 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 183 | ("SEIColourRemappingInfoFile", cfg_colourRemapSEIFile, string(""), "Colour Remapping Information SEI parameters file name") |
---|
| 184 | #endif |
---|
| 185 | ; |
---|
[313] | 186 | |
---|
| 187 | po::setDefaults(opts); |
---|
| 188 | po::parseConfigFile(opts, cfgFileName); |
---|
| 189 | |
---|
| 190 | m_cInputFile = cfg_InputFile; |
---|
| 191 | m_cReconFile = cfg_ReconFile; |
---|
| 192 | m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str()); |
---|
[494] | 193 | #if AUXILIARY_PICTURES |
---|
| 194 | m_InputChromaFormat = numberToChromaFormat(tmpInputChromaFormat); |
---|
| 195 | m_chromaFormatIDC = ((tmpChromaFormat == 0) ? (m_InputChromaFormat) : (numberToChromaFormat(tmpChromaFormat))); |
---|
| 196 | #endif |
---|
[906] | 197 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 198 | m_colourRemapSEIFile = cfg_colourRemapSEIFile.empty() ? NULL : strdup(cfg_colourRemapSEIFile.c_str()); |
---|
| 199 | #endif |
---|
[313] | 200 | |
---|
| 201 | // reading external dQP description from file |
---|
| 202 | if ( m_pchdQPFile ) |
---|
| 203 | { |
---|
| 204 | FILE* fpt=fopen( m_pchdQPFile, "r" ); |
---|
| 205 | if ( fpt ) |
---|
| 206 | { |
---|
| 207 | Int iValue; |
---|
| 208 | Int iPOC = 0; |
---|
| 209 | while ( iPOC < m_cAppEncCfg->getNumFrameToBeEncoded() ) |
---|
| 210 | { |
---|
| 211 | if ( fscanf(fpt, "%d", &iValue ) == EOF ) break; |
---|
| 212 | m_aidQP[ iPOC ] = iValue; |
---|
| 213 | iPOC++; |
---|
| 214 | } |
---|
| 215 | fclose(fpt); |
---|
| 216 | } |
---|
| 217 | } |
---|
[906] | 218 | |
---|
| 219 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 220 | if( m_colourRemapSEIFile.size() > 0 ) |
---|
| 221 | { |
---|
| 222 | FILE* fic; |
---|
| 223 | Int retval; |
---|
| 224 | if((fic = fopen(m_colourRemapSEIFile.c_str(),"r")) == (FILE*)NULL) |
---|
| 225 | { |
---|
| 226 | fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", m_colourRemapSEIFile.c_str()); |
---|
| 227 | exit(EXIT_FAILURE); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | Int tempCode; |
---|
| 231 | retval = fscanf( fic, "%d", &m_colourRemapSEIId ); |
---|
| 232 | retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEICancelFlag = tempCode ? 1 : 0; |
---|
| 233 | if( !m_colourRemapSEICancelFlag ) |
---|
| 234 | { |
---|
| 235 | retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIPersistenceFlag = tempCode ? 1 : 0; |
---|
| 236 | retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIVideoSignalInfoPresentFlag = tempCode ? 1 : 0; |
---|
| 237 | if( m_colourRemapSEIVideoSignalInfoPresentFlag ) |
---|
| 238 | { |
---|
| 239 | retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIFullRangeFlag = tempCode ? 1 : 0; |
---|
| 240 | retval = fscanf( fic, "%d", &m_colourRemapSEIPrimaries ); |
---|
| 241 | retval = fscanf( fic, "%d", &m_colourRemapSEITransferFunction ); |
---|
| 242 | retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixCoefficients ); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | retval = fscanf( fic, "%d", &m_colourRemapSEIInputBitDepth ); |
---|
| 246 | retval = fscanf( fic, "%d", &m_colourRemapSEIBitDepth ); |
---|
| 247 | |
---|
| 248 | for( Int c=0 ; c<3 ; c++ ) |
---|
| 249 | { |
---|
| 250 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutNumValMinus1[c] ); |
---|
| 251 | if( m_colourRemapSEIPreLutNumValMinus1[c]>0 ) |
---|
| 252 | { |
---|
| 253 | m_colourRemapSEIPreLutCodedValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1]; |
---|
| 254 | m_colourRemapSEIPreLutTargetValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1]; |
---|
| 255 | for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++ ) |
---|
| 256 | { |
---|
| 257 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutCodedValue[c][i] ); |
---|
| 258 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutTargetValue[c][i] ); |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | retval = fscanf( fic, "%d", &tempCode );m_colourRemapSEIMatrixPresentFlag = tempCode ? 1 : 0; |
---|
| 264 | if( m_colourRemapSEIMatrixPresentFlag ) |
---|
| 265 | { |
---|
| 266 | retval = fscanf( fic, "%d", &m_colourRemapSEILog2MatrixDenom ); |
---|
| 267 | for( Int c=0 ; c<3 ; c++ ) |
---|
| 268 | for( Int i=0 ; i<3 ; i++ ) |
---|
| 269 | retval = fscanf( fic, "%d", &m_colourRemapSEICoeffs[c][i] ); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | for( Int c=0 ; c<3 ; c++ ) |
---|
| 273 | { |
---|
| 274 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutNumValMinus1[c] ); |
---|
| 275 | if( m_colourRemapSEIPostLutNumValMinus1[c]>0 ) |
---|
| 276 | { |
---|
| 277 | m_colourRemapSEIPostLutCodedValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1]; |
---|
| 278 | m_colourRemapSEIPostLutTargetValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1]; |
---|
| 279 | for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++ ) |
---|
| 280 | { |
---|
| 281 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutCodedValue[c][i] ); |
---|
| 282 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutTargetValue[c][i] ); |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | fclose( fic ); |
---|
| 289 | if( retval != 1 ) |
---|
| 290 | { |
---|
| 291 | fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n"); |
---|
| 292 | exit(EXIT_FAILURE); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | #endif |
---|
| 296 | |
---|
[313] | 297 | return true; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | Void TAppEncLayerCfg::xPrintParameter() |
---|
| 301 | { |
---|
| 302 | printf("Input File : %s\n", m_cInputFile.c_str() ); |
---|
| 303 | printf("Reconstruction File : %s\n", m_cReconFile.c_str() ); |
---|
[713] | 304 | #if REPN_FORMAT_IN_VPS |
---|
[906] | 305 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - ( m_confWinLeft + m_confWinRight ) * TComSPS::getWinUnitX( m_chromaFormatIDC ), m_iSourceHeight - ( m_confWinTop + m_confWinBottom ) * TComSPS::getWinUnitY( m_chromaFormatIDC ), m_iFrameRate ); |
---|
[713] | 306 | #else |
---|
[906] | 307 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - m_confWinLeft - m_confWinRight, m_iSourceHeight - m_confWinTop - m_confWinBottom, m_iFrameRate ); |
---|
[713] | 308 | #endif |
---|
[313] | 309 | printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); |
---|
[494] | 310 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
| 311 | printf("Input bit depth : (Y:%d, C:%d)\n", m_inputBitDepthY , m_inputBitDepthC ); |
---|
| 312 | printf("Internal bit depth : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC ); |
---|
| 313 | printf("PCM sample bit depth : (Y:%d, C:%d)\n", m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthY : m_internalBitDepthY, m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthC : m_internalBitDepthC ); |
---|
| 314 | #endif |
---|
| 315 | #if LAYER_CTB |
---|
| 316 | printf("CU size / depth : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth ); |
---|
| 317 | printf("RQT trans. size (min / max) : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
| 318 | printf("Max RQT depth inter : %d\n", m_uiQuadtreeTUMaxDepthInter); |
---|
| 319 | printf("Max RQT depth intra : %d\n", m_uiQuadtreeTUMaxDepthIntra); |
---|
| 320 | #endif |
---|
[313] | 321 | printf("QP : %5.2f\n", m_fQP ); |
---|
| 322 | printf("Intra period : %d\n", m_iIntraPeriod ); |
---|
| 323 | #if RC_SHVC_HARMONIZATION |
---|
| 324 | printf("RateControl : %d\n", m_RCEnableRateControl ); |
---|
| 325 | if(m_RCEnableRateControl) |
---|
| 326 | { |
---|
| 327 | printf("TargetBitrate : %d\n", m_RCTargetBitrate ); |
---|
| 328 | printf("KeepHierarchicalBit : %d\n", m_RCKeepHierarchicalBit ); |
---|
| 329 | printf("LCULevelRC : %d\n", m_RCLCULevelRC ); |
---|
| 330 | printf("UseLCUSeparateModel : %d\n", m_RCUseLCUSeparateModel ); |
---|
| 331 | printf("InitialQP : %d\n", m_RCInitialQP ); |
---|
| 332 | printf("ForceIntraQP : %d\n", m_RCForceIntraQP ); |
---|
| 333 | } |
---|
| 334 | #endif |
---|
[906] | 335 | printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_waveFrontSynchro, m_iWaveFrontSubstreams); |
---|
[494] | 336 | #if LAYER_CTB |
---|
| 337 | printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0); |
---|
| 338 | #endif |
---|
[313] | 339 | } |
---|
| 340 | |
---|
| 341 | Bool confirmPara(Bool bflag, const char* message); |
---|
| 342 | |
---|
[442] | 343 | Bool TAppEncLayerCfg::xCheckParameter( Bool isField ) |
---|
[313] | 344 | { |
---|
| 345 | switch (m_conformanceMode) |
---|
| 346 | { |
---|
| 347 | case 0: |
---|
| 348 | { |
---|
| 349 | // no cropping or padding |
---|
[906] | 350 | m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0; |
---|
[313] | 351 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
| 352 | break; |
---|
| 353 | } |
---|
| 354 | case 1: |
---|
| 355 | { |
---|
| 356 | // automatic padding to minimum CU size |
---|
[494] | 357 | #if LAYER_CTB |
---|
| 358 | Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1); |
---|
| 359 | #else |
---|
[313] | 360 | Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1); |
---|
[494] | 361 | #endif |
---|
[313] | 362 | if (m_iSourceWidth % minCuSize) |
---|
| 363 | { |
---|
[906] | 364 | m_aiPad[0] = m_confWinRight = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth; |
---|
| 365 | m_iSourceWidth += m_confWinRight; |
---|
[713] | 366 | #if REPN_FORMAT_IN_VPS |
---|
[906] | 367 | m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC ); |
---|
[713] | 368 | #endif |
---|
[313] | 369 | } |
---|
| 370 | if (m_iSourceHeight % minCuSize) |
---|
| 371 | { |
---|
[906] | 372 | m_aiPad[1] = m_confWinBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight; |
---|
| 373 | m_iSourceHeight += m_confWinBottom; |
---|
[442] | 374 | if ( isField ) |
---|
| 375 | { |
---|
[906] | 376 | m_iSourceHeightOrg += m_confWinBottom << 1; |
---|
| 377 | m_aiPad[1] = m_confWinBottom << 1; |
---|
[442] | 378 | } |
---|
[713] | 379 | #if REPN_FORMAT_IN_VPS |
---|
[906] | 380 | m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC ); |
---|
[713] | 381 | #endif |
---|
[313] | 382 | } |
---|
| 383 | break; |
---|
| 384 | } |
---|
| 385 | case 2: |
---|
| 386 | { |
---|
| 387 | //padding |
---|
| 388 | m_iSourceWidth += m_aiPad[0]; |
---|
| 389 | m_iSourceHeight += m_aiPad[1]; |
---|
[906] | 390 | m_confWinRight = m_aiPad[0]; |
---|
| 391 | m_confWinBottom = m_aiPad[1]; |
---|
[713] | 392 | #if REPN_FORMAT_IN_VPS |
---|
[906] | 393 | m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC ); |
---|
| 394 | m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC ); |
---|
[713] | 395 | #endif |
---|
[313] | 396 | break; |
---|
| 397 | } |
---|
| 398 | case 3: |
---|
| 399 | { |
---|
| 400 | // conformance |
---|
[906] | 401 | if ((m_confWinLeft == 0) && (m_confWinRight == 0) && (m_confWinTop == 0) && (m_confWinBottom == 0)) |
---|
[313] | 402 | { |
---|
| 403 | fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n"); |
---|
| 404 | } |
---|
| 405 | if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0)) |
---|
| 406 | { |
---|
| 407 | fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n"); |
---|
| 408 | } |
---|
| 409 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
| 410 | break; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | // allocate slice-based dQP values |
---|
| 415 | Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded(); |
---|
| 416 | Int iGOPSize = m_cAppEncCfg->getGOPSize(); |
---|
| 417 | if( m_aidQP == NULL ) |
---|
| 418 | m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ]; |
---|
| 419 | ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) ); |
---|
| 420 | |
---|
| 421 | // handling of floating-point QP values |
---|
| 422 | // if QP is not integer, sequence is split into two sections having QP and QP+1 |
---|
| 423 | m_iQP = (Int)( m_fQP ); |
---|
| 424 | if ( m_iQP < m_fQP ) |
---|
| 425 | { |
---|
| 426 | Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 ); |
---|
| 427 | |
---|
| 428 | |
---|
| 429 | iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize; |
---|
| 430 | for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ ) |
---|
| 431 | { |
---|
| 432 | m_aidQP[i] = 1; |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
[494] | 436 | #if LAYER_CTB |
---|
| 437 | UInt maxCUWidth = m_uiMaxCUWidth; |
---|
| 438 | UInt maxCUHeight = m_uiMaxCUHeight; |
---|
| 439 | UInt maxCUDepth = m_uiMaxCUDepth; |
---|
| 440 | #else |
---|
[313] | 441 | UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth(); |
---|
| 442 | UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight(); |
---|
| 443 | UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth(); |
---|
[494] | 444 | #endif |
---|
[313] | 445 | bool check_failed = false; /* abort if there is a fatal configuration problem */ |
---|
| 446 | #define xConfirmPara(a,b) check_failed |= confirmPara(a,b) |
---|
| 447 | // check range of parameters |
---|
| 448 | xConfirmPara( m_iFrameRate <= 0, "Frame rate must be more than 1" ); |
---|
| 449 | xConfirmPara( (m_iSourceWidth % (maxCUWidth >> (maxCUDepth-1)))!=0, "Resulting coded frame width must be a multiple of the minimum CU size"); |
---|
| 450 | xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0, "Resulting coded frame height must be a multiple of the minimum CU size"); |
---|
| 451 | xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" ); |
---|
| 452 | if (m_cAppEncCfg->getDecodingRefreshType() == 2) |
---|
| 453 | { |
---|
| 454 | xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize , "Intra period must be larger than GOP size for periodic IDR pictures"); |
---|
| 455 | } |
---|
| 456 | |
---|
[494] | 457 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
| 458 | for(UInt layer = 0; layer < MAX_LAYERS; layer++) |
---|
| 459 | { |
---|
| 460 | xConfirmPara( m_iQP < -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY(layer) - 8) || m_iQP > 51, "QP exceeds supported range (-QpBDOffsety to 51)" ); |
---|
| 461 | } |
---|
| 462 | #else |
---|
[313] | 463 | xConfirmPara( m_iQP < -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51, "QP exceeds supported range (-QpBDOffsety to 51)" ); |
---|
[494] | 464 | #endif |
---|
[313] | 465 | |
---|
[906] | 466 | m_iWaveFrontSubstreams = m_waveFrontSynchro ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1; |
---|
| 467 | xConfirmPara( m_waveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" ); |
---|
[313] | 468 | xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" ); |
---|
[906] | 469 | xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_waveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" ); |
---|
[313] | 470 | |
---|
| 471 | //chekc parameters |
---|
| 472 | xConfirmPara( m_iSourceWidth % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling"); |
---|
| 473 | xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling"); |
---|
| 474 | |
---|
| 475 | xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling"); |
---|
| 476 | xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling"); |
---|
| 477 | |
---|
[713] | 478 | #if !REPN_FORMAT_IN_VPS |
---|
[313] | 479 | xConfirmPara( m_confLeft % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
| 480 | xConfirmPara( m_confRight % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
| 481 | xConfirmPara( m_confTop % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
| 482 | xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
[713] | 483 | #endif |
---|
[494] | 484 | |
---|
| 485 | #if LAYER_CTB |
---|
| 486 | xConfirmPara( (m_uiMaxCUWidth >> m_uiMaxCUDepth) < 4, "Minimum partition width size should be larger than or equal to 8"); |
---|
| 487 | xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4, "Minimum partition height size should be larger than or equal to 8"); |
---|
| 488 | xConfirmPara( m_uiMaxCUWidth < 16, "Maximum partition width size should be larger than or equal to 16"); |
---|
| 489 | xConfirmPara( m_uiMaxCUHeight < 16, "Maximum partition height size should be larger than or equal to 16"); |
---|
| 490 | xConfirmPara( m_uiQuadtreeTULog2MinSize < 2, "QuadtreeTULog2MinSize must be 2 or greater."); |
---|
| 491 | xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5, "QuadtreeTULog2MaxSize must be 5 or smaller."); |
---|
| 492 | xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth, "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller."); |
---|
| 493 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize, "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize."); |
---|
| 494 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
| 495 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
| 496 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." ); |
---|
| 497 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." ); |
---|
| 498 | xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1, "QuadtreeTUMaxDepthInter must be greater than or equal to 1" ); |
---|
| 499 | 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" ); |
---|
| 500 | xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1, "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" ); |
---|
| 501 | 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" ); |
---|
| 502 | |
---|
| 503 | // max CU width and height should be power of 2 |
---|
| 504 | UInt ui = m_uiMaxCUWidth; |
---|
| 505 | while(ui) |
---|
| 506 | { |
---|
| 507 | ui >>= 1; |
---|
| 508 | if( (ui & 1) == 1) |
---|
| 509 | xConfirmPara( ui != 1 , "Width should be 2^n"); |
---|
| 510 | } |
---|
| 511 | ui = m_uiMaxCUHeight; |
---|
| 512 | while(ui) |
---|
| 513 | { |
---|
| 514 | ui >>= 1; |
---|
| 515 | if( (ui & 1) == 1) |
---|
| 516 | xConfirmPara( ui != 1 , "Height should be 2^n"); |
---|
| 517 | } |
---|
| 518 | #endif |
---|
[906] | 519 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 520 | if ( ( m_colourRemapSEIFile.size() > 0 ) && !m_colourRemapSEICancelFlag ) |
---|
| 521 | { |
---|
| 522 | xConfirmPara( m_colourRemapSEIInputBitDepth < 8 || m_colourRemapSEIInputBitDepth > 16 , "colour_remap_input_bit_depth shall be in the range of 8 to 16, inclusive"); |
---|
| 523 | xConfirmPara( m_colourRemapSEIBitDepth < 8 || m_colourRemapSEIBitDepth > 16, "colour_remap_bit_depth shall be in the range of 8 to 16, inclusive"); |
---|
| 524 | for( Int c=0 ; c<3 ; c++) |
---|
| 525 | { |
---|
| 526 | xConfirmPara( m_colourRemapSEIPreLutNumValMinus1[c] < 0 || m_colourRemapSEIPreLutNumValMinus1[c] > 32, "pre_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive"); |
---|
| 527 | if( m_colourRemapSEIPreLutNumValMinus1[c]>0 ) |
---|
| 528 | for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++) |
---|
| 529 | { |
---|
| 530 | xConfirmPara( m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_colourRemapSEIInputBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_input_bit_depth)-1, inclusive"); |
---|
| 531 | xConfirmPara( m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive"); |
---|
| 532 | } |
---|
| 533 | xConfirmPara( m_colourRemapSEIPostLutNumValMinus1[c] < 0 || m_colourRemapSEIPostLutNumValMinus1[c] > 32, "post_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive"); |
---|
| 534 | if( m_colourRemapSEIPostLutNumValMinus1[c]>0 ) |
---|
| 535 | for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++) |
---|
| 536 | { |
---|
| 537 | xConfirmPara( m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive"); |
---|
| 538 | xConfirmPara( m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_colourRemapSEIBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_bit_depth)-1, inclusive"); |
---|
| 539 | } |
---|
| 540 | } |
---|
| 541 | if( m_colourRemapSEIMatrixPresentFlag ) |
---|
| 542 | { |
---|
| 543 | xConfirmPara( m_colourRemapSEILog2MatrixDenom < 0 || m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive"); |
---|
| 544 | for( Int c=0 ; c<3 ; c++) |
---|
| 545 | for( Int i=0 ; i<3 ; i++) |
---|
| 546 | xConfirmPara( m_colourRemapSEICoeffs[c][i] < -32768 || m_colourRemapSEICoeffs[c][i] > 32767, "colour_remap_coeffs[c][i] shall be in the range of -32768 and 32767, inclusive"); |
---|
| 547 | } |
---|
| 548 | } |
---|
| 549 | #endif |
---|
[494] | 550 | |
---|
[313] | 551 | #undef xConfirmPara |
---|
| 552 | return check_failed; |
---|
| 553 | } |
---|
| 554 | |
---|
[494] | 555 | #endif //SVC_EXTENSION |
---|
[313] | 556 | |
---|
| 557 | |
---|
| 558 | //! \} |
---|