1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TAppEncCfg.cpp |
---|
35 | \brief Handle encoder configuration parameters |
---|
36 | */ |
---|
37 | |
---|
38 | #include <stdlib.h> |
---|
39 | #include <cassert> |
---|
40 | #include <cstring> |
---|
41 | #include <string> |
---|
42 | #include "TLibCommon/TComRom.h" |
---|
43 | #include "TAppEncCfg.h" |
---|
44 | #include "TAppCommon/program_options_lite.h" |
---|
45 | #include "TLibEncoder/TEncRateCtrl.h" |
---|
46 | #ifdef WIN32 |
---|
47 | #define strdup _strdup |
---|
48 | #endif |
---|
49 | |
---|
50 | using namespace std; |
---|
51 | namespace po = df::program_options_lite; |
---|
52 | |
---|
53 | //! \ingroup TAppEncoder |
---|
54 | //! \{ |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Constructor / destructor / initialization / destroy |
---|
58 | // ==================================================================================================================== |
---|
59 | |
---|
60 | TAppEncCfg::TAppEncCfg() |
---|
61 | #if SVC_EXTENSION |
---|
62 | : m_pchBitstreamFile() |
---|
63 | , m_pchColumnWidth() |
---|
64 | , m_pchRowHeight() |
---|
65 | , m_scalingListFile() |
---|
66 | #if REF_IDX_FRAMEWORK |
---|
67 | , m_elRapSliceBEnabled(0) |
---|
68 | #endif |
---|
69 | #else |
---|
70 | : m_pchInputFile() |
---|
71 | , m_pchBitstreamFile() |
---|
72 | , m_pchReconFile() |
---|
73 | , m_pchdQPFile() |
---|
74 | , m_pchColumnWidth() |
---|
75 | , m_pchRowHeight() |
---|
76 | , m_scalingListFile() |
---|
77 | #endif |
---|
78 | { |
---|
79 | #if SVC_EXTENSION |
---|
80 | for(UInt layer=0; layer<MAX_LAYERS; layer++) |
---|
81 | { |
---|
82 | m_acLayerCfg[layer].setAppEncCfg(this); |
---|
83 | } |
---|
84 | #else |
---|
85 | m_aidQP = NULL; |
---|
86 | #endif |
---|
87 | } |
---|
88 | |
---|
89 | TAppEncCfg::~TAppEncCfg() |
---|
90 | { |
---|
91 | #if !SVC_EXTENSION |
---|
92 | if ( m_aidQP ) |
---|
93 | { |
---|
94 | delete[] m_aidQP; |
---|
95 | } |
---|
96 | free(m_pchInputFile); |
---|
97 | #endif |
---|
98 | free(m_pchBitstreamFile); |
---|
99 | #if !SVC_EXTENSION |
---|
100 | free(m_pchReconFile); |
---|
101 | free(m_pchdQPFile); |
---|
102 | #endif |
---|
103 | free(m_pchColumnWidth); |
---|
104 | free(m_pchRowHeight); |
---|
105 | free(m_scalingListFile); |
---|
106 | } |
---|
107 | |
---|
108 | Void TAppEncCfg::create() |
---|
109 | { |
---|
110 | } |
---|
111 | |
---|
112 | Void TAppEncCfg::destroy() |
---|
113 | { |
---|
114 | } |
---|
115 | |
---|
116 | std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry) //input |
---|
117 | { |
---|
118 | in>>entry.m_sliceType; |
---|
119 | in>>entry.m_POC; |
---|
120 | in>>entry.m_QPOffset; |
---|
121 | in>>entry.m_QPFactor; |
---|
122 | in>>entry.m_temporalId; |
---|
123 | in>>entry.m_numRefPicsActive; |
---|
124 | #if !TEMPORAL_LAYER_NON_REFERENCE |
---|
125 | in>>entry.m_refPic; |
---|
126 | #endif |
---|
127 | in>>entry.m_numRefPics; |
---|
128 | for ( Int i = 0; i < entry.m_numRefPics; i++ ) |
---|
129 | { |
---|
130 | in>>entry.m_referencePics[i]; |
---|
131 | } |
---|
132 | in>>entry.m_interRPSPrediction; |
---|
133 | #if AUTO_INTER_RPS |
---|
134 | if (entry.m_interRPSPrediction==1) |
---|
135 | { |
---|
136 | #if !J0234_INTER_RPS_SIMPL |
---|
137 | in>>entry.m_deltaRIdxMinus1; |
---|
138 | #endif |
---|
139 | in>>entry.m_deltaRPS; |
---|
140 | in>>entry.m_numRefIdc; |
---|
141 | for ( Int i = 0; i < entry.m_numRefIdc; i++ ) |
---|
142 | { |
---|
143 | in>>entry.m_refIdc[i]; |
---|
144 | } |
---|
145 | } |
---|
146 | else if (entry.m_interRPSPrediction==2) |
---|
147 | { |
---|
148 | #if !J0234_INTER_RPS_SIMPL |
---|
149 | in>>entry.m_deltaRIdxMinus1; |
---|
150 | #endif |
---|
151 | in>>entry.m_deltaRPS; |
---|
152 | } |
---|
153 | #else |
---|
154 | if (entry.m_interRPSPrediction) |
---|
155 | { |
---|
156 | #if !J0234_INTER_RPS_SIMPL |
---|
157 | in>>entry.m_deltaRIdxMinus1; |
---|
158 | #endif |
---|
159 | in>>entry.m_deltaRPS; |
---|
160 | in>>entry.m_numRefIdc; |
---|
161 | for ( Int i = 0; i < entry.m_numRefIdc; i++ ) |
---|
162 | { |
---|
163 | in>>entry.m_refIdc[i]; |
---|
164 | } |
---|
165 | } |
---|
166 | #endif |
---|
167 | return in; |
---|
168 | } |
---|
169 | |
---|
170 | #if SVC_EXTENSION |
---|
171 | void TAppEncCfg::getDirFilename(string& filename, string& dir, const string path) |
---|
172 | { |
---|
173 | size_t pos = path.find_last_of("\\"); |
---|
174 | if(pos != std::string::npos) |
---|
175 | { |
---|
176 | filename.assign(path.begin() + pos + 1, path.end()); |
---|
177 | dir.assign(path.begin(), path.begin() + pos + 1); |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | pos = path.find_last_of("/"); |
---|
182 | if(pos != std::string::npos) |
---|
183 | { |
---|
184 | filename.assign(path.begin() + pos + 1, path.end()); |
---|
185 | dir.assign(path.begin(), path.begin() + pos + 1); |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | filename = path; |
---|
190 | dir.assign(""); |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | #endif |
---|
195 | |
---|
196 | // ==================================================================================================================== |
---|
197 | // Public member functions |
---|
198 | // ==================================================================================================================== |
---|
199 | |
---|
200 | /** \param argc number of arguments |
---|
201 | \param argv array of arguments |
---|
202 | \retval true when success |
---|
203 | */ |
---|
204 | Bool TAppEncCfg::parseCfg( Int argc, Char* argv[] ) |
---|
205 | { |
---|
206 | bool do_help = false; |
---|
207 | |
---|
208 | #if SVC_EXTENSION |
---|
209 | string cfg_LayerCfgFile [MAX_LAYERS]; |
---|
210 | string cfg_BitstreamFile; |
---|
211 | string* cfg_InputFile [MAX_LAYERS]; |
---|
212 | string* cfg_ReconFile [MAX_LAYERS]; |
---|
213 | Double* cfg_fQP [MAX_LAYERS]; |
---|
214 | |
---|
215 | Int* cfg_SourceWidth [MAX_LAYERS]; |
---|
216 | Int* cfg_SourceHeight [MAX_LAYERS]; |
---|
217 | Int* cfg_FrameRate [MAX_LAYERS]; |
---|
218 | Int* cfg_IntraPeriod [MAX_LAYERS]; |
---|
219 | Int* cfg_CroppingMode [MAX_LAYERS]; |
---|
220 | for(UInt layer = 0; layer < MAX_LAYERS; layer++) |
---|
221 | { |
---|
222 | cfg_InputFile[layer] = &m_acLayerCfg[layer].m_cInputFile; |
---|
223 | cfg_ReconFile[layer] = &m_acLayerCfg[layer].m_cReconFile; |
---|
224 | cfg_fQP[layer] = &m_acLayerCfg[layer].m_fQP; |
---|
225 | cfg_SourceWidth[layer] = &m_acLayerCfg[layer].m_iSourceWidth; |
---|
226 | cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight; |
---|
227 | cfg_FrameRate[layer] = &m_acLayerCfg[layer].m_iFrameRate; |
---|
228 | cfg_IntraPeriod[layer] = &m_acLayerCfg[layer].m_iIntraPeriod; |
---|
229 | cfg_CroppingMode[layer] = &m_acLayerCfg[layer].m_croppingMode; |
---|
230 | } |
---|
231 | #else |
---|
232 | string cfg_InputFile; |
---|
233 | string cfg_BitstreamFile; |
---|
234 | string cfg_ReconFile; |
---|
235 | string cfg_dQPFile; |
---|
236 | #endif |
---|
237 | string cfg_ColumnWidth; |
---|
238 | string cfg_RowHeight; |
---|
239 | string cfg_ScalingListFile; |
---|
240 | po::Options opts; |
---|
241 | opts.addOptions() |
---|
242 | ("help", do_help, false, "this help text") |
---|
243 | ("c", po::parseConfigFile, "configuration file name") |
---|
244 | |
---|
245 | // File, I/O and source parameters |
---|
246 | #if SVC_EXTENSION |
---|
247 | ("InputFile%d,-i%d", cfg_InputFile, string(""), MAX_LAYERS, "original YUV input file name for layer %d") |
---|
248 | ("ReconFile%d,-o%d", cfg_ReconFile, string(""), MAX_LAYERS, "reconstruction YUV input file name for layer %d") |
---|
249 | ("LayerConfig%d,-lc%d", cfg_LayerCfgFile, string(""), MAX_LAYERS, "layer %d configuration file name") |
---|
250 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream output file name") |
---|
251 | ("SourceWidth%d,-wdt%d", cfg_SourceWidth, 0, MAX_LAYERS, "Source picture width for layer %d") |
---|
252 | ("SourceHeight%d,-hgt%d", cfg_SourceHeight, 0, MAX_LAYERS, "Source picture height for layer %d") |
---|
253 | ("FrameRate%d,-fr%d", cfg_FrameRate, 0, MAX_LAYERS, "Frame rate for layer %d") |
---|
254 | ("LambdaModifier%d,-LM%d", m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d") |
---|
255 | ("CroppingMode%d", cfg_CroppingMode,0, MAX_LAYERS, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping") |
---|
256 | ("InputBitDepth", m_uiInputBitDepth, 8u, "bit-depth of input file") |
---|
257 | ("BitDepth", m_uiInputBitDepth, 8u, "deprecated alias of InputBitDepth") |
---|
258 | ("OutputBitDepth", m_uiOutputBitDepth, 0u, "bit-depth of output file") |
---|
259 | ("InternalBitDepth", m_uiInternalBitDepth, 0u, "Internal bit-depth (BitDepth+BitIncrement)") |
---|
260 | #if AVC_BASE |
---|
261 | ("InputBLFile,-ibl", *cfg_InputFile[0], string(""), "Original BL rec YUV input file name") |
---|
262 | #endif |
---|
263 | #if REF_IDX_FRAMEWORK |
---|
264 | ("EnableElRapB,-use-rap-b", m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture_") |
---|
265 | #endif |
---|
266 | #else |
---|
267 | ("InputFile,i", cfg_InputFile, string(""), "Original YUV input file name") |
---|
268 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "Bitstream output file name") |
---|
269 | ("ReconFile,o", cfg_ReconFile, string(""), "Reconstructed YUV output file name") |
---|
270 | ("SourceWidth,-wdt", m_iSourceWidth, 0, "Source picture width") |
---|
271 | ("SourceHeight,-hgt", m_iSourceHeight, 0, "Source picture height") |
---|
272 | ("InputBitDepth", m_uiInputBitDepth, 8u, "Bit-depth of input file") |
---|
273 | ("BitDepth", m_uiInputBitDepth, 8u, "Deprecated alias of InputBitDepth") |
---|
274 | ("OutputBitDepth", m_uiOutputBitDepth, 0u, "Bit-depth of output file") |
---|
275 | ("InternalBitDepth", m_uiInternalBitDepth, 0u, "Internal bit-depth (BitDepth+BitIncrement)") |
---|
276 | ("CroppingMode", m_croppingMode, 0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping") |
---|
277 | ("HorizontalPadding,-pdx",m_aiPad[0], 0, "Horizontal source padding for cropping mode 2") |
---|
278 | ("VerticalPadding,-pdy", m_aiPad[1], 0, "Vertical source padding for cropping mode 2") |
---|
279 | ("CropLeft", m_cropLeft, 0, "Left cropping for cropping mode 3") |
---|
280 | ("CropRight", m_cropRight, 0, "Right cropping for cropping mode 3") |
---|
281 | ("CropTop", m_cropTop, 0, "Top cropping for cropping mode 3") |
---|
282 | ("CropBottom", m_cropBottom, 0, "Bottom cropping for cropping mode 3") |
---|
283 | ("FrameRate,-fr", m_iFrameRate, 0, "Frame rate") |
---|
284 | #endif |
---|
285 | ("FrameSkip,-fs", m_FrameSkip, 0u, "Number of frames to skip at start of input YUV") |
---|
286 | ("FramesToBeEncoded,f", m_iFrameToBeEncoded, 0, "Number of frames to be encoded (default=all)") |
---|
287 | |
---|
288 | #if SVC_EXTENSION |
---|
289 | ("NumLayers", m_numLayers, 1, "Number of layers to code") |
---|
290 | #endif |
---|
291 | |
---|
292 | // Unit definition parameters |
---|
293 | ("MaxCUWidth", m_uiMaxCUWidth, 64u) |
---|
294 | ("MaxCUHeight", m_uiMaxCUHeight, 64u) |
---|
295 | // todo: remove defaults from MaxCUSize |
---|
296 | ("MaxCUSize,s", m_uiMaxCUWidth, 64u, "Maximum CU size") |
---|
297 | ("MaxCUSize,s", m_uiMaxCUHeight, 64u, "Maximum CU size") |
---|
298 | ("MaxPartitionDepth,h", m_uiMaxCUDepth, 4u, "CU depth") |
---|
299 | |
---|
300 | ("QuadtreeTULog2MaxSize", m_uiQuadtreeTULog2MaxSize, 6u, "Maximum TU size in logarithm base 2") |
---|
301 | ("QuadtreeTULog2MinSize", m_uiQuadtreeTULog2MinSize, 2u, "Minimum TU size in logarithm base 2") |
---|
302 | |
---|
303 | ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs") |
---|
304 | ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs") |
---|
305 | |
---|
306 | // Coding structure paramters |
---|
307 | #if SVC_EXTENSION |
---|
308 | ("IntraPeriod%d,-ip%d", cfg_IntraPeriod, -1, MAX_LAYERS, "intra period in frames for layer %d, (-1: only first frame)") |
---|
309 | #else |
---|
310 | ("IntraPeriod,-ip", m_iIntraPeriod, -1, "Intra period in frames, (-1: only first frame)") |
---|
311 | #endif |
---|
312 | ("DecodingRefreshType,-dr", m_iDecodingRefreshType, 0, "Intra refresh type (0:none 1:CRA 2:IDR)") |
---|
313 | ("GOPSize,g", m_iGOPSize, 1, "GOP size of temporal structure") |
---|
314 | ("ListCombination,-lc", m_bUseLComb, true, "Combined reference list for uni-prediction estimation in B-slices") |
---|
315 | // motion options |
---|
316 | ("FastSearch", m_iFastSearch, 1, "0:Full search 1:Diamond 2:PMVFAST") |
---|
317 | ("SearchRange,-sr", m_iSearchRange, 96, "Motion search range") |
---|
318 | ("BipredSearchRange", m_bipredSearchRange, 4, "Motion search range for bipred refinement") |
---|
319 | ("HadamardME", m_bUseHADME, true, "Hadamard ME for fractional-pel") |
---|
320 | ("ASR", m_bUseASR, false, "Adaptive motion search range") |
---|
321 | |
---|
322 | #if !SVC_EXTENSION |
---|
323 | // Mode decision parameters |
---|
324 | ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( double )1.0, "Lambda modifier for temporal layer 0") |
---|
325 | ("LambdaModifier1,-LM1", m_adLambdaModifier[ 1 ], ( double )1.0, "Lambda modifier for temporal layer 1") |
---|
326 | ("LambdaModifier2,-LM2", m_adLambdaModifier[ 2 ], ( double )1.0, "Lambda modifier for temporal layer 2") |
---|
327 | ("LambdaModifier3,-LM3", m_adLambdaModifier[ 3 ], ( double )1.0, "Lambda modifier for temporal layer 3") |
---|
328 | ("LambdaModifier4,-LM4", m_adLambdaModifier[ 4 ], ( double )1.0, "Lambda modifier for temporal layer 4") |
---|
329 | ("LambdaModifier5,-LM5", m_adLambdaModifier[ 5 ], ( double )1.0, "Lambda modifier for temporal layer 5") |
---|
330 | ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( double )1.0, "Lambda modifier for temporal layer 6") |
---|
331 | ("LambdaModifier7,-LM7", m_adLambdaModifier[ 7 ], ( double )1.0, "Lambda modifier for temporal layer 7") |
---|
332 | #endif |
---|
333 | |
---|
334 | /* Quantization parameters */ |
---|
335 | #if SVC_EXTENSION |
---|
336 | ("QP%d,-q%d", cfg_fQP, 30.0, MAX_LAYERS, "Qp value for layer %d, if value is float, QP is switched once during encoding") |
---|
337 | #else |
---|
338 | ("QP,q", m_fQP, 30.0, "Qp value, if value is float, QP is switched once during encoding") |
---|
339 | #endif |
---|
340 | ("DeltaQpRD,-dqr",m_uiDeltaQpRD, 0u, "max dQp offset for slice") |
---|
341 | ("MaxDeltaQP,d", m_iMaxDeltaQP, 0, "max dQp offset for block") |
---|
342 | ("MaxCuDQPDepth,-dqd", m_iMaxCuDQPDepth, 0, "max depth for a minimum CuDQP") |
---|
343 | |
---|
344 | ("CbQpOffset,-cbqpofs", m_cbQpOffset, 0, "Chroma Cb QP Offset") |
---|
345 | ("CrQpOffset,-crqpofs", m_crQpOffset, 0, "Chroma Cr QP Offset") |
---|
346 | |
---|
347 | #if ADAPTIVE_QP_SELECTION |
---|
348 | ("AdaptiveQpSelection,-aqps", m_bUseAdaptQpSelect, false, "AdaptiveQpSelection") |
---|
349 | #endif |
---|
350 | |
---|
351 | ("AdaptiveQP,-aq", m_bUseAdaptiveQP, false, "QP adaptation based on a psycho-visual model") |
---|
352 | ("MaxQPAdaptationRange,-aqr", m_iQPAdaptationRange, 6, "QP adaptation range") |
---|
353 | #if !SVC_EXTENSION |
---|
354 | ("dQPFile,m", cfg_dQPFile, string(""), "dQP file name") |
---|
355 | #endif |
---|
356 | ("RDOQ", m_bUseRDOQ, true ) |
---|
357 | |
---|
358 | // Entropy coding parameters |
---|
359 | ("SBACRD", m_bUseSBACRD, true, "SBAC based RD estimation") |
---|
360 | |
---|
361 | // Deblocking filter parameters |
---|
362 | ("LoopFilterDisable", m_bLoopFilterDisable, false ) |
---|
363 | ("LoopFilterOffsetInPPS", m_loopFilterOffsetInPPS, false ) |
---|
364 | ("LoopFilterBetaOffset_div2", m_loopFilterBetaOffsetDiv2, 0 ) |
---|
365 | ("LoopFilterTcOffset_div2", m_loopFilterTcOffsetDiv2, 0 ) |
---|
366 | ("DeblockingFilterControlPresent", m_DeblockingFilterControlPresent, false ) |
---|
367 | |
---|
368 | // Coding tools |
---|
369 | #if !REMOVE_NSQT |
---|
370 | ("NSQT", m_enableNSQT, true, "Enable non-square transforms") |
---|
371 | #endif |
---|
372 | ("AMP", m_enableAMP, true, "Enable asymmetric motion partitions") |
---|
373 | #if !REMOVE_LMCHROMA |
---|
374 | ("LMChroma", m_bUseLMChroma, true, "Intra chroma prediction based on reconstructed luma") |
---|
375 | #endif |
---|
376 | ("TransformSkip", m_useTransformSkip, false, "Intra transform skipping") |
---|
377 | ("TransformSkipFast", m_useTransformSkipFast, false, "Fast intra transform skipping") |
---|
378 | #if !REMOVE_ALF |
---|
379 | ("ALF", m_bUseALF, true, "Enable Adaptive Loop Filter") |
---|
380 | #endif |
---|
381 | ("SAO", m_bUseSAO, true, "Enable Sample Adaptive Offset") |
---|
382 | ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "Max number of SAO offset per picture (Default: 2048)") |
---|
383 | #if SAO_LCU_BOUNDARY |
---|
384 | ("SAOLcuBoundary", m_saoLcuBoundary, false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas") |
---|
385 | #endif |
---|
386 | ("SAOLcuBasedOptimization", m_saoLcuBasedOptimization, true, "0: SAO picture-based optimization, 1: SAO LCU-based optimization ") |
---|
387 | #if !REMOVE_ALF |
---|
388 | ("ALFLowLatencyEncode", m_alfLowLatencyEncoding, false, "Low-latency ALF encoding, 0: picture latency (trained from current frame), 1: LCU latency(trained from previous frame)") |
---|
389 | #endif |
---|
390 | ("SliceMode", m_iSliceMode, 0, "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes") |
---|
391 | ("SliceArgument", m_iSliceArgument, 0, "if SliceMode==1 SliceArgument represents max # of LCUs. if SliceMode==2 SliceArgument represents max # of bytes.") |
---|
392 | ("DependentSliceMode", m_iDependentSliceMode, 0, "0: Disable all dependent slice limits, 1: Enforce max # of LCUs, 2: Enforce constraint based dependent slices") |
---|
393 | ("DependentSliceArgument", m_iDependentSliceArgument,0, "if DependentSliceMode==1 SliceArgument represents max # of LCUs. if DependentSliceMode==2 DependentSliceArgument represents max # of bins.") |
---|
394 | #if DEPENDENT_SLICES |
---|
395 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
396 | ("EntropySliceEnabledFlag", m_entropySliceEnabledFlag, false, "Enable use of entropy slices instead of dependent slices." ) |
---|
397 | #else |
---|
398 | ("CabacIndependentFlag", m_bCabacIndependentFlag, false) |
---|
399 | #endif |
---|
400 | #endif |
---|
401 | #if !REMOVE_FGS |
---|
402 | ("SliceGranularity", m_iSliceGranularity, 0, "0: Slices always end at LCU borders. 1-3: slices may end at a depth of 1-3 below LCU level.") |
---|
403 | #endif |
---|
404 | ("LFCrossSliceBoundaryFlag", m_bLFCrossSliceBoundaryFlag, true) |
---|
405 | |
---|
406 | ("ConstrainedIntraPred", m_bUseConstrainedIntraPred, false, "Constrained Intra Prediction") |
---|
407 | ("PCMEnabledFlag", m_usePCM , false) |
---|
408 | ("PCMLog2MaxSize", m_pcmLog2MaxSize, 5u) |
---|
409 | ("PCMLog2MinSize", m_uiPCMLog2MinSize, 3u) |
---|
410 | |
---|
411 | ("PCMInputBitDepthFlag", m_bPCMInputBitDepthFlag, true) |
---|
412 | ("PCMFilterDisableFlag", m_bPCMFilterDisableFlag, false) |
---|
413 | ("LosslessCuEnabled", m_useLossless, false) |
---|
414 | ("weighted_pred_flag,-wpP", m_bUseWeightPred, false, "weighted prediction flag (P-Slices)") |
---|
415 | ("weighted_bipred_flag,-wpB", m_useWeightedBiPred, false, "weighted bipred flag (B-Slices)") |
---|
416 | ("Log2ParallelMergeLevel", m_log2ParallelMergeLevel, 2u, "Parallel merge estimation region") |
---|
417 | ("UniformSpacingIdc", m_iUniformSpacingIdr, 0, "Indicates if the column and row boundaries are distributed uniformly") |
---|
418 | ("NumTileColumnsMinus1", m_iNumColumnsMinus1, 0, "Number of columns in a picture minus 1") |
---|
419 | ("ColumnWidthArray", cfg_ColumnWidth, string(""), "Array containing ColumnWidth values in units of LCU") |
---|
420 | ("NumTileRowsMinus1", m_iNumRowsMinus1, 0, "Number of rows in a picture minus 1") |
---|
421 | ("RowHeightArray", cfg_RowHeight, string(""), "Array containing RowHeight values in units of LCU") |
---|
422 | ("LFCrossTileBoundaryFlag", m_bLFCrossTileBoundaryFlag, true, "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering") |
---|
423 | ("WaveFrontSynchro", m_iWaveFrontSynchro, 0, "0: no synchro; 1 synchro with TR; 2 TRR etc") |
---|
424 | ("ScalingList", m_useScalingListId, 0, "0: no scaling list, 1: default scaling lists, 2: scaling lists specified in ScalingListFile") |
---|
425 | ("ScalingListFile", cfg_ScalingListFile, string(""), "Scaling list file name") |
---|
426 | ("SignHideFlag,-SBH", m_signHideFlag, 1) |
---|
427 | ("MaxNumMergeCand", m_maxNumMergeCand, 5u, "Maximum number of merge candidates") |
---|
428 | |
---|
429 | /* Misc. */ |
---|
430 | ("SEIpictureDigest", m_decodePictureHashSEIEnabled, 0, "Control generation of decode picture hash SEI messages\n" |
---|
431 | "\t3: checksum\n" |
---|
432 | "\t2: CRC\n" |
---|
433 | "\t1: use MD5\n" |
---|
434 | "\t0: disable") |
---|
435 | ("TMVPMode", m_TMVPModeId, 1, "TMVP mode 0: TMVP disable for all slices. 1: TMVP enable for all slices (default) 2: TMVP enable for certain slices only") |
---|
436 | ("FEN", m_bUseFastEnc, false, "fast encoder setting") |
---|
437 | ("ECU", m_bUseEarlyCU, false, "Early CU setting") |
---|
438 | ("FDM", m_useFastDecisionForMerge, true, "Fast decision for Merge RD Cost") |
---|
439 | ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting") |
---|
440 | ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting") |
---|
441 | ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off") |
---|
442 | ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate") |
---|
443 | ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit") |
---|
444 | |
---|
445 | ("TransquantBypassEnableFlag", m_TransquantBypassEnableFlag, false, "transquant_bypass_enable_flag indicator in PPS") |
---|
446 | ("CUTransquantBypassFlagValue", m_CUTransquantBypassFlagValue, false, "Fixed cu_transquant_bypass_flag value, when transquant_bypass_enable_flag is enabled") |
---|
447 | #if RECALCULATE_QP_ACCORDING_LAMBDA |
---|
448 | ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case") |
---|
449 | #endif |
---|
450 | #if ACTIVE_PARAMETER_SETS_SEI_MESSAGE |
---|
451 | ("ActiveParameterSets", m_activeParameterSetsSEIEnabled, 0, "Control generation of active parameter sets SEI messages\n" |
---|
452 | "\t2: enable active parameter sets SEI message with active_sps_id\n" |
---|
453 | "\t1: enable active parameter sets SEI message without active_sps_id\n" |
---|
454 | "\t0: disable") |
---|
455 | #endif |
---|
456 | #if SUPPORT_FOR_VUI |
---|
457 | ("VuiParametersPresent,-vui", m_vuiParametersPresentFlag, false, "Enable generation of vui_parameters()") |
---|
458 | ("AspectRatioInfoPresent", m_aspectRatioInfoPresentFlag, false, "Signals whether aspect_ratio_idc is present") |
---|
459 | ("AspectRatioIdc", m_aspectRatioIdc, 0, "aspect_ratio_idc") |
---|
460 | ("SarWidth", m_sarWidth, 0, "horizontal size of the sample aspect ratio") |
---|
461 | ("SarHeight", m_sarHeight, 0, "vertical size of the sample aspect ratio") |
---|
462 | ("OverscanInfoPresent", m_overscanInfoPresentFlag, false, "Indicates whether cropped decoded pictures are suitable for display using overscan\n") |
---|
463 | ("OverscanAppropriate", m_overscanAppropriateFlag, false, "Indicates whether cropped decoded pictures are suitable for display using overscan\n") |
---|
464 | ("VideoSignalTypePresent", m_videoSignalTypePresentFlag, false, "Signals whether video_format, video_full_range_flag, and colour_description_present_flag are present") |
---|
465 | ("VideoFormat", m_videoFormat, 5, "Indicates representation of pictures") |
---|
466 | ("VideoFullRange", m_videoFullRangeFlag, false, "Indicates the black level and range of luma and chroma signals") |
---|
467 | ("ColourDescriptionPresent", m_colourDescriptionPresentFlag, false, "Signals whether colour_primaries, transfer_characteristics and matrix_coefficients are present") |
---|
468 | ("ColourPrimaries", m_colourPrimaries, 2, "Indicates chromaticity coordinates of the source primaries") |
---|
469 | ("TransferCharateristics", m_transferCharacteristics, 2, "Indicates the opto-electronic transfer characteristics of the source") |
---|
470 | ("MatrixCoefficients", m_matrixCoefficients, 2, "Describes the matrix coefficients used in deriving luma and chroma from RGB primaries") |
---|
471 | ("ChromaLocInfoPresent", m_chromaLocInfoPresentFlag, false, "Signals whether chroma_sample_loc_type_top_field and chroma_sample_loc_type_bottom_field are present") |
---|
472 | ("ChromaSampleLocTypeTopField", m_chromaSampleLocTypeTopField, 0, "Specifies the location of chroma samples for top field") |
---|
473 | ("ChromaSampleLocTypeBottomField", m_chromaSampleLocTypeBottomField, 0, "Specifies the location of chroma samples for bottom field") |
---|
474 | ("NeutralChromaIndication", m_neutralChromaIndicationFlag, false, "Indicates that the value of all decoded chroma samples is equal to 1<<(BitDepthCr-1)") |
---|
475 | ("BitstreamRestriction", m_bitstreamRestrictionFlag, false, "Signals whether bitstream restriction parameters are present") |
---|
476 | ("TilesFixedStructure", m_tilesFixedStructureFlag, false, "Indicates that each active picture parameter set has the same values of the syntax elements related to tiles") |
---|
477 | ("MotionVectorsOverPicBoundaries", m_motionVectorsOverPicBoundariesFlag, false, "Indicates that no samples outside the picture boundaries are used for inter prediction") |
---|
478 | ("MaxBytesPerPicDenom", m_maxBytesPerPicDenom, 2, "Indicates a number of bytes not exceeded by the sum of the sizes of the VCL NAL units associated with any coded picture") |
---|
479 | ("MaxBitsPerMinCuDenom", m_maxBitsPerMinCuDenom, 1, "Indicates an upper bound for the number of bits of coding_unit() data") |
---|
480 | ("Log2MaxMvLengthHorizontal", m_log2MaxMvLengthHorizontal, 15, "Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units") |
---|
481 | ("Log2MaxMvLengthVertical", m_log2MaxMvLengthVertical, 15, "Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units") |
---|
482 | #endif |
---|
483 | #if RECOVERY_POINT_SEI |
---|
484 | ("SEIRecoveryPoint", m_recoveryPointSEIEnabled, 0, "Control generation of recovery point SEI messages") |
---|
485 | #endif |
---|
486 | #if BUFFERING_PERIOD_AND_TIMING_SEI |
---|
487 | ("SEIBufferingPeriod", m_bufferingPeriodSEIEnabled, 0, "Control generation of buffering period SEI messages") |
---|
488 | ("SEIPictureTiming", m_pictureTimingSEIEnabled, 0, "Control generation of picture timing SEI messages") |
---|
489 | #endif |
---|
490 | ; |
---|
491 | |
---|
492 | for(Int i=1; i<MAX_GOP+1; i++) { |
---|
493 | std::ostringstream cOSS; |
---|
494 | cOSS<<"Frame"<<i; |
---|
495 | opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry()); |
---|
496 | } |
---|
497 | po::setDefaults(opts); |
---|
498 | const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv); |
---|
499 | |
---|
500 | for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) |
---|
501 | { |
---|
502 | fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it); |
---|
503 | } |
---|
504 | |
---|
505 | if (argc == 1 || do_help) |
---|
506 | { |
---|
507 | /* argc == 1: no options have been specified */ |
---|
508 | po::doHelp(cout, opts); |
---|
509 | return false; |
---|
510 | } |
---|
511 | |
---|
512 | /* |
---|
513 | * Set any derived parameters |
---|
514 | */ |
---|
515 | /* convert std::string to c string for compatability */ |
---|
516 | #if SVC_EXTENSION |
---|
517 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
518 | #else |
---|
519 | m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str()); |
---|
520 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
521 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
522 | m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str()); |
---|
523 | #endif |
---|
524 | |
---|
525 | m_pchColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str()); |
---|
526 | m_pchRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str()); |
---|
527 | m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str()); |
---|
528 | |
---|
529 | #if !SVC_EXTENSION |
---|
530 | // TODO:ChromaFmt assumes 4:2:0 below |
---|
531 | switch (m_croppingMode) |
---|
532 | { |
---|
533 | case 0: |
---|
534 | { |
---|
535 | // no cropping or padding |
---|
536 | m_cropLeft = m_cropRight = m_cropTop = m_cropBottom = 0; |
---|
537 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
538 | break; |
---|
539 | } |
---|
540 | case 1: |
---|
541 | { |
---|
542 | // automatic padding to minimum CU size |
---|
543 | Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1); |
---|
544 | if (m_iSourceWidth % minCuSize) |
---|
545 | { |
---|
546 | m_aiPad[0] = m_cropRight = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth; |
---|
547 | m_iSourceWidth += m_cropRight; |
---|
548 | } |
---|
549 | if (m_iSourceHeight % minCuSize) |
---|
550 | { |
---|
551 | m_aiPad[1] = m_cropBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight; |
---|
552 | m_iSourceHeight += m_cropBottom; |
---|
553 | } |
---|
554 | if (m_aiPad[0] % TComSPS::getCropUnitX(CHROMA_420) != 0) |
---|
555 | { |
---|
556 | fprintf(stderr, "Error: picture width is not an integer multiple of the specified chroma subsampling\n"); |
---|
557 | exit(EXIT_FAILURE); |
---|
558 | } |
---|
559 | if (m_aiPad[1] % TComSPS::getCropUnitY(CHROMA_420) != 0) |
---|
560 | { |
---|
561 | fprintf(stderr, "Error: picture height is not an integer multiple of the specified chroma subsampling\n"); |
---|
562 | exit(EXIT_FAILURE); |
---|
563 | } |
---|
564 | break; |
---|
565 | } |
---|
566 | case 2: |
---|
567 | { |
---|
568 | //padding |
---|
569 | m_iSourceWidth += m_aiPad[0]; |
---|
570 | m_iSourceHeight += m_aiPad[1]; |
---|
571 | m_cropRight = m_aiPad[0]; |
---|
572 | m_cropBottom = m_aiPad[1]; |
---|
573 | break; |
---|
574 | } |
---|
575 | case 3: |
---|
576 | { |
---|
577 | // cropping |
---|
578 | if ((m_cropLeft == 0) && (m_cropRight == 0) && (m_cropTop == 0) && (m_cropBottom == 0)) |
---|
579 | { |
---|
580 | fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n"); |
---|
581 | } |
---|
582 | if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0)) |
---|
583 | { |
---|
584 | fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n"); |
---|
585 | } |
---|
586 | m_aiPad[1] = m_aiPad[0] = 0; |
---|
587 | break; |
---|
588 | } |
---|
589 | } |
---|
590 | |
---|
591 | // allocate slice-based dQP values |
---|
592 | m_aidQP = new Int[ m_iFrameToBeEncoded + m_iGOPSize + 1 ]; |
---|
593 | ::memset( m_aidQP, 0, sizeof(Int)*( m_iFrameToBeEncoded + m_iGOPSize + 1 ) ); |
---|
594 | |
---|
595 | // handling of floating-point QP values |
---|
596 | // if QP is not integer, sequence is split into two sections having QP and QP+1 |
---|
597 | m_iQP = (Int)( m_fQP ); |
---|
598 | if ( m_iQP < m_fQP ) |
---|
599 | { |
---|
600 | Int iSwitchPOC = (Int)( m_iFrameToBeEncoded - (m_fQP - m_iQP)*m_iFrameToBeEncoded + 0.5 ); |
---|
601 | |
---|
602 | iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize; |
---|
603 | for ( Int i=iSwitchPOC; i<m_iFrameToBeEncoded + m_iGOPSize + 1; i++ ) |
---|
604 | { |
---|
605 | m_aidQP[i] = 1; |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | // reading external dQP description from file |
---|
610 | if ( m_pchdQPFile ) |
---|
611 | { |
---|
612 | FILE* fpt=fopen( m_pchdQPFile, "r" ); |
---|
613 | if ( fpt ) |
---|
614 | { |
---|
615 | Int iValue; |
---|
616 | Int iPOC = 0; |
---|
617 | while ( iPOC < m_iFrameToBeEncoded ) |
---|
618 | { |
---|
619 | if ( fscanf(fpt, "%d", &iValue ) == EOF ) break; |
---|
620 | m_aidQP[ iPOC ] = iValue; |
---|
621 | iPOC++; |
---|
622 | } |
---|
623 | fclose(fpt); |
---|
624 | } |
---|
625 | } |
---|
626 | m_iWaveFrontSubstreams = m_iWaveFrontSynchro ? (m_iSourceHeight + m_uiMaxCUHeight - 1) / m_uiMaxCUHeight : 1; |
---|
627 | #endif |
---|
628 | // check validity of input parameters |
---|
629 | xCheckParameter(); |
---|
630 | |
---|
631 | // set global varibles |
---|
632 | xSetGlobal(); |
---|
633 | |
---|
634 | // print-out parameters |
---|
635 | xPrintParameter(); |
---|
636 | |
---|
637 | return true; |
---|
638 | } |
---|
639 | |
---|
640 | // ==================================================================================================================== |
---|
641 | // Private member functions |
---|
642 | // ==================================================================================================================== |
---|
643 | |
---|
644 | Bool confirmPara(Bool bflag, const char* message); |
---|
645 | |
---|
646 | Void TAppEncCfg::xCheckParameter() |
---|
647 | { |
---|
648 | if (!m_decodePictureHashSEIEnabled) |
---|
649 | { |
---|
650 | fprintf(stderr, "*************************************************************\n"); |
---|
651 | fprintf(stderr, "** WARNING: --SEIpictureDigest is now disabled by default. **\n"); |
---|
652 | fprintf(stderr, "** Automatic verification of decoded pictures by **\n"); |
---|
653 | fprintf(stderr, "** a decoder requires this option to be enabled. **\n"); |
---|
654 | fprintf(stderr, "*************************************************************\n"); |
---|
655 | } |
---|
656 | |
---|
657 | bool check_failed = false; /* abort if there is a fatal configuration problem */ |
---|
658 | #define xConfirmPara(a,b) check_failed |= confirmPara(a,b) |
---|
659 | // check range of parameters |
---|
660 | xConfirmPara( m_uiInputBitDepth < 8, "InputBitDepth must be at least 8" ); |
---|
661 | #if !SVC_EXTENSION |
---|
662 | xConfirmPara( m_iFrameRate <= 0, "Frame rate must be more than 1" ); |
---|
663 | #endif |
---|
664 | xConfirmPara( m_iFrameToBeEncoded <= 0, "Total Number Of Frames encoded must be more than 0" ); |
---|
665 | xConfirmPara( m_iGOPSize < 1 , "GOP Size must be greater or equal to 1" ); |
---|
666 | xConfirmPara( m_iGOPSize > 1 && m_iGOPSize % 2, "GOP Size must be a multiple of 2, if GOP Size is greater than 1" ); |
---|
667 | #if !SVC_EXTENSION |
---|
668 | xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" ); |
---|
669 | #endif |
---|
670 | xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2, "Decoding Refresh Type must be equal to 0, 1 or 2" ); |
---|
671 | #if !SVC_EXTENSION |
---|
672 | xConfirmPara( m_iQP < -6 * ((Int)m_uiInternalBitDepth - 8) || m_iQP > 51, "QP exceeds supported range (-QpBDOffsety to 51)" ); |
---|
673 | #endif |
---|
674 | xConfirmPara( m_loopFilterBetaOffsetDiv2 < -13 || m_loopFilterBetaOffsetDiv2 > 13, "Loop Filter Beta Offset div. 2 exceeds supported range (-13 to 13)"); |
---|
675 | xConfirmPara( m_loopFilterTcOffsetDiv2 < -13 || m_loopFilterTcOffsetDiv2 > 13, "Loop Filter Tc Offset div. 2 exceeds supported range (-13 to 13)"); |
---|
676 | xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2, "Fast Search Mode is not supported value (0:Full search 1:Diamond 2:PMVFAST)" ); |
---|
677 | xConfirmPara( m_iSearchRange < 0 , "Search Range must be more than 0" ); |
---|
678 | xConfirmPara( m_bipredSearchRange < 0 , "Search Range must be more than 0" ); |
---|
679 | xConfirmPara( m_iMaxDeltaQP > 7, "Absolute Delta QP exceeds supported range (0 to 7)" ); |
---|
680 | xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1, "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" ); |
---|
681 | |
---|
682 | xConfirmPara( m_cbQpOffset < -12, "Min. Chroma Cb QP Offset is -12" ); |
---|
683 | xConfirmPara( m_cbQpOffset > 12, "Max. Chroma Cb QP Offset is 12" ); |
---|
684 | xConfirmPara( m_crQpOffset < -12, "Min. Chroma Cr QP Offset is -12" ); |
---|
685 | xConfirmPara( m_crQpOffset > 12, "Max. Chroma Cr QP Offset is 12" ); |
---|
686 | |
---|
687 | xConfirmPara( m_iQPAdaptationRange <= 0, "QP Adaptation Range must be more than 0" ); |
---|
688 | #if !SVC_EXTENSION |
---|
689 | if (m_iDecodingRefreshType == 2) |
---|
690 | { |
---|
691 | xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= m_iGOPSize , "Intra period must be larger than GOP size for periodic IDR pictures"); |
---|
692 | } |
---|
693 | #endif |
---|
694 | xConfirmPara( (m_uiMaxCUWidth >> m_uiMaxCUDepth) < 4, "Minimum partition width size should be larger than or equal to 8"); |
---|
695 | xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4, "Minimum partition height size should be larger than or equal to 8"); |
---|
696 | xConfirmPara( m_uiMaxCUWidth < 16, "Maximum partition width size should be larger than or equal to 16"); |
---|
697 | xConfirmPara( m_uiMaxCUHeight < 16, "Maximum partition height size should be larger than or equal to 16"); |
---|
698 | #if !SVC_EXTENSION |
---|
699 | xConfirmPara( (m_iSourceWidth % (m_uiMaxCUWidth >> (m_uiMaxCUDepth-1)))!=0, "Resulting coded frame width must be a multiple of the minimum CU size"); |
---|
700 | xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0, "Resulting coded frame height must be a multiple of the minimum CU size"); |
---|
701 | #endif |
---|
702 | |
---|
703 | xConfirmPara( m_uiQuadtreeTULog2MinSize < 2, "QuadtreeTULog2MinSize must be 2 or greater."); |
---|
704 | xConfirmPara( m_uiQuadtreeTULog2MinSize > 5, "QuadtreeTULog2MinSize must be 5 or smaller."); |
---|
705 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < 2, "QuadtreeTULog2MaxSize must be 2 or greater."); |
---|
706 | xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5, "QuadtreeTULog2MaxSize must be 5 or smaller."); |
---|
707 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize, "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize."); |
---|
708 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
709 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
710 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." ); |
---|
711 | xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." ); |
---|
712 | xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1, "QuadtreeTUMaxDepthInter must be greater than or equal to 1" ); |
---|
713 | xConfirmPara( m_uiQuadtreeTUMaxDepthInter > m_uiQuadtreeTULog2MaxSize - m_uiQuadtreeTULog2MinSize + 1, "QuadtreeTUMaxDepthInter must be less than or equal to the difference between QuadtreeTULog2MaxSize and QuadtreeTULog2MinSize plus 1" ); |
---|
714 | xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1, "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" ); |
---|
715 | xConfirmPara( m_uiQuadtreeTUMaxDepthIntra > m_uiQuadtreeTULog2MaxSize - m_uiQuadtreeTULog2MinSize + 1, "QuadtreeTUMaxDepthIntra must be less than or equal to the difference between QuadtreeTULog2MaxSize and QuadtreeTULog2MinSize plus 1" ); |
---|
716 | |
---|
717 | xConfirmPara( m_maxNumMergeCand < 1, "MaxNumMergeCand must be 1 or greater."); |
---|
718 | xConfirmPara( m_maxNumMergeCand > 5, "MaxNumMergeCand must be 5 or smaller."); |
---|
719 | |
---|
720 | #if !SVC_EXTENSION |
---|
721 | #if ADAPTIVE_QP_SELECTION |
---|
722 | xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP < 0, "AdaptiveQpSelection must be disabled when QP < 0."); |
---|
723 | xConfirmPara( m_bUseAdaptQpSelect == true && (m_cbQpOffset !=0 || m_crQpOffset != 0 ), "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0."); |
---|
724 | #endif |
---|
725 | #endif |
---|
726 | |
---|
727 | if( m_usePCM) |
---|
728 | { |
---|
729 | xConfirmPara( m_uiPCMLog2MinSize < 3, "PCMLog2MinSize must be 3 or greater."); |
---|
730 | xConfirmPara( m_uiPCMLog2MinSize > 5, "PCMLog2MinSize must be 5 or smaller."); |
---|
731 | xConfirmPara( m_pcmLog2MaxSize > 5, "PCMLog2MaxSize must be 5 or smaller."); |
---|
732 | xConfirmPara( m_pcmLog2MaxSize < m_uiPCMLog2MinSize, "PCMLog2MaxSize must be equal to or greater than m_uiPCMLog2MinSize."); |
---|
733 | } |
---|
734 | |
---|
735 | xConfirmPara( m_iSliceMode < 0 || m_iSliceMode > 3, "SliceMode exceeds supported range (0 to 3)" ); |
---|
736 | if (m_iSliceMode!=0) |
---|
737 | { |
---|
738 | xConfirmPara( m_iSliceArgument < 1 , "SliceArgument should be larger than or equal to 1" ); |
---|
739 | } |
---|
740 | #if !REMOVE_FGS |
---|
741 | if (m_iSliceMode==3) |
---|
742 | { |
---|
743 | xConfirmPara( m_iSliceGranularity > 0 , "When SliceMode == 3 is chosen, the SliceGranularity must be 0" ); |
---|
744 | } |
---|
745 | #endif |
---|
746 | xConfirmPara( m_iDependentSliceMode < 0 || m_iDependentSliceMode > 2, "DependentSliceMode exceeds supported range (0 to 2)" ); |
---|
747 | if (m_iDependentSliceMode!=0) |
---|
748 | { |
---|
749 | xConfirmPara( m_iDependentSliceArgument < 1 , "DependentSliceArgument should be larger than or equal to 1" ); |
---|
750 | } |
---|
751 | #if !REMOVE_FGS |
---|
752 | xConfirmPara( m_iSliceGranularity >= m_uiMaxCUDepth, "SliceGranularity must be smaller than maximum cu depth"); |
---|
753 | xConfirmPara( m_iSliceGranularity <0 || m_iSliceGranularity > 3, "SliceGranularity exceeds supported range (0 to 3)" ); |
---|
754 | xConfirmPara( m_iSliceGranularity > m_iMaxCuDQPDepth, "SliceGranularity must be smaller smaller than or equal to maximum dqp depth" ); |
---|
755 | #endif |
---|
756 | |
---|
757 | bool tileFlag = (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0 ); |
---|
758 | #if !TILES_WPP_ENTROPYSLICES_FLAGS |
---|
759 | xConfirmPara( tileFlag && m_iDependentSliceMode, "Tile and Dependent Slice can not be applied together"); |
---|
760 | #endif |
---|
761 | xConfirmPara( tileFlag && m_iWaveFrontSynchro, "Tile and Wavefront can not be applied together"); |
---|
762 | #if !DEPENDENT_SLICES |
---|
763 | xConfirmPara( m_iWaveFrontSynchro && m_iDependentSliceMode, "Wavefront and Dependent Slice can not be applied together"); |
---|
764 | #endif |
---|
765 | #if DEPENDENT_SLICES |
---|
766 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
767 | xConfirmPara( m_iWaveFrontSynchro && m_entropySliceEnabledFlag, "WaveFrontSynchro and EntropySliceEnabledFlag can not be applied together"); |
---|
768 | #else |
---|
769 | xConfirmPara( m_iWaveFrontSynchro && m_bCabacIndependentFlag, "Wavefront and CabacIndependentFlag can not be applied together"); |
---|
770 | #endif |
---|
771 | #endif |
---|
772 | |
---|
773 | //TODO:ChromaFmt assumes 4:2:0 below |
---|
774 | #if !SVC_EXTENSION |
---|
775 | xConfirmPara( m_iSourceWidth % TComSPS::getCropUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling"); |
---|
776 | xConfirmPara( m_iSourceHeight % TComSPS::getCropUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling"); |
---|
777 | #endif |
---|
778 | |
---|
779 | #if !SVC_EXTENSION |
---|
780 | xConfirmPara( m_aiPad[0] % TComSPS::getCropUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling"); |
---|
781 | xConfirmPara( m_aiPad[1] % TComSPS::getCropUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling"); |
---|
782 | |
---|
783 | xConfirmPara( m_cropLeft % TComSPS::getCropUnitX(CHROMA_420) != 0, "Left cropping must be an integer multiple of the specified chroma subsampling"); |
---|
784 | xConfirmPara( m_cropRight % TComSPS::getCropUnitX(CHROMA_420) != 0, "Right cropping must be an integer multiple of the specified chroma subsampling"); |
---|
785 | xConfirmPara( m_cropTop % TComSPS::getCropUnitY(CHROMA_420) != 0, "Top cropping must be an integer multiple of the specified chroma subsampling"); |
---|
786 | xConfirmPara( m_cropBottom % TComSPS::getCropUnitY(CHROMA_420) != 0, "Bottom cropping must be an integer multiple of the specified chroma subsampling"); |
---|
787 | #endif |
---|
788 | |
---|
789 | #if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV |
---|
790 | xConfirmPara( REF_IDX_ME_AROUND_ZEROMV && REF_IDX_ME_ZEROMV, "REF_IDX_ME_AROUND_ZEROMV and REF_IDX_ME_ZEROMV cannot be enabled simultaneously"); |
---|
791 | #endif |
---|
792 | // max CU width and height should be power of 2 |
---|
793 | UInt ui = m_uiMaxCUWidth; |
---|
794 | while(ui) |
---|
795 | { |
---|
796 | ui >>= 1; |
---|
797 | if( (ui & 1) == 1) |
---|
798 | xConfirmPara( ui != 1 , "Width should be 2^n"); |
---|
799 | } |
---|
800 | ui = m_uiMaxCUHeight; |
---|
801 | while(ui) |
---|
802 | { |
---|
803 | ui >>= 1; |
---|
804 | if( (ui & 1) == 1) |
---|
805 | xConfirmPara( ui != 1 , "Height should be 2^n"); |
---|
806 | } |
---|
807 | |
---|
808 | Bool verifiedGOP=false; |
---|
809 | Bool errorGOP=false; |
---|
810 | Int checkGOP=1; |
---|
811 | Int numRefs = 1; |
---|
812 | Int refList[MAX_NUM_REF_PICS+1]; |
---|
813 | refList[0]=0; |
---|
814 | Bool isOK[MAX_GOP]; |
---|
815 | for(Int i=0; i<MAX_GOP; i++) |
---|
816 | { |
---|
817 | isOK[i]=false; |
---|
818 | } |
---|
819 | Int numOK=0; |
---|
820 | #if !SVC_EXTENSION |
---|
821 | xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" ); |
---|
822 | #endif |
---|
823 | |
---|
824 | for(Int i=0; i<m_iGOPSize; i++) |
---|
825 | { |
---|
826 | if(m_GOPList[i].m_POC==m_iGOPSize) |
---|
827 | { |
---|
828 | xConfirmPara( m_GOPList[i].m_temporalId!=0 , "The last frame in each GOP must have temporal ID = 0 " ); |
---|
829 | } |
---|
830 | } |
---|
831 | |
---|
832 | m_extraRPSs=0; |
---|
833 | |
---|
834 | #if SVC_EXTENSION |
---|
835 | // verify layer configuration parameters |
---|
836 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
837 | { |
---|
838 | if(m_acLayerCfg[layer].xCheckParameter()) |
---|
839 | { |
---|
840 | printf("\nError: invalid configuration parameter found in layer %d \n", layer); |
---|
841 | check_failed = true; |
---|
842 | } |
---|
843 | } |
---|
844 | #endif |
---|
845 | |
---|
846 | //start looping through frames in coding order until we can verify that the GOP structure is correct. |
---|
847 | while(!verifiedGOP&&!errorGOP) |
---|
848 | { |
---|
849 | Int curGOP = (checkGOP-1)%m_iGOPSize; |
---|
850 | Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_GOPList[curGOP].m_POC; |
---|
851 | if(m_GOPList[curGOP].m_POC<0) |
---|
852 | { |
---|
853 | printf("\nError: found fewer Reference Picture Sets than GOPSize\n"); |
---|
854 | errorGOP=true; |
---|
855 | } |
---|
856 | else |
---|
857 | { |
---|
858 | //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP. |
---|
859 | Bool beforeI = false; |
---|
860 | for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) |
---|
861 | { |
---|
862 | Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i]; |
---|
863 | if(absPOC < 0) |
---|
864 | { |
---|
865 | beforeI=true; |
---|
866 | } |
---|
867 | else |
---|
868 | { |
---|
869 | Bool found=false; |
---|
870 | for(Int j=0; j<numRefs; j++) |
---|
871 | { |
---|
872 | if(refList[j]==absPOC) |
---|
873 | { |
---|
874 | found=true; |
---|
875 | for(Int k=0; k<m_iGOPSize; k++) |
---|
876 | { |
---|
877 | if(absPOC%m_iGOPSize == m_GOPList[k].m_POC%m_iGOPSize) |
---|
878 | { |
---|
879 | #if TEMPORAL_LAYER_NON_REFERENCE |
---|
880 | if(m_GOPList[k].m_temporalId==m_GOPList[curGOP].m_temporalId) |
---|
881 | { |
---|
882 | m_GOPList[k].m_refPic = true; |
---|
883 | } |
---|
884 | #endif |
---|
885 | m_GOPList[curGOP].m_usedByCurrPic[i]=m_GOPList[k].m_temporalId<=m_GOPList[curGOP].m_temporalId; |
---|
886 | } |
---|
887 | } |
---|
888 | } |
---|
889 | } |
---|
890 | if(!found) |
---|
891 | { |
---|
892 | printf("\nError: ref pic %d is not available for GOP frame %d\n",m_GOPList[curGOP].m_referencePics[i],curGOP+1); |
---|
893 | errorGOP=true; |
---|
894 | } |
---|
895 | } |
---|
896 | } |
---|
897 | if(!beforeI&&!errorGOP) |
---|
898 | { |
---|
899 | //all ref frames were present |
---|
900 | if(!isOK[curGOP]) |
---|
901 | { |
---|
902 | numOK++; |
---|
903 | isOK[curGOP]=true; |
---|
904 | if(numOK==m_iGOPSize) |
---|
905 | { |
---|
906 | verifiedGOP=true; |
---|
907 | } |
---|
908 | } |
---|
909 | } |
---|
910 | else |
---|
911 | { |
---|
912 | //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0) |
---|
913 | m_GOPList[m_iGOPSize+m_extraRPSs]=m_GOPList[curGOP]; |
---|
914 | Int newRefs=0; |
---|
915 | for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) |
---|
916 | { |
---|
917 | Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i]; |
---|
918 | if(absPOC>=0) |
---|
919 | { |
---|
920 | m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=m_GOPList[curGOP].m_referencePics[i]; |
---|
921 | m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=m_GOPList[curGOP].m_usedByCurrPic[i]; |
---|
922 | newRefs++; |
---|
923 | } |
---|
924 | } |
---|
925 | Int numPrefRefs = m_GOPList[curGOP].m_numRefPicsActive; |
---|
926 | |
---|
927 | for(Int offset = -1; offset>-checkGOP; offset--) |
---|
928 | { |
---|
929 | //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0. |
---|
930 | Int offGOP = (checkGOP-1+offset)%m_iGOPSize; |
---|
931 | Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + m_GOPList[offGOP].m_POC; |
---|
932 | #if TEMPORAL_LAYER_NON_REFERENCE |
---|
933 | if(offPOC>=0&&m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId) |
---|
934 | #else |
---|
935 | if(offPOC>=0&&m_GOPList[offGOP].m_refPic&&m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId) |
---|
936 | #endif |
---|
937 | { |
---|
938 | Bool newRef=false; |
---|
939 | for(Int i=0; i<numRefs; i++) |
---|
940 | { |
---|
941 | if(refList[i]==offPOC) |
---|
942 | { |
---|
943 | newRef=true; |
---|
944 | } |
---|
945 | } |
---|
946 | for(Int i=0; i<newRefs; i++) |
---|
947 | { |
---|
948 | if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC) |
---|
949 | { |
---|
950 | newRef=false; |
---|
951 | } |
---|
952 | } |
---|
953 | if(newRef) |
---|
954 | { |
---|
955 | Int insertPoint=newRefs; |
---|
956 | //this picture can be added, find appropriate place in list and insert it. |
---|
957 | #if TEMPORAL_LAYER_NON_REFERENCE |
---|
958 | if(m_GOPList[offGOP].m_temporalId==m_GOPList[curGOP].m_temporalId) |
---|
959 | { |
---|
960 | m_GOPList[offGOP].m_refPic = true; |
---|
961 | } |
---|
962 | #endif |
---|
963 | for(Int j=0; j<newRefs; j++) |
---|
964 | { |
---|
965 | if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0) |
---|
966 | { |
---|
967 | insertPoint = j; |
---|
968 | break; |
---|
969 | } |
---|
970 | } |
---|
971 | Int prev = offPOC-curPOC; |
---|
972 | Int prevUsed = m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId; |
---|
973 | for(Int j=insertPoint; j<newRefs+1; j++) |
---|
974 | { |
---|
975 | Int newPrev = m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]; |
---|
976 | Int newUsed = m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]; |
---|
977 | m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev; |
---|
978 | m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed; |
---|
979 | prevUsed=newUsed; |
---|
980 | prev=newPrev; |
---|
981 | } |
---|
982 | newRefs++; |
---|
983 | } |
---|
984 | } |
---|
985 | if(newRefs>=numPrefRefs) |
---|
986 | { |
---|
987 | break; |
---|
988 | } |
---|
989 | } |
---|
990 | m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs; |
---|
991 | m_GOPList[m_iGOPSize+m_extraRPSs].m_POC = curPOC; |
---|
992 | if (m_extraRPSs == 0) |
---|
993 | { |
---|
994 | m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0; |
---|
995 | m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0; |
---|
996 | } |
---|
997 | else |
---|
998 | { |
---|
999 | Int rIdx = m_iGOPSize + m_extraRPSs - 1; |
---|
1000 | Int refPOC = m_GOPList[rIdx].m_POC; |
---|
1001 | Int refPics = m_GOPList[rIdx].m_numRefPics; |
---|
1002 | Int newIdc=0; |
---|
1003 | for(Int i = 0; i<= refPics; i++) |
---|
1004 | { |
---|
1005 | Int deltaPOC = ((i != refPics)? m_GOPList[rIdx].m_referencePics[i] : 0); // check if the reference abs POC is >= 0 |
---|
1006 | Int absPOCref = refPOC+deltaPOC; |
---|
1007 | Int refIdc = 0; |
---|
1008 | for (Int j = 0; j < m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics; j++) |
---|
1009 | { |
---|
1010 | if ( (absPOCref - curPOC) == m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]) |
---|
1011 | { |
---|
1012 | if (m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]) |
---|
1013 | { |
---|
1014 | refIdc = 1; |
---|
1015 | } |
---|
1016 | else |
---|
1017 | { |
---|
1018 | refIdc = 2; |
---|
1019 | } |
---|
1020 | } |
---|
1021 | } |
---|
1022 | m_GOPList[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc; |
---|
1023 | newIdc++; |
---|
1024 | } |
---|
1025 | m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1; |
---|
1026 | m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc; |
---|
1027 | m_GOPList[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - m_GOPList[m_iGOPSize+m_extraRPSs].m_POC; |
---|
1028 | #if !J0234_INTER_RPS_SIMPL |
---|
1029 | m_GOPList[m_iGOPSize+m_extraRPSs].m_deltaRIdxMinus1 = 0; |
---|
1030 | #endif |
---|
1031 | } |
---|
1032 | curGOP=m_iGOPSize+m_extraRPSs; |
---|
1033 | m_extraRPSs++; |
---|
1034 | } |
---|
1035 | numRefs=0; |
---|
1036 | for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) |
---|
1037 | { |
---|
1038 | Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i]; |
---|
1039 | if(absPOC >= 0) |
---|
1040 | { |
---|
1041 | refList[numRefs]=absPOC; |
---|
1042 | numRefs++; |
---|
1043 | } |
---|
1044 | } |
---|
1045 | refList[numRefs]=curPOC; |
---|
1046 | numRefs++; |
---|
1047 | } |
---|
1048 | checkGOP++; |
---|
1049 | } |
---|
1050 | xConfirmPara(errorGOP,"Invalid GOP structure given"); |
---|
1051 | m_maxTempLayer = 1; |
---|
1052 | for(Int i=0; i<m_iGOPSize; i++) |
---|
1053 | { |
---|
1054 | if(m_GOPList[i].m_temporalId >= m_maxTempLayer) |
---|
1055 | { |
---|
1056 | m_maxTempLayer = m_GOPList[i].m_temporalId+1; |
---|
1057 | } |
---|
1058 | xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P', "Slice type must be equal to B or P"); |
---|
1059 | } |
---|
1060 | for(Int i=0; i<MAX_TLAYER; i++) |
---|
1061 | { |
---|
1062 | m_numReorderPics[i] = 0; |
---|
1063 | m_maxDecPicBuffering[i] = 0; |
---|
1064 | } |
---|
1065 | for(Int i=0; i<m_iGOPSize; i++) |
---|
1066 | { |
---|
1067 | if(m_GOPList[i].m_numRefPics > m_maxDecPicBuffering[m_GOPList[i].m_temporalId]) |
---|
1068 | { |
---|
1069 | m_maxDecPicBuffering[m_GOPList[i].m_temporalId] = m_GOPList[i].m_numRefPics; |
---|
1070 | } |
---|
1071 | Int highestDecodingNumberWithLowerPOC = 0; |
---|
1072 | for(Int j=0; j<m_iGOPSize; j++) |
---|
1073 | { |
---|
1074 | if(m_GOPList[j].m_POC <= m_GOPList[i].m_POC) |
---|
1075 | { |
---|
1076 | highestDecodingNumberWithLowerPOC = j; |
---|
1077 | } |
---|
1078 | } |
---|
1079 | Int numReorder = 0; |
---|
1080 | for(Int j=0; j<highestDecodingNumberWithLowerPOC; j++) |
---|
1081 | { |
---|
1082 | if(m_GOPList[j].m_temporalId <= m_GOPList[i].m_temporalId && |
---|
1083 | m_GOPList[j].m_POC > m_GOPList[i].m_POC) |
---|
1084 | { |
---|
1085 | numReorder++; |
---|
1086 | } |
---|
1087 | } |
---|
1088 | if(numReorder > m_numReorderPics[m_GOPList[i].m_temporalId]) |
---|
1089 | { |
---|
1090 | m_numReorderPics[m_GOPList[i].m_temporalId] = numReorder; |
---|
1091 | } |
---|
1092 | } |
---|
1093 | for(Int i=0; i<MAX_TLAYER-1; i++) |
---|
1094 | { |
---|
1095 | // a lower layer can not have higher value of m_numReorderPics than a higher layer |
---|
1096 | if(m_numReorderPics[i+1] < m_numReorderPics[i]) |
---|
1097 | { |
---|
1098 | m_numReorderPics[i+1] = m_numReorderPics[i]; |
---|
1099 | } |
---|
1100 | // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive |
---|
1101 | if(m_numReorderPics[i] > m_maxDecPicBuffering[i]) |
---|
1102 | { |
---|
1103 | m_maxDecPicBuffering[i] = m_numReorderPics[i]; |
---|
1104 | } |
---|
1105 | // a lower layer can not have higher value of m_uiMaxDecPicBuffering than a higher layer |
---|
1106 | if(m_maxDecPicBuffering[i+1] < m_maxDecPicBuffering[i]) |
---|
1107 | { |
---|
1108 | m_maxDecPicBuffering[i+1] = m_maxDecPicBuffering[i]; |
---|
1109 | } |
---|
1110 | } |
---|
1111 | // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive |
---|
1112 | if(m_numReorderPics[MAX_TLAYER-1] > m_maxDecPicBuffering[MAX_TLAYER-1]) |
---|
1113 | { |
---|
1114 | m_maxDecPicBuffering[MAX_TLAYER-1] = m_numReorderPics[MAX_TLAYER-1]; |
---|
1115 | } |
---|
1116 | |
---|
1117 | xConfirmPara( m_bUseLComb==false && m_numReorderPics[MAX_TLAYER-1]!=0, "ListCombination can only be 0 in low delay coding (more precisely when L0 and L1 are identical)" ); // Note however this is not the full necessary condition as ref_pic_list_combination_flag can only be 0 if L0 == L1. |
---|
1118 | xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" ); |
---|
1119 | #if !SVC_EXTENSION |
---|
1120 | xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" ); |
---|
1121 | xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" ); |
---|
1122 | #endif |
---|
1123 | |
---|
1124 | xConfirmPara( m_decodePictureHashSEIEnabled<0 || m_decodePictureHashSEIEnabled>3, "this hash type is not correct!\n"); |
---|
1125 | |
---|
1126 | #if !SVC_EXTENSION |
---|
1127 | if(m_enableRateCtrl) |
---|
1128 | { |
---|
1129 | Int numLCUInWidth = (m_iSourceWidth / m_uiMaxCUWidth) + (( m_iSourceWidth % m_uiMaxCUWidth ) ? 1 : 0); |
---|
1130 | Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight % m_uiMaxCUHeight) ? 1 : 0); |
---|
1131 | Int numLCUInPic = numLCUInWidth * numLCUInHeight; |
---|
1132 | |
---|
1133 | xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" ); |
---|
1134 | |
---|
1135 | m_iMaxDeltaQP = MAX_DELTA_QP; |
---|
1136 | m_iMaxCuDQPDepth = MAX_CUDQP_DEPTH; |
---|
1137 | } |
---|
1138 | #endif |
---|
1139 | |
---|
1140 | xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0"); |
---|
1141 | |
---|
1142 | xConfirmPara(m_log2ParallelMergeLevel < 2, "Log2ParallelMergeLevel should be larger than or equal to 2"); |
---|
1143 | |
---|
1144 | #if ACTIVE_PARAMETER_SETS_SEI_MESSAGE |
---|
1145 | xConfirmPara(m_activeParameterSetsSEIEnabled < 0 || m_activeParameterSetsSEIEnabled > 2, "ActiveParametersSEIEnabled exceeds supported range (0 to 2)"); |
---|
1146 | #endif |
---|
1147 | |
---|
1148 | #undef xConfirmPara |
---|
1149 | if (check_failed) |
---|
1150 | { |
---|
1151 | exit(EXIT_FAILURE); |
---|
1152 | } |
---|
1153 | } |
---|
1154 | |
---|
1155 | /** \todo use of global variables should be removed later |
---|
1156 | */ |
---|
1157 | Void TAppEncCfg::xSetGlobal() |
---|
1158 | { |
---|
1159 | // set max CU width & height |
---|
1160 | g_uiMaxCUWidth = m_uiMaxCUWidth; |
---|
1161 | g_uiMaxCUHeight = m_uiMaxCUHeight; |
---|
1162 | |
---|
1163 | // compute actual CU depth with respect to config depth and max transform size |
---|
1164 | g_uiAddCUDepth = 0; |
---|
1165 | while( (m_uiMaxCUWidth>>m_uiMaxCUDepth) > ( 1 << ( m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth ) ) ) g_uiAddCUDepth++; |
---|
1166 | |
---|
1167 | m_uiMaxCUDepth += g_uiAddCUDepth; |
---|
1168 | g_uiAddCUDepth++; |
---|
1169 | g_uiMaxCUDepth = m_uiMaxCUDepth; |
---|
1170 | |
---|
1171 | // set internal bit-depth and constants |
---|
1172 | #if FULL_NBIT |
---|
1173 | g_uiBitDepth = m_uiInternalBitDepth; |
---|
1174 | g_uiBitIncrement = 0; |
---|
1175 | #else |
---|
1176 | g_uiBitDepth = 8; |
---|
1177 | g_uiBitIncrement = m_uiInternalBitDepth - g_uiBitDepth; |
---|
1178 | #endif |
---|
1179 | |
---|
1180 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
1181 | |
---|
1182 | #if IBDI_NOCLIP_RANGE |
---|
1183 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
1184 | #else |
---|
1185 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
1186 | #endif |
---|
1187 | |
---|
1188 | if (m_uiOutputBitDepth == 0) |
---|
1189 | { |
---|
1190 | m_uiOutputBitDepth = m_uiInternalBitDepth; |
---|
1191 | } |
---|
1192 | |
---|
1193 | g_uiPCMBitDepthLuma = m_uiPCMBitDepthLuma = ((m_bPCMInputBitDepthFlag)? m_uiInputBitDepth : m_uiInternalBitDepth); |
---|
1194 | g_uiPCMBitDepthChroma = ((m_bPCMInputBitDepthFlag)? m_uiInputBitDepth : m_uiInternalBitDepth); |
---|
1195 | } |
---|
1196 | |
---|
1197 | Void TAppEncCfg::xPrintParameter() |
---|
1198 | { |
---|
1199 | printf("\n"); |
---|
1200 | #if SVC_EXTENSION |
---|
1201 | printf("Total number of layers : %d\n", m_numLayers ); |
---|
1202 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1203 | { |
---|
1204 | printf("=== Layer %d settings === \n", layer); |
---|
1205 | m_acLayerCfg[layer].xPrintParameter(); |
---|
1206 | printf("\n"); |
---|
1207 | } |
---|
1208 | printf("=== Common configuration settings === \n"); |
---|
1209 | printf("Bitstream File : %s\n", m_pchBitstreamFile ); |
---|
1210 | #else |
---|
1211 | printf("Input File : %s\n", m_pchInputFile ); |
---|
1212 | printf("Bitstream File : %s\n", m_pchBitstreamFile ); |
---|
1213 | printf("Reconstruction File : %s\n", m_pchReconFile ); |
---|
1214 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - m_cropLeft - m_cropRight, m_iSourceHeight - m_cropTop - m_cropBottom, m_iFrameRate ); |
---|
1215 | printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); |
---|
1216 | #endif |
---|
1217 | printf("Frame index : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_iFrameToBeEncoded-1, m_iFrameToBeEncoded ); |
---|
1218 | printf("CU size / depth : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth ); |
---|
1219 | printf("RQT trans. size (min / max) : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
1220 | printf("Max RQT depth inter : %d\n", m_uiQuadtreeTUMaxDepthInter); |
---|
1221 | printf("Max RQT depth intra : %d\n", m_uiQuadtreeTUMaxDepthIntra); |
---|
1222 | printf("Min PCM size : %d\n", 1 << m_uiPCMLog2MinSize); |
---|
1223 | printf("Motion search range : %d\n", m_iSearchRange ); |
---|
1224 | #if !SVC_EXTENSION |
---|
1225 | printf("Intra period : %d\n", m_iIntraPeriod ); |
---|
1226 | #endif |
---|
1227 | printf("Decoding refresh type : %d\n", m_iDecodingRefreshType ); |
---|
1228 | #if !SVC_EXTENSION |
---|
1229 | printf("QP : %5.2f\n", m_fQP ); |
---|
1230 | #endif |
---|
1231 | printf("Max dQP signaling depth : %d\n", m_iMaxCuDQPDepth); |
---|
1232 | |
---|
1233 | printf("Cb QP Offset : %d\n", m_cbQpOffset ); |
---|
1234 | printf("Cr QP Offset : %d\n", m_crQpOffset); |
---|
1235 | |
---|
1236 | printf("QP adaptation : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) ); |
---|
1237 | printf("GOP size : %d\n", m_iGOPSize ); |
---|
1238 | printf("Internal bit depth : %d\n", m_uiInternalBitDepth ); |
---|
1239 | printf("PCM sample bit depth : %d\n", m_uiPCMBitDepthLuma ); |
---|
1240 | printf("RateControl : %d\n", m_enableRateCtrl); |
---|
1241 | if(m_enableRateCtrl) |
---|
1242 | { |
---|
1243 | printf("TargetBitrate : %d\n", m_targetBitrate); |
---|
1244 | printf("NumLCUInUnit : %d\n", m_numLCUInUnit); |
---|
1245 | } |
---|
1246 | printf("Max Num Merge Candidates : %d\n", m_maxNumMergeCand); |
---|
1247 | printf("\n"); |
---|
1248 | |
---|
1249 | printf("TOOL CFG: "); |
---|
1250 | #if !REMOVE_ALF |
---|
1251 | printf("ALF:%d ", m_bUseALF ); |
---|
1252 | printf("ALFLowLatencyEncode:%d ", m_alfLowLatencyEncoding?1:0); |
---|
1253 | #endif |
---|
1254 | printf("IBD:%d ", !!g_uiBitIncrement); |
---|
1255 | printf("HAD:%d ", m_bUseHADME ); |
---|
1256 | printf("SRD:%d ", m_bUseSBACRD ); |
---|
1257 | printf("RDQ:%d ", m_bUseRDOQ ); |
---|
1258 | printf("SQP:%d ", m_uiDeltaQpRD ); |
---|
1259 | printf("ASR:%d ", m_bUseASR ); |
---|
1260 | printf("LComb:%d ", m_bUseLComb ); |
---|
1261 | printf("FEN:%d ", m_bUseFastEnc ); |
---|
1262 | printf("ECU:%d ", m_bUseEarlyCU ); |
---|
1263 | printf("FDM:%d ", m_useFastDecisionForMerge ); |
---|
1264 | printf("CFM:%d ", m_bUseCbfFastMode ); |
---|
1265 | printf("ESD:%d ", m_useEarlySkipDetection ); |
---|
1266 | printf("RQT:%d ", 1 ); |
---|
1267 | #if !REMOVE_LMCHROMA |
---|
1268 | printf("LMC:%d ", m_bUseLMChroma ); |
---|
1269 | #endif |
---|
1270 | printf("TransformSkip:%d ", m_useTransformSkip ); |
---|
1271 | printf("TransformSkipFast:%d ", m_useTransformSkipFast ); |
---|
1272 | #if REMOVE_FGS |
---|
1273 | printf("Slice: M=%d ", m_iSliceMode); |
---|
1274 | #else |
---|
1275 | printf("Slice: G=%d M=%d ", m_iSliceGranularity, m_iSliceMode); |
---|
1276 | #endif |
---|
1277 | if (m_iSliceMode!=0) |
---|
1278 | { |
---|
1279 | printf("A=%d ", m_iSliceArgument); |
---|
1280 | } |
---|
1281 | printf("DependentSlice: M=%d ",m_iDependentSliceMode); |
---|
1282 | if (m_iDependentSliceMode!=0) |
---|
1283 | { |
---|
1284 | printf("A=%d ", m_iDependentSliceArgument); |
---|
1285 | } |
---|
1286 | printf("CIP:%d ", m_bUseConstrainedIntraPred); |
---|
1287 | printf("SAO:%d ", (m_bUseSAO)?(1):(0)); |
---|
1288 | printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0); |
---|
1289 | printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0)); |
---|
1290 | |
---|
1291 | printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 ); |
---|
1292 | printf("WPP:%d ", (Int)m_bUseWeightPred); |
---|
1293 | printf("WPB:%d ", (Int)m_useWeightedBiPred); |
---|
1294 | printf("PME:%d ", m_log2ParallelMergeLevel); |
---|
1295 | #if !SVC_EXTENSION |
---|
1296 | printf(" WaveFrontSynchro:%d WaveFrontSubstreams:%d", |
---|
1297 | m_iWaveFrontSynchro, m_iWaveFrontSubstreams); |
---|
1298 | #endif |
---|
1299 | printf(" ScalingList:%d ", m_useScalingListId ); |
---|
1300 | printf("TMVPMode:%d ", m_TMVPModeId ); |
---|
1301 | #if ADAPTIVE_QP_SELECTION |
---|
1302 | printf("AQpS:%d", m_bUseAdaptQpSelect ); |
---|
1303 | #endif |
---|
1304 | |
---|
1305 | printf(" SignBitHidingFlag:%d ", m_signHideFlag); |
---|
1306 | #if SVC_EXTENSION |
---|
1307 | #if RECALCULATE_QP_ACCORDING_LAMBDA |
---|
1308 | printf("RecalQP:%d ", m_recalculateQPAccordingToLambda ? 1 : 0 ); |
---|
1309 | #endif |
---|
1310 | #if REF_IDX_FRAMEWORK |
---|
1311 | printf("REF_IDX_FRAMEWORK:%d ", REF_IDX_FRAMEWORK); |
---|
1312 | printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled); |
---|
1313 | printf("REF_IDX_ME_AROUND_ZEROMV:%d ", REF_IDX_ME_AROUND_ZEROMV); |
---|
1314 | printf("REF_IDX_ME_ZEROMV: %d", REF_IDX_ME_ZEROMV); |
---|
1315 | #else |
---|
1316 | printf("INTRA_BL:%d ", INTRA_BL); |
---|
1317 | printf("AVC_BASE:%d ", AVC_BASE); |
---|
1318 | #if !AVC_BASE |
---|
1319 | printf("SVC_MVP:%d ", SVC_MVP ); |
---|
1320 | printf("SVC_BL_CAND_INTRA:%d", SVC_BL_CAND_INTRA ); |
---|
1321 | #endif |
---|
1322 | #endif |
---|
1323 | #else |
---|
1324 | #if RECALCULATE_QP_ACCORDING_LAMBDA |
---|
1325 | printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 ); |
---|
1326 | #endif |
---|
1327 | #endif |
---|
1328 | printf("\n\n"); |
---|
1329 | |
---|
1330 | fflush(stdout); |
---|
1331 | } |
---|
1332 | |
---|
1333 | Bool confirmPara(Bool bflag, const char* message) |
---|
1334 | { |
---|
1335 | if (!bflag) |
---|
1336 | return false; |
---|
1337 | |
---|
1338 | printf("Error: %s\n",message); |
---|
1339 | return true; |
---|
1340 | } |
---|
1341 | |
---|
1342 | //! \} |
---|