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 | m_uiMCWThreshold = 0; |
---|
424 | } |
---|
425 | |
---|
426 | #if !NEWVLC |
---|
427 | // RDOQ is supported only for SBAC |
---|
428 | if ( !m_bUseSBACRD ) |
---|
429 | { |
---|
430 | m_bUseRDOQ = false; |
---|
431 | } |
---|
432 | #endif |
---|
433 | #if defined(QC_AMVRES) && TEN_DIRECTIONAL_INTERP |
---|
434 | if(m_iInterpFilterType == IPF_TEN_DIF) |
---|
435 | m_bUseAMVRes = false; |
---|
436 | #endif |
---|
437 | |
---|
438 | #ifdef EDGE_BASED_PREDICTION |
---|
439 | //Edge based prediction: adapt the value of the threshold to integrate it in the bitstream |
---|
440 | if(m_bEdgePredictionEnable) |
---|
441 | { |
---|
442 | int maxThreshold = (1<<16) - (1<<8); |
---|
443 | if(m_iEdgeDetectionThreshold < 0) |
---|
444 | m_iEdgeDetectionThreshold = 0; |
---|
445 | if(m_iEdgeDetectionThreshold > maxThreshold) |
---|
446 | m_iEdgeDetectionThreshold = maxThreshold; |
---|
447 | int tmpThreshold = (m_iEdgeDetectionThreshold>>8); |
---|
448 | m_iEdgeDetectionThreshold = tmpThreshold<<8; |
---|
449 | } |
---|
450 | #endif //EDGE_BASED_PREDICTION |
---|
451 | |
---|
452 | #undef xConfirmPara |
---|
453 | if (check_failed) { |
---|
454 | exit(EXIT_FAILURE); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | /** \todo use of global variables should be removed later |
---|
459 | */ |
---|
460 | Void TAppEncCfg::xSetGlobal() |
---|
461 | { |
---|
462 | // set max CU width & height |
---|
463 | g_uiMaxCUWidth = m_uiMaxCUWidth; |
---|
464 | g_uiMaxCUHeight = m_uiMaxCUHeight; |
---|
465 | |
---|
466 | // compute actual CU depth with respect to config depth and max transform size |
---|
467 | g_uiAddCUDepth = 0; |
---|
468 | if( ((m_uiMaxCUWidth>>(m_uiMaxCUDepth-1)) > (m_uiMaxTrSize>>m_uiMaxTrDepth)) ) |
---|
469 | { |
---|
470 | while( (m_uiMaxCUWidth>>(m_uiMaxCUDepth-1)) > (m_uiMaxTrSize<<g_uiAddCUDepth) ) g_uiAddCUDepth++; |
---|
471 | } |
---|
472 | m_uiMaxCUDepth += g_uiAddCUDepth; |
---|
473 | g_uiAddCUDepth++; |
---|
474 | g_uiMaxCUDepth = m_uiMaxCUDepth; |
---|
475 | |
---|
476 | // set internal bit-depth and constants |
---|
477 | g_uiBitDepth = m_uiBitDepth; // base bit-depth |
---|
478 | g_uiBitIncrement = m_uiBitIncrement; // increments |
---|
479 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
480 | |
---|
481 | #if IBDI_NOCLIP_RANGE |
---|
482 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
483 | #else |
---|
484 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
485 | #endif |
---|
486 | } |
---|
487 | |
---|
488 | Void TAppEncCfg::xPrintParameter() |
---|
489 | { |
---|
490 | printf("\n"); |
---|
491 | printf("Input File : %s\n", m_pchInputFile ); |
---|
492 | printf("Bitstream File : %s\n", m_pchBitstreamFile ); |
---|
493 | printf("Reconstruction File : %s\n", m_pchReconFile ); |
---|
494 | printf("Real Format : %dx%d %dHz\n", m_iSourceWidth - m_aiPad[0], m_iSourceHeight-m_aiPad[1], m_iFrameRate ); |
---|
495 | printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); |
---|
496 | printf("Frame index : %d - %d (%d frames)\n", m_iFrameSkip, m_iFrameSkip+m_iFrameToBeEncoded-1, m_iFrameToBeEncoded ); |
---|
497 | printf("Number of Ref. frames (P) : %d\n", m_iNumOfReference); |
---|
498 | printf("Number of Ref. frames (B_L0) : %d\n", m_iNumOfReferenceB_L0); |
---|
499 | printf("Number of Ref. frames (B_L1) : %d\n", m_iNumOfReferenceB_L1); |
---|
500 | printf("Number of Reference frames : %d\n", m_iNumOfReference); |
---|
501 | printf("CU size / depth : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth ); |
---|
502 | printf("Transform depth (min / max) : %d / %d\n", m_uiMinTrDepth, m_uiMaxTrDepth ); |
---|
503 | printf("Motion search range : %d\n", m_iSearchRange ); |
---|
504 | printf("Intra period : %d\n", m_iIntraPeriod ); |
---|
505 | printf("QP : %5.2f\n", m_fQP ); |
---|
506 | printf("GOP size : %d\n", m_iGOPSize ); |
---|
507 | printf("Rate GOP size : %d\n", m_iRateGOPSize ); |
---|
508 | printf("Max physical trans. size : %d\n", m_uiMaxTrSize ); |
---|
509 | printf("Bit increment : %d\n", m_uiBitIncrement ); |
---|
510 | |
---|
511 | #if HHI_INTERP_FILTER |
---|
512 | switch ( m_iInterpFilterType ) |
---|
513 | { |
---|
514 | #if TEN_DIRECTIONAL_INTERP |
---|
515 | case IPF_TEN_DIF: |
---|
516 | printf("Luma interpolation : %s\n", "TEN directional interpolation filter" ); |
---|
517 | printf("Chroma interpolation : %s\n", "TEN two-stage bi-linear filter" ); |
---|
518 | break; |
---|
519 | #endif |
---|
520 | case IPF_HHI_4TAP_MOMS: |
---|
521 | printf("Luma interpolation : %s\n", "HHI 4-tap MOMS filter" ); |
---|
522 | printf("Chroma interpolation : %s\n", "HHI 4-tap MOMS filter" ); |
---|
523 | break; |
---|
524 | case IPF_HHI_6TAP_MOMS: |
---|
525 | printf("Luma interpolation : %s\n", "HHI 6-tap MOMS filter" ); |
---|
526 | printf("Chroma interpolation : %s\n", "HHI 6-tap MOMS filter" ); |
---|
527 | break; |
---|
528 | #ifdef QC_SIFO |
---|
529 | case IPF_QC_SIFO: |
---|
530 | printf("Luma interpolation : Qualcomm %d-tap SIFO\n", m_iDIFTap ); |
---|
531 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
532 | break; |
---|
533 | #endif |
---|
534 | default: |
---|
535 | #ifdef QC_CONFIG |
---|
536 | printf("Luma interpolation : Samsung %d-tap filter\n", m_iDIFTap ); |
---|
537 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
538 | #else |
---|
539 | printf("Luma interpolation : %s\n", "Samsung 12-tap filter" ); |
---|
540 | printf("Chroma interpolation : %s\n", "Bi-linear filter" ); |
---|
541 | #endif |
---|
542 | } |
---|
543 | #else |
---|
544 | printf("Number of int. taps (luma) : %d\n", m_iDIFTap ); |
---|
545 | printf("Number of int. taps (chroma) : %d\n", 2 ); |
---|
546 | #endif |
---|
547 | |
---|
548 | if ( m_pchGRefMode != NULL ) |
---|
549 | { |
---|
550 | printf("Additional reference frame : weighted prediction\n"); |
---|
551 | } |
---|
552 | |
---|
553 | if ( m_iSymbolMode == 0 ) |
---|
554 | { |
---|
555 | printf("Entropy coder : VLC\n"); |
---|
556 | } |
---|
557 | else if( m_iSymbolMode == 1 ) |
---|
558 | { |
---|
559 | printf("Entropy coder : CABAC\n"); |
---|
560 | } |
---|
561 | else if( m_iSymbolMode == 2 ) |
---|
562 | { |
---|
563 | printf("Entropy coder : PIPE\n"); |
---|
564 | } |
---|
565 | else |
---|
566 | { |
---|
567 | printf("Entropy coder : V2V with load balancing on %d bin decoders\n", m_uiBalancedCPUs); |
---|
568 | } |
---|
569 | |
---|
570 | printf("\n"); |
---|
571 | |
---|
572 | printf("TOOL CFG: "); |
---|
573 | printf("ALF:%d ", m_bUseALF ); |
---|
574 | printf("IBD:%d ", m_uiBitIncrement!=0 ); |
---|
575 | printf("HAD:%d ", m_bUseHADME ); |
---|
576 | printf("SRD:%d ", m_bUseSBACRD ); |
---|
577 | printf("RDQ:%d ", m_bUseRDOQ ); |
---|
578 | printf("SQP:%d ", m_uiDeltaQpRD ); |
---|
579 | printf("ASR:%d ", m_bUseASR ); |
---|
580 | printf("PAD:%d ", m_bUsePAD ); |
---|
581 | printf("LDC:%d ", m_bUseLDC ); |
---|
582 | printf("NRF:%d ", m_bUseNRF ); |
---|
583 | printf("BQP:%d ", m_bUseBQP ); |
---|
584 | printf("QBO:%d ", m_bUseQBO ); |
---|
585 | printf("GPB:%d ", m_bUseGPB ); |
---|
586 | printf("FEN:%d ", m_bUseFastEnc ); |
---|
587 | #ifdef EDGE_BASED_PREDICTION |
---|
588 | printf("EdgePrediction:%d ", m_bEdgePredictionEnable); |
---|
589 | #endif //EDGE_BASED_PREDICTION |
---|
590 | #if HHI_RQT |
---|
591 | printf("RQT:%d ", m_bQuadtreeTUFlag ); |
---|
592 | #endif |
---|
593 | #if HHI_ALLOW_CIP_SWITCH |
---|
594 | printf("CIP:%d ", m_bUseCIP ); |
---|
595 | #endif |
---|
596 | #if HHI_ALLOW_ROT_SWITCH |
---|
597 | printf("ROT:%d ", m_bUseROT ); |
---|
598 | #endif |
---|
599 | #if HHI_AIS |
---|
600 | printf("AIS:%d ", m_bUseAIS ); // BB: adaptive intra smoothing |
---|
601 | #endif |
---|
602 | #if HHI_MRG |
---|
603 | printf("MRG:%d ", m_bUseMRG ); // SOPH: Merge Mode |
---|
604 | #endif |
---|
605 | #if HHI_IMVP |
---|
606 | printf("IMP:%d ", m_bUseIMP ); // SOPH: Interleaved MV Predictor |
---|
607 | #endif |
---|
608 | #ifdef QC_AMVRES |
---|
609 | printf("AMVRES:%d ", m_bUseAMVRes ); |
---|
610 | #endif |
---|
611 | #ifdef QC_SIFO_PRED |
---|
612 | printf("SPF:%d ", m_bUseSIFO_Pred ); |
---|
613 | #endif |
---|
614 | printf("AMP:%d ", m_bUseAMP); |
---|
615 | printf("\n"); |
---|
616 | |
---|
617 | fflush(stdout); |
---|
618 | } |
---|
619 | |
---|
620 | Void TAppEncCfg::xPrintUsage() |
---|
621 | { |
---|
622 | printf( " <name> = ALF - adaptive loop filter\n"); |
---|
623 | printf( " IBD - bit-depth increasement\n"); |
---|
624 | printf( " GPB - generalized B instead of P in low-delay mode\n"); |
---|
625 | printf( " HAD - hadamard ME for fractional-pel\n"); |
---|
626 | printf( " SRD - SBAC based RD estimation\n"); |
---|
627 | printf( " RDQ - RDOQ\n"); |
---|
628 | printf( " LDC - low-delay mode\n"); |
---|
629 | printf( " NRF - non-reference frame marking in last layer\n"); |
---|
630 | printf( " BQP - hier-P style QP assignment in low-delay mode\n"); |
---|
631 | printf( " PAD - automatic source padding of multiple of 16\n"); |
---|
632 | printf( " QBO - skip refers highest quality picture\n"); |
---|
633 | printf( " ASR - adaptive motion search range\n"); |
---|
634 | printf( " FEN - fast encoder setting\n"); |
---|
635 | #if HHI_AIS |
---|
636 | printf( " AIS - adaptive intra smoothing\n"); // BB: adaptive intra smoothing |
---|
637 | #endif |
---|
638 | #if HHI_MRG |
---|
639 | printf( " MRG - merging of motion partitions\n"); // SOPH: Merge Mode |
---|
640 | #endif |
---|
641 | #if HHI_IMVP |
---|
642 | printf( " IMP - interleaved motion vector predictor\n"); /// SOPH: Interleaved MV Predictor |
---|
643 | #endif |
---|
644 | #ifdef QC_AMVRES |
---|
645 | printf( " AMVRES - Adaptive motion resolution\n"); |
---|
646 | #endif |
---|
647 | printf( "\n" ); |
---|
648 | printf( " Example 1) TAppEncoder.exe -c test.cfg -q 32 -g 8 -f 9 -s 64 -h 4\n"); |
---|
649 | printf(" -> QP 32, hierarchical-B GOP 8, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
650 | printf( " Example 2) TAppEncoder.exe -c test.cfg -q 32 -g 4 -f 9 -s 64 -h 4 -1 LDC\n"); |
---|
651 | printf(" -> QP 32, hierarchical-P GOP 4, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
652 | 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"); |
---|
653 | printf(" -> QP 32, IPPP with hierarchical-P of GOP 4 style QP, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
654 | 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"); |
---|
655 | printf(" -> QP 32, IPPP with hierarchical-B of GOP 4 style QP, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n"); |
---|
656 | } |
---|
657 | |
---|
658 | Bool confirmPara(Bool bflag, const char* message) |
---|
659 | { |
---|
660 | if (!bflag) |
---|
661 | return false; |
---|
662 | |
---|
663 | printf("Error: %s\n",message); |
---|
664 | return true; |
---|
665 | } |
---|
666 | |
---|
667 | /* helper for -ldm */ |
---|
668 | void doOldStyleCmdlineLDM(po::Options& opts, const std::string& arg) |
---|
669 | { |
---|
670 | /* xxx: warn this option is depricated */ |
---|
671 | if (arg == "1") { |
---|
672 | po::storePair(opts, "QBO", "1"); |
---|
673 | po::storePair(opts, "BQP", "0"); |
---|
674 | po::storePair(opts, "NRF", "1"); |
---|
675 | return; |
---|
676 | } |
---|
677 | if (arg == "0") { |
---|
678 | po::storePair(opts, "QBO", "0"); |
---|
679 | po::storePair(opts, "BQP", "1"); |
---|
680 | po::storePair(opts, "NRF", "0"); |
---|
681 | return; |
---|
682 | } |
---|
683 | /* invalid parse */ |
---|
684 | cerr << "Invalid argument to -ldm: `" << arg << "'" << endl; |
---|
685 | } |
---|
686 | |
---|
687 | /* helper function */ |
---|
688 | /* for handling "-1/-0 FOO" */ |
---|
689 | void translateOldStyleCmdline(const char* value, po::Options& opts, const std::string& arg) |
---|
690 | { |
---|
691 | const char* argv[] = {arg.c_str(), value}; |
---|
692 | /* replace some short names with their long name varients */ |
---|
693 | if (arg == "LDC") { |
---|
694 | argv[0] = "LowDelayCoding"; |
---|
695 | } |
---|
696 | else if (arg == "RDQ") { |
---|
697 | argv[0] = "RDOQ"; |
---|
698 | } |
---|
699 | else if (arg == "HAD") { |
---|
700 | argv[0] = "HadamardME"; |
---|
701 | } |
---|
702 | else if (arg == "SRD") { |
---|
703 | argv[0] = "SBACRD"; |
---|
704 | } |
---|
705 | else if (arg == "IBD") { |
---|
706 | argv[0] = "BitIncrement"; |
---|
707 | } |
---|
708 | /* issue a warning for change in FEN behaviour */ |
---|
709 | if (arg == "FEN") { |
---|
710 | /* xxx todo */ |
---|
711 | } |
---|
712 | po::storePair(opts, argv[0], argv[1]); |
---|
713 | } |
---|
714 | |
---|
715 | void doOldStyleCmdlineOn(po::Options& opts, const std::string& arg) |
---|
716 | { |
---|
717 | if (arg == "IBD") { |
---|
718 | translateOldStyleCmdline("4", opts, arg); |
---|
719 | return; |
---|
720 | } |
---|
721 | translateOldStyleCmdline("1", opts, arg); |
---|
722 | } |
---|
723 | void doOldStyleCmdlineOff(po::Options& opts, const std::string& arg) |
---|
724 | { |
---|
725 | translateOldStyleCmdline("0", opts, arg); |
---|
726 | } |
---|