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 | #if RWTH_SDC_DLT_B0036 |
---|
651 | m_cSPS.setUseDLT ( m_bUseDLT ); |
---|
652 | #endif |
---|
653 | |
---|
654 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
655 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
656 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
657 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
658 | |
---|
659 | #if LOSSLESS_CODING |
---|
660 | m_cSPS.setUseLossless ( m_useLossless ); |
---|
661 | #endif |
---|
662 | #if !PIC_CROPPING |
---|
663 | m_cSPS.setUsePAD ( m_bUsePAD ); |
---|
664 | #endif |
---|
665 | m_cSPS.setUseLMChroma ( m_bUseLMChroma ); |
---|
666 | |
---|
667 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
668 | |
---|
669 | m_cSPS.setUseLComb ( m_bUseLComb ); |
---|
670 | m_cSPS.setLCMod ( m_bLCMod ); |
---|
671 | m_cSPS.setUseNSQT( m_useNSQT ); |
---|
672 | |
---|
673 | Int i; |
---|
674 | #if HHI_AMVP_OFF |
---|
675 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
676 | { |
---|
677 | m_cSPS.setAMVPMode( i, AM_NONE ); |
---|
678 | } |
---|
679 | #else |
---|
680 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
681 | { |
---|
682 | m_cSPS.setAMVPMode( i, AM_EXPL ); |
---|
683 | } |
---|
684 | #endif |
---|
685 | |
---|
686 | for (i = 0; i < g_uiMaxCUDepth-1; i++ ) |
---|
687 | { |
---|
688 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
689 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
690 | } |
---|
691 | |
---|
692 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
693 | |
---|
694 | for (i = g_uiMaxCUDepth-1; i < g_uiMaxCUDepth; i++ ) |
---|
695 | { |
---|
696 | m_cSPS.setAMPAcc(i, 0); |
---|
697 | } |
---|
698 | |
---|
699 | m_cSPS.setBitDepth ( g_uiBitDepth ); |
---|
700 | m_cSPS.setBitIncrement( g_uiBitIncrement ); |
---|
701 | #if H0736_AVC_STYLE_QP_RANGE |
---|
702 | m_cSPS.setQpBDOffsetY ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
703 | m_cSPS.setQpBDOffsetC ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
704 | #endif |
---|
705 | |
---|
706 | m_cSPS.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
707 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
708 | |
---|
709 | #if !H0566_TLA |
---|
710 | if ( m_bTLayering ) |
---|
711 | { |
---|
712 | Int iMaxTLayers = 1; |
---|
713 | for ( i = 1; ; i++) |
---|
714 | { |
---|
715 | iMaxTLayers = i; |
---|
716 | if ( (m_iGOPSize >> i) == 0 ) |
---|
717 | { |
---|
718 | break; |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | m_cSPS.setMaxTLayers( (UInt)iMaxTLayers ); |
---|
723 | |
---|
724 | Bool bTemporalIdNestingFlag = true; |
---|
725 | for ( i = 0; i < m_cSPS.getMaxTLayers()-1; i++ ) |
---|
726 | { |
---|
727 | if ( !m_abTLayerSwitchingFlag[i] ) |
---|
728 | { |
---|
729 | bTemporalIdNestingFlag = false; |
---|
730 | break; |
---|
731 | } |
---|
732 | } |
---|
733 | |
---|
734 | m_cSPS.setTemporalIdNestingFlag( bTemporalIdNestingFlag ); |
---|
735 | } |
---|
736 | else |
---|
737 | { |
---|
738 | m_cSPS.setMaxTLayers( 1 ); |
---|
739 | m_cSPS.setTemporalIdNestingFlag( false ); |
---|
740 | } |
---|
741 | #else |
---|
742 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
743 | m_cSPS.setTemporalIdNestingFlag( false ); |
---|
744 | #endif |
---|
745 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
746 | for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ ) |
---|
747 | { |
---|
748 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
749 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
750 | } |
---|
751 | #endif |
---|
752 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
753 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
754 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
755 | |
---|
756 | m_cSPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
757 | m_cSPS.setUniformSpacingIdr( m_iUniformSpacingIdr ); |
---|
758 | #if !REMOVE_TILE_DEPENDENCE |
---|
759 | m_cSPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr ); |
---|
760 | #endif |
---|
761 | m_cSPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
762 | m_cSPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
763 | if( m_iUniformSpacingIdr == 0 ) |
---|
764 | { |
---|
765 | m_cSPS.setColumnWidth( m_puiColumnWidth ); |
---|
766 | m_cSPS.setRowHeight( m_puiRowHeight ); |
---|
767 | } |
---|
768 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
769 | m_cSPS.setUseDF( m_loopFilterOffsetInAPS ); |
---|
770 | |
---|
771 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
772 | m_cSPS.setUseDMM( m_bUseDMM ); |
---|
773 | #endif |
---|
774 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
775 | m_cSPS.setUseQTLPC( m_bUseQTLPC ); |
---|
776 | #endif |
---|
777 | #if HHI_MPI |
---|
778 | m_cSPS.setUseMVI( m_bUseMVI ); |
---|
779 | #endif |
---|
780 | |
---|
781 | if( m_isDepth ) |
---|
782 | { |
---|
783 | m_cSPS.initMultiviewSPSDepth ( m_viewId, m_iViewOrderIdx ); |
---|
784 | #if DEPTH_MAP_GENERATION |
---|
785 | m_cSPS.setPredDepthMapGeneration( m_viewId, true ); |
---|
786 | #endif |
---|
787 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
788 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
789 | #endif |
---|
790 | } |
---|
791 | else |
---|
792 | { |
---|
793 | m_cSPS.initMultiviewSPS ( m_viewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset ); |
---|
794 | if( m_viewId ) |
---|
795 | { |
---|
796 | #if DEPTH_MAP_GENERATION |
---|
797 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
798 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
799 | #else |
---|
800 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, 0, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
801 | #endif |
---|
802 | #endif |
---|
803 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
804 | m_cSPS.setMultiviewResPredMode ( m_uiMultiviewResPredMode ); |
---|
805 | #endif |
---|
806 | } |
---|
807 | else |
---|
808 | { |
---|
809 | #if DEPTH_MAP_GENERATION |
---|
810 | m_cSPS.setPredDepthMapGeneration( m_viewId, false ); |
---|
811 | #endif |
---|
812 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
813 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
814 | #endif |
---|
815 | } |
---|
816 | } |
---|
817 | } |
---|
818 | |
---|
819 | Void TEncTop::xInitPPS() |
---|
820 | { |
---|
821 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
822 | m_cPPS.setSliceGranularity(m_iSliceGranularity); |
---|
823 | #if !H0566_TLA |
---|
824 | if ( m_cSPS.getTemporalIdNestingFlag() ) |
---|
825 | { |
---|
826 | m_cPPS.setNumTLayerSwitchingFlags( 0 ); |
---|
827 | for ( UInt i = 0; i < m_cSPS.getMaxTLayers() - 1; i++ ) |
---|
828 | { |
---|
829 | m_cPPS.setTLayerSwitchingFlag( i, true ); |
---|
830 | } |
---|
831 | } |
---|
832 | else |
---|
833 | { |
---|
834 | m_cPPS.setNumTLayerSwitchingFlags( m_cSPS.getMaxTLayers() - 1 ); |
---|
835 | for ( UInt i = 0; i < m_cPPS.getNumTLayerSwitchingFlags(); i++ ) |
---|
836 | { |
---|
837 | m_cPPS.setTLayerSwitchingFlag( i, m_abTLayerSwitchingFlag[i] ); |
---|
838 | } |
---|
839 | } |
---|
840 | #endif |
---|
841 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
842 | |
---|
843 | #if LOSSLESS_CODING |
---|
844 | #if H0736_AVC_STYLE_QP_RANGE |
---|
845 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
846 | #else |
---|
847 | Int lowestQP = 0; |
---|
848 | #endif |
---|
849 | |
---|
850 | if(getUseLossless()) |
---|
851 | { |
---|
852 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
853 | { |
---|
854 | bUseDQP = false; |
---|
855 | } |
---|
856 | else |
---|
857 | { |
---|
858 | bUseDQP = true; |
---|
859 | } |
---|
860 | } |
---|
861 | else |
---|
862 | { |
---|
863 | if(bUseDQP == false) |
---|
864 | { |
---|
865 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
866 | { |
---|
867 | bUseDQP = true; |
---|
868 | } |
---|
869 | } |
---|
870 | } |
---|
871 | |
---|
872 | #else |
---|
873 | if(bUseDQP == false) |
---|
874 | { |
---|
875 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
876 | { |
---|
877 | bUseDQP = true; |
---|
878 | } |
---|
879 | } |
---|
880 | #endif |
---|
881 | |
---|
882 | if(bUseDQP) |
---|
883 | { |
---|
884 | m_cPPS.setUseDQP(true); |
---|
885 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
886 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
887 | } |
---|
888 | else |
---|
889 | { |
---|
890 | m_cPPS.setUseDQP(false); |
---|
891 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
892 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
893 | } |
---|
894 | |
---|
895 | m_cPPS.setChromaQpOffset ( m_iChromaQpOffset ); |
---|
896 | m_cPPS.setChromaQpOffset2nd( m_iChromaQpOffset2nd ); |
---|
897 | |
---|
898 | m_cPPS.setEntropyCodingMode( 1 ); // In the PPS now, but also remains in slice header! |
---|
899 | #if !WPP_SIMPLIFICATION |
---|
900 | m_cPPS.setEntropyCodingSynchro(m_iWaveFrontSynchro); |
---|
901 | m_cPPS.setCabacIstateReset(m_iWaveFrontFlush != 0); |
---|
902 | #endif |
---|
903 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
904 | m_cPPS.setUseWP( m_bUseWeightPred ); |
---|
905 | m_cPPS.setWPBiPredIdc( m_uiBiPredIdc ); |
---|
906 | m_cPPS.setEnableTMVPFlag( m_bEnableTMVP ); |
---|
907 | #if H0388 |
---|
908 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
909 | #endif |
---|
910 | #if MULTIBITS_DATA_HIDING |
---|
911 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
912 | m_cPPS.setTSIG(getTSIG()); |
---|
913 | #endif |
---|
914 | #if DBL_CONTROL |
---|
915 | m_cPPS.setDeblockingFilterControlPresent (m_DeblockingFilterControlPresent ); |
---|
916 | #endif |
---|
917 | #if PARALLEL_MERGE |
---|
918 | m_cPPS.setLog2ParallelMergeLevelMinus2 (LOG2_PARALLEL_MERGE_LEVEL_MINUS2); |
---|
919 | #endif |
---|
920 | #if CABAC_INIT_FLAG |
---|
921 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
922 | #endif |
---|
923 | } |
---|
924 | |
---|
925 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
926 | Void TEncTop::xInitRPS() |
---|
927 | { |
---|
928 | TComReferencePictureSet* rps; |
---|
929 | |
---|
930 | m_RPSList.create(getGOPSize()+m_extraRPSs); |
---|
931 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
932 | { |
---|
933 | GOPEntryMvc ge = getGOPEntry(i); |
---|
934 | rps = m_RPSList.getReferencePictureSet(i); |
---|
935 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
936 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
937 | Int numNeg = 0; |
---|
938 | Int numPos = 0; |
---|
939 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
940 | { |
---|
941 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
942 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
943 | if(ge.m_referencePics[j]>0) |
---|
944 | { |
---|
945 | numPos++; |
---|
946 | } |
---|
947 | else |
---|
948 | { |
---|
949 | numNeg++; |
---|
950 | } |
---|
951 | } |
---|
952 | rps->setNumberOfNegativePictures(numNeg); |
---|
953 | rps->setNumberOfPositivePictures(numPos); |
---|
954 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
955 | if (ge.m_interRPSPrediction) |
---|
956 | { |
---|
957 | rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1); |
---|
958 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
959 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
960 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
961 | { |
---|
962 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
963 | } |
---|
964 | #if WRITE_BACK |
---|
965 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
966 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
967 | numNeg = 0; |
---|
968 | numPos = 0; |
---|
969 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1)); |
---|
970 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
971 | { |
---|
972 | if (ge.m_refIdc[j]) |
---|
973 | { |
---|
974 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
975 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
976 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
977 | if (deltaPOC<0) |
---|
978 | { |
---|
979 | numNeg++; |
---|
980 | } |
---|
981 | else |
---|
982 | { |
---|
983 | numPos++; |
---|
984 | } |
---|
985 | } |
---|
986 | } |
---|
987 | rps->setNumberOfNegativePictures(numNeg); |
---|
988 | rps->setNumberOfPositivePictures(numPos); |
---|
989 | rps->sortDeltaPOC(); |
---|
990 | #endif |
---|
991 | } |
---|
992 | } |
---|
993 | |
---|
994 | } |
---|
995 | |
---|
996 | // This is a function that |
---|
997 | // determines what Reference Picture Set to use |
---|
998 | // for a specific slice (with POC = POCCurr) |
---|
999 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic ) |
---|
1000 | { |
---|
1001 | if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 ) |
---|
1002 | { |
---|
1003 | TComReferencePictureSet* rps = slice->getLocalRPS(); |
---|
1004 | rps->setNumberOfNegativePictures(0); |
---|
1005 | rps->setNumberOfPositivePictures(0); |
---|
1006 | rps->setNumberOfLongtermPictures(0); |
---|
1007 | rps->setNumberOfPictures(0); |
---|
1008 | slice->setRPS(rps); |
---|
1009 | } |
---|
1010 | else |
---|
1011 | { |
---|
1012 | slice->setRPSidx(GOPid); |
---|
1013 | |
---|
1014 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1015 | { |
---|
1016 | if(m_uiIntraPeriod > 0) |
---|
1017 | { |
---|
1018 | if(POCCurr%m_uiIntraPeriod==m_GOPList[extraNum].m_POC) |
---|
1019 | { |
---|
1020 | slice->setRPSidx(extraNum); |
---|
1021 | } |
---|
1022 | } |
---|
1023 | else |
---|
1024 | { |
---|
1025 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1026 | { |
---|
1027 | slice->setRPSidx(extraNum); |
---|
1028 | } |
---|
1029 | } |
---|
1030 | } |
---|
1031 | |
---|
1032 | slice->setRPS(getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1033 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1034 | } |
---|
1035 | } |
---|
1036 | |
---|
1037 | Void TEncTop::xInitSPSforInterViewRefs() |
---|
1038 | { |
---|
1039 | // base view |
---|
1040 | if( getGOPEntry( MAX_GOP ).m_POC == -1 ) |
---|
1041 | { |
---|
1042 | m_cSPS.setNumberOfUsableInterViewRefs( 0 ); |
---|
1043 | m_cSPS.setListsModificationPresentFlag( false ); |
---|
1044 | return; |
---|
1045 | } |
---|
1046 | |
---|
1047 | Int numberUsableInterViewRefs = 0; |
---|
1048 | for( Int i = 0; i < getGOPSize()+1 && numberUsableInterViewRefs < MAX_VIEW_NUM; i++ ) |
---|
1049 | { |
---|
1050 | GOPEntryMvc ge = ( i < getGOPSize() ) ? getGOPEntry( i ) : getGOPEntry( MAX_GOP ); |
---|
1051 | for( Int j = 0; j < ge.m_numInterViewRefPics; j++ ) |
---|
1052 | { |
---|
1053 | // add ref view to list |
---|
1054 | Bool onList = false; |
---|
1055 | for( Int k = 0; k < numberUsableInterViewRefs; k++ ) |
---|
1056 | { |
---|
1057 | if( ge.m_interViewRefs[j] == m_cSPS.getUsableInterViewRef( k ) ) |
---|
1058 | { |
---|
1059 | onList = true; |
---|
1060 | break; |
---|
1061 | } |
---|
1062 | } |
---|
1063 | if( !onList ) |
---|
1064 | { |
---|
1065 | m_cSPS.setUsableInterViewRef( (UInt)numberUsableInterViewRefs, ge.m_interViewRefs[j] ); |
---|
1066 | numberUsableInterViewRefs++; |
---|
1067 | } |
---|
1068 | } |
---|
1069 | } |
---|
1070 | m_cSPS.setNumberOfUsableInterViewRefs( numberUsableInterViewRefs ); |
---|
1071 | |
---|
1072 | // sort inter view refs |
---|
1073 | for( Int j = 1; j < m_cSPS.getNumberOfUsableInterViewRefs(); j++ ) |
---|
1074 | { |
---|
1075 | Int deltaViewId = m_cSPS.getUsableInterViewRef( j ); |
---|
1076 | for( Int k = j-1; k >= 0; k-- ) |
---|
1077 | { |
---|
1078 | Int temp = m_cSPS.getUsableInterViewRef( k ); |
---|
1079 | if( deltaViewId > temp ) |
---|
1080 | { |
---|
1081 | m_cSPS.setUsableInterViewRef( k+1, temp ); |
---|
1082 | m_cSPS.setUsableInterViewRef( k, deltaViewId ); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | } |
---|
1086 | |
---|
1087 | m_cSPS.setListsModificationPresentFlag( true ); |
---|
1088 | } |
---|
1089 | |
---|
1090 | Void TEncTop::xInitPPSforTiles() |
---|
1091 | { |
---|
1092 | m_cPPS.setColumnRowInfoPresent( m_iColumnRowInfoPresent ); |
---|
1093 | m_cPPS.setUniformSpacingIdr( m_iUniformSpacingIdr ); |
---|
1094 | #if !REMOVE_TILE_DEPENDENCE |
---|
1095 | m_cPPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr ); |
---|
1096 | #endif |
---|
1097 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1098 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1099 | if( m_iUniformSpacingIdr == 0 ) |
---|
1100 | { |
---|
1101 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1102 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1103 | } |
---|
1104 | m_cPPS.setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag ); |
---|
1105 | m_cPPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
1106 | |
---|
1107 | // # substreams is "per tile" when tiles are independent. |
---|
1108 | #if FIX_REMOVE_TILE_DEPENDENCE |
---|
1109 | if ( m_iWaveFrontSynchro ) |
---|
1110 | #else |
---|
1111 | if (m_iTileBoundaryIndependenceIdr && m_iWaveFrontSynchro) |
---|
1112 | #endif |
---|
1113 | { |
---|
1114 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)); |
---|
1115 | } |
---|
1116 | } |
---|
1117 | |
---|
1118 | Void TEncCfg::xCheckGSParameters() |
---|
1119 | { |
---|
1120 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1121 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1122 | UInt uiCummulativeColumnWidth = 0; |
---|
1123 | UInt uiCummulativeRowHeight = 0; |
---|
1124 | |
---|
1125 | //check the column relative parameters |
---|
1126 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1127 | { |
---|
1128 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1129 | exit( EXIT_FAILURE ); |
---|
1130 | } |
---|
1131 | |
---|
1132 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1133 | { |
---|
1134 | printf( "The current picture can not have so many columns.\n" ); |
---|
1135 | exit( EXIT_FAILURE ); |
---|
1136 | } |
---|
1137 | |
---|
1138 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1139 | { |
---|
1140 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1141 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1142 | |
---|
1143 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1144 | { |
---|
1145 | printf( "The width of the column is too large.\n" ); |
---|
1146 | exit( EXIT_FAILURE ); |
---|
1147 | } |
---|
1148 | } |
---|
1149 | |
---|
1150 | //check the row relative parameters |
---|
1151 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1152 | { |
---|
1153 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1154 | exit( EXIT_FAILURE ); |
---|
1155 | } |
---|
1156 | |
---|
1157 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1158 | { |
---|
1159 | printf( "The current picture can not have so many rows.\n" ); |
---|
1160 | exit( EXIT_FAILURE ); |
---|
1161 | } |
---|
1162 | |
---|
1163 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1164 | { |
---|
1165 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1166 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1167 | |
---|
1168 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1169 | { |
---|
1170 | printf( "The height of the row is too large.\n" ); |
---|
1171 | exit( EXIT_FAILURE ); |
---|
1172 | } |
---|
1173 | } |
---|
1174 | } |
---|
1175 | |
---|
1176 | Void TEncTop::setTEncTopList(std::vector<TEncTop*>* pacTEncTopList ) |
---|
1177 | { |
---|
1178 | assert(m_viewId!=-1); // not to be set for single view coding |
---|
1179 | |
---|
1180 | m_pacTEncTopList=pacTEncTopList; |
---|
1181 | |
---|
1182 | } |
---|
1183 | |
---|
1184 | Void TEncTop::printOutSummary(UInt uiNumAllPicCoded) |
---|
1185 | { |
---|
1186 | assert (uiNumAllPicCoded == m_cAnalyzeAll.getNumPic()); |
---|
1187 | |
---|
1188 | //--CFG_KDY |
---|
1189 | m_cAnalyzeAll.setFrmRate( getFrameRate() ); |
---|
1190 | m_cAnalyzeI.setFrmRate( getFrameRate() ); |
---|
1191 | m_cAnalyzeP.setFrmRate( getFrameRate() ); |
---|
1192 | m_cAnalyzeB.setFrmRate( getFrameRate() ); |
---|
1193 | |
---|
1194 | //-- all |
---|
1195 | if(m_viewId==-1) |
---|
1196 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1197 | else { |
---|
1198 | if ( m_isDepth ) |
---|
1199 | { |
---|
1200 | printf( "\n\nSUMMARY ---------------------------------------------- DEPTH %2d\n", m_viewId ); |
---|
1201 | } |
---|
1202 | else |
---|
1203 | { |
---|
1204 | printf( "\n\nSUMMARY ---------------------------------------------- VIDEO %2d\n", m_viewId ); |
---|
1205 | } |
---|
1206 | }; |
---|
1207 | m_cAnalyzeAll.printOut('a'); |
---|
1208 | |
---|
1209 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1210 | m_cAnalyzeI.printOut('i'); |
---|
1211 | |
---|
1212 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1213 | m_cAnalyzeP.printOut('p'); |
---|
1214 | |
---|
1215 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1216 | m_cAnalyzeB.printOut('b'); |
---|
1217 | |
---|
1218 | // m_cAnalyzeAll.printSummaryOut(); |
---|
1219 | // m_cAnalyzeI.printSummary('I'); |
---|
1220 | // m_cAnalyzeP.printSummary('P'); |
---|
1221 | // m_cAnalyzeB.printSummary('B'); |
---|
1222 | } |
---|
1223 | |
---|
1224 | //! \} |
---|