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