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-2012, 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 "../../App/TAppEncoder/TAppEncTop.h" |
---|
42 | #if FAST_BIT_EST |
---|
43 | #include "TLibCommon/ContextModel.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | //! \ingroup TLibEncoder |
---|
47 | //! \{ |
---|
48 | |
---|
49 | // ==================================================================================================================== |
---|
50 | // Constructor / destructor / create / destroy |
---|
51 | // ==================================================================================================================== |
---|
52 | |
---|
53 | TEncTop::TEncTop() |
---|
54 | { |
---|
55 | m_iPOCLast = -1; |
---|
56 | m_iNumPicRcvd = 0; |
---|
57 | m_uiNumAllPicCoded = 0; |
---|
58 | m_pppcRDSbacCoder = NULL; |
---|
59 | m_pppcBinCoderCABAC = NULL; |
---|
60 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
61 | #if ENC_DEC_TRACE |
---|
62 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
63 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
64 | g_nSymbolCounter = 0; |
---|
65 | #endif |
---|
66 | |
---|
67 | m_iMaxRefPicNum = 0; |
---|
68 | |
---|
69 | #if FAST_BIT_EST |
---|
70 | ContextModel::buildNextStateTable(); |
---|
71 | #endif |
---|
72 | |
---|
73 | m_pcSbacCoders = NULL; |
---|
74 | m_pcBinCoderCABACs = NULL; |
---|
75 | m_ppppcRDSbacCoders = NULL; |
---|
76 | m_ppppcBinCodersCABAC = NULL; |
---|
77 | m_pcRDGoOnSbacCoders = NULL; |
---|
78 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
79 | m_pcBitCounters = NULL; |
---|
80 | m_pcRdCosts = NULL; |
---|
81 | } |
---|
82 | |
---|
83 | TEncTop::~TEncTop() |
---|
84 | { |
---|
85 | #if ENC_DEC_TRACE |
---|
86 | fclose( g_hTrace ); |
---|
87 | #endif |
---|
88 | } |
---|
89 | |
---|
90 | Void TEncTop::create () |
---|
91 | { |
---|
92 | // initialize global variables |
---|
93 | #if FIX_INIT_ROM |
---|
94 | if( m_viewId == 0 && m_isDepth == false ) |
---|
95 | { |
---|
96 | #endif |
---|
97 | initROM(); |
---|
98 | #if FIX_INIT_ROM |
---|
99 | } |
---|
100 | #endif |
---|
101 | |
---|
102 | |
---|
103 | // create processing unit classes |
---|
104 | m_cGOPEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
105 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
106 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
107 | if (m_bUseSAO) |
---|
108 | { |
---|
109 | #if SAO_UNIT_INTERLEAVING |
---|
110 | m_cEncSAO.setSaoInterleavingFlag(getSaoInterleavingFlag()); |
---|
111 | m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); |
---|
112 | #endif |
---|
113 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
114 | m_cEncSAO.createEncBuffer(); |
---|
115 | } |
---|
116 | #if ADAPTIVE_QP_SELECTION |
---|
117 | if (m_bUseAdaptQpSelect) |
---|
118 | { |
---|
119 | m_cTrQuant.initSliceQpDelta(); |
---|
120 | } |
---|
121 | #endif |
---|
122 | m_cAdaptiveLoopFilter.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
123 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
124 | |
---|
125 | #if DEPTH_MAP_GENERATION |
---|
126 | m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) ); |
---|
127 | #endif |
---|
128 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
129 | m_cResidualGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement ); |
---|
130 | #endif |
---|
131 | |
---|
132 | if(m_bUseALF) |
---|
133 | { |
---|
134 | #if LCU_SYNTAX_ALF |
---|
135 | m_cAdaptiveLoopFilter.setAlfCoefInSlice(m_bALFParamInSlice); |
---|
136 | m_cAdaptiveLoopFilter.createAlfGlobalBuffers(); |
---|
137 | #else |
---|
138 | m_cAdaptiveLoopFilter.setGOPSize( getGOPSize() ); |
---|
139 | m_cAdaptiveLoopFilter.createAlfGlobalBuffers(m_iALFEncodePassReduction); |
---|
140 | #endif |
---|
141 | } |
---|
142 | |
---|
143 | if(m_bUseSAO || m_bUseALF) |
---|
144 | { |
---|
145 | m_vAPS.reserve(MAX_NUM_SUPPORTED_APS); |
---|
146 | } |
---|
147 | |
---|
148 | // if SBAC-based RD optimization is used |
---|
149 | if( m_bUseSBACRD ) |
---|
150 | { |
---|
151 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
152 | #if FAST_BIT_EST |
---|
153 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
154 | #else |
---|
155 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
156 | #endif |
---|
157 | |
---|
158 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
159 | { |
---|
160 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
161 | #if FAST_BIT_EST |
---|
162 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
163 | #else |
---|
164 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
165 | #endif |
---|
166 | |
---|
167 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
168 | { |
---|
169 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
170 | #if FAST_BIT_EST |
---|
171 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
172 | #else |
---|
173 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
174 | #endif |
---|
175 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | m_pcTAppEncTop = NULL; |
---|
180 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
181 | if( g_aacWedgeLists.empty() && m_bUseDMM ) |
---|
182 | { |
---|
183 | initWedgeLists(); |
---|
184 | } |
---|
185 | #endif |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
190 | . |
---|
191 | \param iNumSubstreams Determines how much information to allocate. |
---|
192 | */ |
---|
193 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
194 | { |
---|
195 | if (m_pcSbacCoders != NULL) |
---|
196 | return; // already generated. |
---|
197 | |
---|
198 | m_iNumSubstreams = iNumSubstreams; |
---|
199 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
200 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
201 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
202 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
203 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
204 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
205 | |
---|
206 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
207 | { |
---|
208 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
209 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
210 | } |
---|
211 | if( m_bUseSBACRD ) |
---|
212 | { |
---|
213 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
214 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
215 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
216 | { |
---|
217 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
218 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
219 | |
---|
220 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
221 | { |
---|
222 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
223 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
224 | |
---|
225 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
226 | { |
---|
227 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
228 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
229 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | Void TEncTop::destroy () |
---|
237 | { |
---|
238 | if(m_bUseALF) |
---|
239 | { |
---|
240 | m_cAdaptiveLoopFilter.destroyAlfGlobalBuffers(); |
---|
241 | } |
---|
242 | |
---|
243 | for(Int i=0; i< m_vAPS.size(); i++) |
---|
244 | { |
---|
245 | TComAPS& cAPS = m_vAPS[i]; |
---|
246 | m_cGOPEncoder.freeAPS(&cAPS, &m_cSPS); |
---|
247 | } |
---|
248 | |
---|
249 | // destroy processing unit classes |
---|
250 | m_cGOPEncoder. destroy(); |
---|
251 | m_cSliceEncoder. destroy(); |
---|
252 | m_cCuEncoder. destroy(); |
---|
253 | if (m_cSPS.getUseSAO()) |
---|
254 | { |
---|
255 | m_cEncSAO.destroy(); |
---|
256 | m_cEncSAO.destroyEncBuffer(); |
---|
257 | } |
---|
258 | m_cAdaptiveLoopFilter.destroy(); |
---|
259 | m_cLoopFilter. destroy(); |
---|
260 | |
---|
261 | #if DEPTH_MAP_GENERATION |
---|
262 | m_cDepthMapGenerator. destroy(); |
---|
263 | #endif |
---|
264 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
265 | m_cResidualGenerator. destroy(); |
---|
266 | #endif |
---|
267 | |
---|
268 | m_RPSList. destroy(); |
---|
269 | |
---|
270 | // SBAC RD |
---|
271 | if( m_bUseSBACRD ) |
---|
272 | { |
---|
273 | Int iDepth; |
---|
274 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
275 | { |
---|
276 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
277 | { |
---|
278 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
279 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
284 | { |
---|
285 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
286 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
287 | } |
---|
288 | |
---|
289 | delete [] m_pppcRDSbacCoder; |
---|
290 | delete [] m_pppcBinCoderCABAC; |
---|
291 | |
---|
292 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
293 | { |
---|
294 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
295 | { |
---|
296 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
297 | { |
---|
298 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
299 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
304 | { |
---|
305 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
306 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
307 | } |
---|
308 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
309 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
310 | } |
---|
311 | delete[] m_ppppcRDSbacCoders; |
---|
312 | delete[] m_ppppcBinCodersCABAC; |
---|
313 | } |
---|
314 | delete[] m_pcSbacCoders; |
---|
315 | delete[] m_pcBinCoderCABACs; |
---|
316 | delete[] m_pcRDGoOnSbacCoders; |
---|
317 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
318 | delete[] m_pcBitCounters; |
---|
319 | delete[] m_pcRdCosts; |
---|
320 | |
---|
321 | // destroy ROM |
---|
322 | if(m_viewId == 0 && m_isDepth == false) |
---|
323 | { |
---|
324 | destroyROM(); |
---|
325 | } |
---|
326 | |
---|
327 | return; |
---|
328 | } |
---|
329 | |
---|
330 | Void TEncTop::init( TAppEncTop* pcTAppEncTop ) |
---|
331 | { |
---|
332 | UInt *aTable4=NULL, *aTable8=NULL; |
---|
333 | UInt* aTableLastPosVlcIndex=NULL; |
---|
334 | // initialize SPS |
---|
335 | xInitSPS(); |
---|
336 | |
---|
337 | // initialize PPS |
---|
338 | m_cPPS.setSPS(&m_cSPS); |
---|
339 | #if RPS_IN_SPS |
---|
340 | m_cSPS.setRPSList(&m_RPSList); |
---|
341 | #else |
---|
342 | m_cPPS.setRPSList(&m_RPSList); |
---|
343 | #endif |
---|
344 | xInitPPS(); |
---|
345 | xInitRPS(); |
---|
346 | |
---|
347 | xInitSPSforInterViewRefs(); |
---|
348 | xInitPPSforTiles(); |
---|
349 | |
---|
350 | // initialize processing unit classes |
---|
351 | m_cGOPEncoder. init( this ); |
---|
352 | m_cSliceEncoder.init( this ); |
---|
353 | m_cCuEncoder. init( this ); |
---|
354 | |
---|
355 | m_pcTAppEncTop = pcTAppEncTop; |
---|
356 | |
---|
357 | #if DEPTH_MAP_GENERATION |
---|
358 | #if VIDYO_VPS_INTEGRATION |
---|
359 | m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() ); |
---|
360 | #else |
---|
361 | m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() ); |
---|
362 | #endif |
---|
363 | #endif |
---|
364 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
365 | m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator ); |
---|
366 | #endif |
---|
367 | |
---|
368 | // initialize transform & quantization class |
---|
369 | m_pcCavlcCoder = getCavlcCoder(); |
---|
370 | |
---|
371 | m_cTrQuant.init( g_uiMaxCUWidth, g_uiMaxCUHeight, 1 << m_uiQuadtreeTULog2MaxSize, |
---|
372 | 0, |
---|
373 | aTable4, aTable8, |
---|
374 | aTableLastPosVlcIndex, m_bUseRDOQ, true |
---|
375 | #if ADAPTIVE_QP_SELECTION |
---|
376 | , m_bUseAdaptQpSelect |
---|
377 | #endif |
---|
378 | ); |
---|
379 | |
---|
380 | // initialize encoder search class |
---|
381 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
382 | |
---|
383 | if(m_bUseALF) |
---|
384 | { |
---|
385 | m_cAdaptiveLoopFilter.setALFEncodePassReduction( m_iALFEncodePassReduction ); |
---|
386 | m_cAdaptiveLoopFilter.setALFMaxNumberFilters( m_iALFMaxNumberFilters ); |
---|
387 | #if LCU_SYNTAX_ALF |
---|
388 | m_cAdaptiveLoopFilter.initPicQuadTreePartition(m_bALFPicBasedEncode ); |
---|
389 | #endif |
---|
390 | } |
---|
391 | |
---|
392 | m_iMaxRefPicNum = 0; |
---|
393 | } |
---|
394 | |
---|
395 | // ==================================================================================================================== |
---|
396 | // Public member functions |
---|
397 | // ==================================================================================================================== |
---|
398 | |
---|
399 | Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcOrgPdmDepth ) |
---|
400 | { |
---|
401 | TComPic* pcPicCurr = NULL; |
---|
402 | |
---|
403 | // get original YUV |
---|
404 | xGetNewPicBuffer( pcPicCurr ); |
---|
405 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
406 | |
---|
407 | #if SONY_COLPIC_AVAILABILITY |
---|
408 | pcPicCurr->setViewOrderIdx(m_iViewOrderIdx); |
---|
409 | #endif |
---|
410 | pcPicCurr->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset ); |
---|
411 | |
---|
412 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
413 | if( m_uiMultiviewMvRegMode ) |
---|
414 | { |
---|
415 | AOF( pcOrgPdmDepth ); |
---|
416 | AOF( pcPicCurr->getOrgDepthMap() ); |
---|
417 | pcOrgPdmDepth->copyToPic( pcPicCurr->getOrgDepthMap() ); |
---|
418 | } |
---|
419 | else |
---|
420 | { |
---|
421 | AOT( pcOrgPdmDepth ); |
---|
422 | AOT( pcPicCurr->getOrgDepthMap() ); |
---|
423 | } |
---|
424 | #endif |
---|
425 | |
---|
426 | #if DEPTH_MAP_GENERATION |
---|
427 | // add extra pic buffers |
---|
428 | Bool bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 ); |
---|
429 | if( bNeedPrdDepthMapBuf && !pcPicCurr->getPredDepthMap() ) |
---|
430 | { |
---|
431 | pcPicCurr->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) ); |
---|
432 | } |
---|
433 | #endif |
---|
434 | |
---|
435 | // compute image characteristics |
---|
436 | if ( getUseAdaptiveQP() ) |
---|
437 | { |
---|
438 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
439 | } |
---|
440 | } |
---|
441 | |
---|
442 | Void TEncTop::deletePicBuffer() |
---|
443 | { |
---|
444 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
445 | Int iSize = Int( m_cListPic.size() ); |
---|
446 | |
---|
447 | for ( Int i = 0; i < iSize; i++ ) |
---|
448 | { |
---|
449 | TComPic* pcPic = *(iterPic++); |
---|
450 | |
---|
451 | pcPic->destroy(); |
---|
452 | delete pcPic; |
---|
453 | pcPic = NULL; |
---|
454 | } |
---|
455 | } |
---|
456 | |
---|
457 | /** |
---|
458 | - Application has picture buffer list with size of GOP + 1 |
---|
459 | - Picture buffer list acts like as ring buffer |
---|
460 | - End of the list has the latest picture |
---|
461 | . |
---|
462 | \param bEos true if end-of-sequence is reached |
---|
463 | \param pcPicYuvOrg original YUV picture |
---|
464 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
465 | \retval rcListBitstreamOut list of output bitstreams |
---|
466 | \retval iNumEncoded number of encoded pictures |
---|
467 | */ |
---|
468 | Void TEncTop::encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Int gopId ) |
---|
469 | { |
---|
470 | |
---|
471 | if( gopId == 0) |
---|
472 | { |
---|
473 | m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
474 | } |
---|
475 | |
---|
476 | { |
---|
477 | m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId ); |
---|
478 | } |
---|
479 | |
---|
480 | if( gopId + 1 == m_cGOPEncoder.getGOPSize() ) |
---|
481 | { |
---|
482 | iNumEncoded = m_iNumPicRcvd; |
---|
483 | m_iNumPicRcvd = 0; |
---|
484 | m_uiNumAllPicCoded += iNumEncoded; |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | #if HHI_INTERVIEW_SKIP || HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED |
---|
490 | Void |
---|
491 | TEncTop::deleteExtraPicBuffers( Int iPoc ) |
---|
492 | { |
---|
493 | TComPic* pcPic = 0; |
---|
494 | TComList<TComPic*>::iterator cIter = m_cListPic.begin(); |
---|
495 | TComList<TComPic*>::iterator cEnd = m_cListPic.end (); |
---|
496 | for( ; cIter != cEnd; cIter++ ) |
---|
497 | { |
---|
498 | if( (*cIter)->getPOC() == iPoc ) |
---|
499 | { |
---|
500 | pcPic = *cIter; |
---|
501 | break; |
---|
502 | } |
---|
503 | } |
---|
504 | AOF( pcPic ); |
---|
505 | if ( pcPic ) |
---|
506 | { |
---|
507 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
508 | pcPic->removeOrgDepthMapBuffer(); |
---|
509 | #endif |
---|
510 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
511 | pcPic->removeResidualBuffer (); |
---|
512 | #endif |
---|
513 | #if HHI_INTERVIEW_SKIP |
---|
514 | pcPic->removeUsedPelsMapBuffer(); |
---|
515 | #endif |
---|
516 | } |
---|
517 | } |
---|
518 | #endif |
---|
519 | |
---|
520 | Void |
---|
521 | TEncTop::compressMotion( Int iPoc ) |
---|
522 | { |
---|
523 | TComPic* pcPic = 0; |
---|
524 | TComList<TComPic*>::iterator cIter = m_cListPic.begin(); |
---|
525 | TComList<TComPic*>::iterator cEnd = m_cListPic.end (); |
---|
526 | for( ; cIter != cEnd; cIter++ ) |
---|
527 | { |
---|
528 | if( (*cIter)->getPOC() == iPoc ) |
---|
529 | { |
---|
530 | pcPic = *cIter; |
---|
531 | break; |
---|
532 | } |
---|
533 | } |
---|
534 | AOF( pcPic ); |
---|
535 | if ( pcPic ) |
---|
536 | { |
---|
537 | pcPic->compressMotion(); |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | // ==================================================================================================================== |
---|
542 | // Protected member functions |
---|
543 | // ==================================================================================================================== |
---|
544 | |
---|
545 | /** |
---|
546 | - Application has picture buffer list with size of GOP + 1 |
---|
547 | - Picture buffer list acts like as ring buffer |
---|
548 | - End of the list has the latest picture |
---|
549 | . |
---|
550 | \retval rpcPic obtained picture buffer |
---|
551 | */ |
---|
552 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
553 | { |
---|
554 | TComSlice::sortPicList(m_cListPic); |
---|
555 | |
---|
556 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
557 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
558 | #else |
---|
559 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxNumberOfReferencePictures() + 2) ) |
---|
560 | #endif |
---|
561 | { |
---|
562 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
563 | Int iSize = Int( m_cListPic.size() ); |
---|
564 | for ( Int i = 0; i < iSize; i++ ) |
---|
565 | { |
---|
566 | rpcPic = *(++iterPic); |
---|
567 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
568 | break; |
---|
569 | } |
---|
570 | } |
---|
571 | else |
---|
572 | { |
---|
573 | if ( getUseAdaptiveQP() ) |
---|
574 | { |
---|
575 | TEncPic* pcEPic = new TEncPic; |
---|
576 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ); |
---|
577 | rpcPic = pcEPic; |
---|
578 | } |
---|
579 | else |
---|
580 | { |
---|
581 | rpcPic = new TComPic; |
---|
582 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
583 | } |
---|
584 | m_cListPic.pushBack( rpcPic ); |
---|
585 | } |
---|
586 | #if HHI_INTERVIEW_SKIP |
---|
587 | if( m_bInterViewSkip ) |
---|
588 | { |
---|
589 | rpcPic->addUsedPelsMapBuffer(); |
---|
590 | } |
---|
591 | #endif |
---|
592 | rpcPic->setReconMark (false); |
---|
593 | |
---|
594 | m_iPOCLast++; |
---|
595 | m_iNumPicRcvd++; |
---|
596 | |
---|
597 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
598 | if( m_uiMultiviewMvRegMode ) |
---|
599 | { |
---|
600 | rpcPic->addOrgDepthMapBuffer(); |
---|
601 | } |
---|
602 | #endif |
---|
603 | |
---|
604 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
605 | // mark it should be extended |
---|
606 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
607 | #if FIXES |
---|
608 | rpcPic->getPicYuvOrg()->setBorderExtension(false); |
---|
609 | #endif |
---|
610 | } |
---|
611 | |
---|
612 | Void TEncTop::xInitSPS() |
---|
613 | { |
---|
614 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
615 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
616 | #if PIC_CROPPING |
---|
617 | m_cSPS.setPicCroppingFlag( m_croppingMode!= 0 ); |
---|
618 | if (m_croppingMode != 0) |
---|
619 | { |
---|
620 | m_cSPS.setPicCropLeftOffset( m_cropLeft ); |
---|
621 | m_cSPS.setPicCropRightOffset( m_cropRight ); |
---|
622 | m_cSPS.setPicCropTopOffset( m_cropTop ); |
---|
623 | m_cSPS.setPicCropBottomOffset( m_cropBottom ); |
---|
624 | } |
---|
625 | #else |
---|
626 | m_cSPS.setPad ( m_aiPad ); |
---|
627 | #endif |
---|
628 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
629 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
630 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
631 | m_cSPS.setMinTrDepth ( 0 ); |
---|
632 | m_cSPS.setMaxTrDepth ( 1 ); |
---|
633 | |
---|
634 | #if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
635 | m_cSPS.setMaxNumberOfReferencePictures(m_maxNumberOfReferencePictures); |
---|
636 | m_cSPS.setNumReorderFrames(m_numReorderFrames); |
---|
637 | #endif |
---|
638 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
639 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
640 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
641 | |
---|
642 | m_cSPS.setUseALF ( m_bUseALF ); |
---|
643 | #if LCU_SYNTAX_ALF |
---|
644 | if(m_bUseALF) |
---|
645 | { |
---|
646 | m_cSPS.setUseALFCoefInSlice(m_bALFParamInSlice); |
---|
647 | } |
---|
648 | #endif |
---|
649 | |
---|
650 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
651 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
652 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
653 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
654 | |
---|
655 | #if LOSSLESS_CODING |
---|
656 | m_cSPS.setUseLossless ( m_useLossless ); |
---|
657 | #endif |
---|
658 | #if !PIC_CROPPING |
---|
659 | m_cSPS.setUsePAD ( m_bUsePAD ); |
---|
660 | #endif |
---|
661 | m_cSPS.setUseLMChroma ( m_bUseLMChroma ); |
---|
662 | |
---|
663 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
664 | |
---|
665 | m_cSPS.setUseLComb ( m_bUseLComb ); |
---|
666 | m_cSPS.setLCMod ( m_bLCMod ); |
---|
667 | m_cSPS.setUseNSQT( m_useNSQT ); |
---|
668 | |
---|
669 | Int i; |
---|
670 | #if HHI_AMVP_OFF |
---|
671 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
672 | { |
---|
673 | m_cSPS.setAMVPMode( i, AM_NONE ); |
---|
674 | } |
---|
675 | #else |
---|
676 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
677 | { |
---|
678 | m_cSPS.setAMVPMode( i, AM_EXPL ); |
---|
679 | } |
---|
680 | #endif |
---|
681 | |
---|
682 | for (i = 0; i < g_uiMaxCUDepth-1; i++ ) |
---|
683 | { |
---|
684 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
685 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
686 | } |
---|
687 | |
---|
688 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
689 | |
---|
690 | for (i = g_uiMaxCUDepth-1; i < g_uiMaxCUDepth; i++ ) |
---|
691 | { |
---|
692 | m_cSPS.setAMPAcc(i, 0); |
---|
693 | } |
---|
694 | |
---|
695 | m_cSPS.setBitDepth ( g_uiBitDepth ); |
---|
696 | m_cSPS.setBitIncrement( g_uiBitIncrement ); |
---|
697 | #if H0736_AVC_STYLE_QP_RANGE |
---|
698 | m_cSPS.setQpBDOffsetY ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
699 | m_cSPS.setQpBDOffsetC ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
700 | #endif |
---|
701 | |
---|
702 | m_cSPS.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
703 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
704 | |
---|
705 | #if !H0566_TLA |
---|
706 | if ( m_bTLayering ) |
---|
707 | { |
---|
708 | Int iMaxTLayers = 1; |
---|
709 | for ( i = 1; ; i++) |
---|
710 | { |
---|
711 | iMaxTLayers = i; |
---|
712 | if ( (m_iGOPSize >> i) == 0 ) |
---|
713 | { |
---|
714 | break; |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | m_cSPS.setMaxTLayers( (UInt)iMaxTLayers ); |
---|
719 | |
---|
720 | Bool bTemporalIdNestingFlag = true; |
---|
721 | for ( i = 0; i < m_cSPS.getMaxTLayers()-1; i++ ) |
---|
722 | { |
---|
723 | if ( !m_abTLayerSwitchingFlag[i] ) |
---|
724 | { |
---|
725 | bTemporalIdNestingFlag = false; |
---|
726 | break; |
---|
727 | } |
---|
728 | } |
---|
729 | |
---|
730 | m_cSPS.setTemporalIdNestingFlag( bTemporalIdNestingFlag ); |
---|
731 | } |
---|
732 | else |
---|
733 | { |
---|
734 | m_cSPS.setMaxTLayers( 1 ); |
---|
735 | m_cSPS.setTemporalIdNestingFlag( false ); |
---|
736 | } |
---|
737 | #else |
---|
738 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
739 | m_cSPS.setTemporalIdNestingFlag( false ); |
---|
740 | #endif |
---|
741 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
742 | for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ ) |
---|
743 | { |
---|
744 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
745 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
746 | } |
---|
747 | #endif |
---|
748 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
749 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
750 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
751 | |
---|
752 | m_cSPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
753 | m_cSPS.setUniformSpacingIdr( m_iUniformSpacingIdr ); |
---|
754 | #if !REMOVE_TILE_DEPENDENCE |
---|
755 | m_cSPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr ); |
---|
756 | #endif |
---|
757 | m_cSPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
758 | m_cSPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
759 | if( m_iUniformSpacingIdr == 0 ) |
---|
760 | { |
---|
761 | m_cSPS.setColumnWidth( m_puiColumnWidth ); |
---|
762 | m_cSPS.setRowHeight( m_puiRowHeight ); |
---|
763 | } |
---|
764 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
765 | m_cSPS.setUseDF( m_loopFilterOffsetInAPS ); |
---|
766 | |
---|
767 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
768 | m_cSPS.setUseDMM( m_bUseDMM ); |
---|
769 | #endif |
---|
770 | #if OL_DEPTHLIMIT_A0044 |
---|
771 | m_cSPS.setUseDPL( m_bDepthPartitionLimiting ); |
---|
772 | #endif |
---|
773 | #if HHI_MPI |
---|
774 | m_cSPS.setUseMVI( m_bUseMVI ); |
---|
775 | #endif |
---|
776 | |
---|
777 | if( m_isDepth ) |
---|
778 | { |
---|
779 | m_cSPS.initMultiviewSPSDepth ( m_viewId, m_iViewOrderIdx ); |
---|
780 | #if DEPTH_MAP_GENERATION |
---|
781 | m_cSPS.setPredDepthMapGeneration( m_viewId, true ); |
---|
782 | #endif |
---|
783 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
784 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
785 | #endif |
---|
786 | } |
---|
787 | else |
---|
788 | { |
---|
789 | m_cSPS.initMultiviewSPS ( m_viewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset ); |
---|
790 | if( m_viewId ) |
---|
791 | { |
---|
792 | #if DEPTH_MAP_GENERATION |
---|
793 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
794 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
795 | #else |
---|
796 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, 0, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
797 | #endif |
---|
798 | #endif |
---|
799 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
800 | m_cSPS.setMultiviewResPredMode ( m_uiMultiviewResPredMode ); |
---|
801 | #endif |
---|
802 | } |
---|
803 | else |
---|
804 | { |
---|
805 | #if DEPTH_MAP_GENERATION |
---|
806 | m_cSPS.setPredDepthMapGeneration( m_viewId, false ); |
---|
807 | #endif |
---|
808 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
809 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
810 | #endif |
---|
811 | } |
---|
812 | } |
---|
813 | } |
---|
814 | |
---|
815 | Void TEncTop::xInitPPS() |
---|
816 | { |
---|
817 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
818 | m_cPPS.setSliceGranularity(m_iSliceGranularity); |
---|
819 | #if !H0566_TLA |
---|
820 | if ( m_cSPS.getTemporalIdNestingFlag() ) |
---|
821 | { |
---|
822 | m_cPPS.setNumTLayerSwitchingFlags( 0 ); |
---|
823 | for ( UInt i = 0; i < m_cSPS.getMaxTLayers() - 1; i++ ) |
---|
824 | { |
---|
825 | m_cPPS.setTLayerSwitchingFlag( i, true ); |
---|
826 | } |
---|
827 | } |
---|
828 | else |
---|
829 | { |
---|
830 | m_cPPS.setNumTLayerSwitchingFlags( m_cSPS.getMaxTLayers() - 1 ); |
---|
831 | for ( UInt i = 0; i < m_cPPS.getNumTLayerSwitchingFlags(); i++ ) |
---|
832 | { |
---|
833 | m_cPPS.setTLayerSwitchingFlag( i, m_abTLayerSwitchingFlag[i] ); |
---|
834 | } |
---|
835 | } |
---|
836 | #endif |
---|
837 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
838 | |
---|
839 | #if LOSSLESS_CODING |
---|
840 | #if H0736_AVC_STYLE_QP_RANGE |
---|
841 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
842 | #else |
---|
843 | Int lowestQP = 0; |
---|
844 | #endif |
---|
845 | |
---|
846 | if(getUseLossless()) |
---|
847 | { |
---|
848 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
849 | { |
---|
850 | bUseDQP = false; |
---|
851 | } |
---|
852 | else |
---|
853 | { |
---|
854 | bUseDQP = true; |
---|
855 | } |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | if(bUseDQP == false) |
---|
860 | { |
---|
861 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
862 | { |
---|
863 | bUseDQP = true; |
---|
864 | } |
---|
865 | } |
---|
866 | } |
---|
867 | |
---|
868 | #else |
---|
869 | if(bUseDQP == false) |
---|
870 | { |
---|
871 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
872 | { |
---|
873 | bUseDQP = true; |
---|
874 | } |
---|
875 | } |
---|
876 | #endif |
---|
877 | |
---|
878 | if(bUseDQP) |
---|
879 | { |
---|
880 | m_cPPS.setUseDQP(true); |
---|
881 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
882 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
883 | } |
---|
884 | else |
---|
885 | { |
---|
886 | m_cPPS.setUseDQP(false); |
---|
887 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
888 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
889 | } |
---|
890 | |
---|
891 | m_cPPS.setChromaQpOffset ( m_iChromaQpOffset ); |
---|
892 | m_cPPS.setChromaQpOffset2nd( m_iChromaQpOffset2nd ); |
---|
893 | |
---|
894 | m_cPPS.setEntropyCodingMode( 1 ); // In the PPS now, but also remains in slice header! |
---|
895 | #if !WPP_SIMPLIFICATION |
---|
896 | m_cPPS.setEntropyCodingSynchro(m_iWaveFrontSynchro); |
---|
897 | m_cPPS.setCabacIstateReset(m_iWaveFrontFlush != 0); |
---|
898 | #endif |
---|
899 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
900 | m_cPPS.setUseWP( m_bUseWeightPred ); |
---|
901 | m_cPPS.setWPBiPredIdc( m_uiBiPredIdc ); |
---|
902 | m_cPPS.setEnableTMVPFlag( m_bEnableTMVP ); |
---|
903 | #if H0388 |
---|
904 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
905 | #endif |
---|
906 | #if MULTIBITS_DATA_HIDING |
---|
907 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
908 | m_cPPS.setTSIG(getTSIG()); |
---|
909 | #endif |
---|
910 | #if DBL_CONTROL |
---|
911 | m_cPPS.setDeblockingFilterControlPresent (m_DeblockingFilterControlPresent ); |
---|
912 | #endif |
---|
913 | #if PARALLEL_MERGE |
---|
914 | m_cPPS.setLog2ParallelMergeLevelMinus2 (LOG2_PARALLEL_MERGE_LEVEL_MINUS2); |
---|
915 | #endif |
---|
916 | #if CABAC_INIT_FLAG |
---|
917 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
918 | #endif |
---|
919 | } |
---|
920 | |
---|
921 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
922 | Void TEncTop::xInitRPS() |
---|
923 | { |
---|
924 | TComReferencePictureSet* rps; |
---|
925 | |
---|
926 | m_RPSList.create(getGOPSize()+m_extraRPSs); |
---|
927 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
928 | { |
---|
929 | GOPEntryMvc ge = getGOPEntry(i); |
---|
930 | rps = m_RPSList.getReferencePictureSet(i); |
---|
931 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
932 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
933 | Int numNeg = 0; |
---|
934 | Int numPos = 0; |
---|
935 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
936 | { |
---|
937 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
938 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
939 | if(ge.m_referencePics[j]>0) |
---|
940 | { |
---|
941 | numPos++; |
---|
942 | } |
---|
943 | else |
---|
944 | { |
---|
945 | numNeg++; |
---|
946 | } |
---|
947 | } |
---|
948 | rps->setNumberOfNegativePictures(numNeg); |
---|
949 | rps->setNumberOfPositivePictures(numPos); |
---|
950 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
951 | if (ge.m_interRPSPrediction) |
---|
952 | { |
---|
953 | rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1); |
---|
954 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
955 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
956 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
957 | { |
---|
958 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
959 | } |
---|
960 | #if WRITE_BACK |
---|
961 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
962 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
963 | numNeg = 0; |
---|
964 | numPos = 0; |
---|
965 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1)); |
---|
966 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
967 | { |
---|
968 | if (ge.m_refIdc[j]) |
---|
969 | { |
---|
970 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
971 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
972 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
973 | if (deltaPOC<0) |
---|
974 | { |
---|
975 | numNeg++; |
---|
976 | } |
---|
977 | else |
---|
978 | { |
---|
979 | numPos++; |
---|
980 | } |
---|
981 | } |
---|
982 | } |
---|
983 | rps->setNumberOfNegativePictures(numNeg); |
---|
984 | rps->setNumberOfPositivePictures(numPos); |
---|
985 | rps->sortDeltaPOC(); |
---|
986 | #endif |
---|
987 | } |
---|
988 | } |
---|
989 | |
---|
990 | } |
---|
991 | |
---|
992 | // This is a function that |
---|
993 | // determines what Reference Picture Set to use |
---|
994 | // for a specific slice (with POC = POCCurr) |
---|
995 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic ) |
---|
996 | { |
---|
997 | if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 ) |
---|
998 | { |
---|
999 | TComReferencePictureSet* rps = slice->getLocalRPS(); |
---|
1000 | rps->setNumberOfNegativePictures(0); |
---|
1001 | rps->setNumberOfPositivePictures(0); |
---|
1002 | rps->setNumberOfLongtermPictures(0); |
---|
1003 | rps->setNumberOfPictures(0); |
---|
1004 | slice->setRPS(rps); |
---|
1005 | } |
---|
1006 | else |
---|
1007 | { |
---|
1008 | slice->setRPSidx(GOPid); |
---|
1009 | |
---|
1010 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1011 | { |
---|
1012 | if(m_uiIntraPeriod > 0) |
---|
1013 | { |
---|
1014 | if(POCCurr%m_uiIntraPeriod==m_GOPList[extraNum].m_POC) |
---|
1015 | { |
---|
1016 | slice->setRPSidx(extraNum); |
---|
1017 | } |
---|
1018 | } |
---|
1019 | else |
---|
1020 | { |
---|
1021 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1022 | { |
---|
1023 | slice->setRPSidx(extraNum); |
---|
1024 | } |
---|
1025 | } |
---|
1026 | } |
---|
1027 | |
---|
1028 | slice->setRPS(getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1029 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1030 | } |
---|
1031 | } |
---|
1032 | |
---|
1033 | Void TEncTop::xInitSPSforInterViewRefs() |
---|
1034 | { |
---|
1035 | // base view |
---|
1036 | if( getGOPEntry( MAX_GOP ).m_POC == -1 ) |
---|
1037 | { |
---|
1038 | m_cSPS.setNumberOfUsableInterViewRefs( 0 ); |
---|
1039 | m_cSPS.setListsModificationPresentFlag( false ); |
---|
1040 | return; |
---|
1041 | } |
---|
1042 | |
---|
1043 | Int numberUsableInterViewRefs = 0; |
---|
1044 | for( Int i = 0; i < getGOPSize()+1 && numberUsableInterViewRefs < MAX_VIEW_NUM; i++ ) |
---|
1045 | { |
---|
1046 | GOPEntryMvc ge = ( i < getGOPSize() ) ? getGOPEntry( i ) : getGOPEntry( MAX_GOP ); |
---|
1047 | for( Int j = 0; j < ge.m_numInterViewRefPics; j++ ) |
---|
1048 | { |
---|
1049 | // add ref view to list |
---|
1050 | Bool onList = false; |
---|
1051 | for( Int k = 0; k < numberUsableInterViewRefs; k++ ) |
---|
1052 | { |
---|
1053 | if( ge.m_interViewRefs[j] == m_cSPS.getUsableInterViewRef( k ) ) |
---|
1054 | { |
---|
1055 | onList = true; |
---|
1056 | break; |
---|
1057 | } |
---|
1058 | } |
---|
1059 | if( !onList ) |
---|
1060 | { |
---|
1061 | m_cSPS.setUsableInterViewRef( (UInt)numberUsableInterViewRefs, ge.m_interViewRefs[j] ); |
---|
1062 | numberUsableInterViewRefs++; |
---|
1063 | } |
---|
1064 | } |
---|
1065 | } |
---|
1066 | m_cSPS.setNumberOfUsableInterViewRefs( numberUsableInterViewRefs ); |
---|
1067 | |
---|
1068 | // sort inter view refs |
---|
1069 | for( Int j = 1; j < m_cSPS.getNumberOfUsableInterViewRefs(); j++ ) |
---|
1070 | { |
---|
1071 | Int deltaViewId = m_cSPS.getUsableInterViewRef( j ); |
---|
1072 | for( Int k = j-1; k >= 0; k-- ) |
---|
1073 | { |
---|
1074 | Int temp = m_cSPS.getUsableInterViewRef( k ); |
---|
1075 | if( deltaViewId > temp ) |
---|
1076 | { |
---|
1077 | m_cSPS.setUsableInterViewRef( k+1, temp ); |
---|
1078 | m_cSPS.setUsableInterViewRef( k, deltaViewId ); |
---|
1079 | } |
---|
1080 | } |
---|
1081 | } |
---|
1082 | |
---|
1083 | m_cSPS.setListsModificationPresentFlag( true ); |
---|
1084 | } |
---|
1085 | |
---|
1086 | Void TEncTop::xInitPPSforTiles() |
---|
1087 | { |
---|
1088 | m_cPPS.setColumnRowInfoPresent( m_iColumnRowInfoPresent ); |
---|
1089 | m_cPPS.setUniformSpacingIdr( m_iUniformSpacingIdr ); |
---|
1090 | #if !REMOVE_TILE_DEPENDENCE |
---|
1091 | m_cPPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr ); |
---|
1092 | #endif |
---|
1093 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1094 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1095 | if( m_iUniformSpacingIdr == 0 ) |
---|
1096 | { |
---|
1097 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1098 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1099 | } |
---|
1100 | m_cPPS.setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag ); |
---|
1101 | m_cPPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
1102 | |
---|
1103 | // # substreams is "per tile" when tiles are independent. |
---|
1104 | #if FIX_REMOVE_TILE_DEPENDENCE |
---|
1105 | if ( m_iWaveFrontSynchro ) |
---|
1106 | #else |
---|
1107 | if (m_iTileBoundaryIndependenceIdr && m_iWaveFrontSynchro) |
---|
1108 | #endif |
---|
1109 | { |
---|
1110 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)); |
---|
1111 | } |
---|
1112 | } |
---|
1113 | |
---|
1114 | Void TEncCfg::xCheckGSParameters() |
---|
1115 | { |
---|
1116 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1117 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1118 | UInt uiCummulativeColumnWidth = 0; |
---|
1119 | UInt uiCummulativeRowHeight = 0; |
---|
1120 | |
---|
1121 | //check the column relative parameters |
---|
1122 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1123 | { |
---|
1124 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1125 | exit( EXIT_FAILURE ); |
---|
1126 | } |
---|
1127 | |
---|
1128 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1129 | { |
---|
1130 | printf( "The current picture can not have so many columns.\n" ); |
---|
1131 | exit( EXIT_FAILURE ); |
---|
1132 | } |
---|
1133 | |
---|
1134 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1135 | { |
---|
1136 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1137 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1138 | |
---|
1139 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1140 | { |
---|
1141 | printf( "The width of the column is too large.\n" ); |
---|
1142 | exit( EXIT_FAILURE ); |
---|
1143 | } |
---|
1144 | } |
---|
1145 | |
---|
1146 | //check the row relative parameters |
---|
1147 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1148 | { |
---|
1149 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1150 | exit( EXIT_FAILURE ); |
---|
1151 | } |
---|
1152 | |
---|
1153 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1154 | { |
---|
1155 | printf( "The current picture can not have so many rows.\n" ); |
---|
1156 | exit( EXIT_FAILURE ); |
---|
1157 | } |
---|
1158 | |
---|
1159 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1160 | { |
---|
1161 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1162 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1163 | |
---|
1164 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1165 | { |
---|
1166 | printf( "The height of the row is too large.\n" ); |
---|
1167 | exit( EXIT_FAILURE ); |
---|
1168 | } |
---|
1169 | } |
---|
1170 | } |
---|
1171 | |
---|
1172 | Void TEncTop::setTEncTopList(std::vector<TEncTop*>* pacTEncTopList ) |
---|
1173 | { |
---|
1174 | assert(m_viewId!=-1); // not to be set for single view coding |
---|
1175 | |
---|
1176 | m_pacTEncTopList=pacTEncTopList; |
---|
1177 | |
---|
1178 | } |
---|
1179 | |
---|
1180 | Void TEncTop::printOutSummary(UInt uiNumAllPicCoded) |
---|
1181 | { |
---|
1182 | assert (uiNumAllPicCoded == m_cAnalyzeAll.getNumPic()); |
---|
1183 | |
---|
1184 | //--CFG_KDY |
---|
1185 | m_cAnalyzeAll.setFrmRate( getFrameRate() ); |
---|
1186 | m_cAnalyzeI.setFrmRate( getFrameRate() ); |
---|
1187 | m_cAnalyzeP.setFrmRate( getFrameRate() ); |
---|
1188 | m_cAnalyzeB.setFrmRate( getFrameRate() ); |
---|
1189 | |
---|
1190 | //-- all |
---|
1191 | if(m_viewId==-1) |
---|
1192 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1193 | else { |
---|
1194 | if ( m_isDepth ) |
---|
1195 | { |
---|
1196 | printf( "\n\nSUMMARY ---------------------------------------------- DEPTH %2d\n", m_viewId ); |
---|
1197 | } |
---|
1198 | else |
---|
1199 | { |
---|
1200 | printf( "\n\nSUMMARY ---------------------------------------------- VIDEO %2d\n", m_viewId ); |
---|
1201 | } |
---|
1202 | }; |
---|
1203 | m_cAnalyzeAll.printOut('a'); |
---|
1204 | |
---|
1205 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1206 | m_cAnalyzeI.printOut('i'); |
---|
1207 | |
---|
1208 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1209 | m_cAnalyzeP.printOut('p'); |
---|
1210 | |
---|
1211 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1212 | m_cAnalyzeB.printOut('b'); |
---|
1213 | |
---|
1214 | // m_cAnalyzeAll.printSummaryOut(); |
---|
1215 | // m_cAnalyzeI.printSummary('I'); |
---|
1216 | // m_cAnalyzeP.printSummary('P'); |
---|
1217 | // m_cAnalyzeB.printSummary('B'); |
---|
1218 | } |
---|
1219 | |
---|
1220 | //! \} |
---|