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