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