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-2015, 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 TEncTop.cpp |
---|
35 | \brief encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TLibCommon/CommonDef.h" |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncPic.h" |
---|
41 | #include "TLibCommon/TComChromaFormat.h" |
---|
42 | #if FAST_BIT_EST |
---|
43 | #include "TLibCommon/ContextModel.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | //! \ingroup TLibEncoder |
---|
47 | //! \{ |
---|
48 | #if SVC_EXTENSION |
---|
49 | Int TEncTop::m_iSPSIdCnt = 0; |
---|
50 | Int TEncTop::m_iPPSIdCnt = 0; |
---|
51 | TComVPS TEncCfg::m_cVPS; |
---|
52 | #endif |
---|
53 | |
---|
54 | // ==================================================================================================================== |
---|
55 | // Constructor / destructor / create / destroy |
---|
56 | // ==================================================================================================================== |
---|
57 | |
---|
58 | TEncTop::TEncTop() |
---|
59 | { |
---|
60 | m_iPOCLast = -1; |
---|
61 | m_iNumPicRcvd = 0; |
---|
62 | m_uiNumAllPicCoded = 0; |
---|
63 | m_pppcRDSbacCoder = NULL; |
---|
64 | m_pppcBinCoderCABAC = NULL; |
---|
65 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
66 | #if ENC_DEC_TRACE |
---|
67 | if (g_hTrace == NULL) |
---|
68 | { |
---|
69 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
70 | } |
---|
71 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
72 | g_nSymbolCounter = 0; |
---|
73 | #endif |
---|
74 | |
---|
75 | m_iMaxRefPicNum = 0; |
---|
76 | |
---|
77 | #if FAST_BIT_EST |
---|
78 | ContextModel::buildNextStateTable(); |
---|
79 | #endif |
---|
80 | |
---|
81 | #if SVC_EXTENSION |
---|
82 | memset( m_cIlpPic, 0, sizeof(m_cIlpPic) ); |
---|
83 | m_bMFMEnabledFlag = false; |
---|
84 | m_numRefLayerLocationOffsets = 0; |
---|
85 | m_pocAdjustmentValue = 0; |
---|
86 | #if NO_CLRAS_OUTPUT_FLAG |
---|
87 | m_noClrasOutputFlag = false; |
---|
88 | m_layerInitializedFlag = false; |
---|
89 | m_firstPicInLayerDecodedFlag = false; |
---|
90 | m_noOutputOfPriorPicsFlags = false; |
---|
91 | #endif |
---|
92 | m_pocDecrementedInDPBFlag = false; |
---|
93 | #endif //SVC_EXTENSION |
---|
94 | } |
---|
95 | |
---|
96 | TEncTop::~TEncTop() |
---|
97 | { |
---|
98 | #if ENC_DEC_TRACE |
---|
99 | if (g_hTrace != stdout) |
---|
100 | { |
---|
101 | fclose( g_hTrace ); |
---|
102 | } |
---|
103 | #endif |
---|
104 | } |
---|
105 | |
---|
106 | Void TEncTop::create () |
---|
107 | { |
---|
108 | #if !SVC_EXTENSION |
---|
109 | // initialize global variables |
---|
110 | initROM(); |
---|
111 | #endif |
---|
112 | |
---|
113 | // create processing unit classes |
---|
114 | #if SVC_EXTENSION |
---|
115 | m_cGOPEncoder. create( m_layerId ); |
---|
116 | #else |
---|
117 | m_cGOPEncoder. create( ); |
---|
118 | #endif |
---|
119 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth ); |
---|
120 | m_cCuEncoder. create( m_maxTotalCUDepth, m_maxCUWidth, m_maxCUHeight, m_chromaFormatIDC ); |
---|
121 | if (m_bUseSAO) |
---|
122 | { |
---|
123 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA], m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
---|
124 | m_cEncSAO.createEncData(getSaoCtuBoundary()); |
---|
125 | } |
---|
126 | #if ADAPTIVE_QP_SELECTION |
---|
127 | if (m_bUseAdaptQpSelect) |
---|
128 | { |
---|
129 | m_cTrQuant.initSliceQpDelta(); |
---|
130 | } |
---|
131 | #endif |
---|
132 | |
---|
133 | m_cLoopFilter.create( m_maxTotalCUDepth ); |
---|
134 | |
---|
135 | if ( m_RCEnableRateControl ) |
---|
136 | { |
---|
137 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
138 | m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
139 | } |
---|
140 | |
---|
141 | m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1]; |
---|
142 | #if FAST_BIT_EST |
---|
143 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1]; |
---|
144 | #else |
---|
145 | m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1]; |
---|
146 | #endif |
---|
147 | |
---|
148 | for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
149 | { |
---|
150 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
151 | #if FAST_BIT_EST |
---|
152 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
153 | #else |
---|
154 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
155 | #endif |
---|
156 | |
---|
157 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
158 | { |
---|
159 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
160 | #if FAST_BIT_EST |
---|
161 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
162 | #else |
---|
163 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
164 | #endif |
---|
165 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | #if LAYER_CTB |
---|
170 | memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) ); |
---|
171 | memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) ); |
---|
172 | memcpy(g_auiLayerRasterToPelX[m_layerId], g_auiRasterToPelX, sizeof( g_auiRasterToPelX ) ); |
---|
173 | memcpy(g_auiLayerRasterToPelY[m_layerId], g_auiRasterToPelY, sizeof( g_auiRasterToPelY ) ); |
---|
174 | #endif |
---|
175 | } |
---|
176 | |
---|
177 | Void TEncTop::destroy () |
---|
178 | { |
---|
179 | // destroy processing unit classes |
---|
180 | m_cGOPEncoder. destroy(); |
---|
181 | m_cSliceEncoder. destroy(); |
---|
182 | m_cCuEncoder. destroy(); |
---|
183 | m_cEncSAO. destroyEncData(); |
---|
184 | m_cEncSAO. destroy(); |
---|
185 | m_cLoopFilter. destroy(); |
---|
186 | m_cRateCtrl. destroy(); |
---|
187 | Int iDepth; |
---|
188 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
189 | { |
---|
190 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
191 | { |
---|
192 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
193 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
198 | { |
---|
199 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
200 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
201 | } |
---|
202 | |
---|
203 | delete [] m_pppcRDSbacCoder; |
---|
204 | delete [] m_pppcBinCoderCABAC; |
---|
205 | |
---|
206 | #if SVC_EXTENSION |
---|
207 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
208 | { |
---|
209 | if(m_cIlpPic[i]) |
---|
210 | { |
---|
211 | m_cIlpPic[i]->destroy(); |
---|
212 | delete m_cIlpPic[i]; |
---|
213 | m_cIlpPic[i] = NULL; |
---|
214 | } |
---|
215 | } |
---|
216 | #else |
---|
217 | // destroy ROM |
---|
218 | destroyROM(); |
---|
219 | #endif |
---|
220 | return; |
---|
221 | } |
---|
222 | |
---|
223 | Void TEncTop::init(Bool isFieldCoding) |
---|
224 | { |
---|
225 | // initialize SPS |
---|
226 | xInitSPS(); |
---|
227 | xInitVPS(); |
---|
228 | |
---|
229 | m_cRdCost.setCostMode(m_costMode); |
---|
230 | |
---|
231 | // initialize PPS |
---|
232 | xInitPPS(); |
---|
233 | xInitRPS(isFieldCoding); |
---|
234 | |
---|
235 | xInitPPSforTiles(); |
---|
236 | |
---|
237 | // initialize processing unit classes |
---|
238 | m_cGOPEncoder. init( this ); |
---|
239 | m_cSliceEncoder.init( this ); |
---|
240 | m_cCuEncoder. init( this ); |
---|
241 | |
---|
242 | // initialize transform & quantization class |
---|
243 | m_pcCavlcCoder = getCavlcCoder(); |
---|
244 | |
---|
245 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
246 | m_useRDOQ, |
---|
247 | m_useRDOQTS, |
---|
248 | #if T0196_SELECTIVE_RDOQ |
---|
249 | m_useSelectiveRDOQ, |
---|
250 | #endif |
---|
251 | true |
---|
252 | ,m_useTransformSkipFast |
---|
253 | #if ADAPTIVE_QP_SELECTION |
---|
254 | ,m_bUseAdaptQpSelect |
---|
255 | #endif |
---|
256 | ); |
---|
257 | |
---|
258 | // initialize encoder search class |
---|
259 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
260 | |
---|
261 | m_iMaxRefPicNum = 0; |
---|
262 | |
---|
263 | xInitScalingLists(); |
---|
264 | |
---|
265 | #if SVC_EXTENSION |
---|
266 | m_iSPSIdCnt ++; |
---|
267 | m_iPPSIdCnt ++; |
---|
268 | xInitILRP(); |
---|
269 | #endif |
---|
270 | } |
---|
271 | |
---|
272 | Void TEncTop::xInitScalingLists() |
---|
273 | { |
---|
274 | // Initialise scaling lists |
---|
275 | // The encoder will only use the SPS scaling lists. The PPS will never be marked present. |
---|
276 | const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] = |
---|
277 | { |
---|
278 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA), |
---|
279 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA) |
---|
280 | }; |
---|
281 | if(getUseScalingListId() == SCALING_LIST_OFF) |
---|
282 | { |
---|
283 | #if SVC_EXTENSION |
---|
284 | getTrQuant()->setFlatScalingList( maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) ); |
---|
285 | #else |
---|
286 | getTrQuant()->setFlatScalingList(maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
287 | #endif |
---|
288 | getTrQuant()->setUseScalingList(false); |
---|
289 | m_cSPS.setScalingListPresentFlag(false); |
---|
290 | m_cPPS.setScalingListPresentFlag(false); |
---|
291 | } |
---|
292 | else if(getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
293 | { |
---|
294 | #if SVC_EXTENSION |
---|
295 | // inferring of the scaling list can be moved to the config file |
---|
296 | UInt refLayerId = 0; |
---|
297 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
298 | { |
---|
299 | m_cSPS.setInferScalingListFlag( true ); |
---|
300 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
---|
301 | m_cSPS.setScalingListPresentFlag( false ); |
---|
302 | m_cPPS.setInferScalingListFlag( false ); |
---|
303 | m_cPPS.setScalingListPresentFlag( false ); |
---|
304 | |
---|
305 | // infer the scaling list from the reference layer |
---|
306 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) ); |
---|
307 | } |
---|
308 | else |
---|
309 | { |
---|
310 | #endif |
---|
311 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
312 | m_cSPS.setScalingListPresentFlag(false); |
---|
313 | m_cPPS.setScalingListPresentFlag(false); |
---|
314 | |
---|
315 | #if SVC_EXTENSION |
---|
316 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId)); |
---|
317 | #else |
---|
318 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
319 | #endif |
---|
320 | #if SVC_EXTENSION |
---|
321 | } |
---|
322 | #endif |
---|
323 | getTrQuant()->setUseScalingList(true); |
---|
324 | } |
---|
325 | else if(getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
326 | { |
---|
327 | #if SVC_EXTENSION |
---|
328 | // inferring of the scaling list can be moved to the config file |
---|
329 | UInt refLayerId = 0; |
---|
330 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
331 | { |
---|
332 | m_cSPS.setInferScalingListFlag( true ); |
---|
333 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
---|
334 | m_cSPS.setScalingListPresentFlag( false ); |
---|
335 | m_cPPS.setInferScalingListFlag( false ); |
---|
336 | m_cPPS.setScalingListPresentFlag( false ); |
---|
337 | |
---|
338 | // infer the scaling list from the reference layer |
---|
339 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) ); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | #endif |
---|
344 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
345 | if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile())) |
---|
346 | { |
---|
347 | Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string |
---|
348 | assert(bParsedScalingList); |
---|
349 | exit(1); |
---|
350 | } |
---|
351 | m_cSPS.getScalingList().checkDcOfMatrix(); |
---|
352 | m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList()); |
---|
353 | m_cPPS.setScalingListPresentFlag(false); |
---|
354 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
355 | #if SVC_EXTENSION |
---|
356 | } |
---|
357 | #endif |
---|
358 | getTrQuant()->setUseScalingList(true); |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | printf("error : ScalingList == %d not supported\n",getUseScalingListId()); |
---|
363 | assert(0); |
---|
364 | } |
---|
365 | |
---|
366 | if (getUseScalingListId() != SCALING_LIST_OFF) |
---|
367 | { |
---|
368 | // Prepare delta's: |
---|
369 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
370 | { |
---|
371 | const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries. |
---|
372 | |
---|
373 | for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep) |
---|
374 | { |
---|
375 | m_cSPS.getScalingList().checkPredMode( sizeId, listId ); |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | // ==================================================================================================================== |
---|
382 | // Public member functions |
---|
383 | // ==================================================================================================================== |
---|
384 | |
---|
385 | Void TEncTop::deletePicBuffer() |
---|
386 | { |
---|
387 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
388 | Int iSize = Int( m_cListPic.size() ); |
---|
389 | |
---|
390 | for ( Int i = 0; i < iSize; i++ ) |
---|
391 | { |
---|
392 | TComPic* pcPic = *(iterPic++); |
---|
393 | |
---|
394 | pcPic->destroy(); |
---|
395 | delete pcPic; |
---|
396 | pcPic = NULL; |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | /** |
---|
401 | - Application has picture buffer list with size of GOP + 1 |
---|
402 | - Picture buffer list acts like as ring buffer |
---|
403 | - End of the list has the latest picture |
---|
404 | . |
---|
405 | \param flush cause encoder to encode a partial GOP |
---|
406 | \param pcPicYuvOrg original YUV picture |
---|
407 | \param pcPicYuvTrueOrg |
---|
408 | \param snrCSC |
---|
409 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
410 | \retval accessUnitsOut list of output access units |
---|
411 | \retval iNumEncoded number of encoded pictures |
---|
412 | */ |
---|
413 | #if SVC_EXTENSION |
---|
414 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
415 | { |
---|
416 | // compress GOP |
---|
417 | #if !RC_SHVC_HARMONIZATION |
---|
418 | if ( m_RCEnableRateControl ) |
---|
419 | { |
---|
420 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
421 | } |
---|
422 | #endif |
---|
423 | |
---|
424 | // compress GOP |
---|
425 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
426 | |
---|
427 | #if !RC_SHVC_HARMONIZATION |
---|
428 | if ( m_RCEnableRateControl ) |
---|
429 | { |
---|
430 | m_cRateCtrl.destroyRCGOP(); |
---|
431 | } |
---|
432 | #endif |
---|
433 | |
---|
434 | m_uiNumAllPicCoded ++; |
---|
435 | } |
---|
436 | |
---|
437 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ) |
---|
438 | { |
---|
439 | if (pcPicYuvOrg != NULL) |
---|
440 | { |
---|
441 | // get original YUV |
---|
442 | TComPic* pcPicCurr = NULL; |
---|
443 | xGetNewPicBuffer( pcPicCurr ); |
---|
444 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
445 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
446 | |
---|
447 | // compute image characteristics |
---|
448 | if ( getUseAdaptiveQP() ) |
---|
449 | { |
---|
450 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
451 | } |
---|
452 | } |
---|
453 | } |
---|
454 | #else |
---|
455 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
456 | { |
---|
457 | if (pcPicYuvOrg != NULL) |
---|
458 | { |
---|
459 | // get original YUV |
---|
460 | TComPic* pcPicCurr = NULL; |
---|
461 | |
---|
462 | xGetNewPicBuffer( pcPicCurr ); |
---|
463 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
464 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
465 | |
---|
466 | // compute image characteristics |
---|
467 | if ( getUseAdaptiveQP() ) |
---|
468 | { |
---|
469 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0))) |
---|
474 | { |
---|
475 | iNumEncoded = 0; |
---|
476 | return; |
---|
477 | } |
---|
478 | |
---|
479 | if ( m_RCEnableRateControl ) |
---|
480 | { |
---|
481 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
482 | } |
---|
483 | |
---|
484 | // compress GOP |
---|
485 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
486 | |
---|
487 | if ( m_RCEnableRateControl ) |
---|
488 | { |
---|
489 | m_cRateCtrl.destroyRCGOP(); |
---|
490 | } |
---|
491 | |
---|
492 | iNumEncoded = m_iNumPicRcvd; |
---|
493 | m_iNumPicRcvd = 0; |
---|
494 | m_uiNumAllPicCoded += iNumEncoded; |
---|
495 | } |
---|
496 | #endif |
---|
497 | |
---|
498 | /**------------------------------------------------ |
---|
499 | Separate interlaced frame into two fields |
---|
500 | -------------------------------------------------**/ |
---|
501 | Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
---|
502 | { |
---|
503 | if (!isTop) |
---|
504 | { |
---|
505 | org += stride; |
---|
506 | } |
---|
507 | for (Int y = 0; y < height>>1; y++) |
---|
508 | { |
---|
509 | for (Int x = 0; x < width; x++) |
---|
510 | { |
---|
511 | dstField[x] = org[x]; |
---|
512 | } |
---|
513 | |
---|
514 | dstField += stride; |
---|
515 | org += stride*2; |
---|
516 | } |
---|
517 | |
---|
518 | } |
---|
519 | |
---|
520 | #if SVC_EXTENSION |
---|
521 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ) |
---|
522 | { |
---|
523 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
524 | { |
---|
525 | if (pcPicYuvOrg) |
---|
526 | { |
---|
527 | /* -- field initialization -- */ |
---|
528 | const Bool isTopField=isTff==(fieldNum==0); |
---|
529 | |
---|
530 | TComPic *pcField; |
---|
531 | xGetNewPicBuffer( pcField ); |
---|
532 | pcField->setReconMark (false); // where is this normally? |
---|
533 | |
---|
534 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
535 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
536 | |
---|
537 | pcField->setTopField(isTopField); // interlaced requirement |
---|
538 | |
---|
539 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
540 | { |
---|
541 | const ComponentID component = ComponentID(componentIndex); |
---|
542 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
543 | |
---|
544 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
545 | pcField->getPicYuvOrg()->getAddr(component), |
---|
546 | pcPicYuvOrg->getStride(component), |
---|
547 | pcPicYuvOrg->getWidth(component), |
---|
548 | pcPicYuvOrg->getHeight(component), |
---|
549 | isTopField); |
---|
550 | |
---|
551 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
552 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
553 | pcPicYuvTrueOrg->getStride(component), |
---|
554 | pcPicYuvTrueOrg->getWidth(component), |
---|
555 | pcPicYuvTrueOrg->getHeight(component), |
---|
556 | isTopField); |
---|
557 | } |
---|
558 | |
---|
559 | // compute image characteristics |
---|
560 | if ( getUseAdaptiveQP() ) |
---|
561 | { |
---|
562 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
563 | } |
---|
564 | } |
---|
565 | } |
---|
566 | } |
---|
567 | |
---|
568 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ) |
---|
569 | { |
---|
570 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
571 | { |
---|
572 | if (pcPicYuvOrg) |
---|
573 | { |
---|
574 | if (fieldNum==1) // where is this normally? |
---|
575 | { |
---|
576 | TComPicYuv* rpcPicYuvRec; |
---|
577 | |
---|
578 | // org. buffer |
---|
579 | if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. |
---|
580 | { |
---|
581 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
582 | } |
---|
583 | else |
---|
584 | { |
---|
585 | rpcPicYuvRec = new TComPicYuv; |
---|
586 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true); |
---|
587 | } |
---|
588 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
589 | } |
---|
590 | } |
---|
591 | |
---|
592 | // compress GOP |
---|
593 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
594 | } |
---|
595 | |
---|
596 | m_uiNumAllPicCoded ++; |
---|
597 | } |
---|
598 | #else |
---|
599 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
---|
600 | { |
---|
601 | iNumEncoded = 0; |
---|
602 | |
---|
603 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
604 | { |
---|
605 | if (pcPicYuvOrg) |
---|
606 | { |
---|
607 | |
---|
608 | /* -- field initialization -- */ |
---|
609 | const Bool isTopField=isTff==(fieldNum==0); |
---|
610 | |
---|
611 | TComPic *pcField; |
---|
612 | xGetNewPicBuffer( pcField ); |
---|
613 | pcField->setReconMark (false); // where is this normally? |
---|
614 | |
---|
615 | if (fieldNum==1) // where is this normally? |
---|
616 | { |
---|
617 | TComPicYuv* rpcPicYuvRec; |
---|
618 | |
---|
619 | // org. buffer |
---|
620 | if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. |
---|
621 | { |
---|
622 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
623 | } |
---|
624 | else |
---|
625 | { |
---|
626 | rpcPicYuvRec = new TComPicYuv; |
---|
627 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true); |
---|
628 | } |
---|
629 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
630 | } |
---|
631 | |
---|
632 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
633 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
634 | |
---|
635 | pcField->setTopField(isTopField); // interlaced requirement |
---|
636 | |
---|
637 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
638 | { |
---|
639 | const ComponentID component = ComponentID(componentIndex); |
---|
640 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
641 | |
---|
642 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
643 | pcField->getPicYuvOrg()->getAddr(component), |
---|
644 | pcPicYuvOrg->getStride(component), |
---|
645 | pcPicYuvOrg->getWidth(component), |
---|
646 | pcPicYuvOrg->getHeight(component), |
---|
647 | isTopField); |
---|
648 | |
---|
649 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
650 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
651 | pcPicYuvTrueOrg->getStride(component), |
---|
652 | pcPicYuvTrueOrg->getWidth(component), |
---|
653 | pcPicYuvTrueOrg->getHeight(component), |
---|
654 | isTopField); |
---|
655 | } |
---|
656 | |
---|
657 | // compute image characteristics |
---|
658 | if ( getUseAdaptiveQP() ) |
---|
659 | { |
---|
660 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) |
---|
665 | { |
---|
666 | // compress GOP |
---|
667 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
668 | |
---|
669 | iNumEncoded += m_iNumPicRcvd; |
---|
670 | m_uiNumAllPicCoded += m_iNumPicRcvd; |
---|
671 | m_iNumPicRcvd = 0; |
---|
672 | } |
---|
673 | } |
---|
674 | } |
---|
675 | #endif |
---|
676 | |
---|
677 | // ==================================================================================================================== |
---|
678 | // Protected member functions |
---|
679 | // ==================================================================================================================== |
---|
680 | |
---|
681 | /** |
---|
682 | - Application has picture buffer list with size of GOP + 1 |
---|
683 | - Picture buffer list acts like as ring buffer |
---|
684 | - End of the list has the latest picture |
---|
685 | . |
---|
686 | \retval rpcPic obtained picture buffer |
---|
687 | */ |
---|
688 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
689 | { |
---|
690 | // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic. |
---|
691 | |
---|
692 | TComSlice::sortPicList(m_cListPic); |
---|
693 | |
---|
694 | |
---|
695 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
696 | { |
---|
697 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
698 | Int iSize = Int( m_cListPic.size() ); |
---|
699 | for ( Int i = 0; i < iSize; i++ ) |
---|
700 | { |
---|
701 | rpcPic = *(iterPic++); |
---|
702 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
703 | { |
---|
704 | break; |
---|
705 | } |
---|
706 | } |
---|
707 | } |
---|
708 | else |
---|
709 | { |
---|
710 | if ( getUseAdaptiveQP() ) |
---|
711 | { |
---|
712 | TEncPic* pcEPic = new TEncPic; |
---|
713 | |
---|
714 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
715 | if( m_layerId > 0 ) |
---|
716 | { |
---|
717 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
718 | { |
---|
719 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
720 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
721 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
722 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
723 | |
---|
724 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
725 | |
---|
726 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
727 | |
---|
728 | const Int bitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, &m_cSPS, m_layerId); |
---|
729 | const Int bitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, &m_cSPS, m_layerId); |
---|
730 | const Int refBitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, pcEncTopBase->getSPS(), refLayerId); |
---|
731 | const Int refBitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, pcEncTopBase->getSPS(), refLayerId); |
---|
732 | |
---|
733 | Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma ); |
---|
734 | |
---|
735 | if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase ) |
---|
736 | { |
---|
737 | pcEPic->setEqualPictureSizeAndOffsetFlag( i, true ); |
---|
738 | } |
---|
739 | |
---|
740 | if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths |
---|
741 | #if CGS_3D_ASYMLUT |
---|
742 | || m_cPPS.getCGSFlag() > 0 |
---|
743 | #endif |
---|
744 | #if LAYER_CTB |
---|
745 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
746 | #endif |
---|
747 | ) |
---|
748 | { |
---|
749 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
---|
750 | |
---|
751 | //only for scalable extension |
---|
752 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
753 | } |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | pcEPic->create( m_cVPS, m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId); |
---|
758 | #else //SVC_EXTENSION |
---|
759 | pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false); |
---|
760 | #endif //SVC_EXTENSION |
---|
761 | rpcPic = pcEPic; |
---|
762 | } |
---|
763 | else |
---|
764 | { |
---|
765 | rpcPic = new TComPic; |
---|
766 | |
---|
767 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
768 | if( m_layerId > 0 ) |
---|
769 | { |
---|
770 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
771 | { |
---|
772 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
773 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
774 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
775 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
776 | |
---|
777 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
778 | |
---|
779 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
780 | |
---|
781 | const Int bitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, &m_cSPS, m_layerId); |
---|
782 | const Int bitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, &m_cSPS, m_layerId); |
---|
783 | const Int refBitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, pcEncTopBase->getSPS(), refLayerId); |
---|
784 | const Int refBitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, pcEncTopBase->getSPS(), refLayerId); |
---|
785 | |
---|
786 | Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma ); |
---|
787 | |
---|
788 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths |
---|
789 | || !equalOffsets |
---|
790 | || !zeroPhase |
---|
791 | #if CGS_3D_ASYMLUT |
---|
792 | || m_cPPS.getCGSFlag() > 0 |
---|
793 | #endif |
---|
794 | #if LAYER_CTB |
---|
795 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
796 | #endif |
---|
797 | ) |
---|
798 | { |
---|
799 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
---|
800 | |
---|
801 | //only for scalable extension |
---|
802 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
803 | } |
---|
804 | } |
---|
805 | } |
---|
806 | |
---|
807 | rpcPic->create( m_cVPS, m_cSPS, m_cPPS, false, m_layerId ); |
---|
808 | #else //SVC_EXTENSION |
---|
809 | rpcPic->create( m_cSPS, m_cPPS, false ); |
---|
810 | #endif //SVC_EXTENSION |
---|
811 | } |
---|
812 | |
---|
813 | m_cListPic.pushBack( rpcPic ); |
---|
814 | } |
---|
815 | rpcPic->setReconMark (false); |
---|
816 | |
---|
817 | m_iPOCLast++; |
---|
818 | m_iNumPicRcvd++; |
---|
819 | |
---|
820 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
821 | // mark it should be extended |
---|
822 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
823 | } |
---|
824 | |
---|
825 | Void TEncTop::xInitVPS() |
---|
826 | { |
---|
827 | // The SPS must have already been set up. |
---|
828 | // set the VPS profile information. |
---|
829 | #if SVC_EXTENSION |
---|
830 | m_cVPS.setVpsVuiPresentFlag( true ); |
---|
831 | #else |
---|
832 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
833 | m_cVPS.setMaxOpSets(1); |
---|
834 | #endif |
---|
835 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
836 | m_cVPS.setNumHrdParameters( 0 ); |
---|
837 | |
---|
838 | m_cVPS.createHrdParamBuffer(); |
---|
839 | for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ ) |
---|
840 | { |
---|
841 | m_cVPS.setHrdOpSetIdx( 0, i ); |
---|
842 | m_cVPS.setCprmsPresentFlag( false, i ); |
---|
843 | // Set up HrdParameters here. |
---|
844 | } |
---|
845 | } |
---|
846 | |
---|
847 | Void TEncTop::xInitSPS() |
---|
848 | { |
---|
849 | #if SVC_EXTENSION |
---|
850 | m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false ); |
---|
851 | m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers); |
---|
852 | |
---|
853 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
854 | { |
---|
855 | m_cSPS.setLayerId(0); // layer ID 0 for independent layers |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | m_cSPS.setLayerId(m_layerId); |
---|
860 | } |
---|
861 | #endif //SVC_EXTENSION |
---|
862 | |
---|
863 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
864 | profileTierLevel.setLevelIdc(m_level); |
---|
865 | profileTierLevel.setTierFlag(m_levelTier); |
---|
866 | profileTierLevel.setProfileIdc(m_profile); |
---|
867 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
868 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
869 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
870 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
871 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
872 | profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue); |
---|
873 | profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue); |
---|
874 | profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag); |
---|
875 | profileTierLevel.setOnePictureOnlyConstraintFlag(m_onePictureOnlyConstraintFlag); |
---|
876 | profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag); |
---|
877 | |
---|
878 | if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8)) |
---|
879 | { |
---|
880 | /* The above constraint is equal to Profile::MAIN */ |
---|
881 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
882 | } |
---|
883 | if (m_profile == Profile::MAIN) |
---|
884 | { |
---|
885 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
886 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
887 | } |
---|
888 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
889 | /* XXX: may be a good idea to refactor the above into a function |
---|
890 | * that chooses the actual compatibility based upon options */ |
---|
891 | |
---|
892 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
893 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
894 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
895 | m_cSPS.setMaxCUWidth ( m_maxCUWidth ); |
---|
896 | m_cSPS.setMaxCUHeight ( m_maxCUHeight ); |
---|
897 | m_cSPS.setMaxTotalCUDepth ( m_maxTotalCUDepth ); |
---|
898 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
---|
899 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize); |
---|
900 | |
---|
901 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() ); |
---|
902 | Int log2MinCUSize = 0; |
---|
903 | while(minCUSize > 1) |
---|
904 | { |
---|
905 | minCUSize >>= 1; |
---|
906 | log2MinCUSize++; |
---|
907 | } |
---|
908 | |
---|
909 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
910 | |
---|
911 | #if SVC_EXTENSION |
---|
912 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
913 | #endif |
---|
914 | |
---|
915 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
916 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
917 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
918 | |
---|
919 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
920 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
921 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
922 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
923 | |
---|
924 | m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1)); |
---|
925 | |
---|
926 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
927 | |
---|
928 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
929 | |
---|
930 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
931 | { |
---|
932 | #if SVC_EXTENSION |
---|
933 | m_cSPS.setBitDepth (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) ); |
---|
934 | #if O0043_BEST_EFFORT_DECODING |
---|
935 | m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] ); |
---|
936 | #endif |
---|
937 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8))); |
---|
938 | #else |
---|
939 | m_cSPS.setBitDepth (ChannelType(channelType), m_bitDepth[channelType] ); |
---|
940 | #if O0043_BEST_EFFORT_DECODING |
---|
941 | m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] ); |
---|
942 | #endif |
---|
943 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8))); |
---|
944 | #endif |
---|
945 | m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType] ); |
---|
946 | } |
---|
947 | |
---|
948 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
949 | |
---|
950 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
951 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
952 | |
---|
953 | for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
954 | { |
---|
955 | #if SVC_EXTENSION |
---|
956 | assert( i < MAX_TLAYER ); |
---|
957 | #endif |
---|
958 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
959 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
960 | } |
---|
961 | |
---|
962 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
963 | m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 ); |
---|
964 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
965 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
966 | |
---|
967 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
968 | { |
---|
969 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
970 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag()); |
---|
971 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
972 | pcVUI->setSarWidth(getSarWidth()); |
---|
973 | pcVUI->setSarHeight(getSarHeight()); |
---|
974 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
975 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
976 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
977 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
978 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
979 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
980 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
981 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
982 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
983 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
984 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
985 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
986 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
987 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
988 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
989 | pcVUI->setFieldSeqFlag(false); |
---|
990 | pcVUI->setHrdParametersPresentFlag(false); |
---|
991 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
992 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
993 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
994 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
995 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
996 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
997 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
998 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
999 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
1000 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
1001 | } |
---|
1002 | m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS); |
---|
1003 | assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS); |
---|
1004 | for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++) |
---|
1005 | { |
---|
1006 | m_cSPS.setLtRefPicPocLsbSps(k, 0); |
---|
1007 | m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0); |
---|
1008 | } |
---|
1009 | if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
1010 | { |
---|
1011 | xInitHrdParameters(); |
---|
1012 | } |
---|
1013 | if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
1014 | { |
---|
1015 | m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
1016 | } |
---|
1017 | |
---|
1018 | // Set up SPS range extension settings |
---|
1019 | m_cSPS.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag); |
---|
1020 | m_cSPS.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag); |
---|
1021 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
1022 | { |
---|
1023 | m_cSPS.getSpsRangeExtension().setRdpcmEnabledFlag(RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
---|
1024 | } |
---|
1025 | m_cSPS.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag); |
---|
1026 | m_cSPS.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag ); |
---|
1027 | m_cSPS.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag); |
---|
1028 | m_cSPS.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag); |
---|
1029 | m_cSPS.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag); |
---|
1030 | } |
---|
1031 | |
---|
1032 | Void TEncTop::xInitHrdParameters() |
---|
1033 | { |
---|
1034 | Bool useSubCpbParams = (getSliceMode() > 0) || (getSliceSegmentMode() > 0); |
---|
1035 | Int bitRate = getTargetBitrate(); |
---|
1036 | Bool isRandomAccess = getIntraPeriod() > 0; |
---|
1037 | |
---|
1038 | if( !getVuiParametersPresentFlag() ) |
---|
1039 | { |
---|
1040 | return; |
---|
1041 | } |
---|
1042 | |
---|
1043 | TComVUI *vui = m_cSPS.getVuiParameters(); |
---|
1044 | TComHRD *hrd = vui->getHrdParameters(); |
---|
1045 | |
---|
1046 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
1047 | |
---|
1048 | #if SVC_EXTENSION |
---|
1049 | if( m_layerId > 0 ) |
---|
1050 | { |
---|
1051 | timingInfo->setTimingInfoPresentFlag( false ); |
---|
1052 | return; |
---|
1053 | } |
---|
1054 | #endif |
---|
1055 | |
---|
1056 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
1057 | switch( getFrameRate() ) |
---|
1058 | { |
---|
1059 | case 24: |
---|
1060 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1061 | break; |
---|
1062 | case 25: |
---|
1063 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1064 | break; |
---|
1065 | case 30: |
---|
1066 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1067 | break; |
---|
1068 | case 50: |
---|
1069 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1070 | break; |
---|
1071 | case 60: |
---|
1072 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1073 | break; |
---|
1074 | default: |
---|
1075 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
1076 | break; |
---|
1077 | } |
---|
1078 | |
---|
1079 | Bool rateCnt = ( bitRate > 0 ); |
---|
1080 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
1081 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
1082 | |
---|
1083 | hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams ); |
---|
1084 | |
---|
1085 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1086 | { |
---|
1087 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
1088 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
1089 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
1090 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
1091 | } |
---|
1092 | else |
---|
1093 | { |
---|
1094 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
1095 | } |
---|
1096 | |
---|
1097 | hrd->setBitRateScale( 4 ); // in units of 2^( 6 + 4 ) = 1,024 bps |
---|
1098 | hrd->setCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
1099 | hrd->setDuCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
1100 | |
---|
1101 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
1102 | if( isRandomAccess ) |
---|
1103 | { |
---|
1104 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
1105 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
1106 | } |
---|
1107 | else |
---|
1108 | { |
---|
1109 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
1110 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
1111 | } |
---|
1112 | |
---|
1113 | // Note: parameters for all temporal layers are initialized with the same values |
---|
1114 | Int i, j; |
---|
1115 | UInt bitrateValue, cpbSizeValue; |
---|
1116 | UInt duCpbSizeValue; |
---|
1117 | UInt duBitRateValue = 0; |
---|
1118 | |
---|
1119 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
1120 | { |
---|
1121 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
1122 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
1123 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
1124 | hrd->setCpbCntMinus1( i, 0 ); |
---|
1125 | |
---|
1126 | //! \todo check for possible PTL violations |
---|
1127 | // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale ) |
---|
1128 | bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) ); // bitRate is in bits, so it needs to be scaled down |
---|
1129 | // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale ) |
---|
1130 | cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) ); // using bitRate results in 1 second CPB size |
---|
1131 | |
---|
1132 | // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know |
---|
1133 | // in how many DUs the slice segment settings will result |
---|
1134 | duCpbSizeValue = bitrateValue; |
---|
1135 | duBitRateValue = cpbSizeValue; |
---|
1136 | |
---|
1137 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
1138 | { |
---|
1139 | hrd->setBitRateValueMinus1( i, j, 0, ( bitrateValue - 1 ) ); |
---|
1140 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
1141 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) ); |
---|
1142 | hrd->setDuBitRateValueMinus1( i, j, 0, ( duBitRateValue - 1 ) ); |
---|
1143 | hrd->setCbrFlag( i, j, 0, false ); |
---|
1144 | |
---|
1145 | hrd->setBitRateValueMinus1( i, j, 1, ( bitrateValue - 1) ); |
---|
1146 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
1147 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( duCpbSizeValue - 1 ) ); |
---|
1148 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
1149 | hrd->setCbrFlag( i, j, 1, false ); |
---|
1150 | } |
---|
1151 | } |
---|
1152 | } |
---|
1153 | |
---|
1154 | Void TEncTop::xInitPPS() |
---|
1155 | { |
---|
1156 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
1157 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
1158 | |
---|
1159 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
1160 | { |
---|
1161 | bUseDQP = true; |
---|
1162 | } |
---|
1163 | |
---|
1164 | if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING) |
---|
1165 | { |
---|
1166 | bUseDQP=false; |
---|
1167 | } |
---|
1168 | |
---|
1169 | |
---|
1170 | if ( m_RCEnableRateControl ) |
---|
1171 | { |
---|
1172 | m_cPPS.setUseDQP(true); |
---|
1173 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
1174 | } |
---|
1175 | else if(bUseDQP) |
---|
1176 | { |
---|
1177 | m_cPPS.setUseDQP(true); |
---|
1178 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
1179 | } |
---|
1180 | else |
---|
1181 | { |
---|
1182 | m_cPPS.setUseDQP(false); |
---|
1183 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
1184 | } |
---|
1185 | |
---|
1186 | if ( m_diffCuChromaQpOffsetDepth >= 0 ) |
---|
1187 | { |
---|
1188 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth); |
---|
1189 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
1190 | m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6); |
---|
1191 | /* todo, insert table entries from command line (NB, 0 should not be touched) */ |
---|
1192 | } |
---|
1193 | else |
---|
1194 | { |
---|
1195 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0); |
---|
1196 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
1197 | } |
---|
1198 | m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag); |
---|
1199 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA ]); |
---|
1200 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]); |
---|
1201 | |
---|
1202 | m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset ); |
---|
1203 | m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset ); |
---|
1204 | |
---|
1205 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
1206 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
1207 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
1208 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
1209 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
1210 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
1211 | |
---|
1212 | if ( getDeblockingFilterMetric() ) |
---|
1213 | { |
---|
1214 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
1215 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() ); |
---|
1220 | m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() ); |
---|
1221 | } |
---|
1222 | |
---|
1223 | if (! m_cPPS.getPicDisableDeblockingFilterFlag()) |
---|
1224 | { |
---|
1225 | m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() ); |
---|
1226 | m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() ); |
---|
1227 | } |
---|
1228 | else |
---|
1229 | { |
---|
1230 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
1231 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
1232 | } |
---|
1233 | |
---|
1234 | // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values: |
---|
1235 | const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() || |
---|
1236 | m_cPPS.getPicDisableDeblockingFilterFlag() || |
---|
1237 | m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 || |
---|
1238 | m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0; |
---|
1239 | |
---|
1240 | m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag); |
---|
1241 | |
---|
1242 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
1243 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
1244 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
1245 | |
---|
1246 | |
---|
1247 | Int histogram[MAX_NUM_REF + 1]; |
---|
1248 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
1249 | { |
---|
1250 | histogram[i]=0; |
---|
1251 | } |
---|
1252 | for( Int i = 0; i < getGOPSize(); i++) |
---|
1253 | { |
---|
1254 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
1255 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
1256 | } |
---|
1257 | |
---|
1258 | Int maxHist=-1; |
---|
1259 | Int bestPos=0; |
---|
1260 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
1261 | { |
---|
1262 | if(histogram[i]>maxHist) |
---|
1263 | { |
---|
1264 | maxHist=histogram[i]; |
---|
1265 | bestPos=i; |
---|
1266 | } |
---|
1267 | } |
---|
1268 | assert(bestPos <= 15); |
---|
1269 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
1270 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
1271 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
1272 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
1273 | m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize ); |
---|
1274 | |
---|
1275 | if (m_sliceSegmentMode != NO_SLICES) |
---|
1276 | { |
---|
1277 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
1278 | } |
---|
1279 | |
---|
1280 | #if SVC_EXTENSION |
---|
1281 | m_cPPS.setLayerId( m_layerId ); |
---|
1282 | |
---|
1283 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
1284 | { |
---|
1285 | m_cPPS.setLayerId(0); // layer ID 0 for independent layers |
---|
1286 | } |
---|
1287 | |
---|
1288 | if( m_layerId > 0 ) |
---|
1289 | { |
---|
1290 | m_cPPS.setListsModificationPresentFlag(true); |
---|
1291 | m_cPPS.setExtensionFlag(true); |
---|
1292 | } |
---|
1293 | else |
---|
1294 | { |
---|
1295 | m_cPPS.setListsModificationPresentFlag(false); |
---|
1296 | m_cPPS.setExtensionFlag(false); |
---|
1297 | } |
---|
1298 | |
---|
1299 | m_cPPS.setPPSId( m_iPPSIdCnt ); |
---|
1300 | m_cPPS.setSPSId( m_iSPSIdCnt ); |
---|
1301 | |
---|
1302 | if( m_crossLayerBLAFlag ) |
---|
1303 | { |
---|
1304 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
1305 | } |
---|
1306 | |
---|
1307 | m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets); |
---|
1308 | for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++) |
---|
1309 | { |
---|
1310 | m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]); |
---|
1311 | m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
---|
1312 | m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i]; |
---|
1313 | m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] ); |
---|
1314 | m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] ); |
---|
1315 | m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] ); |
---|
1316 | m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] ); |
---|
1317 | m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] ); |
---|
1318 | m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] ); |
---|
1319 | m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] ); |
---|
1320 | } |
---|
1321 | #if CGS_3D_ASYMLUT |
---|
1322 | m_cPPS.setCGSFlag( m_nCGSFlag ); |
---|
1323 | #endif |
---|
1324 | m_cPPS.setPocResetInfoPresentFlag( true ); |
---|
1325 | m_cPPS.setExtensionFlag( true ); |
---|
1326 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
---|
1327 | #endif //SVC_EXTENSION |
---|
1328 | } |
---|
1329 | |
---|
1330 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
1331 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
1332 | { |
---|
1333 | TComReferencePictureSet* rps; |
---|
1334 | |
---|
1335 | m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1); |
---|
1336 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
1337 | |
---|
1338 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
1339 | { |
---|
1340 | GOPEntry ge = getGOPEntry(i); |
---|
1341 | rps = rpsList->getReferencePictureSet(i); |
---|
1342 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
1343 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1344 | Int numNeg = 0; |
---|
1345 | Int numPos = 0; |
---|
1346 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
1347 | { |
---|
1348 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
1349 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
1350 | if(ge.m_referencePics[j]>0) |
---|
1351 | { |
---|
1352 | numPos++; |
---|
1353 | } |
---|
1354 | else |
---|
1355 | { |
---|
1356 | numNeg++; |
---|
1357 | } |
---|
1358 | } |
---|
1359 | rps->setNumberOfNegativePictures(numNeg); |
---|
1360 | rps->setNumberOfPositivePictures(numPos); |
---|
1361 | |
---|
1362 | // handle inter RPS intialization from the config file. |
---|
1363 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
1364 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
1365 | TComReferencePictureSet* RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL; // get the reference RPS |
---|
1366 | |
---|
1367 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
1368 | { |
---|
1369 | assert (RPSRef!=NULL); |
---|
1370 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
1371 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
1372 | |
---|
1373 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
1374 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
1375 | Int count=0; |
---|
1376 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
1377 | { |
---|
1378 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
1379 | rps->setRefIdc(j, 0); |
---|
1380 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
1381 | { |
---|
1382 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
1383 | { |
---|
1384 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
1385 | count++; |
---|
1386 | break; |
---|
1387 | } |
---|
1388 | } |
---|
1389 | } |
---|
1390 | if (count != rps->getNumberOfPictures()) |
---|
1391 | { |
---|
1392 | printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file. Setting Inter RPS to false for this RPS.\n"); |
---|
1393 | rps->setInterRPSPrediction(0); |
---|
1394 | } |
---|
1395 | } |
---|
1396 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
1397 | { |
---|
1398 | assert (RPSRef!=NULL); |
---|
1399 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1400 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1401 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1402 | { |
---|
1403 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1404 | } |
---|
1405 | // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1406 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
1407 | numNeg = 0; |
---|
1408 | numPos = 0; |
---|
1409 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
1410 | |
---|
1411 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1412 | { |
---|
1413 | if (ge.m_refIdc[j]) |
---|
1414 | { |
---|
1415 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1416 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1417 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1418 | if (deltaPOC<0) |
---|
1419 | { |
---|
1420 | numNeg++; |
---|
1421 | } |
---|
1422 | else |
---|
1423 | { |
---|
1424 | numPos++; |
---|
1425 | } |
---|
1426 | } |
---|
1427 | } |
---|
1428 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
1429 | { |
---|
1430 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1431 | rps->setNumberOfNegativePictures(numNeg); |
---|
1432 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1433 | } |
---|
1434 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
1435 | { |
---|
1436 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1437 | rps->setNumberOfPositivePictures(numPos); |
---|
1438 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1439 | } |
---|
1440 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1441 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1442 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1443 | // check if Delta POC and Used are the same |
---|
1444 | // print warning if they are not. |
---|
1445 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1446 | { |
---|
1447 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1448 | { |
---|
1449 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1450 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1451 | } |
---|
1452 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1453 | { |
---|
1454 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1455 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1456 | } |
---|
1457 | } |
---|
1458 | } |
---|
1459 | } |
---|
1460 | //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. |
---|
1461 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
1462 | if (isFieldCoding) |
---|
1463 | { |
---|
1464 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
1465 | rps->setNumberOfPictures(1); |
---|
1466 | rps->setNumberOfNegativePictures(1); |
---|
1467 | rps->setNumberOfPositivePictures(0); |
---|
1468 | rps->setNumberOfLongtermPictures(0); |
---|
1469 | rps->setDeltaPOC(0,-1); |
---|
1470 | rps->setPOC(0,0); |
---|
1471 | rps->setUsed(0,true); |
---|
1472 | rps->setInterRPSPrediction(false); |
---|
1473 | rps->setDeltaRIdxMinus1(0); |
---|
1474 | rps->setDeltaRPS(0); |
---|
1475 | rps->setNumRefIdc(0); |
---|
1476 | } |
---|
1477 | } |
---|
1478 | |
---|
1479 | // This is a function that |
---|
1480 | // determines what Reference Picture Set to use |
---|
1481 | // for a specific slice (with POC = POCCurr) |
---|
1482 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1483 | { |
---|
1484 | slice->setRPSidx(GOPid); |
---|
1485 | |
---|
1486 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1487 | { |
---|
1488 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1489 | { |
---|
1490 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1491 | if(POCIndex == 0) |
---|
1492 | { |
---|
1493 | POCIndex = m_uiIntraPeriod; |
---|
1494 | } |
---|
1495 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1496 | { |
---|
1497 | slice->setRPSidx(extraNum); |
---|
1498 | } |
---|
1499 | } |
---|
1500 | else |
---|
1501 | { |
---|
1502 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1503 | { |
---|
1504 | slice->setRPSidx(extraNum); |
---|
1505 | } |
---|
1506 | } |
---|
1507 | } |
---|
1508 | |
---|
1509 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
1510 | { |
---|
1511 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
1512 | } |
---|
1513 | |
---|
1514 | const TComReferencePictureSet *rps = (slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1515 | slice->setRPS(rps); |
---|
1516 | } |
---|
1517 | |
---|
1518 | Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid ) |
---|
1519 | { |
---|
1520 | Int rpsIdx = GOPid; |
---|
1521 | |
---|
1522 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1523 | { |
---|
1524 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1525 | { |
---|
1526 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1527 | if(POCIndex == 0) |
---|
1528 | { |
---|
1529 | POCIndex = m_uiIntraPeriod; |
---|
1530 | } |
---|
1531 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1532 | { |
---|
1533 | rpsIdx = extraNum; |
---|
1534 | } |
---|
1535 | } |
---|
1536 | else |
---|
1537 | { |
---|
1538 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1539 | { |
---|
1540 | rpsIdx = extraNum; |
---|
1541 | } |
---|
1542 | } |
---|
1543 | } |
---|
1544 | |
---|
1545 | return rpsIdx; |
---|
1546 | } |
---|
1547 | |
---|
1548 | Void TEncTop::xInitPPSforTiles() |
---|
1549 | { |
---|
1550 | m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag ); |
---|
1551 | m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1552 | m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 ); |
---|
1553 | if( !m_tileUniformSpacingFlag ) |
---|
1554 | { |
---|
1555 | m_cPPS.setTileColumnWidth( m_tileColumnWidth ); |
---|
1556 | m_cPPS.setTileRowHeight( m_tileRowHeight ); |
---|
1557 | } |
---|
1558 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1559 | |
---|
1560 | // # substreams is "per tile" when tiles are independent. |
---|
1561 | } |
---|
1562 | |
---|
1563 | Void TEncCfg::xCheckGSParameters() |
---|
1564 | { |
---|
1565 | Int iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth; |
---|
1566 | Int iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight; |
---|
1567 | UInt uiCummulativeColumnWidth = 0; |
---|
1568 | UInt uiCummulativeRowHeight = 0; |
---|
1569 | |
---|
1570 | //check the column relative parameters |
---|
1571 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1572 | { |
---|
1573 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1574 | exit( EXIT_FAILURE ); |
---|
1575 | } |
---|
1576 | |
---|
1577 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1578 | { |
---|
1579 | printf( "The current picture can not have so many columns.\n" ); |
---|
1580 | exit( EXIT_FAILURE ); |
---|
1581 | } |
---|
1582 | |
---|
1583 | if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1584 | { |
---|
1585 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1586 | { |
---|
1587 | uiCummulativeColumnWidth += m_tileColumnWidth[i]; |
---|
1588 | } |
---|
1589 | |
---|
1590 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1591 | { |
---|
1592 | printf( "The width of the column is too large.\n" ); |
---|
1593 | exit( EXIT_FAILURE ); |
---|
1594 | } |
---|
1595 | } |
---|
1596 | |
---|
1597 | //check the row relative parameters |
---|
1598 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1599 | { |
---|
1600 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1601 | exit( EXIT_FAILURE ); |
---|
1602 | } |
---|
1603 | |
---|
1604 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1605 | { |
---|
1606 | printf( "The current picture can not have so many rows.\n" ); |
---|
1607 | exit( EXIT_FAILURE ); |
---|
1608 | } |
---|
1609 | |
---|
1610 | if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1611 | { |
---|
1612 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1613 | { |
---|
1614 | uiCummulativeRowHeight += m_tileRowHeight[i]; |
---|
1615 | } |
---|
1616 | |
---|
1617 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1618 | { |
---|
1619 | printf( "The height of the row is too large.\n" ); |
---|
1620 | exit( EXIT_FAILURE ); |
---|
1621 | } |
---|
1622 | } |
---|
1623 | } |
---|
1624 | |
---|
1625 | #if SVC_EXTENSION |
---|
1626 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx ) |
---|
1627 | { |
---|
1628 | if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 ) |
---|
1629 | { |
---|
1630 | return (TEncTop *)getLayerEnc( 0 ); |
---|
1631 | } |
---|
1632 | |
---|
1633 | return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) ); |
---|
1634 | } |
---|
1635 | |
---|
1636 | Void TEncTop::xInitILRP() |
---|
1637 | { |
---|
1638 | if( m_layerId > 0 ) |
---|
1639 | { |
---|
1640 | if( m_cIlpPic[0] == NULL ) |
---|
1641 | { |
---|
1642 | for (Int j=0; j < m_numDirectRefLayers; j++) |
---|
1643 | { |
---|
1644 | m_cIlpPic[j] = new TComPic; |
---|
1645 | m_cIlpPic[j]->create(m_cVPS, m_cSPS, m_cPPS, true, m_layerId); |
---|
1646 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++) |
---|
1647 | { |
---|
1648 | m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i); |
---|
1649 | } |
---|
1650 | } |
---|
1651 | } |
---|
1652 | |
---|
1653 | if( m_cVPS.getNumRefLayers( m_layerId ) == 0 ) |
---|
1654 | { |
---|
1655 | UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId ); |
---|
1656 | RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx)); |
---|
1657 | |
---|
1658 | if( m_cPPS.getLayerId() == 0 && |
---|
1659 | m_cSPS.getLayerId() == 0 && |
---|
1660 | repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() && |
---|
1661 | repFmt->getSeparateColourPlaneVpsFlag() == 0 && |
---|
1662 | repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() && |
---|
1663 | repFmt->getPicWidthVpsInLumaSamples() == m_cSPS.getPicWidthInLumaSamples() && |
---|
1664 | repFmt->getBitDepthVpsLuma() == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) && |
---|
1665 | repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) && |
---|
1666 | repFmt->getConformanceWindowVps().getWindowLeftOffset() == m_cSPS.getConformanceWindow().getWindowLeftOffset() && |
---|
1667 | repFmt->getConformanceWindowVps().getWindowRightOffset() == m_cSPS.getConformanceWindow().getWindowRightOffset() && |
---|
1668 | repFmt->getConformanceWindowVps().getWindowTopOffset() == m_cSPS.getConformanceWindow().getWindowTopOffset() && |
---|
1669 | repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() ) |
---|
1670 | { |
---|
1671 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1); |
---|
1672 | } |
---|
1673 | else |
---|
1674 | { |
---|
1675 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0); |
---|
1676 | } |
---|
1677 | } |
---|
1678 | } |
---|
1679 | } |
---|
1680 | |
---|
1681 | Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId) |
---|
1682 | { |
---|
1683 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
1684 | { |
---|
1685 | if (layerId == m_refLocationOffsetLayerId[i]) |
---|
1686 | { |
---|
1687 | return m_scaledRefLayerWindow[i]; |
---|
1688 | } |
---|
1689 | } |
---|
1690 | |
---|
1691 | return Window(); |
---|
1692 | } |
---|
1693 | |
---|
1694 | Window TEncTop::getRefLayerWindowForLayer(Int layerId) |
---|
1695 | { |
---|
1696 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
1697 | { |
---|
1698 | if (layerId == m_refLayerId[i]) |
---|
1699 | { |
---|
1700 | return m_refLayerWindow[i]; |
---|
1701 | } |
---|
1702 | } |
---|
1703 | |
---|
1704 | return Window(); |
---|
1705 | } |
---|
1706 | #endif //SVC_EXTENSION |
---|
1707 | //! \} |
---|