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