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 HHI_MPI |
---|
771 | m_cSPS.setUseMVI( m_bUseMVI ); |
---|
772 | #endif |
---|
773 | |
---|
774 | if( m_isDepth ) |
---|
775 | { |
---|
776 | m_cSPS.initMultiviewSPSDepth ( m_viewId, m_iViewOrderIdx ); |
---|
777 | #if DEPTH_MAP_GENERATION |
---|
778 | m_cSPS.setPredDepthMapGeneration( m_viewId, true ); |
---|
779 | #endif |
---|
780 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
781 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
782 | #endif |
---|
783 | } |
---|
784 | else |
---|
785 | { |
---|
786 | m_cSPS.initMultiviewSPS ( m_viewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset ); |
---|
787 | if( m_viewId ) |
---|
788 | { |
---|
789 | #if DEPTH_MAP_GENERATION |
---|
790 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
791 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
792 | #else |
---|
793 | m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, 0, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset ); |
---|
794 | #endif |
---|
795 | #endif |
---|
796 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
797 | m_cSPS.setMultiviewResPredMode ( m_uiMultiviewResPredMode ); |
---|
798 | #endif |
---|
799 | } |
---|
800 | else |
---|
801 | { |
---|
802 | #if DEPTH_MAP_GENERATION |
---|
803 | m_cSPS.setPredDepthMapGeneration( m_viewId, false ); |
---|
804 | #endif |
---|
805 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
806 | m_cSPS.setMultiviewResPredMode ( 0 ); |
---|
807 | #endif |
---|
808 | } |
---|
809 | } |
---|
810 | } |
---|
811 | |
---|
812 | Void TEncTop::xInitPPS() |
---|
813 | { |
---|
814 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
815 | m_cPPS.setSliceGranularity(m_iSliceGranularity); |
---|
816 | #if !H0566_TLA |
---|
817 | if ( m_cSPS.getTemporalIdNestingFlag() ) |
---|
818 | { |
---|
819 | m_cPPS.setNumTLayerSwitchingFlags( 0 ); |
---|
820 | for ( UInt i = 0; i < m_cSPS.getMaxTLayers() - 1; i++ ) |
---|
821 | { |
---|
822 | m_cPPS.setTLayerSwitchingFlag( i, true ); |
---|
823 | } |
---|
824 | } |
---|
825 | else |
---|
826 | { |
---|
827 | m_cPPS.setNumTLayerSwitchingFlags( m_cSPS.getMaxTLayers() - 1 ); |
---|
828 | for ( UInt i = 0; i < m_cPPS.getNumTLayerSwitchingFlags(); i++ ) |
---|
829 | { |
---|
830 | m_cPPS.setTLayerSwitchingFlag( i, m_abTLayerSwitchingFlag[i] ); |
---|
831 | } |
---|
832 | } |
---|
833 | #endif |
---|
834 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
835 | |
---|
836 | #if LOSSLESS_CODING |
---|
837 | #if H0736_AVC_STYLE_QP_RANGE |
---|
838 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
839 | #else |
---|
840 | Int lowestQP = 0; |
---|
841 | #endif |
---|
842 | |
---|
843 | if(getUseLossless()) |
---|
844 | { |
---|
845 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
846 | { |
---|
847 | bUseDQP = false; |
---|
848 | } |
---|
849 | else |
---|
850 | { |
---|
851 | bUseDQP = true; |
---|
852 | } |
---|
853 | } |
---|
854 | else |
---|
855 | { |
---|
856 | if(bUseDQP == false) |
---|
857 | { |
---|
858 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
859 | { |
---|
860 | bUseDQP = true; |
---|
861 | } |
---|
862 | } |
---|
863 | } |
---|
864 | |
---|
865 | #else |
---|
866 | if(bUseDQP == false) |
---|
867 | { |
---|
868 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
869 | { |
---|
870 | bUseDQP = true; |
---|
871 | } |
---|
872 | } |
---|
873 | #endif |
---|
874 | |
---|
875 | if(bUseDQP) |
---|
876 | { |
---|
877 | m_cPPS.setUseDQP(true); |
---|
878 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
879 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
880 | } |
---|
881 | else |
---|
882 | { |
---|
883 | m_cPPS.setUseDQP(false); |
---|
884 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
885 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
886 | } |
---|
887 | |
---|
888 | m_cPPS.setChromaQpOffset ( m_iChromaQpOffset ); |
---|
889 | m_cPPS.setChromaQpOffset2nd( m_iChromaQpOffset2nd ); |
---|
890 | |
---|
891 | m_cPPS.setEntropyCodingMode( 1 ); // In the PPS now, but also remains in slice header! |
---|
892 | #if !WPP_SIMPLIFICATION |
---|
893 | m_cPPS.setEntropyCodingSynchro(m_iWaveFrontSynchro); |
---|
894 | m_cPPS.setCabacIstateReset(m_iWaveFrontFlush != 0); |
---|
895 | #endif |
---|
896 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
897 | m_cPPS.setUseWP( m_bUseWeightPred ); |
---|
898 | m_cPPS.setWPBiPredIdc( m_uiBiPredIdc ); |
---|
899 | m_cPPS.setEnableTMVPFlag( m_bEnableTMVP ); |
---|
900 | #if H0388 |
---|
901 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
902 | #endif |
---|
903 | #if MULTIBITS_DATA_HIDING |
---|
904 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
905 | m_cPPS.setTSIG(getTSIG()); |
---|
906 | #endif |
---|
907 | #if DBL_CONTROL |
---|
908 | m_cPPS.setDeblockingFilterControlPresent (m_DeblockingFilterControlPresent ); |
---|
909 | #endif |
---|
910 | #if PARALLEL_MERGE |
---|
911 | m_cPPS.setLog2ParallelMergeLevelMinus2 (LOG2_PARALLEL_MERGE_LEVEL_MINUS2); |
---|
912 | #endif |
---|
913 | #if CABAC_INIT_FLAG |
---|
914 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
915 | #endif |
---|
916 | } |
---|
917 | |
---|
918 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
919 | Void TEncTop::xInitRPS() |
---|
920 | { |
---|
921 | TComReferencePictureSet* rps; |
---|
922 | |
---|
923 | m_RPSList.create(getGOPSize()+m_extraRPSs); |
---|
924 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
925 | { |
---|
926 | GOPEntryMvc ge = getGOPEntry(i); |
---|
927 | rps = m_RPSList.getReferencePictureSet(i); |
---|
928 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
929 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
930 | Int numNeg = 0; |
---|
931 | Int numPos = 0; |
---|
932 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
933 | { |
---|
934 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
935 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
936 | if(ge.m_referencePics[j]>0) |
---|
937 | { |
---|
938 | numPos++; |
---|
939 | } |
---|
940 | else |
---|
941 | { |
---|
942 | numNeg++; |
---|
943 | } |
---|
944 | } |
---|
945 | rps->setNumberOfNegativePictures(numNeg); |
---|
946 | rps->setNumberOfPositivePictures(numPos); |
---|
947 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
948 | if (ge.m_interRPSPrediction) |
---|
949 | { |
---|
950 | rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1); |
---|
951 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
952 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
953 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
954 | { |
---|
955 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
956 | } |
---|
957 | #if WRITE_BACK |
---|
958 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
959 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
960 | numNeg = 0; |
---|
961 | numPos = 0; |
---|
962 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1)); |
---|
963 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
964 | { |
---|
965 | if (ge.m_refIdc[j]) |
---|
966 | { |
---|
967 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
968 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
969 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
970 | if (deltaPOC<0) |
---|
971 | { |
---|
972 | numNeg++; |
---|
973 | } |
---|
974 | else |
---|
975 | { |
---|
976 | numPos++; |
---|
977 | } |
---|
978 | } |
---|
979 | } |
---|
980 | rps->setNumberOfNegativePictures(numNeg); |
---|
981 | rps->setNumberOfPositivePictures(numPos); |
---|
982 | rps->sortDeltaPOC(); |
---|
983 | #endif |
---|
984 | } |
---|
985 | } |
---|
986 | |
---|
987 | } |
---|
988 | |
---|
989 | // This is a function that |
---|
990 | // determines what Reference Picture Set to use |
---|
991 | // for a specific slice (with POC = POCCurr) |
---|
992 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic ) |
---|
993 | { |
---|
994 | if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 ) |
---|
995 | { |
---|
996 | TComReferencePictureSet* rps = slice->getLocalRPS(); |
---|
997 | rps->setNumberOfNegativePictures(0); |
---|
998 | rps->setNumberOfPositivePictures(0); |
---|
999 | rps->setNumberOfLongtermPictures(0); |
---|
1000 | rps->setNumberOfPictures(0); |
---|
1001 | slice->setRPS(rps); |
---|
1002 | } |
---|
1003 | else |
---|
1004 | { |
---|
1005 | slice->setRPSidx(GOPid); |
---|
1006 | |
---|
1007 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1008 | { |
---|
1009 | if(m_uiIntraPeriod > 0) |
---|
1010 | { |
---|
1011 | if(POCCurr%m_uiIntraPeriod==m_GOPList[extraNum].m_POC) |
---|
1012 | { |
---|
1013 | slice->setRPSidx(extraNum); |
---|
1014 | } |
---|
1015 | } |
---|
1016 | else |
---|
1017 | { |
---|
1018 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1019 | { |
---|
1020 | slice->setRPSidx(extraNum); |
---|
1021 | } |
---|
1022 | } |
---|
1023 | } |
---|
1024 | |
---|
1025 | slice->setRPS(getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1026 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1027 | } |
---|
1028 | } |
---|
1029 | |
---|
1030 | Void TEncTop::xInitSPSforInterViewRefs() |
---|
1031 | { |
---|
1032 | // base view |
---|
1033 | if( getGOPEntry( MAX_GOP ).m_POC == -1 ) |
---|
1034 | { |
---|
1035 | m_cSPS.setNumberOfUsableInterViewRefs( 0 ); |
---|
1036 | m_cSPS.setListsModificationPresentFlag( false ); |
---|
1037 | return; |
---|
1038 | } |
---|
1039 | |
---|
1040 | Int numberUsableInterViewRefs = 0; |
---|
1041 | for( Int i = 0; i < getGOPSize()+1 && numberUsableInterViewRefs < MAX_VIEW_NUM; i++ ) |
---|
1042 | { |
---|
1043 | GOPEntryMvc ge = ( i < getGOPSize() ) ? getGOPEntry( i ) : getGOPEntry( MAX_GOP ); |
---|
1044 | for( Int j = 0; j < ge.m_numInterViewRefPics; j++ ) |
---|
1045 | { |
---|
1046 | // add ref view to list |
---|
1047 | Bool onList = false; |
---|
1048 | for( Int k = 0; k < numberUsableInterViewRefs; k++ ) |
---|
1049 | { |
---|
1050 | if( ge.m_interViewRefs[j] == m_cSPS.getUsableInterViewRef( k ) ) |
---|
1051 | { |
---|
1052 | onList = true; |
---|
1053 | break; |
---|
1054 | } |
---|
1055 | } |
---|
1056 | if( !onList ) |
---|
1057 | { |
---|
1058 | m_cSPS.setUsableInterViewRef( (UInt)numberUsableInterViewRefs, ge.m_interViewRefs[j] ); |
---|
1059 | numberUsableInterViewRefs++; |
---|
1060 | } |
---|
1061 | } |
---|
1062 | } |
---|
1063 | m_cSPS.setNumberOfUsableInterViewRefs( numberUsableInterViewRefs ); |
---|
1064 | |
---|
1065 | // sort inter view refs |
---|
1066 | for( Int j = 1; j < m_cSPS.getNumberOfUsableInterViewRefs(); j++ ) |
---|
1067 | { |
---|
1068 | Int deltaViewId = m_cSPS.getUsableInterViewRef( j ); |
---|
1069 | for( Int k = j-1; k >= 0; k-- ) |
---|
1070 | { |
---|
1071 | Int temp = m_cSPS.getUsableInterViewRef( k ); |
---|
1072 | if( deltaViewId > temp ) |
---|
1073 | { |
---|
1074 | m_cSPS.setUsableInterViewRef( k+1, temp ); |
---|
1075 | m_cSPS.setUsableInterViewRef( k, deltaViewId ); |
---|
1076 | } |
---|
1077 | } |
---|
1078 | } |
---|
1079 | |
---|
1080 | m_cSPS.setListsModificationPresentFlag( true ); |
---|
1081 | } |
---|
1082 | |
---|
1083 | Void TEncTop::xInitPPSforTiles() |
---|
1084 | { |
---|
1085 | m_cPPS.setColumnRowInfoPresent( m_iColumnRowInfoPresent ); |
---|
1086 | m_cPPS.setUniformSpacingIdr( m_iUniformSpacingIdr ); |
---|
1087 | #if !REMOVE_TILE_DEPENDENCE |
---|
1088 | m_cPPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr ); |
---|
1089 | #endif |
---|
1090 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1091 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1092 | if( m_iUniformSpacingIdr == 0 ) |
---|
1093 | { |
---|
1094 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1095 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1096 | } |
---|
1097 | m_cPPS.setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag ); |
---|
1098 | m_cPPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
1099 | |
---|
1100 | // # substreams is "per tile" when tiles are independent. |
---|
1101 | if (m_iTileBoundaryIndependenceIdr && m_iWaveFrontSynchro) |
---|
1102 | { |
---|
1103 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)); |
---|
1104 | } |
---|
1105 | } |
---|
1106 | |
---|
1107 | Void TEncCfg::xCheckGSParameters() |
---|
1108 | { |
---|
1109 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1110 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1111 | UInt uiCummulativeColumnWidth = 0; |
---|
1112 | UInt uiCummulativeRowHeight = 0; |
---|
1113 | |
---|
1114 | //check the column relative parameters |
---|
1115 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1116 | { |
---|
1117 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1118 | exit( EXIT_FAILURE ); |
---|
1119 | } |
---|
1120 | |
---|
1121 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1122 | { |
---|
1123 | printf( "The current picture can not have so many columns.\n" ); |
---|
1124 | exit( EXIT_FAILURE ); |
---|
1125 | } |
---|
1126 | |
---|
1127 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1128 | { |
---|
1129 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1130 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1131 | |
---|
1132 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1133 | { |
---|
1134 | printf( "The width of the column is too large.\n" ); |
---|
1135 | exit( EXIT_FAILURE ); |
---|
1136 | } |
---|
1137 | } |
---|
1138 | |
---|
1139 | //check the row relative parameters |
---|
1140 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1141 | { |
---|
1142 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1143 | exit( EXIT_FAILURE ); |
---|
1144 | } |
---|
1145 | |
---|
1146 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1147 | { |
---|
1148 | printf( "The current picture can not have so many rows.\n" ); |
---|
1149 | exit( EXIT_FAILURE ); |
---|
1150 | } |
---|
1151 | |
---|
1152 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1153 | { |
---|
1154 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1155 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1156 | |
---|
1157 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1158 | { |
---|
1159 | printf( "The height of the row is too large.\n" ); |
---|
1160 | exit( EXIT_FAILURE ); |
---|
1161 | } |
---|
1162 | } |
---|
1163 | } |
---|
1164 | |
---|
1165 | Void TEncTop::setTEncTopList(std::vector<TEncTop*>* pacTEncTopList ) |
---|
1166 | { |
---|
1167 | assert(m_viewId!=-1); // not to be set for single view coding |
---|
1168 | |
---|
1169 | m_pacTEncTopList=pacTEncTopList; |
---|
1170 | |
---|
1171 | } |
---|
1172 | |
---|
1173 | Void TEncTop::printOutSummary(UInt uiNumAllPicCoded) |
---|
1174 | { |
---|
1175 | assert (uiNumAllPicCoded == m_cAnalyzeAll.getNumPic()); |
---|
1176 | |
---|
1177 | //--CFG_KDY |
---|
1178 | m_cAnalyzeAll.setFrmRate( getFrameRate() ); |
---|
1179 | m_cAnalyzeI.setFrmRate( getFrameRate() ); |
---|
1180 | m_cAnalyzeP.setFrmRate( getFrameRate() ); |
---|
1181 | m_cAnalyzeB.setFrmRate( getFrameRate() ); |
---|
1182 | |
---|
1183 | //-- all |
---|
1184 | if(m_viewId==-1) |
---|
1185 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1186 | else { |
---|
1187 | if ( m_isDepth ) |
---|
1188 | { |
---|
1189 | printf( "\n\nSUMMARY ---------------------------------------------- DEPTH %2d\n", m_viewId ); |
---|
1190 | } |
---|
1191 | else |
---|
1192 | { |
---|
1193 | printf( "\n\nSUMMARY ---------------------------------------------- VIDEO %2d\n", m_viewId ); |
---|
1194 | } |
---|
1195 | }; |
---|
1196 | m_cAnalyzeAll.printOut('a'); |
---|
1197 | |
---|
1198 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1199 | m_cAnalyzeI.printOut('i'); |
---|
1200 | |
---|
1201 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1202 | m_cAnalyzeP.printOut('p'); |
---|
1203 | |
---|
1204 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1205 | m_cAnalyzeB.printOut('b'); |
---|
1206 | |
---|
1207 | // m_cAnalyzeAll.printSummaryOut(); |
---|
1208 | // m_cAnalyzeI.printSummary('I'); |
---|
1209 | // m_cAnalyzeP.printSummary('P'); |
---|
1210 | // m_cAnalyzeB.printSummary('B'); |
---|
1211 | } |
---|
1212 | |
---|
1213 | //! \} |
---|