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-2013, 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 | #if FAST_BIT_EST |
---|
42 | #include "TLibCommon/ContextModel.h" |
---|
43 | #endif |
---|
44 | |
---|
45 | //! \ingroup TLibEncoder |
---|
46 | //! \{ |
---|
47 | #if SVC_EXTENSION |
---|
48 | Int TEncTop::m_iSPSIdCnt = 0; |
---|
49 | Int TEncTop::m_iPPSIdCnt = 0; |
---|
50 | TComVPS TEncCfg::m_cVPS; |
---|
51 | #endif |
---|
52 | |
---|
53 | // ==================================================================================================================== |
---|
54 | // Constructor / destructor / create / destroy |
---|
55 | // ==================================================================================================================== |
---|
56 | |
---|
57 | TEncTop::TEncTop() |
---|
58 | { |
---|
59 | m_iPOCLast = -1; |
---|
60 | m_iNumPicRcvd = 0; |
---|
61 | m_uiNumAllPicCoded = 0; |
---|
62 | m_pppcRDSbacCoder = NULL; |
---|
63 | m_pppcBinCoderCABAC = NULL; |
---|
64 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
65 | #if ENC_DEC_TRACE |
---|
66 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
67 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
68 | g_nSymbolCounter = 0; |
---|
69 | #endif |
---|
70 | |
---|
71 | m_iMaxRefPicNum = 0; |
---|
72 | |
---|
73 | #if FAST_BIT_EST |
---|
74 | ContextModel::buildNextStateTable(); |
---|
75 | #endif |
---|
76 | |
---|
77 | m_pcSbacCoders = NULL; |
---|
78 | m_pcBinCoderCABACs = NULL; |
---|
79 | m_ppppcRDSbacCoders = NULL; |
---|
80 | m_ppppcBinCodersCABAC = NULL; |
---|
81 | m_pcRDGoOnSbacCoders = NULL; |
---|
82 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
83 | m_pcBitCounters = NULL; |
---|
84 | m_pcRdCosts = NULL; |
---|
85 | #if SVC_EXTENSION |
---|
86 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
87 | #if REF_IDX_MFM |
---|
88 | m_bMFMEnabledFlag = false; |
---|
89 | #endif |
---|
90 | #if SCALED_REF_LAYER_OFFSETS |
---|
91 | m_numScaledRefLayerOffsets = 0; |
---|
92 | #endif |
---|
93 | #endif |
---|
94 | #if POC_RESET_FLAG |
---|
95 | m_pocAdjustmentValue = 0; |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | TEncTop::~TEncTop() |
---|
100 | { |
---|
101 | #if ENC_DEC_TRACE |
---|
102 | fclose( g_hTrace ); |
---|
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(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
120 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
121 | if (m_bUseSAO) |
---|
122 | { |
---|
123 | m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); |
---|
124 | m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); |
---|
125 | m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); |
---|
126 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
127 | m_cEncSAO.createEncBuffer(); |
---|
128 | } |
---|
129 | #if ADAPTIVE_QP_SELECTION |
---|
130 | if (m_bUseAdaptQpSelect) |
---|
131 | { |
---|
132 | m_cTrQuant.initSliceQpDelta(); |
---|
133 | } |
---|
134 | #endif |
---|
135 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
136 | |
---|
137 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
138 | if ( m_RCEnableRateControl ) |
---|
139 | { |
---|
140 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
141 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
142 | } |
---|
143 | #else |
---|
144 | m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight); |
---|
145 | #endif |
---|
146 | // if SBAC-based RD optimization is used |
---|
147 | if( m_bUseSBACRD ) |
---|
148 | { |
---|
149 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
150 | #if FAST_BIT_EST |
---|
151 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
152 | #else |
---|
153 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
154 | #endif |
---|
155 | |
---|
156 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
157 | { |
---|
158 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
159 | #if FAST_BIT_EST |
---|
160 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
161 | #else |
---|
162 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
163 | #endif |
---|
164 | |
---|
165 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
166 | { |
---|
167 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
168 | #if FAST_BIT_EST |
---|
169 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
170 | #else |
---|
171 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
172 | #endif |
---|
173 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
181 | . |
---|
182 | \param iNumSubstreams Determines how much information to allocate. |
---|
183 | */ |
---|
184 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
185 | { |
---|
186 | if (m_pcSbacCoders != NULL) |
---|
187 | { |
---|
188 | return; // already generated. |
---|
189 | } |
---|
190 | |
---|
191 | m_iNumSubstreams = iNumSubstreams; |
---|
192 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
193 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
194 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
195 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
196 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
197 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
198 | |
---|
199 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
200 | { |
---|
201 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
202 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
203 | } |
---|
204 | if( m_bUseSBACRD ) |
---|
205 | { |
---|
206 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
207 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
208 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
209 | { |
---|
210 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
211 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
212 | |
---|
213 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
214 | { |
---|
215 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
216 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
217 | |
---|
218 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
219 | { |
---|
220 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
221 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
222 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
223 | } |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | Void TEncTop::destroy () |
---|
230 | { |
---|
231 | // destroy processing unit classes |
---|
232 | m_cGOPEncoder. destroy(); |
---|
233 | m_cSliceEncoder. destroy(); |
---|
234 | m_cCuEncoder. destroy(); |
---|
235 | if (m_cSPS.getUseSAO()) |
---|
236 | { |
---|
237 | m_cEncSAO.destroy(); |
---|
238 | m_cEncSAO.destroyEncBuffer(); |
---|
239 | } |
---|
240 | m_cLoopFilter. destroy(); |
---|
241 | m_cRateCtrl. destroy(); |
---|
242 | // SBAC RD |
---|
243 | if( m_bUseSBACRD ) |
---|
244 | { |
---|
245 | Int iDepth; |
---|
246 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
247 | { |
---|
248 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
249 | { |
---|
250 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
251 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
256 | { |
---|
257 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
258 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
259 | } |
---|
260 | |
---|
261 | delete [] m_pppcRDSbacCoder; |
---|
262 | delete [] m_pppcBinCoderCABAC; |
---|
263 | |
---|
264 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
265 | { |
---|
266 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
267 | { |
---|
268 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
269 | { |
---|
270 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
271 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
276 | { |
---|
277 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
278 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
279 | } |
---|
280 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
281 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
282 | } |
---|
283 | delete[] m_ppppcRDSbacCoders; |
---|
284 | delete[] m_ppppcBinCodersCABAC; |
---|
285 | } |
---|
286 | delete[] m_pcSbacCoders; |
---|
287 | delete[] m_pcBinCoderCABACs; |
---|
288 | delete[] m_pcRDGoOnSbacCoders; |
---|
289 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
290 | delete[] m_pcBitCounters; |
---|
291 | delete[] m_pcRdCosts; |
---|
292 | |
---|
293 | #if SVC_EXTENSION |
---|
294 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
295 | { |
---|
296 | if(m_cIlpPic[i]) |
---|
297 | { |
---|
298 | m_cIlpPic[i]->destroy(); |
---|
299 | delete m_cIlpPic[i]; |
---|
300 | m_cIlpPic[i] = NULL; |
---|
301 | } |
---|
302 | } |
---|
303 | #else |
---|
304 | // destroy ROM |
---|
305 | destroyROM(); |
---|
306 | #endif |
---|
307 | return; |
---|
308 | } |
---|
309 | |
---|
310 | Void TEncTop::init() |
---|
311 | { |
---|
312 | // initialize SPS |
---|
313 | xInitSPS(); |
---|
314 | |
---|
315 | /* set the VPS profile information */ |
---|
316 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
317 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
318 | // initialize PPS |
---|
319 | m_cPPS.setSPS(&m_cSPS); |
---|
320 | xInitPPS(); |
---|
321 | xInitRPS(); |
---|
322 | |
---|
323 | xInitPPSforTiles(); |
---|
324 | |
---|
325 | // initialize processing unit classes |
---|
326 | m_cGOPEncoder. init( this ); |
---|
327 | m_cSliceEncoder.init( this ); |
---|
328 | m_cCuEncoder. init( this ); |
---|
329 | |
---|
330 | // initialize transform & quantization class |
---|
331 | m_pcCavlcCoder = getCavlcCoder(); |
---|
332 | |
---|
333 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
334 | m_useRDOQ, |
---|
335 | m_useRDOQTS, |
---|
336 | true |
---|
337 | ,m_useTransformSkipFast |
---|
338 | #if ADAPTIVE_QP_SELECTION |
---|
339 | , m_bUseAdaptQpSelect |
---|
340 | #endif |
---|
341 | ); |
---|
342 | |
---|
343 | // initialize encoder search class |
---|
344 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
345 | |
---|
346 | m_iMaxRefPicNum = 0; |
---|
347 | #if SVC_EXTENSION |
---|
348 | m_iSPSIdCnt ++; |
---|
349 | m_iPPSIdCnt ++; |
---|
350 | xInitILRP(); |
---|
351 | #endif |
---|
352 | } |
---|
353 | |
---|
354 | // ==================================================================================================================== |
---|
355 | // Public member functions |
---|
356 | // ==================================================================================================================== |
---|
357 | |
---|
358 | Void TEncTop::deletePicBuffer() |
---|
359 | { |
---|
360 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
361 | Int iSize = Int( m_cListPic.size() ); |
---|
362 | |
---|
363 | for ( Int i = 0; i < iSize; i++ ) |
---|
364 | { |
---|
365 | TComPic* pcPic = *(iterPic++); |
---|
366 | |
---|
367 | pcPic->destroy(); |
---|
368 | delete pcPic; |
---|
369 | pcPic = NULL; |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | /** |
---|
374 | - Application has picture buffer list with size of GOP + 1 |
---|
375 | - Picture buffer list acts like as ring buffer |
---|
376 | - End of the list has the latest picture |
---|
377 | . |
---|
378 | \param flush cause encoder to encode a partial GOP |
---|
379 | \param pcPicYuvOrg original YUV picture |
---|
380 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
381 | \retval rcListBitstreamOut list of output bitstreams |
---|
382 | \retval iNumEncoded number of encoded pictures |
---|
383 | */ |
---|
384 | #if SVC_EXTENSION |
---|
385 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
386 | { |
---|
387 | // compress GOP |
---|
388 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
389 | #if !RC_SHVC_HARMONIZATION |
---|
390 | if ( m_RCEnableRateControl ) |
---|
391 | { |
---|
392 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
393 | } |
---|
394 | #endif |
---|
395 | #endif |
---|
396 | |
---|
397 | // compress GOP |
---|
398 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
399 | |
---|
400 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
401 | #if !RC_SHVC_HARMONIZATION |
---|
402 | if ( m_RCEnableRateControl ) |
---|
403 | { |
---|
404 | m_cRateCtrl.destroyRCGOP(); |
---|
405 | } |
---|
406 | #endif |
---|
407 | #endif |
---|
408 | |
---|
409 | m_uiNumAllPicCoded ++; |
---|
410 | } |
---|
411 | |
---|
412 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg ) |
---|
413 | { |
---|
414 | if (pcPicYuvOrg) |
---|
415 | { |
---|
416 | // get original YUV |
---|
417 | TComPic* pcPicCurr = NULL; |
---|
418 | xGetNewPicBuffer( pcPicCurr ); |
---|
419 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
420 | |
---|
421 | // compute image characteristics |
---|
422 | if ( getUseAdaptiveQP() ) |
---|
423 | { |
---|
424 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
425 | } |
---|
426 | } |
---|
427 | } |
---|
428 | #else |
---|
429 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
430 | { |
---|
431 | if (pcPicYuvOrg) { |
---|
432 | // get original YUV |
---|
433 | TComPic* pcPicCurr = NULL; |
---|
434 | xGetNewPicBuffer( pcPicCurr ); |
---|
435 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
436 | |
---|
437 | // compute image characteristics |
---|
438 | if ( getUseAdaptiveQP() ) |
---|
439 | { |
---|
440 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) |
---|
445 | { |
---|
446 | iNumEncoded = 0; |
---|
447 | return; |
---|
448 | } |
---|
449 | |
---|
450 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
451 | if ( m_RCEnableRateControl ) |
---|
452 | { |
---|
453 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
454 | } |
---|
455 | #endif |
---|
456 | |
---|
457 | // compress GOP |
---|
458 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
459 | |
---|
460 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
461 | if ( m_RCEnableRateControl ) |
---|
462 | { |
---|
463 | m_cRateCtrl.destroyRCGOP(); |
---|
464 | } |
---|
465 | #endif |
---|
466 | |
---|
467 | iNumEncoded = m_iNumPicRcvd; |
---|
468 | m_iNumPicRcvd = 0; |
---|
469 | m_uiNumAllPicCoded += iNumEncoded; |
---|
470 | } |
---|
471 | #endif |
---|
472 | |
---|
473 | // ==================================================================================================================== |
---|
474 | // Protected member functions |
---|
475 | // ==================================================================================================================== |
---|
476 | |
---|
477 | /** |
---|
478 | - Application has picture buffer list with size of GOP + 1 |
---|
479 | - Picture buffer list acts like as ring buffer |
---|
480 | - End of the list has the latest picture |
---|
481 | . |
---|
482 | \retval rpcPic obtained picture buffer |
---|
483 | */ |
---|
484 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
485 | { |
---|
486 | TComSlice::sortPicList(m_cListPic); |
---|
487 | |
---|
488 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
489 | { |
---|
490 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
491 | Int iSize = Int( m_cListPic.size() ); |
---|
492 | for ( Int i = 0; i < iSize; i++ ) |
---|
493 | { |
---|
494 | rpcPic = *(iterPic++); |
---|
495 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
496 | { |
---|
497 | break; |
---|
498 | } |
---|
499 | } |
---|
500 | } |
---|
501 | else |
---|
502 | { |
---|
503 | if ( getUseAdaptiveQP() ) |
---|
504 | { |
---|
505 | TEncPic* pcEPic = new TEncPic; |
---|
506 | |
---|
507 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
508 | if(m_layerId > 0) |
---|
509 | { |
---|
510 | for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
511 | { |
---|
512 | const Window scalEL = getSPS()->getScaledRefLayerWindow(i); |
---|
513 | Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 ); |
---|
514 | |
---|
515 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
516 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
517 | #else |
---|
518 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
519 | #endif |
---|
520 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets ) |
---|
521 | { |
---|
522 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
---|
523 | |
---|
524 | //only for scalable extension |
---|
525 | #if SCALABILITY_MASK_E0104 |
---|
526 | assert( m_cVPS.getScalabilityMask(2) == true ); |
---|
527 | #else |
---|
528 | assert( m_cVPS.getScalabilityMask(1) == true ); |
---|
529 | #endif |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | #endif |
---|
534 | |
---|
535 | #if SVC_UPSAMPLING |
---|
536 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
537 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
538 | #else |
---|
539 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
540 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
541 | #endif |
---|
542 | rpcPic = pcEPic; |
---|
543 | } |
---|
544 | else |
---|
545 | { |
---|
546 | rpcPic = new TComPic; |
---|
547 | |
---|
548 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
549 | if(m_layerId > 0) |
---|
550 | { |
---|
551 | for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
552 | { |
---|
553 | const Window scalEL = getSPS()->getScaledRefLayerWindow(i); |
---|
554 | Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 ); |
---|
555 | |
---|
556 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
557 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
558 | #else |
---|
559 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
560 | #endif |
---|
561 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets ) |
---|
562 | { |
---|
563 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
---|
564 | |
---|
565 | //only for scalable extension |
---|
566 | #if SCALABILITY_MASK_E0104 |
---|
567 | assert( m_cVPS.getScalabilityMask(2) == true ); |
---|
568 | #else |
---|
569 | assert( m_cVPS.getScalabilityMask(1) == true ); |
---|
570 | #endif |
---|
571 | } |
---|
572 | } |
---|
573 | } |
---|
574 | #endif |
---|
575 | |
---|
576 | #if SVC_UPSAMPLING |
---|
577 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
578 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
579 | #else |
---|
580 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
581 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
582 | #endif |
---|
583 | } |
---|
584 | |
---|
585 | if (getUseSAO()) |
---|
586 | { |
---|
587 | rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO); |
---|
588 | } |
---|
589 | m_cListPic.pushBack( rpcPic ); |
---|
590 | } |
---|
591 | rpcPic->setReconMark (false); |
---|
592 | |
---|
593 | m_iPOCLast++; |
---|
594 | m_iNumPicRcvd++; |
---|
595 | |
---|
596 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
597 | // mark it should be extended |
---|
598 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
599 | } |
---|
600 | |
---|
601 | Void TEncTop::xInitSPS() |
---|
602 | { |
---|
603 | #if SVC_EXTENSION |
---|
604 | m_cSPS.setLayerId(m_layerId); |
---|
605 | #endif |
---|
606 | #if REF_IDX_MFM |
---|
607 | #if !M0457_COL_PICTURE_SIGNALING |
---|
608 | m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag); |
---|
609 | #endif |
---|
610 | #endif |
---|
611 | #if SCALED_REF_LAYER_OFFSETS |
---|
612 | m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets); |
---|
613 | for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++) |
---|
614 | { |
---|
615 | m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
---|
616 | } |
---|
617 | #endif |
---|
618 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
619 | profileTierLevel.setLevelIdc(m_level); |
---|
620 | profileTierLevel.setTierFlag(m_levelTier); |
---|
621 | profileTierLevel.setProfileIdc(m_profile); |
---|
622 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
623 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
624 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
625 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
626 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
627 | |
---|
628 | if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8) |
---|
629 | { |
---|
630 | /* The above constraint is equal to Profile::MAIN */ |
---|
631 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
632 | } |
---|
633 | if (m_profile == Profile::MAIN) |
---|
634 | { |
---|
635 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
636 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
637 | } |
---|
638 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
639 | /* XXX: may be a good idea to refactor the above into a function |
---|
640 | * that chooses the actual compatibility based upon options */ |
---|
641 | |
---|
642 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
643 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
644 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
645 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
646 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
647 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
648 | |
---|
649 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth ); |
---|
650 | Int log2MinCUSize = 0; |
---|
651 | while(minCUSize > 1) |
---|
652 | { |
---|
653 | minCUSize >>= 1; |
---|
654 | log2MinCUSize++; |
---|
655 | } |
---|
656 | |
---|
657 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
658 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth); |
---|
659 | #if SVC_EXTENSION |
---|
660 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
661 | #endif |
---|
662 | |
---|
663 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
664 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
665 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
666 | |
---|
667 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
668 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
669 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
670 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
671 | |
---|
672 | m_cSPS.setTMVPFlagsPresent(false); |
---|
673 | m_cSPS.setUseLossless ( m_useLossless ); |
---|
674 | |
---|
675 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
676 | |
---|
677 | Int i; |
---|
678 | |
---|
679 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
680 | { |
---|
681 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
682 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
683 | } |
---|
684 | |
---|
685 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
686 | |
---|
687 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
688 | { |
---|
689 | m_cSPS.setAMPAcc(i, 0); |
---|
690 | } |
---|
691 | |
---|
692 | #if REPN_FORMAT_IN_VPS |
---|
693 | m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() ); |
---|
694 | m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma() ); |
---|
695 | |
---|
696 | m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) ); |
---|
697 | m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma() - 8) ); |
---|
698 | #else |
---|
699 | m_cSPS.setBitDepthY( g_bitDepthY ); |
---|
700 | m_cSPS.setBitDepthC( g_bitDepthC ); |
---|
701 | |
---|
702 | m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) ); |
---|
703 | m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) ); |
---|
704 | #endif |
---|
705 | |
---|
706 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
707 | |
---|
708 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
709 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
710 | for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ ) |
---|
711 | { |
---|
712 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
713 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
714 | } |
---|
715 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
716 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
717 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
718 | |
---|
719 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
720 | |
---|
721 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
722 | |
---|
723 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
724 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
725 | { |
---|
726 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
727 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1); |
---|
728 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
729 | pcVUI->setSarWidth(getSarWidth()); |
---|
730 | pcVUI->setSarHeight(getSarHeight()); |
---|
731 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
732 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
733 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
734 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
735 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
736 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
737 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
738 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
739 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
740 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
741 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
742 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
743 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
744 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
745 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
746 | pcVUI->setFieldSeqFlag(false); |
---|
747 | pcVUI->setHrdParametersPresentFlag(false); |
---|
748 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
749 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
750 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
751 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
752 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
753 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
754 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
755 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
756 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
757 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
758 | } |
---|
759 | } |
---|
760 | |
---|
761 | Void TEncTop::xInitPPS() |
---|
762 | { |
---|
763 | #if IL_SL_SIGNALLING_N0371 |
---|
764 | m_cPPS.setLayerId(m_layerId); |
---|
765 | #endif |
---|
766 | |
---|
767 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
768 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
769 | |
---|
770 | #if REPN_FORMAT_IN_VPS |
---|
771 | Int lowestQP; |
---|
772 | if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() ) |
---|
773 | { |
---|
774 | lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
775 | } |
---|
776 | else |
---|
777 | { |
---|
778 | lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6; |
---|
779 | } |
---|
780 | #else |
---|
781 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
782 | #endif |
---|
783 | |
---|
784 | if(getUseLossless()) |
---|
785 | { |
---|
786 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
787 | { |
---|
788 | bUseDQP = false; |
---|
789 | } |
---|
790 | else |
---|
791 | { |
---|
792 | bUseDQP = true; |
---|
793 | } |
---|
794 | } |
---|
795 | else |
---|
796 | { |
---|
797 | if(bUseDQP == false) |
---|
798 | { |
---|
799 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
800 | { |
---|
801 | bUseDQP = true; |
---|
802 | } |
---|
803 | } |
---|
804 | } |
---|
805 | |
---|
806 | if(bUseDQP) |
---|
807 | { |
---|
808 | m_cPPS.setUseDQP(true); |
---|
809 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
810 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
811 | } |
---|
812 | else |
---|
813 | { |
---|
814 | m_cPPS.setUseDQP(false); |
---|
815 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
816 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
817 | } |
---|
818 | |
---|
819 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
820 | if ( m_RCEnableRateControl ) |
---|
821 | { |
---|
822 | m_cPPS.setUseDQP(true); |
---|
823 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
824 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
825 | } |
---|
826 | #endif |
---|
827 | |
---|
828 | m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); |
---|
829 | m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset ); |
---|
830 | |
---|
831 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
832 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
833 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
834 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
835 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
836 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
837 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
838 | if ( getDeblockingFilterMetric() ) |
---|
839 | { |
---|
840 | m_cPPS.setDeblockingFilterControlPresentFlag (true); |
---|
841 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
842 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
843 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
844 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
845 | } |
---|
846 | else |
---|
847 | { |
---|
848 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
849 | } |
---|
850 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
851 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
852 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
853 | Int histogram[MAX_NUM_REF + 1]; |
---|
854 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
855 | { |
---|
856 | histogram[i]=0; |
---|
857 | } |
---|
858 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
859 | { |
---|
860 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
861 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
862 | } |
---|
863 | Int maxHist=-1; |
---|
864 | Int bestPos=0; |
---|
865 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
866 | { |
---|
867 | if(histogram[i]>maxHist) |
---|
868 | { |
---|
869 | maxHist=histogram[i]; |
---|
870 | bestPos=i; |
---|
871 | } |
---|
872 | } |
---|
873 | assert(bestPos <= 15); |
---|
874 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
875 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
876 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
877 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
878 | if (m_sliceSegmentMode) |
---|
879 | { |
---|
880 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
881 | } |
---|
882 | if( m_cPPS.getDependentSliceSegmentsEnabledFlag() ) |
---|
883 | { |
---|
884 | Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1; |
---|
885 | m_cSliceEncoder.initCtxMem( NumCtx ); |
---|
886 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
887 | { |
---|
888 | TEncSbac* ctx = NULL; |
---|
889 | ctx = new TEncSbac; |
---|
890 | ctx->init( &m_cBinCoderCABAC ); |
---|
891 | m_cSliceEncoder.setCtxMem( ctx, st ); |
---|
892 | } |
---|
893 | } |
---|
894 | #if SVC_EXTENSION |
---|
895 | if (!m_layerId) |
---|
896 | { |
---|
897 | m_cPPS.setListsModificationPresentFlag(false); |
---|
898 | } |
---|
899 | else |
---|
900 | { |
---|
901 | m_cPPS.setListsModificationPresentFlag(true); |
---|
902 | } |
---|
903 | |
---|
904 | m_cPPS.setPPSId ( m_iPPSIdCnt ); |
---|
905 | m_cPPS.setSPSId ( m_iSPSIdCnt ); |
---|
906 | #endif |
---|
907 | #if POC_RESET_FLAG |
---|
908 | m_cPPS.setNumExtraSliceHeaderBits( 2 ); |
---|
909 | #endif |
---|
910 | } |
---|
911 | |
---|
912 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
913 | Void TEncTop::xInitRPS() |
---|
914 | { |
---|
915 | TComReferencePictureSet* rps; |
---|
916 | |
---|
917 | m_cSPS.createRPSList(getGOPSize()+m_extraRPSs); |
---|
918 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
919 | |
---|
920 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
921 | { |
---|
922 | #if FINAL_RPL_CHANGE_N0082 |
---|
923 | GOPEntry ge = m_ppcTEncTop[m_cSPS.getLayerId()]->getGOPEntry(i); |
---|
924 | #else |
---|
925 | GOPEntry ge = getGOPEntry(i); |
---|
926 | #endif |
---|
927 | rps = rpsList->getReferencePictureSet(i); |
---|
928 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
929 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
930 | Int numNeg = 0; |
---|
931 | Int numPos = 0; |
---|
932 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
933 | { |
---|
934 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
935 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
936 | if(ge.m_referencePics[j]>0) |
---|
937 | { |
---|
938 | numPos++; |
---|
939 | } |
---|
940 | else |
---|
941 | { |
---|
942 | numNeg++; |
---|
943 | } |
---|
944 | } |
---|
945 | rps->setNumberOfNegativePictures(numNeg); |
---|
946 | rps->setNumberOfPositivePictures(numPos); |
---|
947 | |
---|
948 | // handle inter RPS intialization from the config file. |
---|
949 | #if AUTO_INTER_RPS |
---|
950 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
951 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
952 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
953 | |
---|
954 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
955 | { |
---|
956 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
957 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
958 | |
---|
959 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
960 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
961 | Int count=0; |
---|
962 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
963 | { |
---|
964 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
965 | rps->setRefIdc(j, 0); |
---|
966 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
967 | { |
---|
968 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
969 | { |
---|
970 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
971 | count++; |
---|
972 | break; |
---|
973 | } |
---|
974 | } |
---|
975 | } |
---|
976 | if (count != rps->getNumberOfPictures()) |
---|
977 | { |
---|
978 | 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"); |
---|
979 | rps->setInterRPSPrediction(0); |
---|
980 | } |
---|
981 | } |
---|
982 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
983 | { |
---|
984 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
985 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
986 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
987 | { |
---|
988 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
989 | } |
---|
990 | #if WRITE_BACK |
---|
991 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
992 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
993 | numNeg = 0; |
---|
994 | numPos = 0; |
---|
995 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
996 | |
---|
997 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
998 | { |
---|
999 | if (ge.m_refIdc[j]) |
---|
1000 | { |
---|
1001 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1002 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1003 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1004 | if (deltaPOC<0) |
---|
1005 | { |
---|
1006 | numNeg++; |
---|
1007 | } |
---|
1008 | else |
---|
1009 | { |
---|
1010 | numPos++; |
---|
1011 | } |
---|
1012 | } |
---|
1013 | } |
---|
1014 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
1015 | { |
---|
1016 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1017 | rps->setNumberOfNegativePictures(numNeg); |
---|
1018 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
1019 | } |
---|
1020 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
1021 | { |
---|
1022 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1023 | rps->setNumberOfPositivePictures(numPos); |
---|
1024 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
1025 | } |
---|
1026 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1027 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1028 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1029 | // check if Delta POC and Used are the same |
---|
1030 | // print warning if they are not. |
---|
1031 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1032 | { |
---|
1033 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1034 | { |
---|
1035 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1036 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1037 | } |
---|
1038 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1039 | { |
---|
1040 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1041 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1042 | } |
---|
1043 | } |
---|
1044 | #endif |
---|
1045 | } |
---|
1046 | #else |
---|
1047 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
1048 | if (ge.m_interRPSPrediction) |
---|
1049 | { |
---|
1050 | rps->setDeltaRIdxMinus1(0); |
---|
1051 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1052 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1053 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1054 | { |
---|
1055 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1056 | } |
---|
1057 | #if WRITE_BACK |
---|
1058 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1059 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
1060 | numNeg = 0; |
---|
1061 | numPos = 0; |
---|
1062 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
1063 | |
---|
1064 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1065 | { |
---|
1066 | if (ge.m_refIdc[j]) |
---|
1067 | { |
---|
1068 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1069 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1070 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1071 | if (deltaPOC<0) |
---|
1072 | { |
---|
1073 | numNeg++; |
---|
1074 | } |
---|
1075 | else |
---|
1076 | { |
---|
1077 | numPos++; |
---|
1078 | } |
---|
1079 | } |
---|
1080 | } |
---|
1081 | rps->setNumberOfNegativePictures(numNeg); |
---|
1082 | rps->setNumberOfPositivePictures(numPos); |
---|
1083 | rps->sortDeltaPOC(); |
---|
1084 | #endif |
---|
1085 | } |
---|
1086 | #endif //INTER_RPS_AUTO |
---|
1087 | } |
---|
1088 | |
---|
1089 | } |
---|
1090 | |
---|
1091 | // This is a function that |
---|
1092 | // determines what Reference Picture Set to use |
---|
1093 | // for a specific slice (with POC = POCCurr) |
---|
1094 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1095 | { |
---|
1096 | slice->setRPSidx(GOPid); |
---|
1097 | |
---|
1098 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1099 | { |
---|
1100 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1101 | { |
---|
1102 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1103 | if(POCIndex == 0) |
---|
1104 | { |
---|
1105 | POCIndex = m_uiIntraPeriod; |
---|
1106 | } |
---|
1107 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1108 | { |
---|
1109 | slice->setRPSidx(extraNum); |
---|
1110 | } |
---|
1111 | } |
---|
1112 | else |
---|
1113 | { |
---|
1114 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1115 | { |
---|
1116 | slice->setRPSidx(extraNum); |
---|
1117 | } |
---|
1118 | } |
---|
1119 | } |
---|
1120 | |
---|
1121 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1122 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1123 | |
---|
1124 | } |
---|
1125 | |
---|
1126 | Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1127 | { |
---|
1128 | int rpsIdx = GOPid; |
---|
1129 | |
---|
1130 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1131 | { |
---|
1132 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1133 | { |
---|
1134 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1135 | if(POCIndex == 0) |
---|
1136 | { |
---|
1137 | POCIndex = m_uiIntraPeriod; |
---|
1138 | } |
---|
1139 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1140 | { |
---|
1141 | rpsIdx = extraNum; |
---|
1142 | } |
---|
1143 | } |
---|
1144 | else |
---|
1145 | { |
---|
1146 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1147 | { |
---|
1148 | rpsIdx = extraNum; |
---|
1149 | } |
---|
1150 | } |
---|
1151 | } |
---|
1152 | |
---|
1153 | return rpsIdx; |
---|
1154 | } |
---|
1155 | |
---|
1156 | Void TEncTop::xInitPPSforTiles() |
---|
1157 | { |
---|
1158 | m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr ); |
---|
1159 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1160 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1161 | if( m_iUniformSpacingIdr == 0 ) |
---|
1162 | { |
---|
1163 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1164 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1165 | } |
---|
1166 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1167 | |
---|
1168 | // # substreams is "per tile" when tiles are independent. |
---|
1169 | if (m_iWaveFrontSynchro |
---|
1170 | ) |
---|
1171 | { |
---|
1172 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
1173 | } |
---|
1174 | } |
---|
1175 | |
---|
1176 | Void TEncCfg::xCheckGSParameters() |
---|
1177 | { |
---|
1178 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1179 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1180 | UInt uiCummulativeColumnWidth = 0; |
---|
1181 | UInt uiCummulativeRowHeight = 0; |
---|
1182 | |
---|
1183 | //check the column relative parameters |
---|
1184 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1185 | { |
---|
1186 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1187 | exit( EXIT_FAILURE ); |
---|
1188 | } |
---|
1189 | |
---|
1190 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1191 | { |
---|
1192 | printf( "The current picture can not have so many columns.\n" ); |
---|
1193 | exit( EXIT_FAILURE ); |
---|
1194 | } |
---|
1195 | |
---|
1196 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1197 | { |
---|
1198 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1199 | { |
---|
1200 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1201 | } |
---|
1202 | |
---|
1203 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1204 | { |
---|
1205 | printf( "The width of the column is too large.\n" ); |
---|
1206 | exit( EXIT_FAILURE ); |
---|
1207 | } |
---|
1208 | } |
---|
1209 | |
---|
1210 | //check the row relative parameters |
---|
1211 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1212 | { |
---|
1213 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1214 | exit( EXIT_FAILURE ); |
---|
1215 | } |
---|
1216 | |
---|
1217 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1218 | { |
---|
1219 | printf( "The current picture can not have so many rows.\n" ); |
---|
1220 | exit( EXIT_FAILURE ); |
---|
1221 | } |
---|
1222 | |
---|
1223 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1224 | { |
---|
1225 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1226 | { |
---|
1227 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1228 | } |
---|
1229 | |
---|
1230 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1231 | { |
---|
1232 | printf( "The height of the row is too large.\n" ); |
---|
1233 | exit( EXIT_FAILURE ); |
---|
1234 | } |
---|
1235 | } |
---|
1236 | } |
---|
1237 | |
---|
1238 | #if SVC_EXTENSION |
---|
1239 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
1240 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc ) |
---|
1241 | { |
---|
1242 | if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 ) |
---|
1243 | { |
---|
1244 | return (TEncTop *)getLayerEnc( 0 ); |
---|
1245 | } |
---|
1246 | |
---|
1247 | return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) ); |
---|
1248 | } |
---|
1249 | #endif |
---|
1250 | |
---|
1251 | #if SVC_EXTENSION |
---|
1252 | #if !REPN_FORMAT_IN_VPS |
---|
1253 | Void TEncTop::xInitILRP() |
---|
1254 | { |
---|
1255 | if(m_layerId>0) |
---|
1256 | { |
---|
1257 | g_bitDepthY = m_cSPS.getBitDepthY(); |
---|
1258 | g_bitDepthC = m_cSPS.getBitDepthC(); |
---|
1259 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
---|
1260 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
---|
1261 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
---|
1262 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
---|
1263 | |
---|
1264 | Int numReorderPics[MAX_TLAYER]; |
---|
1265 | Window &conformanceWindow = m_cSPS.getConformanceWindow(); |
---|
1266 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
1267 | |
---|
1268 | if (m_cIlpPic[0] == NULL) |
---|
1269 | { |
---|
1270 | for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]] |
---|
1271 | { |
---|
1272 | m_cIlpPic[j] = new TComPic; |
---|
1273 | #if SVC_UPSAMPLING |
---|
1274 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
1275 | #else |
---|
1276 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
---|
1277 | #endif |
---|
1278 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
1279 | { |
---|
1280 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
1281 | } |
---|
1282 | } |
---|
1283 | } |
---|
1284 | } |
---|
1285 | } |
---|
1286 | #else |
---|
1287 | Void TEncTop::xInitILRP() |
---|
1288 | { |
---|
1289 | RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) ); |
---|
1290 | Int bitDepthY,bitDepthC,picWidth,picHeight; |
---|
1291 | |
---|
1292 | if( m_cSPS.getUpdateRepFormatFlag() ) |
---|
1293 | { |
---|
1294 | bitDepthY = m_cSPS.getBitDepthY(); |
---|
1295 | bitDepthC = m_cSPS.getBitDepthC(); |
---|
1296 | picWidth = m_cSPS.getPicWidthInLumaSamples(); |
---|
1297 | picHeight = m_cSPS.getPicHeightInLumaSamples(); |
---|
1298 | } |
---|
1299 | else |
---|
1300 | { |
---|
1301 | bitDepthY = repFormat->getBitDepthVpsLuma(); |
---|
1302 | bitDepthC = repFormat->getBitDepthVpsChroma(); |
---|
1303 | picWidth = repFormat->getPicWidthVpsInLumaSamples(); |
---|
1304 | picHeight = repFormat->getPicHeightVpsInLumaSamples(); |
---|
1305 | } |
---|
1306 | |
---|
1307 | if(m_layerId > 0) |
---|
1308 | { |
---|
1309 | g_bitDepthY = bitDepthY; |
---|
1310 | g_bitDepthC = bitDepthC; |
---|
1311 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
---|
1312 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
---|
1313 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
---|
1314 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
---|
1315 | |
---|
1316 | Int numReorderPics[MAX_TLAYER]; |
---|
1317 | Window &conformanceWindow = m_cSPS.getConformanceWindow(); |
---|
1318 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
1319 | |
---|
1320 | if (m_cIlpPic[0] == NULL) |
---|
1321 | { |
---|
1322 | for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]] |
---|
1323 | { |
---|
1324 | m_cIlpPic[j] = new TComPic; |
---|
1325 | #if SVC_UPSAMPLING |
---|
1326 | m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
1327 | #else |
---|
1328 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
---|
1329 | #endif |
---|
1330 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
1331 | { |
---|
1332 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
1333 | } |
---|
1334 | } |
---|
1335 | } |
---|
1336 | } |
---|
1337 | } |
---|
1338 | #endif |
---|
1339 | Void TEncTop::setILRPic(TComPic *pcPic) |
---|
1340 | { |
---|
1341 | for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ ) |
---|
1342 | { |
---|
1343 | Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i); |
---|
1344 | |
---|
1345 | if(m_cIlpPic[refLayerIdc]) |
---|
1346 | { |
---|
1347 | m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec()); |
---|
1348 | m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC()); |
---|
1349 | m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId |
---|
1350 | m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false); |
---|
1351 | m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder(); |
---|
1352 | for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++) // set reference CU layerId |
---|
1353 | { |
---|
1354 | m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId()); |
---|
1355 | } |
---|
1356 | } |
---|
1357 | } |
---|
1358 | } |
---|
1359 | #endif |
---|
1360 | #endif |
---|
1361 | //! \} |
---|