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 TDecTop.cpp |
---|
35 | \brief decoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "NALread.h" |
---|
39 | #include "TDecTop.h" |
---|
40 | |
---|
41 | #if SVC_EXTENSION |
---|
42 | ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder; // storage for parameter sets |
---|
43 | UInt TDecTop::m_prevPOC = MAX_UINT; |
---|
44 | UInt TDecTop::m_uiPrevLayerId = MAX_UINT; |
---|
45 | Bool TDecTop::m_bFirstSliceInSequence = true; |
---|
46 | #endif |
---|
47 | |
---|
48 | //! \ingroup TLibDecoder |
---|
49 | //! \{ |
---|
50 | |
---|
51 | TDecTop::TDecTop() |
---|
52 | : m_SEIs(0) |
---|
53 | { |
---|
54 | m_pcPic = 0; |
---|
55 | m_iGopSize = 0; |
---|
56 | m_bGopSizeSet = false; |
---|
57 | m_iMaxRefPicNum = 0; |
---|
58 | #if ENC_DEC_TRACE |
---|
59 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
---|
60 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
61 | g_nSymbolCounter = 0; |
---|
62 | #endif |
---|
63 | m_bRefreshPending = 0; |
---|
64 | m_pocCRA = 0; |
---|
65 | m_prevRAPisBLA = false; |
---|
66 | m_pocRandomAccess = MAX_INT; |
---|
67 | #if !SVC_EXTENSION |
---|
68 | m_prevPOC = MAX_INT; |
---|
69 | #endif |
---|
70 | m_bFirstSliceInPicture = true; |
---|
71 | #if !SVC_EXTENSION |
---|
72 | m_bFirstSliceInSequence = true; |
---|
73 | #endif |
---|
74 | #if SVC_EXTENSION |
---|
75 | m_layerId = 0; |
---|
76 | #if AVC_BASE |
---|
77 | m_pBLReconFile = NULL; |
---|
78 | #endif |
---|
79 | #endif |
---|
80 | #if REF_IDX_FRAMEWORK |
---|
81 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
82 | #endif |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | TDecTop::~TDecTop() |
---|
87 | { |
---|
88 | #if ENC_DEC_TRACE |
---|
89 | fclose( g_hTrace ); |
---|
90 | #endif |
---|
91 | } |
---|
92 | |
---|
93 | Void TDecTop::create() |
---|
94 | { |
---|
95 | #if SVC_EXTENSION |
---|
96 | m_cGopDecoder.create( m_layerId ); |
---|
97 | #else |
---|
98 | m_cGopDecoder.create(); |
---|
99 | #endif |
---|
100 | m_apcSlicePilot = new TComSlice; |
---|
101 | m_uiSliceIdx = 0; |
---|
102 | } |
---|
103 | |
---|
104 | Void TDecTop::destroy() |
---|
105 | { |
---|
106 | m_cGopDecoder.destroy(); |
---|
107 | |
---|
108 | delete m_apcSlicePilot; |
---|
109 | m_apcSlicePilot = NULL; |
---|
110 | |
---|
111 | m_cSliceDecoder.destroy(); |
---|
112 | #if REF_IDX_FRAMEWORK |
---|
113 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
114 | { |
---|
115 | if(m_cIlpPic[i]) |
---|
116 | { |
---|
117 | //m_cIlpPic[i]->setPicYuvRec(NULL); |
---|
118 | m_cIlpPic[i]->destroy(); |
---|
119 | delete m_cIlpPic[i]; |
---|
120 | m_cIlpPic[i] = NULL; |
---|
121 | } |
---|
122 | } |
---|
123 | #endif |
---|
124 | } |
---|
125 | |
---|
126 | Void TDecTop::init() |
---|
127 | { |
---|
128 | #if !SVC_EXTENSION |
---|
129 | // initialize ROM |
---|
130 | initROM(); |
---|
131 | #endif |
---|
132 | #if SVC_EXTENSION |
---|
133 | #if REMOVE_ALF |
---|
134 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
135 | #else |
---|
136 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO); |
---|
137 | #endif |
---|
138 | m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
139 | #else |
---|
140 | #if REMOVE_ALF |
---|
141 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
142 | #else |
---|
143 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO); |
---|
144 | #endif |
---|
145 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
146 | #endif |
---|
147 | m_cEntropyDecoder.init(&m_cPrediction); |
---|
148 | } |
---|
149 | |
---|
150 | #if REF_IDX_FRAMEWORK |
---|
151 | Void TDecTop::xInitILRP(TComSPS *pcSPS) |
---|
152 | { |
---|
153 | if(m_layerId>0) |
---|
154 | { |
---|
155 | if (m_cIlpPic[0] == NULL) |
---|
156 | { |
---|
157 | for (Int j=0; j<1/*MAX_NUM_REF*/; j++) |
---|
158 | { |
---|
159 | m_cIlpPic[j] = new TComPic; |
---|
160 | //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true); |
---|
161 | #if SVC_UPSAMPLING |
---|
162 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSPS, true); |
---|
163 | #else |
---|
164 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
165 | #endif |
---|
166 | #if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV |
---|
167 | m_cIlpPic[j]->setIsILR(true); |
---|
168 | #endif |
---|
169 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
170 | { |
---|
171 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | Void TDecTop::setILRPic(TComPic *pcPic) |
---|
179 | { |
---|
180 | if(m_cIlpPic[0]) |
---|
181 | { |
---|
182 | //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec()); |
---|
183 | m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec()); |
---|
184 | m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC()); |
---|
185 | m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false); |
---|
186 | m_cIlpPic[0]->getPicYuvRec()->extendPicBorder(); |
---|
187 | } |
---|
188 | } |
---|
189 | #endif |
---|
190 | |
---|
191 | Void TDecTop::deletePicBuffer ( ) |
---|
192 | { |
---|
193 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
194 | Int iSize = Int( m_cListPic.size() ); |
---|
195 | |
---|
196 | for (Int i = 0; i < iSize; i++ ) |
---|
197 | { |
---|
198 | TComPic* pcPic = *(iterPic++); |
---|
199 | #if SVC_EXTENSION |
---|
200 | if( pcPic ) |
---|
201 | { |
---|
202 | pcPic->destroy(); |
---|
203 | |
---|
204 | delete pcPic; |
---|
205 | pcPic = NULL; |
---|
206 | } |
---|
207 | #else |
---|
208 | pcPic->destroy(); |
---|
209 | |
---|
210 | delete pcPic; |
---|
211 | pcPic = NULL; |
---|
212 | #endif |
---|
213 | } |
---|
214 | |
---|
215 | #if !REMOVE_ALF |
---|
216 | // destroy ALF temporary buffers |
---|
217 | m_cAdaptiveLoopFilter.destroy(); |
---|
218 | #endif |
---|
219 | |
---|
220 | m_cSAO.destroy(); |
---|
221 | |
---|
222 | m_cLoopFilter. destroy(); |
---|
223 | |
---|
224 | #if !SVC_EXTENSION |
---|
225 | // destroy ROM |
---|
226 | destroyROM(); |
---|
227 | #endif |
---|
228 | } |
---|
229 | |
---|
230 | Void TDecTop::xUpdateGopSize (TComSlice* pcSlice) |
---|
231 | { |
---|
232 | if ( !pcSlice->isIntra() && !m_bGopSizeSet) |
---|
233 | { |
---|
234 | m_iGopSize = pcSlice->getPOC(); |
---|
235 | m_bGopSizeSet = true; |
---|
236 | |
---|
237 | m_cGopDecoder.setGopSize(m_iGopSize); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic ) |
---|
242 | { |
---|
243 | xUpdateGopSize(pcSlice); |
---|
244 | |
---|
245 | m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded |
---|
246 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
---|
247 | { |
---|
248 | rpcPic = new TComPic(); |
---|
249 | |
---|
250 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
251 | if(m_layerId > 0) |
---|
252 | { |
---|
253 | TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 ); |
---|
254 | //TComPic* pcPic = *(pcTDecTopBase->getListPic()->begin()); |
---|
255 | TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); |
---|
256 | if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() ) |
---|
257 | { |
---|
258 | rpcPic->setSpatialEnhLayerFlag( true ); |
---|
259 | } |
---|
260 | } |
---|
261 | #endif |
---|
262 | |
---|
263 | #if SVC_UPSAMPLING |
---|
264 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true); |
---|
265 | #else |
---|
266 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
267 | #endif |
---|
268 | |
---|
269 | #if REMOVE_APS |
---|
270 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
271 | #endif |
---|
272 | m_cListPic.pushBack( rpcPic ); |
---|
273 | |
---|
274 | return; |
---|
275 | } |
---|
276 | |
---|
277 | Bool bBufferIsAvailable = false; |
---|
278 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
279 | while (iterPic != m_cListPic.end()) |
---|
280 | { |
---|
281 | rpcPic = *(iterPic++); |
---|
282 | if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false) |
---|
283 | { |
---|
284 | rpcPic->setOutputMark(false); |
---|
285 | bBufferIsAvailable = true; |
---|
286 | break; |
---|
287 | } |
---|
288 | |
---|
289 | if ( rpcPic->getSlice( 0 )->isReferenced() == false && rpcPic->getOutputMark() == false) |
---|
290 | { |
---|
291 | #if !SVC_EXTENSION |
---|
292 | rpcPic->setOutputMark(false); |
---|
293 | #endif |
---|
294 | rpcPic->setReconMark( false ); |
---|
295 | rpcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
296 | bBufferIsAvailable = true; |
---|
297 | break; |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | if ( !bBufferIsAvailable ) |
---|
302 | { |
---|
303 | //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer. |
---|
304 | m_iMaxRefPicNum++; |
---|
305 | rpcPic = new TComPic(); |
---|
306 | m_cListPic.pushBack( rpcPic ); |
---|
307 | } |
---|
308 | rpcPic->destroy(); |
---|
309 | |
---|
310 | #if SVC_UPSAMPLING |
---|
311 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true); |
---|
312 | #else |
---|
313 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
314 | #endif |
---|
315 | #if REMOVE_APS |
---|
316 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
317 | #endif |
---|
318 | } |
---|
319 | |
---|
320 | Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
321 | { |
---|
322 | if (!m_pcPic) |
---|
323 | { |
---|
324 | /* nothing to deblock */ |
---|
325 | return; |
---|
326 | } |
---|
327 | |
---|
328 | TComPic*& pcPic = m_pcPic; |
---|
329 | |
---|
330 | // Execute Deblock and ALF only + Cleanup |
---|
331 | |
---|
332 | m_cGopDecoder.filterPicture(pcPic); |
---|
333 | |
---|
334 | TComSlice::sortPicList( m_cListPic ); // sorting for application output |
---|
335 | ruiPOC = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
---|
336 | rpcListPic = &m_cListPic; |
---|
337 | m_cCuDecoder.destroy(); |
---|
338 | m_bFirstSliceInPicture = true; |
---|
339 | |
---|
340 | return; |
---|
341 | } |
---|
342 | |
---|
343 | Void TDecTop::xCreateLostPicture(Int iLostPoc) |
---|
344 | { |
---|
345 | printf("\ninserting lost poc : %d\n",iLostPoc); |
---|
346 | TComSlice cFillSlice; |
---|
347 | cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
348 | cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
349 | #if SET_SLICE_LAYER_ID |
---|
350 | cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() ); |
---|
351 | #else |
---|
352 | cFillSlice.initSlice(); |
---|
353 | #endif |
---|
354 | TComPic *cFillPic; |
---|
355 | xGetNewPicBuffer(&cFillSlice,cFillPic); |
---|
356 | cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
357 | cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
358 | #if SET_SLICE_LAYER_ID |
---|
359 | cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() ); |
---|
360 | #else |
---|
361 | cFillPic->getSlice(0)->initSlice(); |
---|
362 | #endif |
---|
363 | |
---|
364 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
365 | Int closestPoc = 1000000; |
---|
366 | while ( iterPic != m_cListPic.end()) |
---|
367 | { |
---|
368 | TComPic * rpcPic = *(iterPic++); |
---|
369 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)<closestPoc&&abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)!=0&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
370 | { |
---|
371 | closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc); |
---|
372 | } |
---|
373 | } |
---|
374 | iterPic = m_cListPic.begin(); |
---|
375 | while ( iterPic != m_cListPic.end()) |
---|
376 | { |
---|
377 | TComPic *rpcPic = *(iterPic++); |
---|
378 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
379 | { |
---|
380 | printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC()); |
---|
381 | rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec()); |
---|
382 | break; |
---|
383 | } |
---|
384 | } |
---|
385 | cFillPic->setCurrSliceIdx(0); |
---|
386 | for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) |
---|
387 | { |
---|
388 | cFillPic->getCU(i)->initCU(cFillPic,i); |
---|
389 | } |
---|
390 | cFillPic->getSlice(0)->setReferenced(true); |
---|
391 | cFillPic->getSlice(0)->setPOC(iLostPoc); |
---|
392 | cFillPic->setReconMark(true); |
---|
393 | cFillPic->setOutputMark(true); |
---|
394 | if(m_pocRandomAccess == MAX_INT) |
---|
395 | { |
---|
396 | m_pocRandomAccess = iLostPoc; |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | |
---|
401 | Void TDecTop::xActivateParameterSets() |
---|
402 | { |
---|
403 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
---|
404 | |
---|
405 | TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId()); |
---|
406 | assert (pps != 0); |
---|
407 | |
---|
408 | TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId()); |
---|
409 | assert (sps != 0); |
---|
410 | |
---|
411 | m_apcSlicePilot->setPPS(pps); |
---|
412 | m_apcSlicePilot->setSPS(sps); |
---|
413 | pps->setSPS(sps); |
---|
414 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
415 | pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
---|
416 | #else |
---|
417 | pps->setNumSubstreams(pps->getTilesOrEntropyCodingSyncIdc() == 2 ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
---|
418 | #endif |
---|
419 | #if !REMOVE_APS |
---|
420 | #if REMOVE_ALF |
---|
421 | if(sps->getUseSAO()) |
---|
422 | #else |
---|
423 | if(sps->getUseSAO() || sps->getUseALF()) |
---|
424 | #endif |
---|
425 | { |
---|
426 | m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId()) ); |
---|
427 | } |
---|
428 | #endif |
---|
429 | pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) ); |
---|
430 | |
---|
431 | for (Int i = 0; i < sps->getMaxCUDepth() - g_uiAddCUDepth; i++) |
---|
432 | { |
---|
433 | sps->setAMPAcc( i, sps->getUseAMP() ); |
---|
434 | } |
---|
435 | |
---|
436 | for (Int i = sps->getMaxCUDepth() - g_uiAddCUDepth; i < sps->getMaxCUDepth(); i++) |
---|
437 | { |
---|
438 | sps->setAMPAcc( i, 0 ); |
---|
439 | } |
---|
440 | |
---|
441 | m_cSAO.destroy(); |
---|
442 | m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
443 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
444 | } |
---|
445 | |
---|
446 | #if SVC_EXTENSION |
---|
447 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC ) |
---|
448 | #else |
---|
449 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) |
---|
450 | #endif |
---|
451 | { |
---|
452 | TComPic*& pcPic = m_pcPic; |
---|
453 | #if SET_SLICE_LAYER_ID |
---|
454 | m_apcSlicePilot->initSlice( nalu.m_layerId ); |
---|
455 | #else |
---|
456 | m_apcSlicePilot->initSlice(); |
---|
457 | #endif |
---|
458 | |
---|
459 | if (m_bFirstSliceInPicture) |
---|
460 | { |
---|
461 | m_uiSliceIdx = 0; |
---|
462 | } |
---|
463 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
464 | if (!m_bFirstSliceInPicture) |
---|
465 | { |
---|
466 | m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); |
---|
467 | } |
---|
468 | |
---|
469 | m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); |
---|
470 | #if TEMPORAL_LAYER_NON_REFERENCE |
---|
471 | if((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N) || |
---|
472 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) || |
---|
473 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N)) |
---|
474 | { |
---|
475 | m_apcSlicePilot->setTemporalLayerNonReferenceFlag(true); |
---|
476 | } |
---|
477 | #endif |
---|
478 | #if REMOVE_NAL_REF_FLAG |
---|
479 | m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS |
---|
480 | #else |
---|
481 | m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag); |
---|
482 | #endif |
---|
483 | m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId); |
---|
484 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder); |
---|
485 | #if !BYTE_ALIGNMENT |
---|
486 | // byte align |
---|
487 | { |
---|
488 | Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned(); |
---|
489 | if ( numBitsForByteAlignment > 0 ) |
---|
490 | { |
---|
491 | UInt bitsForByteAlignment; |
---|
492 | nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment ); |
---|
493 | assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) ); |
---|
494 | } |
---|
495 | } |
---|
496 | #endif |
---|
497 | // exit when a new picture is found |
---|
498 | #if SVC_EXTENSION |
---|
499 | bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC); |
---|
500 | if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) |
---|
501 | && !m_bFirstSliceInSequence ) |
---|
502 | { |
---|
503 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
504 | curLayerId = m_uiPrevLayerId; |
---|
505 | m_uiPrevLayerId = m_layerId; |
---|
506 | return true; |
---|
507 | } |
---|
508 | #else |
---|
509 | if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence) |
---|
510 | { |
---|
511 | if (m_prevPOC >= m_pocRandomAccess) |
---|
512 | { |
---|
513 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
514 | return true; |
---|
515 | } |
---|
516 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
517 | } |
---|
518 | #endif |
---|
519 | // actual decoding starts here |
---|
520 | xActivateParameterSets(); |
---|
521 | |
---|
522 | if (m_apcSlicePilot->isNextSlice()) |
---|
523 | { |
---|
524 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
525 | #if SVC_EXTENSION |
---|
526 | curLayerId = m_layerId; |
---|
527 | m_uiPrevLayerId = m_layerId; |
---|
528 | #endif |
---|
529 | } |
---|
530 | m_bFirstSliceInSequence = false; |
---|
531 | if (m_apcSlicePilot->isNextSlice()) |
---|
532 | { |
---|
533 | // Skip pictures due to random access |
---|
534 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
---|
535 | { |
---|
536 | return false; |
---|
537 | } |
---|
538 | // Skip TFD pictures associated with BLA/BLANT pictures |
---|
539 | if (isSkipPictureForBLA(iPOCLastDisplay)) |
---|
540 | { |
---|
541 | return false; |
---|
542 | } |
---|
543 | } |
---|
544 | //detect lost reference picture and insert copy of earlier frame. |
---|
545 | Int lostPoc; |
---|
546 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
---|
547 | { |
---|
548 | xCreateLostPicture(lostPoc-1); |
---|
549 | } |
---|
550 | if (m_bFirstSliceInPicture) |
---|
551 | { |
---|
552 | |
---|
553 | #if AVC_BASE |
---|
554 | if( m_layerId == 1 ) |
---|
555 | { |
---|
556 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
557 | FILE* pFile = m_ppcTDecTop[0]->getBLReconFile(); |
---|
558 | UInt uiWidth = pBLPic->getPicYuvRec()->getWidth(); |
---|
559 | UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(); |
---|
560 | |
---|
561 | if( pFile ) |
---|
562 | { |
---|
563 | fseek( pFile, m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2, SEEK_SET ); |
---|
564 | |
---|
565 | Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr(); |
---|
566 | UInt uiStride = pBLPic->getPicYuvRec()->getStride(); |
---|
567 | for( Int i = 0; i < uiHeight; i++ ) |
---|
568 | { |
---|
569 | for( Int j = 0; j < uiWidth; j++ ) |
---|
570 | { |
---|
571 | pPel[j] = fgetc( pFile ); |
---|
572 | } |
---|
573 | pPel += uiStride; |
---|
574 | } |
---|
575 | |
---|
576 | pPel = pBLPic->getPicYuvRec()->getCbAddr(); |
---|
577 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
---|
578 | for( Int i = 0; i < uiHeight/2; i++ ) |
---|
579 | { |
---|
580 | for( Int j = 0; j < uiWidth/2; j++ ) |
---|
581 | { |
---|
582 | pPel[j] = fgetc( pFile ); |
---|
583 | } |
---|
584 | pPel += uiStride; |
---|
585 | } |
---|
586 | |
---|
587 | pPel = pBLPic->getPicYuvRec()->getCrAddr(); |
---|
588 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
---|
589 | for( Int i = 0; i < uiHeight/2; i++ ) |
---|
590 | { |
---|
591 | for( Int j = 0; j < uiWidth/2; j++ ) |
---|
592 | { |
---|
593 | pPel[j] = fgetc( pFile ); |
---|
594 | } |
---|
595 | pPel += uiStride; |
---|
596 | } |
---|
597 | } |
---|
598 | } |
---|
599 | #endif |
---|
600 | |
---|
601 | // Buffer initialize for prediction. |
---|
602 | m_cPrediction.initTempBuff(); |
---|
603 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
---|
604 | // Get a new picture buffer |
---|
605 | xGetNewPicBuffer (m_apcSlicePilot, pcPic); |
---|
606 | |
---|
607 | /* transfer any SEI messages that have been received to the picture */ |
---|
608 | pcPic->setSEIs(m_SEIs); |
---|
609 | m_SEIs = NULL; |
---|
610 | |
---|
611 | // Recursive structure |
---|
612 | m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
613 | #if SVC_EXTENSION |
---|
614 | m_cCuDecoder.init ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId ); |
---|
615 | #else |
---|
616 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
---|
617 | #endif |
---|
618 | m_cTrQuant.init ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize()); |
---|
619 | |
---|
620 | m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
621 | } |
---|
622 | |
---|
623 | // Set picture slice pointer |
---|
624 | TComSlice* pcSlice = m_apcSlicePilot; |
---|
625 | Bool bNextSlice = pcSlice->isNextSlice(); |
---|
626 | |
---|
627 | UInt uiCummulativeTileWidth; |
---|
628 | UInt uiCummulativeTileHeight; |
---|
629 | UInt i, j, p; |
---|
630 | |
---|
631 | //set NumColumnsMins1 and NumRowsMinus1 |
---|
632 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
633 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
634 | |
---|
635 | //create the TComTileArray |
---|
636 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
637 | |
---|
638 | if( pcSlice->getPPS()->getUniformSpacingFlag() ) |
---|
639 | { |
---|
640 | //set the width for each tile |
---|
641 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
642 | { |
---|
643 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
644 | { |
---|
645 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
646 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
647 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
648 | } |
---|
649 | } |
---|
650 | |
---|
651 | //set the height for each tile |
---|
652 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
653 | { |
---|
654 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
655 | { |
---|
656 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
657 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
658 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | else |
---|
663 | { |
---|
664 | //set the width for each tile |
---|
665 | for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++) |
---|
666 | { |
---|
667 | uiCummulativeTileWidth = 0; |
---|
668 | for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++) |
---|
669 | { |
---|
670 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) ); |
---|
671 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i); |
---|
672 | } |
---|
673 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
674 | } |
---|
675 | |
---|
676 | //set the height for each tile |
---|
677 | for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++) |
---|
678 | { |
---|
679 | uiCummulativeTileHeight = 0; |
---|
680 | for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++) |
---|
681 | { |
---|
682 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) ); |
---|
683 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i); |
---|
684 | } |
---|
685 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
686 | } |
---|
687 | } |
---|
688 | |
---|
689 | pcPic->getPicSym()->xInitTiles(); |
---|
690 | |
---|
691 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
692 | UInt uiEncCUAddr; |
---|
693 | for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
694 | { |
---|
695 | pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr); |
---|
696 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i); |
---|
697 | } |
---|
698 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
699 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
700 | |
---|
701 | //convert the start and end CU addresses of the slice and dependent slice into encoding order |
---|
702 | pcSlice->setDependentSliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurStartCUAddr()) ); |
---|
703 | pcSlice->setDependentSliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurEndCUAddr()) ); |
---|
704 | if(pcSlice->isNextSlice()) |
---|
705 | { |
---|
706 | pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr())); |
---|
707 | pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr())); |
---|
708 | } |
---|
709 | |
---|
710 | if (m_bFirstSliceInPicture) |
---|
711 | { |
---|
712 | if(pcPic->getNumAllocatedSlice() != 1) |
---|
713 | { |
---|
714 | pcPic->clearSliceBuffer(); |
---|
715 | } |
---|
716 | } |
---|
717 | else |
---|
718 | { |
---|
719 | pcPic->allocateNewSlice(); |
---|
720 | } |
---|
721 | assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
722 | m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
---|
723 | pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx); |
---|
724 | |
---|
725 | pcPic->setTLayer(nalu.m_temporalId); |
---|
726 | |
---|
727 | #if SVC_EXTENSION |
---|
728 | pcPic->setLayerId(nalu.m_layerId); |
---|
729 | pcSlice->setLayerId(nalu.m_layerId); |
---|
730 | #endif |
---|
731 | |
---|
732 | if (bNextSlice) |
---|
733 | { |
---|
734 | pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic); |
---|
735 | #if !REF_IDX_FRAMEWORK |
---|
736 | // Set reference list |
---|
737 | pcSlice->setRefPicList( m_cListPic ); |
---|
738 | #endif |
---|
739 | |
---|
740 | #if SVC_EXTENSION |
---|
741 | if(m_layerId > 0) |
---|
742 | { |
---|
743 | #if AVC_BASE |
---|
744 | pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() ); |
---|
745 | #else |
---|
746 | TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 ); |
---|
747 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
748 | pcSlice->setBaseColPic ( *cListPic, m_layerId ); |
---|
749 | #endif |
---|
750 | #if SVC_UPSAMPLING |
---|
751 | if ( pcPic->isSpatialEnhLayer()) |
---|
752 | { |
---|
753 | m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() ); |
---|
754 | } |
---|
755 | else |
---|
756 | { |
---|
757 | pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() ); |
---|
758 | } |
---|
759 | pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() ); |
---|
760 | #endif |
---|
761 | } |
---|
762 | #endif |
---|
763 | |
---|
764 | #if REF_IDX_FRAMEWORK |
---|
765 | // Set reference list |
---|
766 | pcSlice->setRefPicList( m_cListPic ); |
---|
767 | if(m_layerId > 0) |
---|
768 | { |
---|
769 | setILRPic(pcPic); |
---|
770 | pcSlice->addRefPicList ( m_cIlpPic, |
---|
771 | 1, |
---|
772 | ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && |
---|
773 | (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1); |
---|
774 | } |
---|
775 | #endif |
---|
776 | |
---|
777 | // For generalized B |
---|
778 | // note: maybe not existed case (always L0 is copied to L1 if L1 is empty) |
---|
779 | if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) |
---|
780 | { |
---|
781 | Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0); |
---|
782 | pcSlice->setNumRefIdx ( REF_PIC_LIST_1, iNumRefIdx ); |
---|
783 | |
---|
784 | for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++) |
---|
785 | { |
---|
786 | pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx); |
---|
787 | } |
---|
788 | } |
---|
789 | if (pcSlice->isInterB()) |
---|
790 | { |
---|
791 | Bool bLowDelay = true; |
---|
792 | Int iCurrPOC = pcSlice->getPOC(); |
---|
793 | Int iRefIdx = 0; |
---|
794 | |
---|
795 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
796 | { |
---|
797 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
798 | { |
---|
799 | bLowDelay = false; |
---|
800 | } |
---|
801 | } |
---|
802 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
803 | { |
---|
804 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
805 | { |
---|
806 | bLowDelay = false; |
---|
807 | } |
---|
808 | } |
---|
809 | |
---|
810 | pcSlice->setCheckLDC(bLowDelay); |
---|
811 | } |
---|
812 | |
---|
813 | //--------------- |
---|
814 | pcSlice->setRefPOCList(); |
---|
815 | pcSlice->setNoBackPredFlag( false ); |
---|
816 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
817 | { |
---|
818 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
819 | { |
---|
820 | pcSlice->setNoBackPredFlag( true ); |
---|
821 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
822 | { |
---|
823 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
824 | { |
---|
825 | pcSlice->setNoBackPredFlag( false ); |
---|
826 | break; |
---|
827 | } |
---|
828 | } |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | |
---|
833 | pcPic->setCurrSliceIdx(m_uiSliceIdx); |
---|
834 | if(pcSlice->getSPS()->getScalingListFlag()) |
---|
835 | { |
---|
836 | pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList() ); |
---|
837 | if(pcSlice->getPPS()->getScalingListPresentFlag()) |
---|
838 | { |
---|
839 | pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList() ); |
---|
840 | } |
---|
841 | #if TS_FLAT_QUANTIZATION_MATRIX |
---|
842 | pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip()); |
---|
843 | #endif |
---|
844 | if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag()) |
---|
845 | { |
---|
846 | pcSlice->setDefaultScalingList(); |
---|
847 | } |
---|
848 | m_cTrQuant.setScalingListDec(pcSlice->getScalingList()); |
---|
849 | m_cTrQuant.setUseScalingList(true); |
---|
850 | } |
---|
851 | else |
---|
852 | { |
---|
853 | m_cTrQuant.setFlatScalingList(); |
---|
854 | m_cTrQuant.setUseScalingList(false); |
---|
855 | } |
---|
856 | |
---|
857 | // Decode a picture |
---|
858 | m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic); |
---|
859 | |
---|
860 | m_bFirstSliceInPicture = false; |
---|
861 | m_uiSliceIdx++; |
---|
862 | |
---|
863 | return false; |
---|
864 | } |
---|
865 | |
---|
866 | Void TDecTop::xDecodeVPS() |
---|
867 | { |
---|
868 | TComVPS* vps = new TComVPS(); |
---|
869 | |
---|
870 | m_cEntropyDecoder.decodeVPS( vps ); |
---|
871 | m_parameterSetManagerDecoder.storePrefetchedVPS(vps); |
---|
872 | } |
---|
873 | |
---|
874 | Void TDecTop::xDecodeSPS() |
---|
875 | { |
---|
876 | TComSPS* sps = new TComSPS(); |
---|
877 | #if SVC_EXTENSION |
---|
878 | sps->setLayerId(m_layerId); |
---|
879 | #endif |
---|
880 | m_cEntropyDecoder.decodeSPS( sps ); |
---|
881 | m_parameterSetManagerDecoder.storePrefetchedSPS(sps); |
---|
882 | #if !REMOVE_ALF |
---|
883 | m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
884 | #endif |
---|
885 | #if REF_IDX_FRAMEWORK |
---|
886 | if(m_numLayer>0) |
---|
887 | { |
---|
888 | xInitILRP(sps); |
---|
889 | } |
---|
890 | #endif |
---|
891 | } |
---|
892 | |
---|
893 | Void TDecTop::xDecodePPS() |
---|
894 | { |
---|
895 | TComPPS* pps = new TComPPS(); |
---|
896 | m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder ); |
---|
897 | m_parameterSetManagerDecoder.storePrefetchedPPS( pps ); |
---|
898 | |
---|
899 | #if DEPENDENT_SLICES |
---|
900 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
901 | if( pps->getDependentSliceEnabledFlag() && (!pps->getEntropySliceEnabledFlag()) ) |
---|
902 | #else |
---|
903 | if( pps->getDependentSliceEnabledFlag() && (!pps->getCabacIndependentFlag()) ) |
---|
904 | #endif |
---|
905 | { |
---|
906 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
907 | int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1; |
---|
908 | #else |
---|
909 | int NumCtx = (pps->getTilesOrEntropyCodingSyncIdc() == 2)?2:1; |
---|
910 | #endif |
---|
911 | m_cSliceDecoder.initCtxMem(NumCtx); |
---|
912 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
913 | { |
---|
914 | TDecSbac* ctx = NULL; |
---|
915 | ctx = new TDecSbac; |
---|
916 | ctx->init( &m_cBinCABAC ); |
---|
917 | m_cSliceDecoder.setCtxMem( ctx, st ); |
---|
918 | } |
---|
919 | } |
---|
920 | #endif |
---|
921 | } |
---|
922 | |
---|
923 | #if !REMOVE_APS |
---|
924 | Void TDecTop::xDecodeAPS() |
---|
925 | { |
---|
926 | TComAPS *aps = new TComAPS(); |
---|
927 | allocAPS (aps); |
---|
928 | decodeAPS(aps); |
---|
929 | m_parameterSetManagerDecoder.storePrefetchedAPS(aps); |
---|
930 | } |
---|
931 | #endif |
---|
932 | |
---|
933 | Void TDecTop::xDecodeSEI( TComInputBitstream* bs ) |
---|
934 | { |
---|
935 | #if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI |
---|
936 | if ( m_SEIs == NULL ) |
---|
937 | #endif |
---|
938 | m_SEIs = new SEImessages; |
---|
939 | #if BUFFERING_PERIOD_AND_TIMING_SEI |
---|
940 | m_SEIs->m_pSPS = m_parameterSetManagerDecoder.getSPS(0); |
---|
941 | #endif |
---|
942 | m_seiReader.parseSEImessage( bs, *m_SEIs ); |
---|
943 | } |
---|
944 | |
---|
945 | #if SVC_EXTENSION |
---|
946 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC) |
---|
947 | #else |
---|
948 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
949 | #endif |
---|
950 | { |
---|
951 | // Initialize entropy decoder |
---|
952 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
---|
953 | m_cEntropyDecoder.setBitstream (nalu.m_Bitstream); |
---|
954 | |
---|
955 | switch (nalu.m_nalUnitType) |
---|
956 | { |
---|
957 | case NAL_UNIT_VPS: |
---|
958 | xDecodeVPS(); |
---|
959 | return false; |
---|
960 | |
---|
961 | case NAL_UNIT_SPS: |
---|
962 | xDecodeSPS(); |
---|
963 | #if AVC_BASE |
---|
964 | { |
---|
965 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
966 | if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL ) |
---|
967 | { |
---|
968 | #if SVC_UPSAMPLING |
---|
969 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true); |
---|
970 | #else |
---|
971 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
972 | #endif |
---|
973 | } |
---|
974 | } |
---|
975 | #endif |
---|
976 | return false; |
---|
977 | |
---|
978 | case NAL_UNIT_PPS: |
---|
979 | xDecodePPS(); |
---|
980 | return false; |
---|
981 | #if !REMOVE_APS |
---|
982 | case NAL_UNIT_APS: |
---|
983 | xDecodeAPS(); |
---|
984 | return false; |
---|
985 | #endif |
---|
986 | |
---|
987 | case NAL_UNIT_SEI: |
---|
988 | xDecodeSEI( nalu.m_Bitstream ); |
---|
989 | return false; |
---|
990 | |
---|
991 | #if NAL_UNIT_TYPES_J1003_D7 |
---|
992 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
993 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
994 | case NAL_UNIT_CODED_SLICE_TLA: |
---|
995 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
996 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
997 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
998 | case NAL_UNIT_CODED_SLICE_BLA: |
---|
999 | case NAL_UNIT_CODED_SLICE_BLANT: |
---|
1000 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
1001 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
1002 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
1003 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
1004 | case NAL_UNIT_CODED_SLICE_DLP: |
---|
1005 | case NAL_UNIT_CODED_SLICE_TFD: |
---|
1006 | #else |
---|
1007 | case NAL_UNIT_CODED_SLICE: |
---|
1008 | case NAL_UNIT_CODED_SLICE_TFD: |
---|
1009 | case NAL_UNIT_CODED_SLICE_TLA: |
---|
1010 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
1011 | case NAL_UNIT_CODED_SLICE_CRANT: |
---|
1012 | case NAL_UNIT_CODED_SLICE_BLA: |
---|
1013 | case NAL_UNIT_CODED_SLICE_BLANT: |
---|
1014 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
1015 | #endif |
---|
1016 | #if SVC_EXTENSION |
---|
1017 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC); |
---|
1018 | #else |
---|
1019 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay); |
---|
1020 | #endif |
---|
1021 | break; |
---|
1022 | default: |
---|
1023 | assert (1); |
---|
1024 | } |
---|
1025 | |
---|
1026 | return false; |
---|
1027 | } |
---|
1028 | |
---|
1029 | /** Function for checking if picture should be skipped because of association with a previous BLA picture |
---|
1030 | * \param iPOCLastDisplay POC of last picture displayed |
---|
1031 | * \returns true if the picture should be skipped |
---|
1032 | * This function skips all TFD pictures that follow a BLA picture |
---|
1033 | * in decoding order and precede it in output order. |
---|
1034 | */ |
---|
1035 | Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay) |
---|
1036 | { |
---|
1037 | if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD) |
---|
1038 | { |
---|
1039 | iPOCLastDisplay++; |
---|
1040 | return true; |
---|
1041 | } |
---|
1042 | return false; |
---|
1043 | } |
---|
1044 | |
---|
1045 | /** Function for checking if picture should be skipped because of random access |
---|
1046 | * \param iSkipFrame skip frame counter |
---|
1047 | * \param iPOCLastDisplay POC of last picture displayed |
---|
1048 | * \returns true if the picture shold be skipped in the random access. |
---|
1049 | * This function checks the skipping of pictures in the case of -s option random access. |
---|
1050 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
---|
1051 | * It also checks the type of Nal unit type at the random access point. |
---|
1052 | * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped. |
---|
1053 | * If the random access point is IDR all pictures after the random access point are decoded. |
---|
1054 | * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC |
---|
1055 | * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random |
---|
1056 | * access point there is no guarantee that the decoder will not crash. |
---|
1057 | */ |
---|
1058 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
1059 | { |
---|
1060 | if (iSkipFrame) |
---|
1061 | { |
---|
1062 | iSkipFrame--; // decrement the counter |
---|
1063 | return true; |
---|
1064 | } |
---|
1065 | else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet. |
---|
1066 | { |
---|
1067 | if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA |
---|
1068 | #if !NAL_UNIT_TYPES_J1003_D7 |
---|
1069 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT |
---|
1070 | #endif |
---|
1071 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1072 | #if SUPPORT_FOR_RAP_N_LP |
---|
1073 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
1074 | #endif |
---|
1075 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
1076 | { |
---|
1077 | // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT. |
---|
1078 | m_pocRandomAccess = m_apcSlicePilot->getPOC(); |
---|
1079 | } |
---|
1080 | #if SUPPORT_FOR_RAP_N_LP |
---|
1081 | else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
1082 | #else |
---|
1083 | else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR) |
---|
1084 | #endif |
---|
1085 | { |
---|
1086 | m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable. |
---|
1087 | } |
---|
1088 | else |
---|
1089 | { |
---|
1090 | static bool warningMessage = false; |
---|
1091 | if(!warningMessage) |
---|
1092 | { |
---|
1093 | printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture"); |
---|
1094 | warningMessage = true; |
---|
1095 | } |
---|
1096 | return true; |
---|
1097 | } |
---|
1098 | } |
---|
1099 | // skip the reordered pictures, if necessary |
---|
1100 | else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD) |
---|
1101 | { |
---|
1102 | iPOCLastDisplay++; |
---|
1103 | return true; |
---|
1104 | } |
---|
1105 | // if we reach here, then the picture is not skipped. |
---|
1106 | return false; |
---|
1107 | } |
---|
1108 | |
---|
1109 | #if !REMOVE_APS |
---|
1110 | Void TDecTop::allocAPS (TComAPS* pAPS) |
---|
1111 | { |
---|
1112 | // we don't know the SPS before it has been activated. These fields could exist |
---|
1113 | // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will |
---|
1114 | // have to be moved for that |
---|
1115 | pAPS->createSaoParam(); |
---|
1116 | m_cSAO.allocSaoParam(pAPS->getSaoParam()); |
---|
1117 | #if !REMOVE_ALF |
---|
1118 | pAPS->createAlfParam(); |
---|
1119 | #endif |
---|
1120 | } |
---|
1121 | #endif |
---|
1122 | |
---|
1123 | //! \} |
---|