1 | /* ==================================================================================================================== |
---|
2 | |
---|
3 | The copyright in this software is being made available under the License included below. |
---|
4 | This software may be subject to other third party and contributor rights, including patent rights, and no such |
---|
5 | rights are granted under this license. |
---|
6 | |
---|
7 | Copyright (c) 2010, SAMSUNG ELECTRONICS CO., LTD. and BRITISH BROADCASTING CORPORATION |
---|
8 | All rights reserved. |
---|
9 | |
---|
10 | Redistribution and use in source and binary forms, with or without modification, are permitted only for |
---|
11 | the purpose of developing standards within the Joint Collaborative Team on Video Coding and for testing and |
---|
12 | promoting such standards. The following conditions are required to be met: |
---|
13 | |
---|
14 | * Redistributions of source code must retain the above copyright notice, this list of conditions and |
---|
15 | the following disclaimer. |
---|
16 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
---|
17 | the following disclaimer in the documentation and/or other materials provided with the distribution. |
---|
18 | * Neither the name of SAMSUNG ELECTRONICS CO., LTD. nor the name of the BRITISH BROADCASTING CORPORATION |
---|
19 | may be used to endorse or promote products derived from this software without specific prior written permission. |
---|
20 | |
---|
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
---|
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
28 | |
---|
29 | * ==================================================================================================================== |
---|
30 | */ |
---|
31 | |
---|
32 | /** \file TAppEncCfg.cpp |
---|
33 | \brief Handle encoder configuration parameters |
---|
34 | */ |
---|
35 | |
---|
36 | #include <stdlib.h> |
---|
37 | #include <cassert> |
---|
38 | #include <cstring> |
---|
39 | #include <string> |
---|
40 | #include "TAppEncCfg.h" |
---|
41 | #include "../../App/TAppCommon/program_options_lite.h" |
---|
42 | |
---|
43 | #ifdef WIN32 |
---|
44 | #define strdup _strdup |
---|
45 | #endif |
---|
46 | |
---|
47 | using namespace std; |
---|
48 | namespace po = df::program_options_lite; |
---|
49 | |
---|
50 | /* configuration helper funcs */ |
---|
51 | void doOldStyleCmdlineLDM(po::Options& opts, const std::string& arg); |
---|
52 | void doOldStyleCmdlineOn(po::Options& opts, const std::string& arg); |
---|
53 | void doOldStyleCmdlineOff(po::Options& opts, const std::string& arg); |
---|
54 | |
---|
55 | // ==================================================================================================================== |
---|
56 | // Local constants |
---|
57 | // ==================================================================================================================== |
---|
58 | |
---|
59 | /// max value of source padding size |
---|
60 | /** \todo replace it by command line option |
---|
61 | */ |
---|
62 | #define MAX_PAD_SIZE 16 |
---|
63 | |
---|
64 | // ==================================================================================================================== |
---|
65 | // Constructor / destructor / initialization / destroy |
---|
66 | // ==================================================================================================================== |
---|
67 | |
---|
68 | TAppEncCfg::TAppEncCfg() |
---|
69 | { |
---|
70 | m_aidQP = NULL; |
---|
71 | m_pchGRefMode = NULL; |
---|
72 | } |
---|
73 | |
---|
74 | TAppEncCfg::~TAppEncCfg() |
---|
75 | { |
---|
76 | if ( m_aidQP ) |
---|
77 | { |
---|
78 | delete[] m_aidQP; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | Void TAppEncCfg::create() |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | Void TAppEncCfg::destroy() |
---|
87 | { |
---|
88 | } |
---|
89 | |
---|
90 | // ==================================================================================================================== |
---|
91 | // Public member functions |
---|
92 | // ==================================================================================================================== |
---|
93 | |
---|
94 | /** \param argc number of arguments |
---|
95 | \param argv array of arguments |
---|
96 | \retval true when success |
---|
97 | */ |
---|
98 | Bool TAppEncCfg::parseCfg( Int argc, Char* argv[] ) |
---|
99 | { |
---|
100 | bool do_help = false; |
---|
101 | |
---|
102 | string cfg_InputFile; |
---|
103 | string cfg_BitstreamFile; |
---|
104 | string cfg_ReconFile; |
---|
105 | string cfg_dQPFile; |
---|
106 | string cfg_GRefMode; |
---|
107 | po::Options opts; |
---|
108 | opts.addOptions() |
---|
109 | ("help", do_help, false, "this help text") |
---|
110 | ("c", po::parseConfigFile, "configuration file name") |
---|
111 | |
---|
112 | /* File, I/O and source parameters */ |
---|
113 | ("InputFile,i", cfg_InputFile, string(""), "original YUV input file name") |
---|
114 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream output file name") |
---|
115 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name") |
---|
116 | |
---|
117 | ("SourceWidth,-wdt", m_iSourceWidth, 0, "Source picture width") |
---|
118 | ("SourceHeight,-hgt", m_iSourceHeight, 0, "Source picture height") |
---|
119 | ("BitDepth", m_uiBitDepth, 8u) |
---|
120 | ("BitIncrement", m_uiBitIncrement,4u, "bit-depth increasement") |
---|
121 | ("HorizontalPadding,-pdx",m_aiPad[0], 0, "horizontal source padding size") |
---|
122 | ("VerticalPadding,-pdy", m_aiPad[1], 0, "vertical source padding size") |
---|
123 | ("PAD", m_bUsePAD, false, "automatic source padding of multiple of 16" ) |
---|
124 | ("FrameRate,-fr", m_iFrameRate, 0, "Frame rate") |
---|
125 | ("FrameSkip,-fs", m_iFrameSkip, 0, "Number of frames to skip at start of input YUV") |
---|
126 | ("FramesToBeEncoded,f", m_iFrameToBeEncoded, 0, "number of frames to be encoded (default=all)") |
---|
127 | ("FrameToBeEncoded", m_iFrameToBeEncoded, 0, "depricated alias of FramesToBeEncoded") |
---|
128 | |
---|
129 | /* Unit definition parameters */ |
---|
130 | ("MaxCUWidth", m_uiMaxCUWidth, 64u) |
---|
131 | ("MaxCUHeight", m_uiMaxCUHeight, 64u) |
---|
132 | /* todo: remove defaults from MaxCUSize */ |
---|
133 | ("MaxCUSize,s", m_uiMaxCUWidth, 64u, "max CU size") |
---|
134 | ("MaxCUSize,s", m_uiMaxCUHeight, 64u, "max CU size") |
---|
135 | ("MaxPartitionDepth,h", m_uiMaxCUDepth, 4u, "CU depth") |
---|
136 | |
---|
137 | ("MaxTrSize,t", m_uiMaxTrSize, 64u, "max transform size") |
---|
138 | ("MaxTrDepth,-utd",m_uiMaxTrDepth, 1u, "max transform depth") |
---|
139 | ("MinTrDepth,-ltd",m_uiMinTrDepth, 0u, "min transform depth") |
---|
140 | |
---|
141 | #if HHI_RQT |
---|
142 | ("QuadtreeTUFlag", m_bQuadtreeTUFlag, true) |
---|
143 | ("QuadtreeTULog2MaxSize", m_uiQuadtreeTULog2MaxSize, 6u) |
---|
144 | ("QuadtreeTULog2MinSize", m_uiQuadtreeTULog2MinSize, 2u) |
---|
145 | #endif |
---|
146 | |
---|
147 | /* Coding structure paramters */ |
---|
148 | ("IntraPeriod,-ip",m_iIntraPeriod, -1, "intra period in frames, (-1: only first frame)") |
---|
149 | ("GOPSize,g", m_iGOPSize, 1, "GOP size of temporal structure") |
---|
150 | ("RateGOPSize,-rg",m_iRateGOPSize, -1, "GOP size of hierarchical QP assignment (-1: implies inherit GOPSize value)") |
---|
151 | ("NumOfReference,r", m_iNumOfReference, 1, "Number of reference (P)") |
---|
152 | ("NumOfReferenceB_L0,-rb0",m_iNumOfReferenceB_L0, 1, "Number of reference (B_L0)") |
---|
153 | ("NumOfReferenceB_L1,-rb1",m_iNumOfReferenceB_L1, 1, "Number of reference (B_L1)") |
---|
154 | ("HierarchicalCoding", m_bHierarchicalCoding, true) |
---|
155 | ("LowDelayCoding", m_bUseLDC, false, "low-delay mode") |
---|
156 | ("GPB", m_bUseGPB, false, "generalized B instead of P in low-delay mode") |
---|
157 | ("QBO", m_bUseQBO, false, "skip refers highest quality picture") |
---|
158 | ("NRF", m_bUseNRF, true, "non-reference frame marking in last layer") |
---|
159 | ("BQP", m_bUseBQP, false, "hier-P style QP assignment in low-delay mode") |
---|
160 | ("-ldm", doOldStyleCmdlineLDM, "recommended low-delay setting (with LDC), (0=slow sequence, 1=fast sequence)") |
---|
161 | |
---|
162 | /* Interpolation filter options */ |
---|
163 | #if HHI_INTERP_FILTER |
---|
164 | ("InterpFilterType,-int", m_iInterpFilterType, (Int)IPF_SAMSUNG_DIF_DEFAULT, "Interpolation Filter:\n" |
---|
165 | " 0: DCT-IF\n" |
---|
166 | " 1: 4-tap MOMS\n" |
---|
167 | " 2: 6-tap MOMS\n" |
---|
168 | # if TEN_DIRECTIONAL_INTERP |
---|
169 | " 3: DIF\n" |
---|
170 | # endif |
---|
171 | # ifdef QC_SIFO |
---|
172 | " 4: SIFO" |
---|
173 | # endif |
---|
174 | ) |
---|
175 | #endif |
---|
176 | ("DIFTap,tap", m_iDIFTap, 12, "number of interpolation filter taps (luma)") |
---|
177 | #ifdef QC_SIFO_PRED |
---|
178 | ("SPF",m_bUseSIFO_Pred, true) |
---|
179 | #endif |
---|
180 | |
---|
181 | /* motion options */ |
---|
182 | ("FastSearch", m_iFastSearch, 1, "0:Full search 1:Diamond 2:PMVFAST") |
---|
183 | ("SearchRange,-sr",m_iSearchRange, 96, "motion search range") |
---|
184 | ("HadamardME", m_bUseHADME, true, "hadamard ME for fractional-pel") |
---|
185 | ("ASR", m_bUseASR, false, "adaptive motion search range") |
---|
186 | #ifdef QC_AMVRES |
---|
187 | ("AMVRES", m_bUseAMVRes, true, "Adaptive motion resolution") |
---|
188 | #endif |
---|
189 | ("GRefMode,v", cfg_GRefMode, string(""), "additional reference for weighted prediction (w: scale+offset, o: offset)") |
---|
190 | |
---|
191 | /* Quantization parameters */ |
---|
192 | ("QP,q", m_fQP, 30.0, "Qp value, if value is float, QP is switched once during encoding") |
---|
193 | ("DeltaQpRD,-dqr",m_uiDeltaQpRD, 0u, "max dQp offset for slice") |
---|
194 | ("MaxDeltaQP,d", m_iMaxDeltaQP, 0, "max dQp offset for block") |
---|
195 | ("dQPFile,m", cfg_dQPFile, string(""), "dQP file name") |
---|
196 | ("RDOQ", m_bUseRDOQ, true) |
---|
197 | ("TemporalLayerQPOffset_L0,-tq0", m_aiTLayerQPOffset[0], MAX_QP + 1, "QP offset of temporal layer 0") |
---|
198 | ("TemporalLayerQPOffset_L1,-tq1", m_aiTLayerQPOffset[1], MAX_QP + 1, "QP offset of temporal layer 1") |
---|
199 | ("TemporalLayerQPOffset_L2,-tq2", m_aiTLayerQPOffset[2], MAX_QP + 1, "QP offset of temporal layer 2") |
---|
200 | ("TemporalLayerQPOffset_L3,-tq3", m_aiTLayerQPOffset[3], MAX_QP + 1, "QP offset of temporal layer 3") |
---|
201 | |
---|
202 | /* Entropy coding parameters */ |
---|
203 | ("SymbolMode,-sym", m_iSymbolMode, 1, "symbol mode (0=VLC, 1=SBAC)") |
---|
204 | ("SBACRD", m_bUseSBACRD, true, "SBAC based RD estimation") |
---|
205 | ("MultiCodewordThreshold", m_uiMCWThreshold, 0u) |
---|
206 | ("MaxPIPEBufferDelay", m_uiMaxPIPEDelay, 0u) |
---|
207 | ("BalancedCPUs", m_uiBalancedCPUs, 8u) |
---|
208 | |
---|
209 | /* Deblocking filter parameters */ |
---|
210 | ("LoopFilterDisable", m_bLoopFilterDisable, false) |
---|
211 | ("LoopFilterAlphaC0Offset", m_iLoopFilterAlphaC0Offset, 0) |
---|
212 | ("LoopFilterBetaOffset", m_iLoopFilterBetaOffset, 0 ) |
---|
213 | |
---|
214 | /* Coding tools */ |
---|
215 | #if HHI_ALLOW_CIP_SWITCH |
---|
216 | ("CIP", m_bUseCIP, true, "combined intra prediction") |
---|
217 | #endif |
---|
218 | #if HHI_AIS |
---|
219 | ("AIS", m_bUseAIS, true, "adaptive intra smoothing") |
---|
220 | #endif |
---|
221 | #if HHI_MRG |
---|
222 | ("MRG", m_bUseMRG, true, "merging of motion partitions") |
---|
223 | #endif |
---|
224 | #if HHI_IMVP |
---|
225 | ("IMP", m_bUseIMP, true, "interleaved motion vector predictor") |
---|
226 | #endif |
---|
227 | #if HHI_ALLOW_ROT_SWITCH |
---|
228 | ("ROT", m_bUseROT, true) |
---|
229 | #endif |
---|
230 | ("ALF", m_bUseALF, true, "Adaptive Loop Filter") |
---|
231 | #if HHI_ALF |
---|
232 | ("ALFSeparateTree", m_bALFUseSeparateQT, true) |
---|
233 | ("ALFSymmetry", m_bALFFilterSymmetry, false) |
---|
234 | ("ALFMinLength", m_iAlfMinLength, 5) |
---|
235 | ("ALFMaxLength", m_iAlfMaxLength, 9) |
---|
236 | #endif |
---|
237 | ("AMP", m_bUseAMP, true, "Asymmetric motion partition") |
---|
238 | #ifdef EDGE_BASED_PREDICTION |
---|
239 | ("EdgePredictionEnable", m_bEdgePredictionEnable, true, "Enable edge based prediction for intra") |
---|
240 | ("EdgeDetectionThreshold", m_iEdgeDetectionThreshold, 10240, "Threshold for edge detection of edge based prediction") |
---|
241 | #endif //EDGE_BASED_PREDICTION |
---|
242 | /* Misc. */ |
---|
243 | ("FEN", m_bUseFastEnc, false, "fast encoder setting") |
---|
244 | |
---|
245 | /* Compatability with old style -1 FOO or -0 FOO options. */ |
---|
246 | ("1", doOldStyleCmdlineOn, "turn option <name> on") |
---|
247 | ("0", doOldStyleCmdlineOff, "turn option <name> off") |
---|
248 | ; |
---|
249 | |
---|
250 | po::setDefaults(opts); |
---|
251 | po::scanArgv(opts, argc, (const char**) argv); |
---|
252 | |
---|
253 | if (argc == 1 || do_help) { |
---|
254 | /* argc == 1: no options have been specified */ |
---|
255 | po::doHelp(cout, opts); |
---|
256 | xPrintUsage(); |
---|
257 | return false; |
---|
258 | } |
---|
259 | |
---|
260 | /* |
---|
261 | * Set any derived parameters |
---|
262 | */ |
---|
263 | /* convert std::string to c string for compatability */ |
---|
264 | m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str()); |
---|
265 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
266 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
267 | m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str()); |
---|
268 | m_pchGRefMode = cfg_GRefMode.empty() ? NULL : strdup(cfg_GRefMode.c_str()); |
---|
269 | |
---|
270 | if (m_iRateGOPSize == -1) { |
---|
271 | /* if rateGOPSize has not been specified, the default value is GOPSize */ |
---|
272 | m_iRateGOPSize = m_iGOPSize; |
---|
273 | } |
---|
274 | |
---|
275 | // compute source padding size |
---|
276 | if ( m_bUsePAD ) |
---|
277 | { |
---|
278 | if ( m_iSourceWidth%MAX_PAD_SIZE ) |
---|
279 | { |
---|
280 | m_aiPad[0] = (m_iSourceWidth/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceWidth; |
---|
281 | } |
---|
282 | |
---|
283 | if ( m_iSourceHeight%MAX_PAD_SIZE ) |
---|
284 | { |
---|
285 | m_aiPad[1] = (m_iSourceHeight/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceHeight; |
---|
286 | } |
---|
287 | } |
---|
288 | m_iSourceWidth += m_aiPad[0]; |
---|
289 | m_iSourceHeight += m_aiPad[1]; |
---|
290 | |
---|
291 | // allocate slice-based dQP values |
---|
292 | m_aidQP = new Int[ m_iFrameToBeEncoded + m_iRateGOPSize + 1 ]; |
---|
293 | ::memset( m_aidQP, 0, sizeof(Int)*( m_iFrameToBeEncoded + m_iRateGOPSize + 1 ) ); |
---|
294 | |
---|
295 | // handling of floating-point QP values |
---|
296 | // if QP is not integer, sequence is split into two sections having QP and QP+1 |
---|
297 | m_iQP = (Int)( m_fQP ); |
---|
298 | if ( m_iQP < m_fQP ) |
---|
299 | { |
---|
300 | Int iSwitchPOC = (Int)( m_iFrameToBeEncoded - (m_fQP - m_iQP)*m_iFrameToBeEncoded + 0.5 ); |
---|
301 | |
---|
302 | iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iRateGOPSize + 0.5 )*m_iRateGOPSize; |
---|
303 | for ( Int i=iSwitchPOC; i<m_iFrameToBeEncoded + m_iRateGOPSize + 1; i++ ) |
---|
304 | { |
---|
305 | m_aidQP[i] = 1; |
---|
306 | } |
---|
307 | } |
---|
308 | |
---|
309 | // reading external dQP description from file |
---|
310 | if ( m_pchdQPFile ) |
---|
311 | { |
---|
312 | FILE* fpt=fopen( m_pchdQPFile, "r" ); |
---|
313 | if ( fpt ) |
---|
314 | { |
---|
315 | Int iValue; |
---|
316 | Int iPOC = 0; |
---|
317 | while ( iPOC < m_iFrameToBeEncoded ) |
---|
318 | { |
---|
319 | if ( fscanf(fpt, "%d", &iValue ) == EOF ) break; |
---|
320 | m_aidQP[ iPOC ] = iValue; |
---|
321 | iPOC++; |
---|
322 | } |
---|
323 | fclose(fpt); |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | // check validity of input parameters |
---|
328 | xCheckParameter(); |
---|
329 | |
---|
330 | // set global varibles |
---|
331 | xSetGlobal(); |
---|
332 | |
---|
333 | // print-out parameters |
---|
334 | xPrintParameter(); |
---|
335 | |
---|
336 | return true; |
---|
337 | } |
---|
338 | |
---|
339 | // ==================================================================================================================== |
---|
340 | // Private member functions |
---|
341 | // ==================================================================================================================== |
---|
342 | |
---|
343 | Bool confirmPara(Bool bflag, const char* message); |
---|
344 | |
---|
345 | Void TAppEncCfg::xCheckParameter() |
---|
346 | { |
---|
347 | bool check_failed = false; /* abort if there is a fatal configuration problem */ |
---|
348 | #define xConfirmPara(a,b) check_failed |= confirmPara(a,b) |
---|
349 | // check range of parameters |
---|
350 | xConfirmPara( m_iFrameRate <= 0, "Frame rate must be more than 1" ); |
---|
351 | xConfirmPara( m_iFrameSkip < 0, "Frame Skipping must be more than 0" ); |
---|
352 | xConfirmPara( m_iFrameToBeEncoded <= 0, "Total Number Of Frames encoded must be more than 1" ); |
---|
353 | xConfirmPara( m_iGOPSize < 1 , "GOP Size must be more than 1" ); |
---|
354 | xConfirmPara( m_iGOPSize > 1 && m_iGOPSize % 2, "GOP Size must be a multiple of 2, if GOP Size is greater than 1" ); |
---|
355 | xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" ); |
---|
356 | xConfirmPara( m_iQP < 0 || m_iQP > 51, "QP exceeds supported range (0 to 51)" ); |
---|
357 | xConfirmPara( m_iLoopFilterAlphaC0Offset < -26 || m_iLoopFilterAlphaC0Offset > 26, "Loop Filter Alpha Offset exceeds supported range (-26 to 26)" ); |
---|
358 | xConfirmPara( m_iLoopFilterBetaOffset < -26 || m_iLoopFilterBetaOffset > 26, "Loop Filter Beta Offset exceeds supported range (-26 to 26)"); |
---|
359 | xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2, "Fast Search Mode is not supported value (0:Full search 1:Diamond 2:PMVFAST)" ); |
---|
360 | xConfirmPara( m_iSearchRange < 0 , "Search Range must be more than 0" ); |
---|
361 | xConfirmPara( m_iMaxDeltaQP > 7, "Absolute Delta QP exceeds supported range (0 to 7)" ); |
---|
362 | xConfirmPara( m_iFrameToBeEncoded != 1 && m_iFrameToBeEncoded <= m_iGOPSize, "Total Number of Frames to be encoded must be larger than GOP size"); |
---|
363 | xConfirmPara( (m_uiMaxCUWidth >> m_uiMaxCUDepth) < 4, "Minimum partition width size should be larger than or equal to 4"); |
---|
364 | xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4, "Minimum partition height size should be larger than or equal to 4"); |
---|
365 | xConfirmPara( m_uiMaxTrDepth < m_uiMinTrDepth, "Max. transform depth should be equal or larger than Min. transform depth"); |
---|
366 | xConfirmPara( m_uiMaxTrSize > 64, "Max physical transform size should be equal or smaller than 64"); |
---|
367 | xConfirmPara( m_uiMaxTrSize < 2, "Max physical transform size should be equal or larger than 2"); |
---|
368 | xConfirmPara( (m_iSourceWidth % (m_uiMaxCUWidth >> (m_uiMaxCUDepth-1)))!=0, "Frame width should be multiple of double size of minimum CU size"); |
---|
369 | xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0, "Frame height should be multiple of double size of minimum CU size"); |
---|
370 | xConfirmPara( m_iDIFTap != 4 && m_iDIFTap != 6 && m_iDIFTap != 8 && m_iDIFTap != 10 && m_iDIFTap != 12, "DIF taps 4, 6, 8, 10 and 12 are supported"); |
---|
371 | |
---|
372 | #if HHI_RQT |
---|
373 | if( m_bQuadtreeTUFlag ) |
---|
374 | { |
---|
375 | xConfirmPara( m_uiQuadtreeTULog2MinSize < 2, "QuadtreeTULog2MinSize must be 2 or greater."); |
---|
376 | xConfirmPara( m_uiQuadtreeTULog2MinSize > 6, "QuadtreeTULog2MinSize must be 6 or smaller."); |
---|
377 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < 2, "QuadtreeTULog2MaxSize must be 2 or greater."); |
---|
378 | xConfirmPara( m_uiQuadtreeTULog2MaxSize > 6, "QuadtreeTULog2MaxSize must be 6 or smaller."); |
---|
379 | xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize, "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize."); |
---|
380 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
381 | xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS |
---|
382 | |
---|
383 | xConfirmPara( 8 != (m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "Minimum CU width must be 8" ); |
---|
384 | xConfirmPara( 8 != (m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "Minimum CU height must be 8" ); |
---|
385 | } |
---|
386 | #endif |
---|
387 | |
---|
388 | #if HHI_INTERP_FILTER && !TEN_DIRECTIONAL_INTERP |
---|
389 | xConfirmPara( m_iInterpFilterType == IPF_TEN_DIF_PLACEHOLDER, "IPF_TEN_DIF is not configurable. Please recompile using TEN_DIRECTIONAL_INTERP." ); |
---|
390 | #endif |
---|
391 | #if HHI_INTERP_FILTER && !defined(QC_SIFO) |
---|
392 | xConfirmPara( m_iInterpFilterType == IPF_QC_SIFO_PLACEHOLDER, "IPF_QC_SIFO is not configurable. Please recompile using QC_SIFO." ); |
---|
393 | #endif |
---|
394 | xConfirmPara( m_iInterpFilterType >= IPF_LAST, "Invalid InterpFilterType" ); |
---|
395 | |
---|
396 | xConfirmPara( m_iSymbolMode < 0 || m_iSymbolMode > 3, "SymbolMode must be equal to 0, 1, 2, or 3" ); |
---|
397 | xConfirmPara( m_uiMaxPIPEDelay != 0 && m_uiMaxPIPEDelay < 64, "MaxPIPEBufferDelay must be greater than or equal to 64" ); |
---|
398 | m_uiMaxPIPEDelay = ( m_uiMCWThreshold > 0 ? 0 : ( m_uiMaxPIPEDelay >> 6 ) << 6 ); |
---|
399 | xConfirmPara( m_uiBalancedCPUs > 255, "BalancedCPUs must not be greater than 255" ); |
---|
400 | |
---|
401 | // max CU width and height should be power of 2 |
---|
402 | UInt ui = m_uiMaxCUWidth; |
---|
403 | while(ui) |
---|
404 | { |
---|
405 | ui >>= 1; |
---|
406 | if( (ui & 1) == 1) |
---|
407 | xConfirmPara( ui != 1 , "Width should be 2^n"); |
---|
408 | } |
---|
409 | ui = m_uiMaxCUHeight; |
---|
410 | while(ui) |
---|
411 | { |
---|
412 | ui >>= 1; |
---|
413 | if( (ui & 1) == 1) |
---|
414 | xConfirmPara( ui != 1 , "Height should be 2^n"); |
---|
415 | } |
---|
416 | |
---|
417 | // SBACRD is supported only for SBAC |
---|
418 | if ( m_iSymbolMode == 0 ) |
---|
419 | { |
---|
420 | m_bUseSBACRD = false; |
---|
421 | } |
---|
422 | else if ( m_iSymbolMode == 3 ) |
---|
423 | { |
---|
424 | m_uiMCWThreshold = 0; |
---|
425 | } |
---|
426 | |
---|
427 | #if !NEWVLC |
---|
428 | // RDOQ is supported only for SBAC |
---|
429 | if ( !m_bUseSBACRD ) |
---|
430 | { |
---|
431 | m_bUseRDOQ = false; |
---|
432 | } |
---|
433 | #endif |
---|
434 | #if defined(QC_AMVRES) && TEN_DIRECTIONAL_INTERP |
---|
435 | if(m_iInterpFilterType == IPF_TEN_DIF) |
---|
436 | m_bUseAMVRes = false; |
---|
437 | #endif |
---|
438 | |
---|
439 | #ifdef EDGE_BASED_PREDICTION |
---|
440 | //Edge based prediction: adapt the value of the threshold to integrate it in the bitstream |
---|
441 | if(m_bEdgePredictionEnable) |
---|
442 | { |
---|
443 | int maxThreshold = (1<<16) - (1<<8); |
---|
444 | if(m_iEdgeDetectionThreshold < 0) |
---|
445 | m_iEdgeDetectionThreshold = 0; |
---|
446 | if(m_iEdgeDetectionThreshold > maxThreshold) |
---|
447 | m_iEdgeDetectionThreshold = maxThreshold; |
---|
448 | int tmpThreshold = (m_iEdgeDetectionThreshold>>8); |
---|
449 | m_iEdgeDetectionThreshold = tmpThreshold<<8; |
---|
450 | } |
---|
451 | #endif //EDGE_BASED_PREDICTION |
---|
452 | |
---|
453 | #undef xConfirmPara |
---|
454 | if (check_failed) { |
---|
455 | exit(EXIT_FAILURE); |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | /** \todo use of global variables should be removed later |
---|
460 | */ |
---|
461 | Void TAppEncCfg::xSetGlobal() |
---|
462 | { |
---|
463 | // set max CU width & height |
---|
464 | g_uiMaxCUWidth = m_uiMaxCUWidth; |
---|
465 | g_uiMaxCUHeight = m_uiMaxCUHeight; |
---|
466 | |
---|
467 | // compute actual CU depth with respect to config depth and max transform size |
---|
468 | g_uiAddCUDepth = 0; |
---|
469 | if( ((m_uiMaxCUWidth>>(m_uiMaxCUDepth-1)) > (m_uiMaxTrSize>>m_uiMaxTrDepth)) ) |
---|
470 | { |
---|
471 | while( (m_uiMaxCUWidth>>(m_uiMaxCUDepth-1)) > (m_uiMaxTrSize<<g_uiAddCUDepth) ) g_uiAddCUDepth++; |
---|
472 | } |
---|
473 | m_uiMaxCUDepth += g_uiAddCUDepth; |
---|
474 | g_uiAddCUDepth++; |
---|
475 | g_uiMaxCUDepth = m_uiMaxCUDepth; |
---|
476 | |
---|
477 | // set internal bit-depth and constants |
---|
478 | g_uiBitDepth = m_uiBitDepth; // base bit-depth |
---|
479 | g_uiBitIncrement = m_uiBitIncrement; // increments |
---|
480 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
481 | |
---|
482 | #if IBDI_NOCLIP_RANGE |
---|
483 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
484 | #else |
---|
485 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
486 | #endif |
---|
487 | } |
---|
488 | |
---|
489 | Void TAppEncCfg::xPrintParameter() |
---|
490 | { |
---|
491 | printf("\n"); |
---|
492 | printf("Input File : %s\n", m_pchInputFile ); |
---|
493 | printf("Bitstream File : %s\n", m_pchBitstreamFile ); |
---|
494 | printf("Reconstruction File : %s\n", m_pchReconFile ); |
---|
495 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - m_aiPad[0], m_iSourceHeight-m_aiPad[1], m_iFrameRate ); |
---|
496 | printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); |
---|
497 | printf("Frame index : %d - %d (%d frames)\n", m_iFrameSkip, m_iFrameSkip+m_iFrameToBeEncoded-1, m_iFrameToBeEncoded ); |
---|
498 | printf("Number of Ref. frames (P) : %d\n", m_iNumOfReference); |
---|
499 | printf("Number of Ref. frames (B_L0) : %d\n", m_iNumOfReferenceB_L0); |
---|
500 | printf("Number of Ref. frames (B_L1) : %d\n", m_iNumOfReferenceB_L1); |
---|
501 | printf("Number of Reference frames : %d\n", m_iNumOfReference); |
---|
502 | printf("CU size / depth : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth ); |
---|
503 | printf("Transform depth (min / max) : %d / %d\n", m_uiMinTrDepth, m_uiMaxTrDepth ); |
---|
504 | printf("Motion search range : %d\n", m_iSearchRange ); |
---|
505 | printf("Intra period : %d\n", m_iIntraPeriod ); |
---|
506 | printf("QP : %5.2f\n", m_fQP ); |
---|
507 | printf("GOP size : %d\n", m_iGOPSize ); |
---|
508 | printf("Rate GOP size : %d\n", m_iRateGOPSize ); |
---|
509 | printf("Max physical trans. size : %d\n", m_uiMaxTrSize ); |
---|
510 | printf("Bit increment : %d\n", m_uiBitIncrement ); |
---|
511 | |
---|
512 | #if HHI_INTERP_FILTER |
---|
513 | switch ( m_iInterpFilterType ) |
---|
514 | { |
---|
515 | #if TEN_DIRECTIONAL_INTERP |
---|
516 | case IPF_TEN_DIF: |
---|
517 | printf("Luma interpolation : %s\n", "TEN directional interpolation filter" ); |
---|
518 | printf("Chroma interpolation : %s\n", "TEN two-stage bi-linear filter" ); |
---|
519 | break; |
---|
520 | #endif |
---|
521 | case IPF_HHI_4TAP_MOMS: |
---|
522 | printf("Luma interpolation : %s\n", "HHI 4-tap MOMS filter" ); |
---|
523 | printf("Chroma interpolation : %s\n", "HHI 4-tap MOMS filter" ); |
---|
524 | break; |
---|
525 | case IPF_HHI_6TAP_MOMS: |
---|
526 | printf("Luma interpolation : %s\n", "HHI 6-tap MOMS filter" ); |
---|
527 | printf("Chroma interpolation : %s\n", "HHI 6-tap MOMS filter" ); |
---|
528 | break; |
---|
529 | #ifdef QC_SIFO |
---|
530 | case IPF_QC_SIFO: |
---|
531 | printf("Luma interpolation : Qualcomm %d-tap SIFO\n", m_iDIFTap ); |
---|
532 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
533 | break; |
---|
534 | #endif |
---|
535 | default: |
---|
536 | #ifdef QC_CONFIG |
---|
537 | printf("Luma interpolation : Samsung %d-tap filter\n", m_iDIFTap ); |
---|
538 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
539 | #else |
---|
540 | printf("Luma interpolation : %s\n", "Samsung 12-tap filter" ); |
---|
541 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
542 | #endif |
---|
543 | } |
---|
544 | #else |
---|
545 | printf("Number of int. taps (luma) : %d\n", m_iDIFTap ); |
---|
546 | printf("Number of int. taps (chroma) : %d\n", 2 ); |
---|
547 | #endif |
---|
548 | |
---|
549 | if ( m_pchGRefMode != NULL ) |
---|
550 | { |
---|
551 | printf("Additional reference frame : weighted prediction\n"); |
---|
552 | } |
---|
553 | |
---|
554 | if ( m_iSymbolMode == 0 ) |
---|
555 | { |
---|
556 | printf("Entropy coder : VLC\n"); |
---|
557 | } |
---|
558 | else if( m_iSymbolMode == 1 ) |
---|
559 | { |
---|
560 | printf("Entropy coder : CABAC\n"); |
---|
561 | } |
---|
562 | else if( m_iSymbolMode == 2 ) |
---|
563 | { |
---|
564 | printf("Entropy coder : PIPE\n"); |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | printf("Entropy coder : V2V with load balancing on %d bin decoders\n", m_uiBalancedCPUs); |
---|
569 | } |
---|
570 | |
---|
571 | printf("\n"); |
---|
572 | |
---|
573 | printf("TOOL CFG: "); |
---|
574 | printf("ALF:%d ", m_bUseALF ); |
---|
575 | printf("IBD:%d ", m_uiBitIncrement!=0 ); |
---|
576 | printf("HAD:%d ", m_bUseHADME ); |
---|
577 | printf("SRD:%d ", m_bUseSBACRD ); |
---|
578 | printf("RDQ:%d ", m_bUseRDOQ ); |
---|
579 | printf("SQP:%d ", m_uiDeltaQpRD ); |
---|
580 | printf("ASR:%d ", m_bUseASR ); |
---|
581 | printf("PAD:%d ", m_bUsePAD ); |
---|
582 | printf("LDC:%d ", m_bUseLDC ); |
---|
583 | printf("NRF:%d ", m_bUseNRF ); |
---|
584 | printf("BQP:%d ", m_bUseBQP ); |
---|
585 | printf("QBO:%d ", m_bUseQBO ); |
---|
586 | printf("GPB:%d ", m_bUseGPB ); |
---|
587 | printf("FEN:%d ", m_bUseFastEnc ); |
---|
588 | #ifdef EDGE_BASED_PREDICTION |
---|
589 | printf("EdgePrediction:%d ", m_bEdgePredictionEnable); |
---|
590 | #endif //EDGE_BASED_PREDICTION |
---|
591 | #if HHI_RQT |
---|
592 | printf("RQT:%d ", m_bQuadtreeTUFlag ); |
---|
593 | #endif |
---|
594 | #if HHI_ALLOW_CIP_SWITCH |
---|
595 | printf("CIP:%d ", m_bUseCIP ); |
---|
596 | #endif |
---|
597 | #if HHI_ALLOW_ROT_SWITCH |
---|
598 | printf("ROT:%d ", m_bUseROT ); |
---|
599 | #endif |
---|
600 | #if HHI_AIS |
---|
601 | printf("AIS:%d ", m_bUseAIS ); // BB: adaptive intra smoothing |
---|
602 | #endif |
---|
603 | #if HHI_MRG |
---|
604 | printf("MRG:%d ", m_bUseMRG ); // SOPH: Merge Mode |
---|
605 | #endif |
---|
606 | #if HHI_IMVP |
---|
607 | printf("IMP:%d ", m_bUseIMP ); // SOPH: Interleaved MV Predictor |
---|
608 | #endif |
---|
609 | #ifdef QC_AMVRES |
---|
610 | printf("AMVRES:%d ", m_bUseAMVRes ); |
---|
611 | #endif |
---|
612 | #ifdef QC_SIFO_PRED |
---|
613 | printf("SPF:%d ", m_bUseSIFO_Pred ); |
---|
614 | #endif |
---|
615 | printf("AMP:%d ", m_bUseAMP); |
---|
616 | printf("\n"); |
---|
617 | |
---|
618 | fflush(stdout); |
---|
619 | } |
---|
620 | |
---|
621 | Void TAppEncCfg::xPrintUsage() |
---|
622 | { |
---|
623 | printf( " <name> = ALF - adaptive loop filter\n"); |
---|
624 | printf( " IBD - bit-depth increasement\n"); |
---|
625 | printf( " GPB - generalized B instead of P in low-delay mode\n"); |
---|
626 | printf( " HAD - hadamard ME for fractional-pel\n"); |
---|
627 | printf( " SRD - SBAC based RD estimation\n"); |
---|
628 | printf( " RDQ - RDOQ\n"); |
---|
629 | printf( " LDC - low-delay mode\n"); |
---|
630 | printf( " NRF - non-reference frame marking in last layer\n"); |
---|
631 | printf( " BQP - hier-P style QP assignment in low-delay mode\n"); |
---|
632 | printf( " PAD - automatic source padding of multiple of 16\n"); |
---|
633 | printf( " QBO - skip refers highest quality picture\n"); |
---|
634 | printf( " ASR - adaptive motion search range\n"); |
---|
635 | printf( " FEN - fast encoder setting\n"); |
---|
636 | #if HHI_AIS |
---|
637 | printf( " AIS - adaptive intra smoothing\n"); // BB: adaptive intra smoothing |
---|
638 | #endif |
---|
639 | #if HHI_MRG |
---|
640 | printf( " MRG - merging of motion partitions\n"); // SOPH: Merge Mode |
---|
641 | #endif |
---|
642 | #if HHI_IMVP |
---|
643 | printf( " IMP - interleaved motion vector predictor\n"); /// SOPH: Interleaved MV Predictor |
---|
644 | #endif |
---|
645 | #ifdef QC_AMVRES |
---|
646 | printf( " AMVRES - Adaptive motion resolution\n"); |
---|
647 | #endif |
---|
648 | printf( "\n" ); |
---|
649 | printf( " Example 1) TAppEncoder.exe -c test.cfg -q 32 -g 8 -f 9 -s 64 -h 4\n"); |
---|
650 | printf(" -> QP 32, hierarchical-B GOP 8, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
651 | printf( " Example 2) TAppEncoder.exe -c test.cfg -q 32 -g 4 -f 9 -s 64 -h 4 -1 LDC\n"); |
---|
652 | printf(" -> QP 32, hierarchical-P GOP 4, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
653 | printf( " Example 3) TAppEncoder.exe -c test.cfg -q 32 -g 1 -f 9 -s 64 -h 4 -1 LDC -ldm 0 -rg 4\n"); |
---|
654 | printf(" -> QP 32, IPPP with hierarchical-P of GOP 4 style QP, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
655 | printf( " Example 4) TAppEncoder.exe -c test.cfg -q 32 -g 1 -f 9 -s 64 -h 4 -1 LDC -ldm 1 -rg 4\n"); |
---|
656 | printf(" -> QP 32, IPPP with hierarchical-B of GOP 4 style QP, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
657 | } |
---|
658 | |
---|
659 | Bool confirmPara(Bool bflag, const char* message) |
---|
660 | { |
---|
661 | if (!bflag) |
---|
662 | return false; |
---|
663 | |
---|
664 | printf("Error: %s\n",message); |
---|
665 | return true; |
---|
666 | } |
---|
667 | |
---|
668 | /* helper for -ldm */ |
---|
669 | void doOldStyleCmdlineLDM(po::Options& opts, const std::string& arg) |
---|
670 | { |
---|
671 | /* xxx: warn this option is depricated */ |
---|
672 | if (arg == "1") { |
---|
673 | po::storePair(opts, "QBO", "1"); |
---|
674 | po::storePair(opts, "BQP", "0"); |
---|
675 | po::storePair(opts, "NRF", "1"); |
---|
676 | return; |
---|
677 | } |
---|
678 | if (arg == "0") { |
---|
679 | po::storePair(opts, "QBO", "0"); |
---|
680 | po::storePair(opts, "BQP", "1"); |
---|
681 | po::storePair(opts, "NRF", "0"); |
---|
682 | return; |
---|
683 | } |
---|
684 | /* invalid parse */ |
---|
685 | cerr << "Invalid argument to -ldm: `" << arg << "'" << endl; |
---|
686 | } |
---|
687 | |
---|
688 | /* helper function */ |
---|
689 | /* for handling "-1/-0 FOO" */ |
---|
690 | void translateOldStyleCmdline(const char* value, po::Options& opts, const std::string& arg) |
---|
691 | { |
---|
692 | const char* argv[] = {arg.c_str(), value}; |
---|
693 | /* replace some short names with their long name varients */ |
---|
694 | if (arg == "LDC") { |
---|
695 | argv[0] = "LowDelayCoding"; |
---|
696 | } |
---|
697 | else if (arg == "RDQ") { |
---|
698 | argv[0] = "RDOQ"; |
---|
699 | } |
---|
700 | else if (arg == "HAD") { |
---|
701 | argv[0] = "HadamardME"; |
---|
702 | } |
---|
703 | else if (arg == "SRD") { |
---|
704 | argv[0] = "SBACRD"; |
---|
705 | } |
---|
706 | else if (arg == "IBD") { |
---|
707 | argv[0] = "BitIncrement"; |
---|
708 | } |
---|
709 | /* issue a warning for change in FEN behaviour */ |
---|
710 | if (arg == "FEN") { |
---|
711 | /* xxx todo */ |
---|
712 | } |
---|
713 | po::storePair(opts, argv[0], argv[1]); |
---|
714 | } |
---|
715 | |
---|
716 | void doOldStyleCmdlineOn(po::Options& opts, const std::string& arg) |
---|
717 | { |
---|
718 | if (arg == "IBD") { |
---|
719 | translateOldStyleCmdline("4", opts, arg); |
---|
720 | return; |
---|
721 | } |
---|
722 | translateOldStyleCmdline("1", opts, arg); |
---|
723 | } |
---|
724 | void doOldStyleCmdlineOff(po::Options& opts, const std::string& arg) |
---|
725 | { |
---|
726 | translateOldStyleCmdline("0", opts, arg); |
---|
727 | } |
---|