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 | |
---|
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 | |
---|
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) |
---|
48 | #if REPN_FORMAT_IN_VPS |
---|
49 | , m_repFormatIdx (-1) |
---|
50 | #endif |
---|
51 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
52 | , m_colourRemapSEIFile(string("")) |
---|
53 | #endif |
---|
54 | { |
---|
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; |
---|
65 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
66 | m_numScaledRefLayerOffsets = 0; |
---|
67 | #if O0098_SCALED_REF_LAYER_ID |
---|
68 | ::memset(m_scaledRefLayerId, 0, sizeof(m_scaledRefLayerId)); |
---|
69 | #endif |
---|
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)); |
---|
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 |
---|
89 | #if P0312_VERT_PHASE_ADJ |
---|
90 | ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag)); |
---|
91 | #endif |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | TAppEncLayerCfg::~TAppEncLayerCfg() |
---|
96 | { |
---|
97 | if ( m_aidQP ) |
---|
98 | { |
---|
99 | delete[] m_aidQP; |
---|
100 | } |
---|
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 |
---|
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; |
---|
146 | #if AUXILIARY_PICTURES |
---|
147 | Int tmpInputChromaFormat; |
---|
148 | Int tmpChromaFormat; |
---|
149 | #endif |
---|
150 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
151 | string cfg_colourRemapSEIFile; |
---|
152 | #endif |
---|
153 | |
---|
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") |
---|
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 |
---|
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") |
---|
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") |
---|
182 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
183 | ("SEIColourRemappingInfoFile", cfg_colourRemapSEIFile, string(""), "Colour Remapping Information SEI parameters file name") |
---|
184 | #endif |
---|
185 | ; |
---|
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()); |
---|
193 | #if AUXILIARY_PICTURES |
---|
194 | m_InputChromaFormat = numberToChromaFormat(tmpInputChromaFormat); |
---|
195 | m_chromaFormatIDC = ((tmpChromaFormat == 0) ? (m_InputChromaFormat) : (numberToChromaFormat(tmpChromaFormat))); |
---|
196 | #endif |
---|
197 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
198 | m_colourRemapSEIFile = cfg_colourRemapSEIFile.empty() ? NULL : strdup(cfg_colourRemapSEIFile.c_str()); |
---|
199 | #endif |
---|
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 | } |
---|
218 | |
---|
219 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
220 | if( m_colourRemapSEIFile.c_str() ) |
---|
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 | retval = fscanf( fic, "%d", &m_colourRemapSEIId ); |
---|
231 | retval = fscanf( fic, "%d", &m_colourRemapSEICancelFlag ); |
---|
232 | if( !m_colourRemapSEICancelFlag ) |
---|
233 | { |
---|
234 | retval = fscanf( fic, "%d", &m_colourRemapSEIPersistenceFlag ); |
---|
235 | retval = fscanf( fic, "%d", &m_colourRemapSEIVideoSignalTypePresentFlag); |
---|
236 | if( m_colourRemapSEIVideoSignalTypePresentFlag ) |
---|
237 | { |
---|
238 | retval = fscanf( fic, "%d", &m_colourRemapSEIVideoFullRangeFlag ); |
---|
239 | retval = fscanf( fic, "%d", &m_colourRemapSEIPrimaries ); |
---|
240 | retval = fscanf( fic, "%d", &m_colourRemapSEITransferCharacteristics ); |
---|
241 | retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixCoeffs ); |
---|
242 | } |
---|
243 | |
---|
244 | retval = fscanf( fic, "%d", &m_colourRemapSEICodedDataBitDepth ); |
---|
245 | retval = fscanf( fic, "%d", &m_colourRemapSEITargetBitDepth ); |
---|
246 | |
---|
247 | for( Int c=0 ; c<3 ; c++ ) |
---|
248 | { |
---|
249 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutNumValMinus1[c] ); |
---|
250 | if( m_colourRemapSEIPreLutNumValMinus1[c]>0 ) |
---|
251 | { |
---|
252 | m_colourRemapSEIPreLutCodedValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1]; |
---|
253 | m_colourRemapSEIPreLutTargetValue[c] = new Int[m_colourRemapSEIPreLutNumValMinus1[c]+1]; |
---|
254 | for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++ ) |
---|
255 | { |
---|
256 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutCodedValue[c][i] ); |
---|
257 | retval = fscanf( fic, "%d", &m_colourRemapSEIPreLutTargetValue[c][i] ); |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | retval = fscanf( fic, "%d", &m_colourRemapSEIMatrixPresentFlag ); |
---|
263 | if( m_colourRemapSEIMatrixPresentFlag ) |
---|
264 | { |
---|
265 | retval = fscanf( fic, "%d", &m_colourRemapSEILog2MatrixDenom ); |
---|
266 | for( Int c=0 ; c<3 ; c++ ) |
---|
267 | for( Int i=0 ; i<3 ; i++ ) |
---|
268 | retval = fscanf( fic, "%d", &m_colourRemapSEICoeffs[c][i] ); |
---|
269 | } |
---|
270 | |
---|
271 | for( Int c=0 ; c<3 ; c++ ) |
---|
272 | { |
---|
273 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutNumValMinus1[c] ); |
---|
274 | if( m_colourRemapSEIPostLutNumValMinus1[c]>0 ) |
---|
275 | { |
---|
276 | m_colourRemapSEIPostLutCodedValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1]; |
---|
277 | m_colourRemapSEIPostLutTargetValue[c] = new Int[m_colourRemapSEIPostLutNumValMinus1[c]+1]; |
---|
278 | for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++ ) |
---|
279 | { |
---|
280 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutCodedValue[c][i] ); |
---|
281 | retval = fscanf( fic, "%d", &m_colourRemapSEIPostLutTargetValue[c][i] ); |
---|
282 | } |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | fclose( fic ); |
---|
288 | if( retval != 1 ) |
---|
289 | { |
---|
290 | fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n"); |
---|
291 | exit(EXIT_FAILURE); |
---|
292 | } |
---|
293 | } |
---|
294 | #endif |
---|
295 | |
---|
296 | return true; |
---|
297 | } |
---|
298 | |
---|
299 | Void TAppEncLayerCfg::xPrintParameter() |
---|
300 | { |
---|
301 | printf("Input File : %s\n", m_cInputFile.c_str() ); |
---|
302 | printf("Reconstruction File : %s\n", m_cReconFile.c_str() ); |
---|
303 | #if REPN_FORMAT_IN_VPS |
---|
304 | 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 ); |
---|
305 | #else |
---|
306 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - m_confWinLeft - m_confWinRight, m_iSourceHeight - m_confWinTop - m_confWinBottom, m_iFrameRate ); |
---|
307 | #endif |
---|
308 | printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); |
---|
309 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
310 | printf("Input bit depth : (Y:%d, C:%d)\n", m_inputBitDepthY , m_inputBitDepthC ); |
---|
311 | printf("Internal bit depth : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC ); |
---|
312 | printf("PCM sample bit depth : (Y:%d, C:%d)\n", m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthY : m_internalBitDepthY, m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthC : m_internalBitDepthC ); |
---|
313 | #endif |
---|
314 | #if LAYER_CTB |
---|
315 | printf("CU size / depth : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth ); |
---|
316 | printf("RQT trans. size (min / max) : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
317 | printf("Max RQT depth inter : %d\n", m_uiQuadtreeTUMaxDepthInter); |
---|
318 | printf("Max RQT depth intra : %d\n", m_uiQuadtreeTUMaxDepthIntra); |
---|
319 | #endif |
---|
320 | printf("QP : %5.2f\n", m_fQP ); |
---|
321 | printf("Intra period : %d\n", m_iIntraPeriod ); |
---|
322 | #if RC_SHVC_HARMONIZATION |
---|
323 | printf("RateControl : %d\n", m_RCEnableRateControl ); |
---|
324 | if(m_RCEnableRateControl) |
---|
325 | { |
---|
326 | printf("TargetBitrate : %d\n", m_RCTargetBitrate ); |
---|
327 | printf("KeepHierarchicalBit : %d\n", m_RCKeepHierarchicalBit ); |
---|
328 | printf("LCULevelRC : %d\n", m_RCLCULevelRC ); |
---|
329 | printf("UseLCUSeparateModel : %d\n", m_RCUseLCUSeparateModel ); |
---|
330 | printf("InitialQP : %d\n", m_RCInitialQP ); |
---|
331 | printf("ForceIntraQP : %d\n", m_RCForceIntraQP ); |
---|
332 | } |
---|
333 | #endif |
---|
334 | printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams); |
---|
335 | #if LAYER_CTB |
---|
336 | printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0); |
---|
337 | #endif |
---|
338 | } |
---|
339 | |
---|
340 | Bool confirmPara(Bool bflag, const char* message); |
---|
341 | |
---|
342 | Bool TAppEncLayerCfg::xCheckParameter( Bool isField ) |
---|
343 | { |
---|
344 | switch (m_conformanceMode) |
---|
345 | { |
---|
346 | case 0: |
---|
347 | { |
---|
348 | // no cropping or padding |
---|
349 | m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0; |
---|
350 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
351 | break; |
---|
352 | } |
---|
353 | case 1: |
---|
354 | { |
---|
355 | // automatic padding to minimum CU size |
---|
356 | #if LAYER_CTB |
---|
357 | Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1); |
---|
358 | #else |
---|
359 | Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1); |
---|
360 | #endif |
---|
361 | if (m_iSourceWidth % minCuSize) |
---|
362 | { |
---|
363 | m_aiPad[0] = m_confWinRight = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth; |
---|
364 | m_iSourceWidth += m_confWinRight; |
---|
365 | #if REPN_FORMAT_IN_VPS |
---|
366 | m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC ); |
---|
367 | #endif |
---|
368 | } |
---|
369 | if (m_iSourceHeight % minCuSize) |
---|
370 | { |
---|
371 | m_aiPad[1] = m_confWinBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight; |
---|
372 | m_iSourceHeight += m_confWinBottom; |
---|
373 | if ( isField ) |
---|
374 | { |
---|
375 | m_iSourceHeightOrg += m_confWinBottom << 1; |
---|
376 | m_aiPad[1] = m_confWinBottom << 1; |
---|
377 | } |
---|
378 | #if REPN_FORMAT_IN_VPS |
---|
379 | m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC ); |
---|
380 | #endif |
---|
381 | } |
---|
382 | break; |
---|
383 | } |
---|
384 | case 2: |
---|
385 | { |
---|
386 | //padding |
---|
387 | m_iSourceWidth += m_aiPad[0]; |
---|
388 | m_iSourceHeight += m_aiPad[1]; |
---|
389 | m_confWinRight = m_aiPad[0]; |
---|
390 | m_confWinBottom = m_aiPad[1]; |
---|
391 | #if REPN_FORMAT_IN_VPS |
---|
392 | m_confWinRight /= TComSPS::getWinUnitX( m_chromaFormatIDC ); |
---|
393 | m_confWinBottom /= TComSPS::getWinUnitY( m_chromaFormatIDC ); |
---|
394 | #endif |
---|
395 | break; |
---|
396 | } |
---|
397 | case 3: |
---|
398 | { |
---|
399 | // conformance |
---|
400 | if ((m_confWinLeft == 0) && (m_confWinRight == 0) && (m_confWinTop == 0) && (m_confWinBottom == 0)) |
---|
401 | { |
---|
402 | fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n"); |
---|
403 | } |
---|
404 | if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0)) |
---|
405 | { |
---|
406 | fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n"); |
---|
407 | } |
---|
408 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
409 | break; |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | // allocate slice-based dQP values |
---|
414 | Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded(); |
---|
415 | Int iGOPSize = m_cAppEncCfg->getGOPSize(); |
---|
416 | if( m_aidQP == NULL ) |
---|
417 | m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ]; |
---|
418 | ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) ); |
---|
419 | |
---|
420 | // handling of floating-point QP values |
---|
421 | // if QP is not integer, sequence is split into two sections having QP and QP+1 |
---|
422 | m_iQP = (Int)( m_fQP ); |
---|
423 | if ( m_iQP < m_fQP ) |
---|
424 | { |
---|
425 | Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 ); |
---|
426 | |
---|
427 | |
---|
428 | iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize; |
---|
429 | for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ ) |
---|
430 | { |
---|
431 | m_aidQP[i] = 1; |
---|
432 | } |
---|
433 | } |
---|
434 | |
---|
435 | #if LAYER_CTB |
---|
436 | UInt maxCUWidth = m_uiMaxCUWidth; |
---|
437 | UInt maxCUHeight = m_uiMaxCUHeight; |
---|
438 | UInt maxCUDepth = m_uiMaxCUDepth; |
---|
439 | #else |
---|
440 | UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth(); |
---|
441 | UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight(); |
---|
442 | UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth(); |
---|
443 | #endif |
---|
444 | bool check_failed = false; /* abort if there is a fatal configuration problem */ |
---|
445 | #define xConfirmPara(a,b) check_failed |= confirmPara(a,b) |
---|
446 | // check range of parameters |
---|
447 | xConfirmPara( m_iFrameRate <= 0, "Frame rate must be more than 1" ); |
---|
448 | xConfirmPara( (m_iSourceWidth % (maxCUWidth >> (maxCUDepth-1)))!=0, "Resulting coded frame width must be a multiple of the minimum CU size"); |
---|
449 | xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0, "Resulting coded frame height must be a multiple of the minimum CU size"); |
---|
450 | xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" ); |
---|
451 | if (m_cAppEncCfg->getDecodingRefreshType() == 2) |
---|
452 | { |
---|
453 | xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize , "Intra period must be larger than GOP size for periodic IDR pictures"); |
---|
454 | } |
---|
455 | |
---|
456 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
457 | for(UInt layer = 0; layer < MAX_LAYERS; layer++) |
---|
458 | { |
---|
459 | xConfirmPara( m_iQP < -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY(layer) - 8) || m_iQP > 51, "QP exceeds supported range (-QpBDOffsety to 51)" ); |
---|
460 | } |
---|
461 | #else |
---|
462 | xConfirmPara( m_iQP < -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51, "QP exceeds supported range (-QpBDOffsety to 51)" ); |
---|
463 | #endif |
---|
464 | |
---|
465 | |
---|
466 | m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1; |
---|
467 | xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" ); |
---|
468 | xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" ); |
---|
469 | |
---|
470 | //chekc parameters |
---|
471 | xConfirmPara( m_iSourceWidth % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling"); |
---|
472 | xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling"); |
---|
473 | |
---|
474 | xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling"); |
---|
475 | xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling"); |
---|
476 | |
---|
477 | #if !REPN_FORMAT_IN_VPS |
---|
478 | xConfirmPara( m_confLeft % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
479 | xConfirmPara( m_confRight % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
480 | xConfirmPara( m_confTop % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
481 | xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling"); |
---|
482 | #endif |
---|
483 | |
---|
484 | #if LAYER_CTB |
---|
485 | xConfirmPara( (m_uiMaxCUWidth >> m_uiMaxCUDepth) < 4, "Minimum partition width size should be larger than or equal to 8"); |
---|
486 | xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4, "Minimum partition height size should be larger than or equal to 8"); |
---|
487 | xConfirmPara( m_uiMaxCUWidth < 16, "Maximum partition width size should be larger than or equal to 16"); |
---|
488 | xConfirmPara( m_uiMaxCUHeight < 16, "Maximum partition height size should be larger than or equal to 16"); |
---|
489 | xConfirmPara( m_uiQuadtreeTULog2MinSize < 2, "QuadtreeTULog2MinSize must be 2 or greater."); |
---|
490 | xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5, "QuadtreeTULog2MaxSize must be 5 or smaller."); |
---|
491 | xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth, "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller."); |
---|
492 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize, "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize."); |
---|
493 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
494 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
495 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." ); |
---|
496 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." ); |
---|
497 | xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1, "QuadtreeTUMaxDepthInter must be greater than or equal to 1" ); |
---|
498 | 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" ); |
---|
499 | xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1, "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" ); |
---|
500 | 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" ); |
---|
501 | |
---|
502 | // max CU width and height should be power of 2 |
---|
503 | UInt ui = m_uiMaxCUWidth; |
---|
504 | while(ui) |
---|
505 | { |
---|
506 | ui >>= 1; |
---|
507 | if( (ui & 1) == 1) |
---|
508 | xConfirmPara( ui != 1 , "Width should be 2^n"); |
---|
509 | } |
---|
510 | ui = m_uiMaxCUHeight; |
---|
511 | while(ui) |
---|
512 | { |
---|
513 | ui >>= 1; |
---|
514 | if( (ui & 1) == 1) |
---|
515 | xConfirmPara( ui != 1 , "Height should be 2^n"); |
---|
516 | } |
---|
517 | #endif |
---|
518 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
519 | if ( m_colourRemapSEIFile.length() && !m_colourRemapSEICancelFlag ) |
---|
520 | { |
---|
521 | xConfirmPara( m_colourRemapSEICodedDataBitDepth < 8 || m_colourRemapSEICodedDataBitDepth > 16 , "colour_remap_coded_data_bit_depth shall be in the range of 8 to 16, inclusive"); |
---|
522 | xConfirmPara( m_colourRemapSEITargetBitDepth < 8 || (m_colourRemapSEITargetBitDepth > 16 && m_colourRemapSEITargetBitDepth < 255) , "colour_remap_target_bit_depth shall be in the range of 8 to 16, inclusive"); |
---|
523 | for( Int c=0 ; c<3 ; c++) |
---|
524 | { |
---|
525 | 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"); |
---|
526 | if( m_colourRemapSEIPreLutNumValMinus1[c]>0 ) |
---|
527 | for( Int i=0 ; i<=m_colourRemapSEIPreLutNumValMinus1[c] ; i++) |
---|
528 | { |
---|
529 | xConfirmPara( m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_colourRemapSEICodedDataBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_coded_data_bit_depth)-1, inclusive"); |
---|
530 | xConfirmPara( m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_colourRemapSEITargetBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive"); |
---|
531 | } |
---|
532 | 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"); |
---|
533 | if( m_colourRemapSEIPostLutNumValMinus1[c]>0 ) |
---|
534 | for( Int i=0 ; i<=m_colourRemapSEIPostLutNumValMinus1[c] ; i++) |
---|
535 | { |
---|
536 | if( m_colourRemapSEIPreLutNumValMinus1[c]>0 || m_colourRemapSEIMatrixPresentFlag ) |
---|
537 | xConfirmPara( m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_colourRemapSEITargetBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive"); |
---|
538 | else |
---|
539 | xConfirmPara( m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_colourRemapSEICodedDataBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_coded_data_bit_depth)-1, inclusive"); |
---|
540 | xConfirmPara( m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_colourRemapSEITargetBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive"); |
---|
541 | } |
---|
542 | } |
---|
543 | if( m_colourRemapSEIMatrixPresentFlag ) |
---|
544 | { |
---|
545 | xConfirmPara( m_colourRemapSEILog2MatrixDenom < 0 || m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive"); |
---|
546 | for( Int c=0 ; c<3 ; c++) |
---|
547 | for( Int i=0 ; i<3 ; i++) |
---|
548 | 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"); |
---|
549 | } |
---|
550 | } |
---|
551 | #endif |
---|
552 | |
---|
553 | #undef xConfirmPara |
---|
554 | return check_failed; |
---|
555 | } |
---|
556 | |
---|
557 | #endif //SVC_EXTENSION |
---|
558 | |
---|
559 | |
---|
560 | //! \} |
---|