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