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 | #if FAST_BIT_EST |
---|
42 | #include "TLibCommon/ContextModel.h" |
---|
43 | #endif |
---|
44 | |
---|
45 | //! \ingroup TLibEncoder |
---|
46 | //! \{ |
---|
47 | #if SVC_EXTENSION |
---|
48 | Int TEncTop::m_iSPSIdCnt = 0; |
---|
49 | Int TEncTop::m_iPPSIdCnt = 0; |
---|
50 | #endif |
---|
51 | |
---|
52 | // ==================================================================================================================== |
---|
53 | // Constructor / destructor / create / destroy |
---|
54 | // ==================================================================================================================== |
---|
55 | |
---|
56 | TEncTop::TEncTop() |
---|
57 | { |
---|
58 | m_iPOCLast = -1; |
---|
59 | m_iNumPicRcvd = 0; |
---|
60 | m_uiNumAllPicCoded = 0; |
---|
61 | m_pppcRDSbacCoder = NULL; |
---|
62 | m_pppcBinCoderCABAC = NULL; |
---|
63 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
64 | #if ENC_DEC_TRACE |
---|
65 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
66 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
67 | g_nSymbolCounter = 0; |
---|
68 | #endif |
---|
69 | |
---|
70 | m_iMaxRefPicNum = 0; |
---|
71 | |
---|
72 | #if FAST_BIT_EST |
---|
73 | ContextModel::buildNextStateTable(); |
---|
74 | #endif |
---|
75 | |
---|
76 | m_pcSbacCoders = NULL; |
---|
77 | m_pcBinCoderCABACs = NULL; |
---|
78 | m_ppppcRDSbacCoders = NULL; |
---|
79 | m_ppppcBinCodersCABAC = NULL; |
---|
80 | m_pcRDGoOnSbacCoders = NULL; |
---|
81 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
82 | m_pcBitCounters = NULL; |
---|
83 | m_pcRdCosts = NULL; |
---|
84 | #if REF_IDX_FRAMEWORK |
---|
85 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
86 | #endif |
---|
87 | #if REF_IDX_MFM |
---|
88 | m_bMFMEnabledFlag = false; |
---|
89 | #endif |
---|
90 | } |
---|
91 | |
---|
92 | TEncTop::~TEncTop() |
---|
93 | { |
---|
94 | #if ENC_DEC_TRACE |
---|
95 | fclose( g_hTrace ); |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | Void TEncTop::create () |
---|
100 | { |
---|
101 | #if !SVC_EXTENSION |
---|
102 | // initialize global variables |
---|
103 | initROM(); |
---|
104 | #endif |
---|
105 | |
---|
106 | // create processing unit classes |
---|
107 | #if SVC_EXTENSION |
---|
108 | m_cGOPEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, m_layerId ); |
---|
109 | #else |
---|
110 | m_cGOPEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
111 | #endif |
---|
112 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
113 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
114 | if (m_bUseSAO) |
---|
115 | { |
---|
116 | #if SAO_LCU_BOUNDARY |
---|
117 | m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); |
---|
118 | #endif |
---|
119 | m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); |
---|
120 | m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); |
---|
121 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
122 | m_cEncSAO.createEncBuffer(); |
---|
123 | } |
---|
124 | #if ADAPTIVE_QP_SELECTION |
---|
125 | if (m_bUseAdaptQpSelect) |
---|
126 | { |
---|
127 | m_cTrQuant.initSliceQpDelta(); |
---|
128 | } |
---|
129 | #endif |
---|
130 | #if !REMOVE_ALF |
---|
131 | m_cAdaptiveLoopFilter.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
132 | #endif |
---|
133 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
134 | |
---|
135 | #if !REMOVE_ALF |
---|
136 | if(m_bUseALF) |
---|
137 | { |
---|
138 | m_cAdaptiveLoopFilter.setALFLowLatencyEncoding( m_alfLowLatencyEncoding ); |
---|
139 | m_cAdaptiveLoopFilter.setGOPSize( getGOPSize() ); |
---|
140 | m_cAdaptiveLoopFilter.createAlfGlobalBuffers(); |
---|
141 | } |
---|
142 | #endif |
---|
143 | |
---|
144 | #if !REMOVE_APS |
---|
145 | #if REMOVE_ALF |
---|
146 | if(m_bUseSAO) |
---|
147 | #else |
---|
148 | if(m_bUseSAO || m_bUseALF) |
---|
149 | #endif |
---|
150 | { |
---|
151 | m_vAPS.reserve(MAX_NUM_SUPPORTED_APS); |
---|
152 | } |
---|
153 | #endif |
---|
154 | m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight); |
---|
155 | // if SBAC-based RD optimization is used |
---|
156 | if( m_bUseSBACRD ) |
---|
157 | { |
---|
158 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
159 | #if FAST_BIT_EST |
---|
160 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
161 | #else |
---|
162 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
163 | #endif |
---|
164 | |
---|
165 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
166 | { |
---|
167 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
168 | #if FAST_BIT_EST |
---|
169 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
170 | #else |
---|
171 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
172 | #endif |
---|
173 | |
---|
174 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
175 | { |
---|
176 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
177 | #if FAST_BIT_EST |
---|
178 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
179 | #else |
---|
180 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
181 | #endif |
---|
182 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
190 | . |
---|
191 | \param iNumSubstreams Determines how much information to allocate. |
---|
192 | */ |
---|
193 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
194 | { |
---|
195 | if (m_pcSbacCoders != NULL) |
---|
196 | { |
---|
197 | return; // already generated. |
---|
198 | } |
---|
199 | |
---|
200 | m_iNumSubstreams = iNumSubstreams; |
---|
201 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
202 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
203 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
204 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
205 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
206 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
207 | |
---|
208 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
209 | { |
---|
210 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
211 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
212 | } |
---|
213 | if( m_bUseSBACRD ) |
---|
214 | { |
---|
215 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
216 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
217 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
218 | { |
---|
219 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
220 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
221 | |
---|
222 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
223 | { |
---|
224 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
225 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
226 | |
---|
227 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
228 | { |
---|
229 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
230 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
231 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
232 | } |
---|
233 | } |
---|
234 | } |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | Void TEncTop::destroy () |
---|
239 | { |
---|
240 | #if !REMOVE_ALF |
---|
241 | if(m_bUseALF) |
---|
242 | { |
---|
243 | m_cAdaptiveLoopFilter.destroyAlfGlobalBuffers(); |
---|
244 | } |
---|
245 | #endif |
---|
246 | #if !REMOVE_APS |
---|
247 | for(Int i=0; i< m_vAPS.size(); i++) |
---|
248 | { |
---|
249 | TComAPS& cAPS = m_vAPS[i]; |
---|
250 | m_cGOPEncoder.freeAPS(&cAPS, &m_cSPS); |
---|
251 | } |
---|
252 | #endif |
---|
253 | // destroy processing unit classes |
---|
254 | m_cGOPEncoder. destroy(); |
---|
255 | m_cSliceEncoder. destroy(); |
---|
256 | m_cCuEncoder. destroy(); |
---|
257 | if (m_cSPS.getUseSAO()) |
---|
258 | { |
---|
259 | m_cEncSAO.destroy(); |
---|
260 | m_cEncSAO.destroyEncBuffer(); |
---|
261 | } |
---|
262 | #if !REMOVE_ALF |
---|
263 | m_cAdaptiveLoopFilter.destroy(); |
---|
264 | #endif |
---|
265 | m_cLoopFilter. destroy(); |
---|
266 | m_cRateCtrl. destroy(); |
---|
267 | // SBAC RD |
---|
268 | if( m_bUseSBACRD ) |
---|
269 | { |
---|
270 | Int iDepth; |
---|
271 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
272 | { |
---|
273 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
274 | { |
---|
275 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
276 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
281 | { |
---|
282 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
283 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
284 | } |
---|
285 | |
---|
286 | delete [] m_pppcRDSbacCoder; |
---|
287 | delete [] m_pppcBinCoderCABAC; |
---|
288 | |
---|
289 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
290 | { |
---|
291 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
292 | { |
---|
293 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
294 | { |
---|
295 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
296 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
301 | { |
---|
302 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
303 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
304 | } |
---|
305 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
306 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
307 | } |
---|
308 | delete[] m_ppppcRDSbacCoders; |
---|
309 | delete[] m_ppppcBinCodersCABAC; |
---|
310 | } |
---|
311 | delete[] m_pcSbacCoders; |
---|
312 | delete[] m_pcBinCoderCABACs; |
---|
313 | delete[] m_pcRDGoOnSbacCoders; |
---|
314 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
315 | delete[] m_pcBitCounters; |
---|
316 | delete[] m_pcRdCosts; |
---|
317 | |
---|
318 | #if !SVC_EXTENSION |
---|
319 | // destroy ROM |
---|
320 | destroyROM(); |
---|
321 | #endif |
---|
322 | #if REF_IDX_FRAMEWORK |
---|
323 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
324 | { |
---|
325 | if(m_cIlpPic[i]) |
---|
326 | { |
---|
327 | //m_cIlpPic[i]->setPicYuvRec(NULL); |
---|
328 | m_cIlpPic[i]->destroy(); |
---|
329 | delete m_cIlpPic[i]; |
---|
330 | m_cIlpPic[i] = NULL; |
---|
331 | } |
---|
332 | } |
---|
333 | #endif |
---|
334 | return; |
---|
335 | } |
---|
336 | |
---|
337 | Void TEncTop::init() |
---|
338 | { |
---|
339 | UInt *aTable4=NULL, *aTable8=NULL; |
---|
340 | UInt* aTableLastPosVlcIndex=NULL; |
---|
341 | |
---|
342 | // initialize SPS |
---|
343 | xInitSPS(); |
---|
344 | |
---|
345 | // initialize PPS |
---|
346 | m_cPPS.setSPS(&m_cSPS); |
---|
347 | xInitPPS(); |
---|
348 | xInitRPS(); |
---|
349 | |
---|
350 | xInitPPSforTiles(); |
---|
351 | |
---|
352 | // initialize processing unit classes |
---|
353 | m_cGOPEncoder. init( this ); |
---|
354 | m_cSliceEncoder.init( this ); |
---|
355 | m_cCuEncoder. init( this ); |
---|
356 | |
---|
357 | // initialize transform & quantization class |
---|
358 | m_pcCavlcCoder = getCavlcCoder(); |
---|
359 | |
---|
360 | m_cTrQuant.init( g_uiMaxCUWidth, g_uiMaxCUHeight, 1 << m_uiQuadtreeTULog2MaxSize, |
---|
361 | 0, |
---|
362 | aTable4, aTable8, |
---|
363 | aTableLastPosVlcIndex, m_bUseRDOQ, true |
---|
364 | ,m_useTransformSkipFast |
---|
365 | #if ADAPTIVE_QP_SELECTION |
---|
366 | , m_bUseAdaptQpSelect |
---|
367 | #endif |
---|
368 | ); |
---|
369 | |
---|
370 | // initialize encoder search class |
---|
371 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
372 | |
---|
373 | m_iMaxRefPicNum = 0; |
---|
374 | #if SVC_EXTENSION |
---|
375 | m_iSPSIdCnt ++; |
---|
376 | m_iPPSIdCnt ++; |
---|
377 | #endif |
---|
378 | #if REF_IDX_FRAMEWORK |
---|
379 | xInitILRP(); |
---|
380 | #endif |
---|
381 | } |
---|
382 | |
---|
383 | #if REF_IDX_FRAMEWORK |
---|
384 | Void TEncTop::xInitILRP() |
---|
385 | { |
---|
386 | if(m_layerId>0) |
---|
387 | { |
---|
388 | if (m_cIlpPic[0] == NULL) |
---|
389 | { |
---|
390 | for (Int j=0; j<1/*MAX_NUM_REF*/; j++) |
---|
391 | { |
---|
392 | m_cIlpPic[j] = new TComPic; |
---|
393 | //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true); |
---|
394 | #if SVC_UPSAMPLING |
---|
395 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true); |
---|
396 | #else |
---|
397 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
398 | #endif |
---|
399 | #if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM |
---|
400 | m_cIlpPic[j]->setIsILR(true); |
---|
401 | #endif |
---|
402 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
403 | { |
---|
404 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
405 | } |
---|
406 | } |
---|
407 | } |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | Void TEncTop::setILRPic(TComPic *pcPic) |
---|
412 | { |
---|
413 | if(m_cIlpPic[0]) |
---|
414 | { |
---|
415 | //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec()); |
---|
416 | m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec()); |
---|
417 | m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC()); |
---|
418 | m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false); |
---|
419 | m_cIlpPic[0]->getPicYuvRec()->extendPicBorder(); |
---|
420 | } |
---|
421 | } |
---|
422 | #endif |
---|
423 | |
---|
424 | // ==================================================================================================================== |
---|
425 | // Public member functions |
---|
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 | #if SVC_EXTENSION |
---|
455 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
456 | { |
---|
457 | // compress GOP |
---|
458 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
459 | |
---|
460 | m_uiNumAllPicCoded ++; |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | Void TEncTop::encodePrep( bool bEos, TComPicYuv* pcPicYuvOrg ) |
---|
465 | { |
---|
466 | TComPic* pcPicCurr = NULL; |
---|
467 | |
---|
468 | // get original YUV |
---|
469 | xGetNewPicBuffer( pcPicCurr ); |
---|
470 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
471 | |
---|
472 | // compute image characteristics |
---|
473 | if ( getUseAdaptiveQP() ) |
---|
474 | { |
---|
475 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | #else |
---|
480 | Void TEncTop::encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
481 | { |
---|
482 | TComPic* pcPicCurr = NULL; |
---|
483 | |
---|
484 | // get original YUV |
---|
485 | xGetNewPicBuffer( pcPicCurr ); |
---|
486 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
487 | |
---|
488 | // compute image characteristics |
---|
489 | if ( getUseAdaptiveQP() ) |
---|
490 | { |
---|
491 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
492 | } |
---|
493 | |
---|
494 | if ( m_iPOCLast != 0 && ( m_iNumPicRcvd != m_iGOPSize && m_iGOPSize ) && !bEos ) |
---|
495 | { |
---|
496 | iNumEncoded = 0; |
---|
497 | return; |
---|
498 | } |
---|
499 | |
---|
500 | // compress GOP |
---|
501 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
502 | |
---|
503 | iNumEncoded = m_iNumPicRcvd; |
---|
504 | m_iNumPicRcvd = 0; |
---|
505 | m_uiNumAllPicCoded += iNumEncoded; |
---|
506 | |
---|
507 | if (bEos) |
---|
508 | { |
---|
509 | #if SVC_EXTENSION |
---|
510 | m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, m_layerId); |
---|
511 | #else |
---|
512 | m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); |
---|
513 | #endif |
---|
514 | } |
---|
515 | } |
---|
516 | #endif |
---|
517 | |
---|
518 | |
---|
519 | // ==================================================================================================================== |
---|
520 | // Protected member functions |
---|
521 | // ==================================================================================================================== |
---|
522 | |
---|
523 | /** |
---|
524 | - Application has picture buffer list with size of GOP + 1 |
---|
525 | - Picture buffer list acts like as ring buffer |
---|
526 | - End of the list has the latest picture |
---|
527 | . |
---|
528 | \retval rpcPic obtained picture buffer |
---|
529 | */ |
---|
530 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
531 | { |
---|
532 | TComSlice::sortPicList(m_cListPic); |
---|
533 | |
---|
534 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
535 | { |
---|
536 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
537 | Int iSize = Int( m_cListPic.size() ); |
---|
538 | for ( Int i = 0; i < iSize; i++ ) |
---|
539 | { |
---|
540 | rpcPic = *(iterPic++); |
---|
541 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
542 | { |
---|
543 | break; |
---|
544 | } |
---|
545 | } |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | if ( getUseAdaptiveQP() ) |
---|
550 | { |
---|
551 | TEncPic* pcEPic = new TEncPic; |
---|
552 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
553 | if(m_layerId > 0) |
---|
554 | { |
---|
555 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
556 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() ) |
---|
557 | { |
---|
558 | pcEPic->setSpatialEnhLayerFlag( true ); |
---|
559 | } |
---|
560 | } |
---|
561 | #endif |
---|
562 | #if SVC_UPSAMPLING |
---|
563 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, &m_cSPS ); |
---|
564 | #else |
---|
565 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ); |
---|
566 | #endif |
---|
567 | rpcPic = pcEPic; |
---|
568 | } |
---|
569 | else |
---|
570 | { |
---|
571 | rpcPic = new TComPic; |
---|
572 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
573 | if(m_layerId > 0) |
---|
574 | { |
---|
575 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
576 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() ) |
---|
577 | { |
---|
578 | rpcPic->setSpatialEnhLayerFlag( true ); |
---|
579 | } |
---|
580 | } |
---|
581 | #endif |
---|
582 | #if SVC_UPSAMPLING |
---|
583 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS ); |
---|
584 | #else |
---|
585 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
586 | #endif |
---|
587 | } |
---|
588 | #if REMOVE_APS |
---|
589 | if (getUseSAO()) |
---|
590 | { |
---|
591 | rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO); |
---|
592 | } |
---|
593 | #endif |
---|
594 | m_cListPic.pushBack( rpcPic ); |
---|
595 | } |
---|
596 | rpcPic->setReconMark (false); |
---|
597 | |
---|
598 | m_iPOCLast++; |
---|
599 | m_iNumPicRcvd++; |
---|
600 | |
---|
601 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
602 | // mark it should be extended |
---|
603 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
604 | |
---|
605 | } |
---|
606 | |
---|
607 | Void TEncTop::xInitSPS() |
---|
608 | { |
---|
609 | #if SVC_EXTENSION |
---|
610 | m_cSPS.setLayerId(m_layerId); |
---|
611 | #endif |
---|
612 | #if REF_IDX_MFM |
---|
613 | m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag); |
---|
614 | #endif |
---|
615 | |
---|
616 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
617 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
618 | m_cSPS.setPicCroppingFlag( m_croppingMode!= 0 ); |
---|
619 | if (m_croppingMode != 0) |
---|
620 | { |
---|
621 | m_cSPS.setPicCropLeftOffset( m_cropLeft ); |
---|
622 | m_cSPS.setPicCropRightOffset( m_cropRight ); |
---|
623 | m_cSPS.setPicCropTopOffset( m_cropTop ); |
---|
624 | m_cSPS.setPicCropBottomOffset( m_cropBottom ); |
---|
625 | } |
---|
626 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
627 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
628 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
629 | m_cSPS.setMinTrDepth ( 0 ); |
---|
630 | m_cSPS.setMaxTrDepth ( 1 ); |
---|
631 | #if SVC_EXTENSION |
---|
632 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
633 | #endif |
---|
634 | |
---|
635 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
636 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
637 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
638 | |
---|
639 | #if !REMOVE_ALF |
---|
640 | m_cSPS.setUseALF ( m_bUseALF ); |
---|
641 | #endif |
---|
642 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
643 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
644 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
645 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
646 | |
---|
647 | m_cSPS.setTMVPFlagsPresent(false); |
---|
648 | m_cSPS.setUseLossless ( m_useLossless ); |
---|
649 | |
---|
650 | #if !REMOVE_LMCHROMA |
---|
651 | m_cSPS.setUseLMChroma ( m_bUseLMChroma ); |
---|
652 | #endif |
---|
653 | #if !PPS_TS_FLAG |
---|
654 | m_cSPS.setUseTransformSkip ( m_useTransformSkip ); |
---|
655 | #endif |
---|
656 | |
---|
657 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
658 | |
---|
659 | m_cSPS.setUseLComb ( m_bUseLComb ); |
---|
660 | #if !REMOVE_NSQT |
---|
661 | m_cSPS.setUseNSQT( m_useNSQT ); |
---|
662 | #endif |
---|
663 | |
---|
664 | Int i; |
---|
665 | #if !SPS_AMVP_CLEANUP |
---|
666 | #if HHI_AMVP_OFF |
---|
667 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
668 | { |
---|
669 | m_cSPS.setAMVPMode( i, AM_NONE ); |
---|
670 | } |
---|
671 | #else |
---|
672 | for ( i = 0; i < g_uiMaxCUDepth; i++ ) |
---|
673 | { |
---|
674 | m_cSPS.setAMVPMode( i, AM_EXPL ); |
---|
675 | } |
---|
676 | #endif |
---|
677 | #endif |
---|
678 | |
---|
679 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
680 | { |
---|
681 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
682 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
683 | } |
---|
684 | |
---|
685 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
686 | |
---|
687 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
688 | { |
---|
689 | m_cSPS.setAMPAcc(i, 0); |
---|
690 | } |
---|
691 | |
---|
692 | m_cSPS.setBitDepth ( g_uiBitDepth ); |
---|
693 | m_cSPS.setBitIncrement( g_uiBitIncrement ); |
---|
694 | m_cSPS.setQpBDOffsetY ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
695 | m_cSPS.setQpBDOffsetC ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) ); |
---|
696 | |
---|
697 | #if !MOVE_LOOP_FILTER_SLICES_FLAG |
---|
698 | m_cSPS.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
699 | #endif |
---|
700 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
701 | |
---|
702 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
703 | m_cSPS.setTemporalIdNestingFlag( false ); |
---|
704 | for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ ) |
---|
705 | { |
---|
706 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
707 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
708 | } |
---|
709 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
710 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
711 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
712 | |
---|
713 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
714 | |
---|
715 | #if SUPPORT_FOR_VUI |
---|
716 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
717 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
718 | { |
---|
719 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
720 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1); |
---|
721 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
722 | pcVUI->setSarWidth(getSarWidth()); |
---|
723 | pcVUI->setSarHeight(getSarHeight()); |
---|
724 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
725 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
726 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
727 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
728 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
729 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
730 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
731 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
732 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
733 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
734 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
735 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
736 | pcVUI->setFieldSeqFlag(false); |
---|
737 | pcVUI->setHrdParametersPresentFlag(false); |
---|
738 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
739 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
740 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
741 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
742 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
743 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
744 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
745 | } |
---|
746 | #endif |
---|
747 | } |
---|
748 | |
---|
749 | Void TEncTop::xInitPPS() |
---|
750 | { |
---|
751 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
752 | #if !REMOVE_FGS |
---|
753 | m_cPPS.setSliceGranularity(m_iSliceGranularity); |
---|
754 | #endif |
---|
755 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
756 | |
---|
757 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
758 | |
---|
759 | if(getUseLossless()) |
---|
760 | { |
---|
761 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
762 | { |
---|
763 | bUseDQP = false; |
---|
764 | } |
---|
765 | else |
---|
766 | { |
---|
767 | bUseDQP = true; |
---|
768 | } |
---|
769 | } |
---|
770 | else |
---|
771 | { |
---|
772 | if(bUseDQP == false) |
---|
773 | { |
---|
774 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
775 | { |
---|
776 | bUseDQP = true; |
---|
777 | } |
---|
778 | } |
---|
779 | } |
---|
780 | |
---|
781 | if(bUseDQP) |
---|
782 | { |
---|
783 | m_cPPS.setUseDQP(true); |
---|
784 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
785 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
786 | } |
---|
787 | else |
---|
788 | { |
---|
789 | m_cPPS.setUseDQP(false); |
---|
790 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
791 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
792 | } |
---|
793 | |
---|
794 | m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); |
---|
795 | m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset ); |
---|
796 | |
---|
797 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
798 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
799 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
800 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
801 | #else |
---|
802 | m_cPPS.setTilesOrEntropyCodingSyncIdc( m_iWaveFrontSynchro ? 2 : ((m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ? 1 : 0)); |
---|
803 | #endif |
---|
804 | m_cPPS.setUseWP( m_bUseWeightPred ); |
---|
805 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
806 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
807 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
808 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
809 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
810 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
811 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
812 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
813 | #endif |
---|
814 | Int histogram[8]; |
---|
815 | for(Int i=0; i<8; i++) |
---|
816 | { |
---|
817 | histogram[i]=0; |
---|
818 | } |
---|
819 | for( Int i = 0; i < getGOPSize(); i++) |
---|
820 | { |
---|
821 | if(getGOPEntry(i).m_numRefPicsActive<8) |
---|
822 | { |
---|
823 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
824 | } |
---|
825 | } |
---|
826 | Int maxHist=-1; |
---|
827 | Int bestPos=0; |
---|
828 | for(Int i=0; i<8; i++) |
---|
829 | { |
---|
830 | if(histogram[i]>maxHist) |
---|
831 | { |
---|
832 | maxHist=histogram[i]; |
---|
833 | bestPos=i; |
---|
834 | } |
---|
835 | } |
---|
836 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
837 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
838 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
839 | #if PPS_TS_FLAG |
---|
840 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
841 | #endif |
---|
842 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
843 | if (m_iDependentSliceMode) |
---|
844 | { |
---|
845 | m_cPPS.setDependentSliceEnabledFlag( true ); |
---|
846 | m_cPPS.setEntropySliceEnabledFlag( m_entropySliceEnabledFlag ); |
---|
847 | } |
---|
848 | #else |
---|
849 | #if DEPENDENT_SLICES |
---|
850 | m_cPPS.setDependentSliceEnabledFlag( m_iDependentSliceMode ); |
---|
851 | m_cPPS.setCabacIndependentFlag( m_bCabacIndependentFlag ? 1 : 0 ); |
---|
852 | #endif |
---|
853 | #endif |
---|
854 | #if DEPENDENT_SLICES |
---|
855 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
856 | if( m_cPPS.getDependentSliceEnabledFlag()&&(!m_cPPS.getEntropySliceEnabledFlag()) ) |
---|
857 | #else |
---|
858 | if( m_cPPS.getDependentSliceEnabledFlag()&&(!m_cPPS.getCabacIndependentFlag()) ) |
---|
859 | #endif |
---|
860 | { |
---|
861 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
862 | int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1; |
---|
863 | #else |
---|
864 | int NumCtx = (m_cPPS.getTilesOrEntropyCodingSyncIdc() == 2)?2:1; |
---|
865 | #endif |
---|
866 | m_cSliceEncoder.initCtxMem( NumCtx ); |
---|
867 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
868 | { |
---|
869 | TEncSbac* ctx = NULL; |
---|
870 | ctx = new TEncSbac; |
---|
871 | ctx->init( &m_cBinCoderCABAC ); |
---|
872 | m_cSliceEncoder.setCtxMem( ctx, st ); |
---|
873 | } |
---|
874 | } |
---|
875 | #endif |
---|
876 | #if SVC_EXTENSION |
---|
877 | m_cPPS.setPPSId ( m_iPPSIdCnt ); |
---|
878 | m_cPPS.setSPSId ( m_iSPSIdCnt ); |
---|
879 | #endif |
---|
880 | } |
---|
881 | |
---|
882 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
883 | Void TEncTop::xInitRPS() |
---|
884 | { |
---|
885 | TComReferencePictureSet* rps; |
---|
886 | |
---|
887 | m_cSPS.createRPSList(getGOPSize()+m_extraRPSs); |
---|
888 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
889 | |
---|
890 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
891 | { |
---|
892 | GOPEntry ge = getGOPEntry(i); |
---|
893 | rps = rpsList->getReferencePictureSet(i); |
---|
894 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
895 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
896 | Int numNeg = 0; |
---|
897 | Int numPos = 0; |
---|
898 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
899 | { |
---|
900 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
901 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
902 | if(ge.m_referencePics[j]>0) |
---|
903 | { |
---|
904 | numPos++; |
---|
905 | } |
---|
906 | else |
---|
907 | { |
---|
908 | numNeg++; |
---|
909 | } |
---|
910 | } |
---|
911 | rps->setNumberOfNegativePictures(numNeg); |
---|
912 | rps->setNumberOfPositivePictures(numPos); |
---|
913 | |
---|
914 | // handle inter RPS intialization from the config file. |
---|
915 | #if AUTO_INTER_RPS |
---|
916 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
917 | #if J0234_INTER_RPS_SIMPL |
---|
918 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
919 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
920 | #else |
---|
921 | rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1); // index to the Reference RPS |
---|
922 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1)); // get the reference RPS |
---|
923 | #endif |
---|
924 | |
---|
925 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
926 | { |
---|
927 | #if J0234_INTER_RPS_SIMPL |
---|
928 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
929 | #else |
---|
930 | Int deltaRPS = getGOPEntry(i-(ge.m_deltaRIdxMinus1+1)).m_POC - ge.m_POC; // the ref POC - current POC |
---|
931 | #endif |
---|
932 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
933 | |
---|
934 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
935 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
936 | Int count=0; |
---|
937 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
938 | { |
---|
939 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
940 | rps->setRefIdc(j, 0); |
---|
941 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
942 | { |
---|
943 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
944 | { |
---|
945 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
946 | count++; |
---|
947 | break; |
---|
948 | } |
---|
949 | } |
---|
950 | } |
---|
951 | if (count != rps->getNumberOfPictures()) |
---|
952 | { |
---|
953 | printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file. Setting Inter RPS to false for this RPS.\n"); |
---|
954 | rps->setInterRPSPrediction(0); |
---|
955 | } |
---|
956 | } |
---|
957 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
958 | { |
---|
959 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
960 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
961 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
962 | { |
---|
963 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
964 | } |
---|
965 | #if WRITE_BACK |
---|
966 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
967 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
968 | numNeg = 0; |
---|
969 | numPos = 0; |
---|
970 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
971 | |
---|
972 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
973 | { |
---|
974 | if (ge.m_refIdc[j]) |
---|
975 | { |
---|
976 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
977 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
978 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
979 | if (deltaPOC<0) |
---|
980 | { |
---|
981 | numNeg++; |
---|
982 | } |
---|
983 | else |
---|
984 | { |
---|
985 | numPos++; |
---|
986 | } |
---|
987 | } |
---|
988 | } |
---|
989 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
990 | { |
---|
991 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
992 | rps->setNumberOfNegativePictures(numNeg); |
---|
993 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
994 | } |
---|
995 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
996 | { |
---|
997 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
998 | rps->setNumberOfPositivePictures(numPos); |
---|
999 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
1000 | } |
---|
1001 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1002 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1003 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1004 | // check if Delta POC and Used are the same |
---|
1005 | // print warning if they are not. |
---|
1006 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1007 | { |
---|
1008 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1009 | { |
---|
1010 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1011 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1012 | } |
---|
1013 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1014 | { |
---|
1015 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1016 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1017 | } |
---|
1018 | } |
---|
1019 | #endif |
---|
1020 | } |
---|
1021 | #else |
---|
1022 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
1023 | if (ge.m_interRPSPrediction) |
---|
1024 | { |
---|
1025 | #if J0234_INTER_RPS_SIMPL |
---|
1026 | rps->setDeltaRIdxMinus1(0); |
---|
1027 | #else |
---|
1028 | rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1); |
---|
1029 | #endif |
---|
1030 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1031 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1032 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1033 | { |
---|
1034 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1035 | } |
---|
1036 | #if WRITE_BACK |
---|
1037 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1038 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
1039 | numNeg = 0; |
---|
1040 | numPos = 0; |
---|
1041 | #if J0234_INTER_RPS_SIMPL |
---|
1042 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
1043 | #else |
---|
1044 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1)); |
---|
1045 | #endif |
---|
1046 | |
---|
1047 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1048 | { |
---|
1049 | if (ge.m_refIdc[j]) |
---|
1050 | { |
---|
1051 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1052 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1053 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1054 | if (deltaPOC<0) |
---|
1055 | { |
---|
1056 | numNeg++; |
---|
1057 | } |
---|
1058 | else |
---|
1059 | { |
---|
1060 | numPos++; |
---|
1061 | } |
---|
1062 | } |
---|
1063 | } |
---|
1064 | rps->setNumberOfNegativePictures(numNeg); |
---|
1065 | rps->setNumberOfPositivePictures(numPos); |
---|
1066 | rps->sortDeltaPOC(); |
---|
1067 | #endif |
---|
1068 | } |
---|
1069 | #endif //INTER_RPS_AUTO |
---|
1070 | } |
---|
1071 | |
---|
1072 | } |
---|
1073 | |
---|
1074 | // This is a function that |
---|
1075 | // determines what Reference Picture Set to use |
---|
1076 | // for a specific slice (with POC = POCCurr) |
---|
1077 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic ) |
---|
1078 | { |
---|
1079 | slice->setRPSidx(GOPid); |
---|
1080 | |
---|
1081 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1082 | { |
---|
1083 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1084 | { |
---|
1085 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1086 | if(POCIndex == 0) |
---|
1087 | { |
---|
1088 | POCIndex = m_uiIntraPeriod; |
---|
1089 | } |
---|
1090 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1091 | { |
---|
1092 | slice->setRPSidx(extraNum); |
---|
1093 | } |
---|
1094 | } |
---|
1095 | else |
---|
1096 | { |
---|
1097 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1098 | { |
---|
1099 | slice->setRPSidx(extraNum); |
---|
1100 | } |
---|
1101 | } |
---|
1102 | } |
---|
1103 | |
---|
1104 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1105 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1106 | |
---|
1107 | } |
---|
1108 | |
---|
1109 | Void TEncTop::xInitPPSforTiles() |
---|
1110 | { |
---|
1111 | m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr ); |
---|
1112 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1113 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1114 | if( m_iUniformSpacingIdr == 0 ) |
---|
1115 | { |
---|
1116 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1117 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1118 | } |
---|
1119 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1120 | |
---|
1121 | // # substreams is "per tile" when tiles are independent. |
---|
1122 | if (m_iWaveFrontSynchro |
---|
1123 | ) |
---|
1124 | { |
---|
1125 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
1126 | } |
---|
1127 | } |
---|
1128 | |
---|
1129 | Void TEncCfg::xCheckGSParameters() |
---|
1130 | { |
---|
1131 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1132 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1133 | UInt uiCummulativeColumnWidth = 0; |
---|
1134 | UInt uiCummulativeRowHeight = 0; |
---|
1135 | |
---|
1136 | //check the column relative parameters |
---|
1137 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1138 | { |
---|
1139 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1140 | exit( EXIT_FAILURE ); |
---|
1141 | } |
---|
1142 | |
---|
1143 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1144 | { |
---|
1145 | printf( "The current picture can not have so many columns.\n" ); |
---|
1146 | exit( EXIT_FAILURE ); |
---|
1147 | } |
---|
1148 | |
---|
1149 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1150 | { |
---|
1151 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1152 | { |
---|
1153 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1154 | } |
---|
1155 | |
---|
1156 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1157 | { |
---|
1158 | printf( "The width of the column is too large.\n" ); |
---|
1159 | exit( EXIT_FAILURE ); |
---|
1160 | } |
---|
1161 | } |
---|
1162 | |
---|
1163 | //check the row relative parameters |
---|
1164 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1165 | { |
---|
1166 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1167 | exit( EXIT_FAILURE ); |
---|
1168 | } |
---|
1169 | |
---|
1170 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1171 | { |
---|
1172 | printf( "The current picture can not have so many rows.\n" ); |
---|
1173 | exit( EXIT_FAILURE ); |
---|
1174 | } |
---|
1175 | |
---|
1176 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1177 | { |
---|
1178 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1179 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1180 | |
---|
1181 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1182 | { |
---|
1183 | printf( "The height of the row is too large.\n" ); |
---|
1184 | exit( EXIT_FAILURE ); |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | //! \} |
---|