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-2014, 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, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
120 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, m_chromaFormatIDC ); |
---|
121 | if (m_bUseSAO) |
---|
122 | { |
---|
123 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA], m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA] ); |
---|
124 | #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK |
---|
125 | m_cEncSAO.createEncData(getSaoCtuBoundary()); |
---|
126 | #else |
---|
127 | m_cEncSAO.createEncData(); |
---|
128 | #endif |
---|
129 | } |
---|
130 | #if ADAPTIVE_QP_SELECTION |
---|
131 | if (m_bUseAdaptQpSelect) |
---|
132 | { |
---|
133 | m_cTrQuant.initSliceQpDelta(); |
---|
134 | } |
---|
135 | #endif |
---|
136 | |
---|
137 | m_cLoopFilter.create( g_uiMaxCUDepth ); |
---|
138 | |
---|
139 | if ( m_RCEnableRateControl ) |
---|
140 | { |
---|
141 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
142 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
143 | } |
---|
144 | |
---|
145 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
146 | #if FAST_BIT_EST |
---|
147 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
148 | #else |
---|
149 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
150 | #endif |
---|
151 | |
---|
152 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
153 | { |
---|
154 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
155 | #if FAST_BIT_EST |
---|
156 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
157 | #else |
---|
158 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
159 | #endif |
---|
160 | |
---|
161 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
162 | { |
---|
163 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
164 | #if FAST_BIT_EST |
---|
165 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
166 | #else |
---|
167 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
168 | #endif |
---|
169 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | #if LAYER_CTB |
---|
174 | memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) ); |
---|
175 | memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) ); |
---|
176 | memcpy(g_auiLayerRasterToPelX[m_layerId], g_auiRasterToPelX, sizeof( g_auiRasterToPelX ) ); |
---|
177 | memcpy(g_auiLayerRasterToPelY[m_layerId], g_auiRasterToPelY, sizeof( g_auiRasterToPelY ) ); |
---|
178 | #endif |
---|
179 | } |
---|
180 | |
---|
181 | Void TEncTop::destroy () |
---|
182 | { |
---|
183 | // destroy processing unit classes |
---|
184 | m_cGOPEncoder. destroy(); |
---|
185 | m_cSliceEncoder. destroy(); |
---|
186 | m_cCuEncoder. destroy(); |
---|
187 | if (m_cSPS.getUseSAO()) |
---|
188 | { |
---|
189 | m_cEncSAO.destroyEncData(); |
---|
190 | m_cEncSAO.destroy(); |
---|
191 | } |
---|
192 | m_cLoopFilter. destroy(); |
---|
193 | m_cRateCtrl. destroy(); |
---|
194 | Int iDepth; |
---|
195 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
196 | { |
---|
197 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
198 | { |
---|
199 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
200 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
205 | { |
---|
206 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
207 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
208 | } |
---|
209 | |
---|
210 | delete [] m_pppcRDSbacCoder; |
---|
211 | delete [] m_pppcBinCoderCABAC; |
---|
212 | |
---|
213 | #if SVC_EXTENSION |
---|
214 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
215 | { |
---|
216 | if(m_cIlpPic[i]) |
---|
217 | { |
---|
218 | m_cIlpPic[i]->destroy(); |
---|
219 | delete m_cIlpPic[i]; |
---|
220 | m_cIlpPic[i] = NULL; |
---|
221 | } |
---|
222 | } |
---|
223 | #else |
---|
224 | // destroy ROM |
---|
225 | destroyROM(); |
---|
226 | #endif |
---|
227 | return; |
---|
228 | } |
---|
229 | |
---|
230 | Void TEncTop::init(Bool isFieldCoding) |
---|
231 | { |
---|
232 | // initialize SPS |
---|
233 | xInitSPS(); |
---|
234 | |
---|
235 | // set the VPS profile information |
---|
236 | #if SVC_EXTENSION |
---|
237 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( true ); |
---|
238 | #else |
---|
239 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
240 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
241 | #endif |
---|
242 | m_cRdCost.setCostMode(m_costMode); |
---|
243 | |
---|
244 | // initialize PPS |
---|
245 | m_cPPS.setSPS(&m_cSPS); |
---|
246 | xInitPPS(); |
---|
247 | xInitRPS(isFieldCoding); |
---|
248 | |
---|
249 | xInitPPSforTiles(); |
---|
250 | |
---|
251 | // initialize processing unit classes |
---|
252 | m_cGOPEncoder. init( this ); |
---|
253 | m_cSliceEncoder.init( this ); |
---|
254 | m_cCuEncoder. init( this ); |
---|
255 | |
---|
256 | // initialize transform & quantization class |
---|
257 | m_pcCavlcCoder = getCavlcCoder(); |
---|
258 | |
---|
259 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
260 | m_useRDOQ, |
---|
261 | m_useRDOQTS, |
---|
262 | true |
---|
263 | ,m_useTransformSkipFast |
---|
264 | #if ADAPTIVE_QP_SELECTION |
---|
265 | ,m_bUseAdaptQpSelect |
---|
266 | #endif |
---|
267 | ); |
---|
268 | |
---|
269 | // initialize encoder search class |
---|
270 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
271 | |
---|
272 | m_iMaxRefPicNum = 0; |
---|
273 | #if SVC_EXTENSION |
---|
274 | m_iSPSIdCnt ++; |
---|
275 | m_iPPSIdCnt ++; |
---|
276 | xInitILRP(); |
---|
277 | #endif |
---|
278 | } |
---|
279 | |
---|
280 | // ==================================================================================================================== |
---|
281 | // Public member functions |
---|
282 | // ==================================================================================================================== |
---|
283 | |
---|
284 | Void TEncTop::deletePicBuffer() |
---|
285 | { |
---|
286 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
287 | Int iSize = Int( m_cListPic.size() ); |
---|
288 | |
---|
289 | for ( Int i = 0; i < iSize; i++ ) |
---|
290 | { |
---|
291 | TComPic* pcPic = *(iterPic++); |
---|
292 | |
---|
293 | pcPic->destroy(); |
---|
294 | delete pcPic; |
---|
295 | pcPic = NULL; |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | /** |
---|
300 | - Application has picture buffer list with size of GOP + 1 |
---|
301 | - Picture buffer list acts like as ring buffer |
---|
302 | - End of the list has the latest picture |
---|
303 | . |
---|
304 | \param flush cause encoder to encode a partial GOP |
---|
305 | \param pcPicYuvOrg original YUV picture |
---|
306 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
307 | \retval rcListBitstreamOut list of output bitstreams |
---|
308 | \retval iNumEncoded number of encoded pictures |
---|
309 | */ |
---|
310 | #if SVC_EXTENSION |
---|
311 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
312 | { |
---|
313 | // compress GOP |
---|
314 | #if !RC_SHVC_HARMONIZATION |
---|
315 | if ( m_RCEnableRateControl ) |
---|
316 | { |
---|
317 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
318 | } |
---|
319 | #endif |
---|
320 | |
---|
321 | // compress GOP |
---|
322 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
323 | |
---|
324 | #if !RC_SHVC_HARMONIZATION |
---|
325 | if ( m_RCEnableRateControl ) |
---|
326 | { |
---|
327 | m_cRateCtrl.destroyRCGOP(); |
---|
328 | } |
---|
329 | #endif |
---|
330 | |
---|
331 | m_uiNumAllPicCoded ++; |
---|
332 | } |
---|
333 | |
---|
334 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ) |
---|
335 | { |
---|
336 | if (pcPicYuvOrg != NULL) |
---|
337 | { |
---|
338 | // get original YUV |
---|
339 | TComPic* pcPicCurr = NULL; |
---|
340 | xGetNewPicBuffer( pcPicCurr ); |
---|
341 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
342 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
343 | |
---|
344 | // compute image characteristics |
---|
345 | if ( getUseAdaptiveQP() ) |
---|
346 | { |
---|
347 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
348 | } |
---|
349 | } |
---|
350 | } |
---|
351 | #else |
---|
352 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
353 | { |
---|
354 | if (pcPicYuvOrg != NULL) |
---|
355 | { |
---|
356 | // get original YUV |
---|
357 | TComPic* pcPicCurr = NULL; |
---|
358 | |
---|
359 | xGetNewPicBuffer( pcPicCurr ); |
---|
360 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
361 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
362 | |
---|
363 | // compute image characteristics |
---|
364 | if ( getUseAdaptiveQP() ) |
---|
365 | { |
---|
366 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0))) |
---|
371 | { |
---|
372 | iNumEncoded = 0; |
---|
373 | return; |
---|
374 | } |
---|
375 | |
---|
376 | if ( m_RCEnableRateControl ) |
---|
377 | { |
---|
378 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
379 | } |
---|
380 | |
---|
381 | // compress GOP |
---|
382 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
383 | |
---|
384 | if ( m_RCEnableRateControl ) |
---|
385 | { |
---|
386 | m_cRateCtrl.destroyRCGOP(); |
---|
387 | } |
---|
388 | |
---|
389 | iNumEncoded = m_iNumPicRcvd; |
---|
390 | m_iNumPicRcvd = 0; |
---|
391 | m_uiNumAllPicCoded += iNumEncoded; |
---|
392 | } |
---|
393 | #endif |
---|
394 | |
---|
395 | /**------------------------------------------------ |
---|
396 | Separate interlaced frame into two fields |
---|
397 | -------------------------------------------------**/ |
---|
398 | Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
---|
399 | { |
---|
400 | if (!isTop) |
---|
401 | { |
---|
402 | org += stride; |
---|
403 | } |
---|
404 | for (Int y = 0; y < height>>1; y++) |
---|
405 | { |
---|
406 | for (Int x = 0; x < width; x++) |
---|
407 | { |
---|
408 | dstField[x] = org[x]; |
---|
409 | } |
---|
410 | |
---|
411 | dstField += stride; |
---|
412 | org += stride*2; |
---|
413 | } |
---|
414 | |
---|
415 | } |
---|
416 | |
---|
417 | #if SVC_EXTENSION |
---|
418 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ) |
---|
419 | { |
---|
420 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
421 | { |
---|
422 | if (pcPicYuvOrg) |
---|
423 | { |
---|
424 | /* -- field initialization -- */ |
---|
425 | const Bool isTopField=isTff==(fieldNum==0); |
---|
426 | |
---|
427 | TComPic *pcField; |
---|
428 | xGetNewPicBuffer( pcField ); |
---|
429 | pcField->setReconMark (false); // where is this normally? |
---|
430 | |
---|
431 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
432 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
433 | |
---|
434 | pcField->setTopField(isTopField); // interlaced requirement |
---|
435 | |
---|
436 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
437 | { |
---|
438 | const ComponentID component = ComponentID(componentIndex); |
---|
439 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
440 | |
---|
441 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
442 | pcField->getPicYuvOrg()->getAddr(component), |
---|
443 | pcPicYuvOrg->getStride(component), |
---|
444 | pcPicYuvOrg->getWidth(component), |
---|
445 | pcPicYuvOrg->getHeight(component), |
---|
446 | isTopField); |
---|
447 | |
---|
448 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
449 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
450 | pcPicYuvTrueOrg->getStride(component), |
---|
451 | pcPicYuvTrueOrg->getWidth(component), |
---|
452 | pcPicYuvTrueOrg->getHeight(component), |
---|
453 | isTopField); |
---|
454 | } |
---|
455 | |
---|
456 | // compute image characteristics |
---|
457 | if ( getUseAdaptiveQP() ) |
---|
458 | { |
---|
459 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ) |
---|
466 | { |
---|
467 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
468 | { |
---|
469 | if (pcPicYuvOrg) |
---|
470 | { |
---|
471 | if (fieldNum==1) // where is this normally? |
---|
472 | { |
---|
473 | TComPicYuv* rpcPicYuvRec; |
---|
474 | |
---|
475 | // org. buffer |
---|
476 | 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. |
---|
477 | { |
---|
478 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
479 | } |
---|
480 | else |
---|
481 | { |
---|
482 | rpcPicYuvRec = new TComPicYuv; |
---|
483 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); |
---|
484 | } |
---|
485 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | // compress GOP |
---|
490 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
491 | } |
---|
492 | |
---|
493 | m_uiNumAllPicCoded ++; |
---|
494 | } |
---|
495 | #else |
---|
496 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
---|
497 | { |
---|
498 | iNumEncoded = 0; |
---|
499 | |
---|
500 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
501 | { |
---|
502 | if (pcPicYuvOrg) |
---|
503 | { |
---|
504 | |
---|
505 | /* -- field initialization -- */ |
---|
506 | const Bool isTopField=isTff==(fieldNum==0); |
---|
507 | |
---|
508 | TComPic *pcField; |
---|
509 | xGetNewPicBuffer( pcField ); |
---|
510 | pcField->setReconMark (false); // where is this normally? |
---|
511 | |
---|
512 | if (fieldNum==1) // where is this normally? |
---|
513 | { |
---|
514 | TComPicYuv* rpcPicYuvRec; |
---|
515 | |
---|
516 | // org. buffer |
---|
517 | 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. |
---|
518 | { |
---|
519 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
520 | } |
---|
521 | else |
---|
522 | { |
---|
523 | rpcPicYuvRec = new TComPicYuv; |
---|
524 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); |
---|
525 | } |
---|
526 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
527 | } |
---|
528 | |
---|
529 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
530 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
531 | |
---|
532 | pcField->setTopField(isTopField); // interlaced requirement |
---|
533 | |
---|
534 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
535 | { |
---|
536 | const ComponentID component = ComponentID(componentIndex); |
---|
537 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
538 | |
---|
539 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
540 | pcField->getPicYuvOrg()->getAddr(component), |
---|
541 | pcPicYuvOrg->getStride(component), |
---|
542 | pcPicYuvOrg->getWidth(component), |
---|
543 | pcPicYuvOrg->getHeight(component), |
---|
544 | isTopField); |
---|
545 | |
---|
546 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
547 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
548 | pcPicYuvTrueOrg->getStride(component), |
---|
549 | pcPicYuvTrueOrg->getWidth(component), |
---|
550 | pcPicYuvTrueOrg->getHeight(component), |
---|
551 | isTopField); |
---|
552 | } |
---|
553 | |
---|
554 | // compute image characteristics |
---|
555 | if ( getUseAdaptiveQP() ) |
---|
556 | { |
---|
557 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) |
---|
562 | { |
---|
563 | // compress GOP |
---|
564 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
565 | |
---|
566 | iNumEncoded += m_iNumPicRcvd; |
---|
567 | m_uiNumAllPicCoded += m_iNumPicRcvd; |
---|
568 | m_iNumPicRcvd = 0; |
---|
569 | } |
---|
570 | } |
---|
571 | } |
---|
572 | #endif |
---|
573 | |
---|
574 | // ==================================================================================================================== |
---|
575 | // Protected member functions |
---|
576 | // ==================================================================================================================== |
---|
577 | |
---|
578 | /** |
---|
579 | - Application has picture buffer list with size of GOP + 1 |
---|
580 | - Picture buffer list acts like as ring buffer |
---|
581 | - End of the list has the latest picture |
---|
582 | . |
---|
583 | \retval rpcPic obtained picture buffer |
---|
584 | */ |
---|
585 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
586 | { |
---|
587 | TComSlice::sortPicList(m_cListPic); |
---|
588 | |
---|
589 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
590 | { |
---|
591 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
592 | Int iSize = Int( m_cListPic.size() ); |
---|
593 | for ( Int i = 0; i < iSize; i++ ) |
---|
594 | { |
---|
595 | rpcPic = *(iterPic++); |
---|
596 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
597 | { |
---|
598 | break; |
---|
599 | } |
---|
600 | } |
---|
601 | } |
---|
602 | else |
---|
603 | { |
---|
604 | if ( getUseAdaptiveQP() ) |
---|
605 | { |
---|
606 | TEncPic* pcEPic = new TEncPic; |
---|
607 | |
---|
608 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
609 | if( m_layerId > 0 ) |
---|
610 | { |
---|
611 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
612 | { |
---|
613 | const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
614 | const Window altRL = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
615 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
616 | Bool zeroPhase = getPPS()->hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
617 | |
---|
618 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
619 | |
---|
620 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
621 | Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] ); |
---|
622 | |
---|
623 | if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase ) |
---|
624 | { |
---|
625 | pcEPic->setEqualPictureSizeAndOffsetFlag( i, true ); |
---|
626 | } |
---|
627 | |
---|
628 | if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths |
---|
629 | #if CGS_3D_ASYMLUT |
---|
630 | || m_cPPS.getCGSFlag() > 0 |
---|
631 | #endif |
---|
632 | #if LAYER_CTB |
---|
633 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
634 | #endif |
---|
635 | ) |
---|
636 | { |
---|
637 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
---|
638 | |
---|
639 | //only for scalable extension |
---|
640 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
646 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
647 | #else //SVC_EXTENSION |
---|
648 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
649 | #endif //SVC_EXTENSION |
---|
650 | rpcPic = pcEPic; |
---|
651 | } |
---|
652 | else |
---|
653 | { |
---|
654 | rpcPic = new TComPic; |
---|
655 | |
---|
656 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
657 | if( m_layerId > 0 ) |
---|
658 | { |
---|
659 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
660 | { |
---|
661 | const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
662 | const Window altRL = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
663 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
664 | Bool zeroPhase = getPPS()->hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
665 | |
---|
666 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
667 | |
---|
668 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
669 | Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] ); |
---|
670 | |
---|
671 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths |
---|
672 | || !equalOffsets |
---|
673 | || !zeroPhase |
---|
674 | #if CGS_3D_ASYMLUT |
---|
675 | || m_cPPS.getCGSFlag() > 0 |
---|
676 | #endif |
---|
677 | #if LAYER_CTB |
---|
678 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
679 | #endif |
---|
680 | ) |
---|
681 | { |
---|
682 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
---|
683 | |
---|
684 | //only for scalable extension |
---|
685 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
686 | } |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
691 | #else //SVC_EXTENSION |
---|
692 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, false ); |
---|
693 | #endif //SVC_EXTENSION |
---|
694 | } |
---|
695 | |
---|
696 | m_cListPic.pushBack( rpcPic ); |
---|
697 | } |
---|
698 | rpcPic->setReconMark (false); |
---|
699 | |
---|
700 | m_iPOCLast++; |
---|
701 | m_iNumPicRcvd++; |
---|
702 | |
---|
703 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
704 | // mark it should be extended |
---|
705 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
706 | } |
---|
707 | |
---|
708 | Void TEncTop::xInitSPS() |
---|
709 | { |
---|
710 | #if SVC_EXTENSION |
---|
711 | m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false ); |
---|
712 | m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers); |
---|
713 | |
---|
714 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
715 | { |
---|
716 | m_cSPS.setLayerId(0); // layer ID 0 for independent layers |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | m_cSPS.setLayerId(m_layerId); |
---|
721 | } |
---|
722 | #endif //SVC_EXTENSION |
---|
723 | |
---|
724 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
725 | profileTierLevel.setLevelIdc(m_level); |
---|
726 | profileTierLevel.setTierFlag(m_levelTier); |
---|
727 | profileTierLevel.setProfileIdc(m_profile); |
---|
728 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
729 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
730 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
731 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
732 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
733 | profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue); |
---|
734 | profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue); |
---|
735 | profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag); |
---|
736 | profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag); |
---|
737 | |
---|
738 | if ((m_profile == Profile::MAIN10) && (g_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (g_bitDepth[CHANNEL_TYPE_CHROMA] == 8)) |
---|
739 | { |
---|
740 | /* The above constraint is equal to Profile::MAIN */ |
---|
741 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
742 | } |
---|
743 | if (m_profile == Profile::MAIN) |
---|
744 | { |
---|
745 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
746 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
747 | } |
---|
748 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
749 | /* XXX: may be a good idea to refactor the above into a function |
---|
750 | * that chooses the actual compatibility based upon options */ |
---|
751 | |
---|
752 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
753 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
754 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
755 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
756 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
757 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
758 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
---|
759 | |
---|
760 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth ); |
---|
761 | Int log2MinCUSize = 0; |
---|
762 | while(minCUSize > 1) |
---|
763 | { |
---|
764 | minCUSize >>= 1; |
---|
765 | log2MinCUSize++; |
---|
766 | } |
---|
767 | |
---|
768 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
769 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth-getMaxCUDepthOffset(m_cSPS.getChromaFormatIdc(), m_cSPS.getQuadtreeTULog2MinSize())); |
---|
770 | #if SVC_EXTENSION |
---|
771 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
772 | #endif |
---|
773 | |
---|
774 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
775 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
776 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
777 | |
---|
778 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
779 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
780 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
781 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
782 | |
---|
783 | m_cSPS.setTMVPFlagsPresent(false); |
---|
784 | |
---|
785 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
786 | |
---|
787 | Int i; |
---|
788 | |
---|
789 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
790 | { |
---|
791 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
792 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
793 | } |
---|
794 | |
---|
795 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
796 | |
---|
797 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
798 | { |
---|
799 | m_cSPS.setAMPAcc(i, 0); |
---|
800 | } |
---|
801 | |
---|
802 | |
---|
803 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
804 | { |
---|
805 | #if SVC_EXTENSION |
---|
806 | m_cSPS.setBitDepth (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) ); |
---|
807 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8))); |
---|
808 | #else |
---|
809 | m_cSPS.setBitDepth (ChannelType(channelType), g_bitDepth[channelType] ); |
---|
810 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (g_bitDepth[channelType] - 8))); |
---|
811 | #endif |
---|
812 | m_cSPS.setPCMBitDepth (ChannelType(channelType), g_PCMBitDepth[channelType] ); |
---|
813 | } |
---|
814 | |
---|
815 | m_cSPS.setUseExtendedPrecision(m_useExtendedPrecision); |
---|
816 | m_cSPS.setUseHighPrecisionPredictionWeighting(m_useHighPrecisionPredictionWeighting); |
---|
817 | |
---|
818 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
819 | m_cSPS.setUseResidualRotation(m_useResidualRotation); |
---|
820 | m_cSPS.setUseSingleSignificanceMapContext(m_useSingleSignificanceMapContext); |
---|
821 | m_cSPS.setUseGolombRiceParameterAdaptation(m_useGolombRiceParameterAdaptation); |
---|
822 | m_cSPS.setAlignCABACBeforeBypass(m_alignCABACBeforeBypass); |
---|
823 | |
---|
824 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
825 | { |
---|
826 | m_cSPS.setUseResidualDPCM(RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]); |
---|
827 | } |
---|
828 | |
---|
829 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
830 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
831 | |
---|
832 | for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
833 | { |
---|
834 | #if SVC_EXTENSION |
---|
835 | assert(i < MAX_TLAYER); |
---|
836 | #endif |
---|
837 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
838 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
839 | } |
---|
840 | |
---|
841 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
842 | m_cSPS.setDisableIntraReferenceSmoothing( m_disableIntraReferenceSmoothing ); |
---|
843 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
844 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
845 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
846 | |
---|
847 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
848 | { |
---|
849 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
850 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag()); |
---|
851 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
852 | pcVUI->setSarWidth(getSarWidth()); |
---|
853 | pcVUI->setSarHeight(getSarHeight()); |
---|
854 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
855 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
856 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
857 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
858 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
859 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
860 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
861 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
862 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
863 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
864 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
865 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
866 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
867 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
868 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
869 | pcVUI->setFieldSeqFlag(false); |
---|
870 | pcVUI->setHrdParametersPresentFlag(false); |
---|
871 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
872 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
873 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
874 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
875 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
876 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
877 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
878 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
879 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
880 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | Void TEncTop::xInitPPS() |
---|
885 | { |
---|
886 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
887 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
888 | |
---|
889 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
890 | { |
---|
891 | bUseDQP = true; |
---|
892 | } |
---|
893 | |
---|
894 | if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING) bUseDQP=false; |
---|
895 | |
---|
896 | if(bUseDQP) |
---|
897 | { |
---|
898 | m_cPPS.setUseDQP(true); |
---|
899 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
900 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
901 | } |
---|
902 | else |
---|
903 | { |
---|
904 | m_cPPS.setUseDQP(false); |
---|
905 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
906 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
907 | } |
---|
908 | |
---|
909 | if ( m_maxCUChromaQpAdjustmentDepth >= 0 ) |
---|
910 | { |
---|
911 | m_cPPS.setMaxCuChromaQpAdjDepth(m_maxCUChromaQpAdjustmentDepth); |
---|
912 | m_cPPS.setChromaQpAdjTableAt(1, 6, 6); |
---|
913 | /* todo, insert table entries from command line (NB, 0 should not be touched) */ |
---|
914 | } |
---|
915 | else |
---|
916 | { |
---|
917 | m_cPPS.setMaxCuChromaQpAdjDepth(0); |
---|
918 | m_cPPS.clearChromaQpAdjTable(); |
---|
919 | } |
---|
920 | |
---|
921 | if ( m_RCEnableRateControl ) |
---|
922 | { |
---|
923 | m_cPPS.setUseDQP(true); |
---|
924 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
925 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
926 | } |
---|
927 | |
---|
928 | m_cPPS.setMinCuChromaQpAdjSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuChromaQpAdjDepth()) ); |
---|
929 | |
---|
930 | m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset ); |
---|
931 | m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset ); |
---|
932 | |
---|
933 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
934 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
935 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
936 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
937 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
938 | m_cPPS.setUseCrossComponentPrediction(m_useCrossComponentPrediction); |
---|
939 | m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_LUMA, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA ]); |
---|
940 | m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA]); |
---|
941 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
942 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
943 | if ( getDeblockingFilterMetric() ) |
---|
944 | { |
---|
945 | m_cPPS.setDeblockingFilterControlPresentFlag (true); |
---|
946 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
947 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
948 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
949 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
950 | } |
---|
951 | else |
---|
952 | { |
---|
953 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
954 | } |
---|
955 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
956 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
957 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
958 | |
---|
959 | Int histogram[MAX_NUM_REF + 1]; |
---|
960 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
961 | { |
---|
962 | histogram[i]=0; |
---|
963 | } |
---|
964 | for( Int i = 0; i < getGOPSize(); i++) |
---|
965 | { |
---|
966 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
967 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
968 | } |
---|
969 | |
---|
970 | Int maxHist=-1; |
---|
971 | Int bestPos=0; |
---|
972 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
973 | { |
---|
974 | if(histogram[i]>maxHist) |
---|
975 | { |
---|
976 | maxHist=histogram[i]; |
---|
977 | bestPos=i; |
---|
978 | } |
---|
979 | } |
---|
980 | assert(bestPos <= 15); |
---|
981 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
982 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
983 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
984 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
985 | m_cPPS.setTransformSkipLog2MaxSize( m_transformSkipLog2MaxSize ); |
---|
986 | |
---|
987 | if (m_sliceSegmentMode != NO_SLICES) |
---|
988 | { |
---|
989 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
990 | } |
---|
991 | |
---|
992 | #if SVC_EXTENSION |
---|
993 | m_cPPS.setLayerId( m_layerId ); |
---|
994 | |
---|
995 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
996 | { |
---|
997 | m_cPPS.setLayerId(0); // layer ID 0 for independent layers |
---|
998 | } |
---|
999 | |
---|
1000 | if( m_layerId > 0 ) |
---|
1001 | { |
---|
1002 | m_cPPS.setListsModificationPresentFlag(true); |
---|
1003 | m_cPPS.setExtensionFlag(true); |
---|
1004 | } |
---|
1005 | else |
---|
1006 | { |
---|
1007 | m_cPPS.setListsModificationPresentFlag(false); |
---|
1008 | m_cPPS.setExtensionFlag(false); |
---|
1009 | } |
---|
1010 | |
---|
1011 | m_cPPS.setPPSId( m_iPPSIdCnt ); |
---|
1012 | m_cPPS.setSPSId( m_iSPSIdCnt ); |
---|
1013 | |
---|
1014 | if( m_crossLayerBLAFlag ) |
---|
1015 | { |
---|
1016 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
1017 | } |
---|
1018 | |
---|
1019 | m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets); |
---|
1020 | for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++) |
---|
1021 | { |
---|
1022 | m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]); |
---|
1023 | m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
---|
1024 | m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i]; |
---|
1025 | m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] ); |
---|
1026 | m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] ); |
---|
1027 | m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] ); |
---|
1028 | m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] ); |
---|
1029 | m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] ); |
---|
1030 | m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] ); |
---|
1031 | m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] ); |
---|
1032 | } |
---|
1033 | #if CGS_3D_ASYMLUT |
---|
1034 | m_cPPS.setCGSFlag( m_nCGSFlag ); |
---|
1035 | #endif |
---|
1036 | m_cPPS.setPocResetInfoPresentFlag( true ); |
---|
1037 | m_cPPS.setExtensionFlag( true ); |
---|
1038 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
---|
1039 | #endif //SVC_EXTENSION |
---|
1040 | } |
---|
1041 | |
---|
1042 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
1043 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
1044 | { |
---|
1045 | TComReferencePictureSet* rps; |
---|
1046 | |
---|
1047 | m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1); |
---|
1048 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
1049 | |
---|
1050 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
1051 | { |
---|
1052 | GOPEntry ge = getGOPEntry(i); |
---|
1053 | rps = rpsList->getReferencePictureSet(i); |
---|
1054 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
1055 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1056 | Int numNeg = 0; |
---|
1057 | Int numPos = 0; |
---|
1058 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
1059 | { |
---|
1060 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
1061 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
1062 | if(ge.m_referencePics[j]>0) |
---|
1063 | { |
---|
1064 | numPos++; |
---|
1065 | } |
---|
1066 | else |
---|
1067 | { |
---|
1068 | numNeg++; |
---|
1069 | } |
---|
1070 | } |
---|
1071 | rps->setNumberOfNegativePictures(numNeg); |
---|
1072 | rps->setNumberOfPositivePictures(numPos); |
---|
1073 | |
---|
1074 | // handle inter RPS intialization from the config file. |
---|
1075 | #if AUTO_INTER_RPS |
---|
1076 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
1077 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
1078 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
1079 | |
---|
1080 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
1081 | { |
---|
1082 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
1083 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
1084 | |
---|
1085 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
1086 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
1087 | Int count=0; |
---|
1088 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
1089 | { |
---|
1090 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
1091 | rps->setRefIdc(j, 0); |
---|
1092 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
1093 | { |
---|
1094 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
1095 | { |
---|
1096 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
1097 | count++; |
---|
1098 | break; |
---|
1099 | } |
---|
1100 | } |
---|
1101 | } |
---|
1102 | if (count != rps->getNumberOfPictures()) |
---|
1103 | { |
---|
1104 | 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"); |
---|
1105 | rps->setInterRPSPrediction(0); |
---|
1106 | } |
---|
1107 | } |
---|
1108 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
1109 | { |
---|
1110 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1111 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1112 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1113 | { |
---|
1114 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1115 | } |
---|
1116 | #if WRITE_BACK |
---|
1117 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1118 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
1119 | numNeg = 0; |
---|
1120 | numPos = 0; |
---|
1121 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
1122 | |
---|
1123 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1124 | { |
---|
1125 | if (ge.m_refIdc[j]) |
---|
1126 | { |
---|
1127 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1128 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1129 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1130 | if (deltaPOC<0) |
---|
1131 | { |
---|
1132 | numNeg++; |
---|
1133 | } |
---|
1134 | else |
---|
1135 | { |
---|
1136 | numPos++; |
---|
1137 | } |
---|
1138 | } |
---|
1139 | } |
---|
1140 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
1141 | { |
---|
1142 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1143 | rps->setNumberOfNegativePictures(numNeg); |
---|
1144 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1145 | } |
---|
1146 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
1147 | { |
---|
1148 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1149 | rps->setNumberOfPositivePictures(numPos); |
---|
1150 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1151 | } |
---|
1152 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1153 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1154 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1155 | // check if Delta POC and Used are the same |
---|
1156 | // print warning if they are not. |
---|
1157 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1158 | { |
---|
1159 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1160 | { |
---|
1161 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1162 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1163 | } |
---|
1164 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1165 | { |
---|
1166 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1167 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1168 | } |
---|
1169 | } |
---|
1170 | #endif |
---|
1171 | } |
---|
1172 | #else |
---|
1173 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
1174 | if (ge.m_interRPSPrediction) |
---|
1175 | { |
---|
1176 | rps->setDeltaRIdxMinus1(0); |
---|
1177 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1178 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1179 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1180 | { |
---|
1181 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1182 | } |
---|
1183 | #if WRITE_BACK |
---|
1184 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1185 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
1186 | numNeg = 0; |
---|
1187 | numPos = 0; |
---|
1188 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
1189 | |
---|
1190 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1191 | { |
---|
1192 | if (ge.m_refIdc[j]) |
---|
1193 | { |
---|
1194 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1195 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1196 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1197 | if (deltaPOC<0) |
---|
1198 | { |
---|
1199 | numNeg++; |
---|
1200 | } |
---|
1201 | else |
---|
1202 | { |
---|
1203 | numPos++; |
---|
1204 | } |
---|
1205 | } |
---|
1206 | } |
---|
1207 | rps->setNumberOfNegativePictures(numNeg); |
---|
1208 | rps->setNumberOfPositivePictures(numPos); |
---|
1209 | rps->sortDeltaPOC(); |
---|
1210 | #endif |
---|
1211 | } |
---|
1212 | #endif //INTER_RPS_AUTO |
---|
1213 | } |
---|
1214 | //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. |
---|
1215 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
1216 | if (isFieldCoding) |
---|
1217 | { |
---|
1218 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
1219 | rps->setNumberOfPictures(1); |
---|
1220 | rps->setNumberOfNegativePictures(1); |
---|
1221 | rps->setNumberOfPositivePictures(0); |
---|
1222 | rps->setNumberOfLongtermPictures(0); |
---|
1223 | rps->setDeltaPOC(0,-1); |
---|
1224 | rps->setPOC(0,0); |
---|
1225 | rps->setUsed(0,true); |
---|
1226 | rps->setInterRPSPrediction(false); |
---|
1227 | rps->setDeltaRIdxMinus1(0); |
---|
1228 | rps->setDeltaRPS(0); |
---|
1229 | rps->setNumRefIdc(0); |
---|
1230 | } |
---|
1231 | } |
---|
1232 | |
---|
1233 | // This is a function that |
---|
1234 | // determines what Reference Picture Set to use |
---|
1235 | // for a specific slice (with POC = POCCurr) |
---|
1236 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1237 | { |
---|
1238 | slice->setRPSidx(GOPid); |
---|
1239 | |
---|
1240 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1241 | { |
---|
1242 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1243 | { |
---|
1244 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1245 | if(POCIndex == 0) |
---|
1246 | { |
---|
1247 | POCIndex = m_uiIntraPeriod; |
---|
1248 | } |
---|
1249 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1250 | { |
---|
1251 | slice->setRPSidx(extraNum); |
---|
1252 | } |
---|
1253 | } |
---|
1254 | else |
---|
1255 | { |
---|
1256 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1257 | { |
---|
1258 | slice->setRPSidx(extraNum); |
---|
1259 | } |
---|
1260 | } |
---|
1261 | } |
---|
1262 | |
---|
1263 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
1264 | { |
---|
1265 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
1266 | } |
---|
1267 | |
---|
1268 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1269 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1270 | } |
---|
1271 | |
---|
1272 | Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1273 | { |
---|
1274 | Int rpsIdx = GOPid; |
---|
1275 | |
---|
1276 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1277 | { |
---|
1278 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1279 | { |
---|
1280 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1281 | if(POCIndex == 0) |
---|
1282 | { |
---|
1283 | POCIndex = m_uiIntraPeriod; |
---|
1284 | } |
---|
1285 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1286 | { |
---|
1287 | rpsIdx = extraNum; |
---|
1288 | } |
---|
1289 | } |
---|
1290 | else |
---|
1291 | { |
---|
1292 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1293 | { |
---|
1294 | rpsIdx = extraNum; |
---|
1295 | } |
---|
1296 | } |
---|
1297 | } |
---|
1298 | |
---|
1299 | return rpsIdx; |
---|
1300 | } |
---|
1301 | |
---|
1302 | Void TEncTop::xInitPPSforTiles() |
---|
1303 | { |
---|
1304 | m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag ); |
---|
1305 | m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1306 | m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 ); |
---|
1307 | if( !m_tileUniformSpacingFlag ) |
---|
1308 | { |
---|
1309 | m_cPPS.setTileColumnWidth( m_tileColumnWidth ); |
---|
1310 | m_cPPS.setTileRowHeight( m_tileRowHeight ); |
---|
1311 | } |
---|
1312 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1313 | |
---|
1314 | // # substreams is "per tile" when tiles are independent. |
---|
1315 | if (m_iWaveFrontSynchro ) |
---|
1316 | { |
---|
1317 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
1318 | } |
---|
1319 | else |
---|
1320 | { |
---|
1321 | m_cPPS.setNumSubstreams((m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1)); |
---|
1322 | } |
---|
1323 | } |
---|
1324 | |
---|
1325 | Void TEncCfg::xCheckGSParameters() |
---|
1326 | { |
---|
1327 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1328 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1329 | UInt uiCummulativeColumnWidth = 0; |
---|
1330 | UInt uiCummulativeRowHeight = 0; |
---|
1331 | |
---|
1332 | //check the column relative parameters |
---|
1333 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1334 | { |
---|
1335 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1336 | exit( EXIT_FAILURE ); |
---|
1337 | } |
---|
1338 | |
---|
1339 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1340 | { |
---|
1341 | printf( "The current picture can not have so many columns.\n" ); |
---|
1342 | exit( EXIT_FAILURE ); |
---|
1343 | } |
---|
1344 | |
---|
1345 | if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1346 | { |
---|
1347 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1348 | { |
---|
1349 | uiCummulativeColumnWidth += m_tileColumnWidth[i]; |
---|
1350 | } |
---|
1351 | |
---|
1352 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1353 | { |
---|
1354 | printf( "The width of the column is too large.\n" ); |
---|
1355 | exit( EXIT_FAILURE ); |
---|
1356 | } |
---|
1357 | } |
---|
1358 | |
---|
1359 | //check the row relative parameters |
---|
1360 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1361 | { |
---|
1362 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1363 | exit( EXIT_FAILURE ); |
---|
1364 | } |
---|
1365 | |
---|
1366 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1367 | { |
---|
1368 | printf( "The current picture can not have so many rows.\n" ); |
---|
1369 | exit( EXIT_FAILURE ); |
---|
1370 | } |
---|
1371 | |
---|
1372 | if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1373 | { |
---|
1374 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1375 | uiCummulativeRowHeight += m_tileRowHeight[i]; |
---|
1376 | |
---|
1377 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1378 | { |
---|
1379 | printf( "The height of the row is too large.\n" ); |
---|
1380 | exit( EXIT_FAILURE ); |
---|
1381 | } |
---|
1382 | } |
---|
1383 | } |
---|
1384 | |
---|
1385 | #if SVC_EXTENSION |
---|
1386 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx ) |
---|
1387 | { |
---|
1388 | if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 ) |
---|
1389 | { |
---|
1390 | return (TEncTop *)getLayerEnc( 0 ); |
---|
1391 | } |
---|
1392 | |
---|
1393 | return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) ); |
---|
1394 | } |
---|
1395 | |
---|
1396 | Void TEncTop::xInitILRP() |
---|
1397 | { |
---|
1398 | RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) ); |
---|
1399 | Int bitDepthY,bitDepthC,picWidth,picHeight; |
---|
1400 | |
---|
1401 | bitDepthY = repFormat->getBitDepthVpsLuma(); |
---|
1402 | bitDepthC = repFormat->getBitDepthVpsChroma(); |
---|
1403 | picWidth = repFormat->getPicWidthVpsInLumaSamples(); |
---|
1404 | picHeight = repFormat->getPicHeightVpsInLumaSamples(); |
---|
1405 | |
---|
1406 | if(m_layerId > 0) |
---|
1407 | { |
---|
1408 | g_bitDepth[CHANNEL_TYPE_LUMA] = bitDepthY; |
---|
1409 | g_bitDepth[CHANNEL_TYPE_CHROMA] = bitDepthC; |
---|
1410 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
---|
1411 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
---|
1412 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
---|
1413 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
---|
1414 | |
---|
1415 | Int numReorderPics[MAX_TLAYER]; |
---|
1416 | Window &conformanceWindow = repFormat->getConformanceWindowVps(); |
---|
1417 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
1418 | |
---|
1419 | if (m_cIlpPic[0] == NULL) |
---|
1420 | { |
---|
1421 | for (Int j=0; j < m_numDirectRefLayers; j++) |
---|
1422 | { |
---|
1423 | m_cIlpPic[j] = new TComPic; |
---|
1424 | #if AUXILIARY_PICTURES |
---|
1425 | m_cIlpPic[j]->create(picWidth, picHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
1426 | #else |
---|
1427 | m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
1428 | #endif |
---|
1429 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++) |
---|
1430 | { |
---|
1431 | m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i); |
---|
1432 | } |
---|
1433 | } |
---|
1434 | } |
---|
1435 | |
---|
1436 | if( m_cVPS.getNumRefLayers( m_layerId ) == 0 ) |
---|
1437 | { |
---|
1438 | UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId ); |
---|
1439 | RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx)); |
---|
1440 | |
---|
1441 | if( m_cPPS.getLayerId() == 0 && |
---|
1442 | m_cSPS.getLayerId() == 0 && |
---|
1443 | repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() && |
---|
1444 | repFmt->getSeparateColourPlaneVpsFlag() == 0 && |
---|
1445 | repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() && |
---|
1446 | repFmt->getPicWidthVpsInLumaSamples() == m_cSPS.getPicWidthInLumaSamples() && |
---|
1447 | repFmt->getBitDepthVpsLuma() == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) && |
---|
1448 | repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) && |
---|
1449 | repFmt->getConformanceWindowVps().getWindowLeftOffset() == m_cSPS.getConformanceWindow().getWindowLeftOffset() && |
---|
1450 | repFmt->getConformanceWindowVps().getWindowRightOffset() == m_cSPS.getConformanceWindow().getWindowRightOffset() && |
---|
1451 | repFmt->getConformanceWindowVps().getWindowTopOffset() == m_cSPS.getConformanceWindow().getWindowTopOffset() && |
---|
1452 | repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() ) |
---|
1453 | { |
---|
1454 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1); |
---|
1455 | } |
---|
1456 | else |
---|
1457 | { |
---|
1458 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0); |
---|
1459 | } |
---|
1460 | } |
---|
1461 | } |
---|
1462 | } |
---|
1463 | |
---|
1464 | Window& TEncTop::getScaledRefLayerWindowForLayer(Int layerId) |
---|
1465 | { |
---|
1466 | static Window win; |
---|
1467 | |
---|
1468 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
1469 | { |
---|
1470 | if (layerId == m_refLocationOffsetLayerId[i]) |
---|
1471 | { |
---|
1472 | return m_scaledRefLayerWindow[i]; |
---|
1473 | } |
---|
1474 | } |
---|
1475 | |
---|
1476 | win.resetWindow(); // scaled reference layer offsets are inferred to be zero when not present |
---|
1477 | return win; |
---|
1478 | } |
---|
1479 | |
---|
1480 | Window& TEncTop::getRefLayerWindowForLayer(Int layerId) |
---|
1481 | { |
---|
1482 | static Window win; |
---|
1483 | |
---|
1484 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
1485 | { |
---|
1486 | if (layerId == m_refLayerId[i]) |
---|
1487 | { |
---|
1488 | return m_refLayerWindow[i]; |
---|
1489 | } |
---|
1490 | } |
---|
1491 | |
---|
1492 | win.resetWindow(); // reference offsets are inferred to be zero when not present |
---|
1493 | return win; |
---|
1494 | } |
---|
1495 | #endif //SVC_EXTENSION |
---|
1496 | //! \} |
---|