source: SHVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 540

Last change on this file since 540 was 540, checked in by seregin, 11 years ago

merge SHM-4.1-dev branch

  • Property svn:eol-style set to native
File size: 79.2 KB
Line 
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-2013, 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
42UInt  TDecTop::m_prevPOC = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence = true;
45#endif
46
47//! \ingroup TLibDecoder
48//! \{
49
50TDecTop::TDecTop()
51{
52  m_pcPic = 0;
53  m_iMaxRefPicNum = 0;
54#if ENC_DEC_TRACE
55  g_hTrace = fopen( "TraceDec.txt", "wb" );
56  g_bJustDoIt = g_bEncDecTraceDisable;
57  g_nSymbolCounter = 0;
58#endif
59  m_associatedIRAPType = NAL_UNIT_INVALID;
60  m_pocCRA = 0;
61  m_pocRandomAccess = MAX_INT;         
62#if !SVC_EXTENSION
63  m_prevPOC                = MAX_INT;
64#endif
65  m_bFirstSliceInPicture    = true;
66#if !SVC_EXTENSION
67  m_bFirstSliceInSequence   = true;
68#endif
69#if SVC_EXTENSION
70  m_layerId = 0;
71#if AVC_BASE
72  m_pBLReconFile = NULL;
73#endif
74  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
75#endif
76#if AVC_SYNTAX || SYNTAX_OUTPUT
77  m_pBLSyntaxFile = NULL;
78#endif
79  m_prevSliceSkipped = false;
80  m_skippedPOC = 0;
81#if NO_CLRAS_OUTPUT_FLAG
82  m_noClrasOutputFlag          = false;
83  m_layerInitializedFlag       = false;
84  m_firstPicInLayerDecodedFlag = false;
85  m_noOutputOfPriorPicsFlags   = false;
86  m_bRefreshPending            = false;
87#endif
88}
89
90TDecTop::~TDecTop()
91{
92#if ENC_DEC_TRACE
93  fclose( g_hTrace );
94#endif
95}
96
97Void TDecTop::create()
98{
99#if SVC_EXTENSION
100  m_cGopDecoder.create( m_layerId );
101#else
102  m_cGopDecoder.create();
103#endif
104  m_apcSlicePilot = new TComSlice;
105  m_uiSliceIdx = 0;
106}
107
108Void TDecTop::destroy()
109{
110  m_cGopDecoder.destroy();
111 
112  delete m_apcSlicePilot;
113  m_apcSlicePilot = NULL;
114 
115  m_cSliceDecoder.destroy();
116#if SVC_EXTENSION
117  for(Int i=0; i<MAX_NUM_REF; i++)
118  {
119    if(m_cIlpPic[i])
120    {
121      m_cIlpPic[i]->destroy();
122      delete m_cIlpPic[i];
123      m_cIlpPic[i] = NULL;
124    }
125  }   
126#endif
127}
128
129Void TDecTop::init()
130{
131#if !SVC_EXTENSION
132  // initialize ROM
133  initROM();
134#endif
135#if SVC_EXTENSION
136  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
137  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
138#else
139  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
140  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
141#endif
142  m_cEntropyDecoder.init(&m_cPrediction);
143}
144
145#if SVC_EXTENSION
146#if !REPN_FORMAT_IN_VPS
147Void TDecTop::xInitILRP(TComSPS *pcSPS)
148#else
149Void TDecTop::xInitILRP(TComSlice *slice)
150#endif
151{
152#if REPN_FORMAT_IN_VPS
153  TComSPS* pcSPS = slice->getSPS();
154  Int bitDepthY   = slice->getBitDepthY();
155  Int bitDepthC   = slice->getBitDepthC();
156  Int picWidth    = slice->getPicWidthInLumaSamples();
157  Int picHeight   = slice->getPicHeightInLumaSamples();
158#endif
159  if(m_layerId>0)
160  {
161#if REPN_FORMAT_IN_VPS
162    g_bitDepthY     = bitDepthY;
163    g_bitDepthC     = bitDepthC;
164#else
165    g_bitDepthY     = pcSPS->getBitDepthY();
166    g_bitDepthC     = pcSPS->getBitDepthC();
167#endif
168    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
169    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
170    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
171    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
172
173    Int  numReorderPics[MAX_TLAYER];
174    Window &conformanceWindow = pcSPS->getConformanceWindow();
175    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
176
177    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
178    {
179#if USE_DPB_SIZE_TABLE
180      if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
181      {
182        assert( this->getLayerId() == 0 );
183        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
184      }
185      else
186      {
187        TComVPS *vps = slice->getVPS();
188        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
189        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getOutputLayerSetIdx() , temporalLayer);
190      }
191#else
192      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
193#endif
194    }
195
196    if (m_cIlpPic[0] == NULL)
197    {
198      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++)  // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
199      {
200
201        m_cIlpPic[j] = new  TComPic;
202#if AUXILIARY_PICTURES
203#if REPN_FORMAT_IN_VPS
204#if SVC_UPSAMPLING
205        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
206#else
207        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
208#endif
209#else
210#if SVC_UPSAMPLING
211        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
212#else
213        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
214#endif
215#endif
216#else
217#if REPN_FORMAT_IN_VPS
218#if SVC_UPSAMPLING
219        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
220#else
221        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
222#endif
223#else
224#if SVC_UPSAMPLING
225        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
226#else
227        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
228#endif
229#endif
230#endif
231        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
232        {
233          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
234        }
235      }
236    }
237  }
238}
239#endif
240
241Void TDecTop::deletePicBuffer ( )
242{
243  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
244  Int iSize = Int( m_cListPic.size() );
245 
246  for (Int i = 0; i < iSize; i++ )
247  {
248    TComPic* pcPic = *(iterPic++);
249#if SVC_EXTENSION
250    if( pcPic )
251    {
252      pcPic->destroy();
253
254      delete pcPic;
255      pcPic = NULL;
256    }
257#else
258    pcPic->destroy();
259   
260    delete pcPic;
261    pcPic = NULL;
262#endif
263  }
264 
265  m_cSAO.destroy();
266 
267  m_cLoopFilter.        destroy();
268 
269#if !SVC_EXTENSION
270  // destroy ROM
271  destroyROM();
272#endif
273}
274
275Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
276{
277  Int  numReorderPics[MAX_TLAYER];
278  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
279  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
280
281  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
282  {
283#if USE_DPB_SIZE_TABLE
284    if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
285    {
286      assert( this->getLayerId() == 0 );
287      numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
288    }
289    else
290    {
291      TComVPS *vps = pcSlice->getVPS();
292      // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
293      numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getOutputLayerSetIdx() , temporalLayer);
294    }
295#else
296    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
297#endif
298  }
299
300#if USE_DPB_SIZE_TABLE
301  if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
302  {
303    assert( this->getLayerId() == 0 );
304    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
305  }
306  else
307  {
308    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
309  }
310#else
311  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
312#endif
313
314#if SVC_EXTENSION
315  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
316#endif
317
318  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
319  {
320    rpcPic = new TComPic();
321
322#if SVC_EXTENSION //Temporal solution, should be modified
323    if(m_layerId > 0)
324    {
325      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
326      {
327#if O0098_SCALED_REF_LAYER_ID
328        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
329#else
330        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
331#endif
332        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
333
334#if VPS_EXTN_DIRECT_REF_LAYERS
335        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
336#else
337        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
338#endif
339        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
340        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
341#if REPN_FORMAT_IN_VPS
342        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
343#else
344        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
345#endif
346        {
347          rpcPic->setSpatialEnhLayerFlag( i, true );
348
349          //only for scalable extension
350#if SCALABILITY_MASK_E0104
351          assert( pcSlice->getVPS()->getScalabilityMask(2) == true );
352#else
353          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
354#endif
355        }
356      }
357    }
358#endif
359   
360#if AUXILIARY_PICTURES
361#if REPN_FORMAT_IN_VPS
362#if SVC_UPSAMPLING
363    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
364                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
365#else
366    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
367                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
368#endif
369#else
370#if SVC_UPSAMPLING
371    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
372                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
373#else
374    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
375                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
376#endif
377#endif
378#else
379#if REPN_FORMAT_IN_VPS
380#if SVC_UPSAMPLING
381    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
382                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
383#else
384    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
385                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
386#endif
387#else
388#if SVC_UPSAMPLING
389    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
390                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
391#else
392    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
393                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
394#endif
395#endif
396#endif
397#if !HM_CLEANUP_SAO
398    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
399#endif
400    m_cListPic.pushBack( rpcPic );
401   
402    return;
403  }
404 
405  Bool bBufferIsAvailable = false;
406  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
407  while (iterPic != m_cListPic.end())
408  {
409    rpcPic = *(iterPic++);
410    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
411    {
412      rpcPic->setOutputMark(false);
413      bBufferIsAvailable = true;
414      break;
415    }
416
417    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
418    {
419#if !SVC_EXTENSION
420      rpcPic->setOutputMark(false);
421#endif
422      rpcPic->setReconMark( false );
423      rpcPic->getPicYuvRec()->setBorderExtension( false );
424      bBufferIsAvailable = true;
425      break;
426    }
427  }
428 
429  if ( !bBufferIsAvailable )
430  {
431    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
432    m_iMaxRefPicNum++;
433    rpcPic = new TComPic();
434    m_cListPic.pushBack( rpcPic );
435  }
436  rpcPic->destroy();
437
438#if AUXILIARY_PICTURES
439#if REPN_FORMAT_IN_VPS
440#if SVC_UPSAMPLING
441  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
442                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
443
444#else
445  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
446                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
447#endif
448#else
449#if SVC_UPSAMPLING
450  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
451                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
452
453#else
454  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
455                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
456#endif
457#endif
458#else
459#if REPN_FORMAT_IN_VPS
460#if SVC_UPSAMPLING
461  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
462                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
463
464#else
465  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
466                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
467#endif
468#else
469#if SVC_UPSAMPLING
470  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
471                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
472
473#else
474  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
475                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
476#endif
477#endif
478#endif
479#if !HM_CLEANUP_SAO
480  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
481#endif
482}
483
484Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
485{
486  if (!m_pcPic)
487  {
488    /* nothing to deblock */
489    return;
490  }
491 
492  TComPic*&   pcPic         = m_pcPic;
493
494  // Execute Deblock + Cleanup
495
496  m_cGopDecoder.filterPicture(pcPic);
497
498#if SYNTAX_OUTPUT
499  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
500#endif
501  TComSlice::sortPicList( m_cListPic ); // sorting for application output
502  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
503  rpcListPic          = &m_cListPic; 
504  m_cCuDecoder.destroy();       
505  m_bFirstSliceInPicture  = true;
506
507  return;
508}
509
510#if EARLY_REF_PIC_MARKING
511Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
512{
513  UInt currTid = m_pcPic->getTLayer();
514  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
515  UInt latestDecLayerId = m_layerId;
516  UInt numTargetDecLayers = 0;
517  Int targetDecLayerIdList[MAX_LAYERS];
518  UInt latestDecIdx = 0;
519  TComSlice* pcSlice = m_pcPic->getSlice(0);
520
521  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
522  {
523    return;
524  }
525
526  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
527  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
528          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
529          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
530          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
531          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
532          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
533          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
534          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
535  {
536    return;
537  }
538
539  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
540  {
541    return;
542  }
543
544  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
545  {
546    if ( latestDecLayerId == (*it) )
547    {
548      latestDecIdx = numTargetDecLayers;
549    }
550    targetDecLayerIdList[numTargetDecLayers++] = (*it);
551  }
552
553  Int remainingInterLayerReferencesFlag = 0;
554#if O0225_MAX_TID_FOR_REF_LAYERS
555  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
556  {
557    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
558    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
559    {
560#else
561  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
562  {
563    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
564    {
565#endif
566      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
567      {
568        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
569        {
570          remainingInterLayerReferencesFlag = 1;
571        }
572      }
573    }
574  }
575
576  if ( remainingInterLayerReferencesFlag == 0 )
577  {
578    pcSlice->setReferenced(false);
579  }
580}
581#endif
582
583Void TDecTop::xCreateLostPicture(Int iLostPoc) 
584{
585  printf("\ninserting lost poc : %d\n",iLostPoc);
586  TComSlice cFillSlice;
587  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
588  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
589#if SVC_EXTENSION
590  cFillSlice.setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
591  cFillSlice.initSlice( m_layerId );
592#else
593  cFillSlice.initSlice();
594#endif
595  TComPic *cFillPic;
596  xGetNewPicBuffer(&cFillSlice,cFillPic);
597  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
598  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
599#if SVC_EXTENSION
600  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
601  cFillPic->getSlice(0)->initSlice( m_layerId );
602#else
603  cFillPic->getSlice(0)->initSlice();
604#endif
605 
606  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
607  Int closestPoc = 1000000;
608  while ( iterPic != m_cListPic.end())
609  {
610    TComPic * rpcPic = *(iterPic++);
611    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())
612    {
613      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
614    }
615  }
616  iterPic = m_cListPic.begin();
617  while ( iterPic != m_cListPic.end())
618  {
619    TComPic *rpcPic = *(iterPic++);
620    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
621    {
622      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
623      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
624      break;
625    }
626  }
627  cFillPic->setCurrSliceIdx(0);
628  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
629  {
630    cFillPic->getCU(i)->initCU(cFillPic,i);
631  }
632  cFillPic->getSlice(0)->setReferenced(true);
633  cFillPic->getSlice(0)->setPOC(iLostPoc);
634  cFillPic->setReconMark(true);
635  cFillPic->setOutputMark(true);
636  if(m_pocRandomAccess == MAX_INT)
637  {
638    m_pocRandomAccess = iLostPoc;
639  }
640}
641
642
643Void TDecTop::xActivateParameterSets()
644{
645  m_parameterSetManagerDecoder.applyPrefetchedPS();
646 
647  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
648  assert (pps != 0);
649
650  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
651  assert (sps != 0);
652
653  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
654  {
655    printf ("Parameter set activation failed!");
656    assert (0);
657  }
658
659#if SCALINGLIST_INFERRING
660  // scaling list settings and checks
661  TComVPS *activeVPS = m_parameterSetManagerDecoder.getActiveVPS();
662  TComSPS *activeSPS = m_parameterSetManagerDecoder.getActiveSPS();
663  TComPPS *activePPS = m_parameterSetManagerDecoder.getActivePPS();
664
665  if( activeSPS->getInferScalingListFlag() )
666  {
667    UInt refLayerId = activeSPS->getScalingListRefLayerId();
668    TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
669
670    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
671    if( activeVPS->getAvcBaseLayerFlag() )
672    {
673      assert( refLayerId > 0 );
674    }
675
676    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
677    // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
678    assert( refSps->getInferScalingListFlag() == false );
679
680    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
681    // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
682    assert( activeVPS->getRecursiveRefLayerFlag( activeSPS->getLayerId(), refLayerId ) == true );
683   
684    if( activeSPS->getScalingList() != refSps->getScalingList() )
685    {
686      // delete created instance of scaling list since it will be inferred
687      delete activeSPS->getScalingList();
688
689      // infer scaling list
690      activeSPS->setScalingList( refSps->getScalingList() );
691    }
692  }
693
694  if( activePPS->getInferScalingListFlag() )
695  {
696    UInt refLayerId = activePPS->getScalingListRefLayerId();
697    TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
698
699    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
700    if( activeVPS->getAvcBaseLayerFlag() )
701    {
702      assert( refLayerId > 0 );
703    }
704
705    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
706    // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
707    assert( refPps->getInferScalingListFlag() == false );
708
709    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
710    // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
711    assert( activeVPS->getRecursiveRefLayerFlag( activePPS->getLayerId(), refLayerId ) == true );
712   
713    if( activePPS->getScalingList() != refPps->getScalingList() )
714    {
715      // delete created instance of scaling list since it will be inferred
716      delete activePPS->getScalingList();
717
718      // infer scaling list
719      activePPS->setScalingList( refPps->getScalingList() );
720    }
721
722  }
723#endif
724
725  if( pps->getDependentSliceSegmentsEnabledFlag() )
726  {
727    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
728
729    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
730    {
731      m_cSliceDecoder.initCtxMem(NumCtx);
732      for ( UInt st = 0; st < NumCtx; st++ )
733      {
734        TDecSbac* ctx = NULL;
735        ctx = new TDecSbac;
736        ctx->init( &m_cBinCABAC );
737        m_cSliceDecoder.setCtxMem( ctx, st );
738      }
739    }
740  }
741
742  m_apcSlicePilot->setPPS(pps);
743  m_apcSlicePilot->setSPS(sps);
744  pps->setSPS(sps);
745#if REPN_FORMAT_IN_VPS
746  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
747#else
748  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
749#endif
750  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
751
752#if REPN_FORMAT_IN_VPS
753  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
754  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
755#else
756  g_bitDepthY     = sps->getBitDepthY();
757  g_bitDepthC     = sps->getBitDepthC();
758#endif
759  g_uiMaxCUWidth  = sps->getMaxCUWidth();
760  g_uiMaxCUHeight = sps->getMaxCUHeight();
761  g_uiMaxCUDepth  = sps->getMaxCUDepth();
762  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
763
764  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
765  {
766    sps->setAMPAcc( i, sps->getUseAMP() );
767  }
768
769  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
770  {
771    sps->setAMPAcc( i, 0 );
772  }
773
774  m_cSAO.destroy();
775#if REPN_FORMAT_IN_VPS
776#if AUXILIARY_PICTURES
777#if HM_CLEANUP_SAO
778  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
779#else
780  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
781#endif
782#else
783#if HM_CLEANUP_SAO
784  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
785#else
786  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
787#endif
788#endif
789#else
790#if HM_CLEANUP_SAO
791  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
792#else
793  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
794#endif
795#endif
796  m_cLoopFilter.create( sps->getMaxCUDepth() );
797}
798
799#if SVC_EXTENSION
800#if POC_RESET_FLAG
801Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
802#else
803Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
804#endif
805#else
806Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
807#endif
808{
809  TComPic*&   pcPic         = m_pcPic;
810#if NO_CLRAS_OUTPUT_FLAG
811  Bool bFirstSliceInSeq;
812#endif
813#if SVC_EXTENSION
814  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
815#if OUTPUT_LAYER_SET_INDEX
816  // Following check should go wherever the VPS is activated
817  checkValueOfOutputLayerSetIdx( m_apcSlicePilot->getVPS());
818#endif
819  m_apcSlicePilot->initSlice( nalu.m_layerId );
820#else
821  m_apcSlicePilot->initSlice();
822#endif
823
824  if (m_bFirstSliceInPicture)
825  {
826    m_uiSliceIdx     = 0;
827  }
828  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
829  if (!m_bFirstSliceInPicture)
830  {
831    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
832  }
833
834  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
835  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
836                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
837                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
838                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
839                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
840  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
841 
842  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
843  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
844
845#if SVC_EXTENSION
846  m_apcSlicePilot->setSliceIdx( m_uiSliceIdx ); // it should be removed if HM will reflect it in above
847#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
848  setRefLayerParams(m_apcSlicePilot->getVPS());
849#endif
850#if M0457_COL_PICTURE_SIGNALING
851  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
852#endif
853#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
854  m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
855#endif
856#endif
857  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
858
859  // set POC for dependent slices in skipped pictures
860  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
861  {
862    m_apcSlicePilot->setPOC(m_skippedPOC);
863  }
864
865  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
866  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
867
868  // Skip pictures due to random access
869  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
870  {
871    m_prevSliceSkipped = true;
872    m_skippedPOC = m_apcSlicePilot->getPOC();
873    return false;
874  }
875  // Skip TFD pictures associated with BLA/BLANT pictures
876  if (isSkipPictureForBLA(iPOCLastDisplay))
877  {
878    m_prevSliceSkipped = true;
879    m_skippedPOC = m_apcSlicePilot->getPOC();
880    return false;
881  }
882
883  // clear previous slice skipped flag
884  m_prevSliceSkipped = false;
885
886  // exit when a new picture is found
887#if SVC_EXTENSION
888  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
889  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
890  {
891    m_prevPOC = m_apcSlicePilot->getPOC();
892    curLayerId = m_uiPrevLayerId; 
893    m_uiPrevLayerId = m_layerId;
894    return true;
895  }
896#else
897  //we should only get a different poc for a new picture (with CTU address==0)
898  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
899  {
900    printf ("Warning, the first slice of a picture might have been lost!\n");
901  }
902  // exit when a new picture is found
903  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
904  {
905    if (m_prevPOC >= m_pocRandomAccess)
906    {
907      m_prevPOC = m_apcSlicePilot->getPOC();
908      return true;
909    }
910    m_prevPOC = m_apcSlicePilot->getPOC();
911  }
912#endif
913  // actual decoding starts here
914  xActivateParameterSets();
915#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS && N0147_IRAP_ALIGN_FLAG
916  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
917  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1
918  if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
919  {
920    assert( m_apcSlicePilot->getPPS()->getNumExtraSliceHeaderBits() > 0);
921  }
922  //When cross_layer_irap_aligned_flag is equal to 1, the value of poc_reset_flag shall be equal to 0 
923  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
924  {
925    assert( m_apcSlicePilot->getPocResetFlag() == 0);
926  }
927#endif
928#if REPN_FORMAT_IN_VPS
929  // Initialize ILRP if needed, only for the current layer 
930  // ILRP intialization should go along with activation of parameters sets,
931  // although activation of parameter sets itself need not be done for each and every slice!!!
932  xInitILRP(m_apcSlicePilot);
933#endif
934  if (m_apcSlicePilot->isNextSlice()) 
935  {
936    m_prevPOC = m_apcSlicePilot->getPOC();
937#if SVC_EXTENSION
938    curLayerId = m_layerId;
939    m_uiPrevLayerId = m_layerId;
940#endif
941  }
942#if NO_CLRAS_OUTPUT_FLAG
943  bFirstSliceInSeq = m_bFirstSliceInSequence;
944#endif
945  m_bFirstSliceInSequence = false;
946#if POC_RESET_FLAG
947  // This operation would do the following:
948  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
949  // 2. Update the value of m_pocCRA.
950  // 3. Reset the POC values at the decoder for the current picture to be zero.
951  // 4. update value of POCLastDisplay
952  if( m_apcSlicePilot->getPocResetFlag() )
953  {
954    if( m_apcSlicePilot->getSliceIdx() == 0 )
955    {
956      Int pocAdjustValue = m_apcSlicePilot->getPOC();
957
958#if PREVTID0_POC_RESET
959      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
960#endif
961      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
962      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
963
964      // Iterate through all picture in DPB
965      while( iterPic != m_cListPic.end() )
966      {
967        TComPic *dpbPic = *iterPic;
968        // Check if the picture pointed to by iterPic is either used for reference or
969        // needed for output, are in the same layer, and not the current picture.
970        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
971            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
972              && ( dpbPic->getReconMark() ) 
973          )
974        {
975          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
976          {
977
978            TComSlice *slice = dpbPic->getSlice(i);
979            TComReferencePictureSet *rps = slice->getRPS();
980            slice->setPOC( slice->getPOC() - pocAdjustValue );
981
982            // Also adjust the POC value stored in the RPS of each such slice
983            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
984            {
985              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
986            }
987            // Also adjust the value of refPOC
988            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
989            {
990              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
991              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
992              {
993                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
994              }
995            }
996          }
997        }
998        iterPic++;
999      }
1000      // Update the value of pocCRA
1001      m_pocCRA -= pocAdjustValue;
1002      // Update value of POCLastDisplay
1003      iPOCLastDisplay -= pocAdjustValue;
1004    }
1005    // Reset current poc for current slice and RPS
1006    m_apcSlicePilot->setPOC( 0 );
1007  }
1008#endif
1009#if ALIGN_TSA_STSA_PICS
1010  if( m_apcSlicePilot->getLayerId() > 0 )
1011  {
1012    // Check for TSA alignment
1013    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1014        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
1015         )
1016    {
1017      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1018      {
1019        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1020        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
1021        if( refpicLayer )
1022        {
1023          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1024                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
1025        } 
1026      }
1027    }
1028    // Check for STSA alignment
1029    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1030         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R
1031         )
1032    {
1033      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1034      {
1035        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1036        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
1037        if( refpicLayer )
1038
1039        {
1040          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1041                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
1042        }
1043      }
1044    }
1045  }
1046#endif
1047  //detect lost reference picture and insert copy of earlier frame.
1048  Int lostPoc;
1049  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1050  {
1051    xCreateLostPicture(lostPoc-1);
1052  }
1053  if (m_bFirstSliceInPicture)
1054  {
1055#if AVC_BASE
1056    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1057    {
1058      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1059      pBLPic->getSlice(0)->setReferenced(true);
1060      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1061      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
1062      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
1063
1064      if( pFile->good() )
1065      {
1066        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
1067
1068        pFile->seekg((UInt)uiPos, ios::beg );
1069
1070        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
1071        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
1072        for( Int i = 0; i < uiHeight; i++ )
1073        {
1074          for( Int j = 0; j < uiWidth; j++ )
1075          {
1076            pPel[j] = pFile->get();
1077          }
1078          pPel += uiStride;
1079        }
1080
1081        pPel = pBLPic->getPicYuvRec()->getCbAddr();
1082        uiStride = pBLPic->getPicYuvRec()->getCStride();
1083        for( Int i = 0; i < uiHeight/2; i++ )
1084        {
1085          for( Int j = 0; j < uiWidth/2; j++ )
1086          {
1087            pPel[j] = pFile->get();
1088          }
1089          pPel += uiStride;
1090        }
1091
1092        pPel = pBLPic->getPicYuvRec()->getCrAddr();
1093        uiStride = pBLPic->getPicYuvRec()->getCStride();
1094        for( Int i = 0; i < uiHeight/2; i++ )
1095        {
1096          for( Int j = 0; j < uiWidth/2; j++ )
1097          {
1098            pPel[j] = pFile->get();
1099          }
1100          pPel += uiStride;
1101        }
1102      }
1103    }
1104#endif
1105
1106#if NO_CLRAS_OUTPUT_FLAG
1107    if (m_layerId == 0 &&
1108        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1109      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1110      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1111      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
1112      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
1113      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
1114    {
1115      if (bFirstSliceInSeq)
1116      {
1117        setNoClrasOutputFlag(true);
1118      }
1119      else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1120            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1121            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
1122      {
1123        setNoClrasOutputFlag(true);
1124      }
1125#if O0149_CROSS_LAYER_BLA_FLAG
1126      else if ((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
1127               m_apcSlicePilot->getCrossLayerBLAFlag())
1128      {
1129        setNoClrasOutputFlag(true);
1130      }
1131#endif
1132      else
1133      {
1134        setNoClrasOutputFlag(false);
1135      }
1136      if (getNoClrasOutputFlag())
1137      {
1138        for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
1139        {
1140          m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1141          m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1142        }
1143      }
1144    }
1145#endif
1146
1147#if NO_CLRAS_OUTPUT_FLAG
1148    m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
1149#endif
1150
1151    // Buffer initialize for prediction.
1152    m_cPrediction.initTempBuff();
1153    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1154    //  Get a new picture buffer
1155    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1156
1157    Bool isField = false;
1158    Bool isTff = false;
1159   
1160    if(!m_SEIs.empty())
1161    {
1162      // Check if any new Picture Timing SEI has arrived
1163      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1164      if (pictureTimingSEIs.size()>0)
1165      {
1166        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
1167        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
1168        isTff =  (pictureTiming->m_picStruct == 1);
1169      }
1170    }
1171   
1172    //Set Field/Frame coding mode
1173    m_pcPic->setField(isField);
1174    m_pcPic->setTopField(isTff);
1175
1176    // transfer any SEI messages that have been received to the picture
1177    pcPic->setSEIs(m_SEIs);
1178    m_SEIs.clear();
1179
1180    // Recursive structure
1181    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1182#if SVC_EXTENSION
1183    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
1184#else
1185    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1186#endif
1187    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1188
1189    m_cSliceDecoder.create();
1190  }
1191  else
1192  {
1193    // Check if any new SEI has arrived
1194    if(!m_SEIs.empty())
1195    {
1196      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
1197      SEIMessages &picSEI = pcPic->getSEIs();
1198      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1199      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1200      deleteSEIs(m_SEIs);
1201    }
1202  }
1203 
1204  //  Set picture slice pointer
1205  TComSlice*  pcSlice = m_apcSlicePilot;
1206  Bool bNextSlice     = pcSlice->isNextSlice();
1207
1208  UInt uiCummulativeTileWidth;
1209  UInt uiCummulativeTileHeight;
1210  UInt i, j, p;
1211
1212  //set NumColumnsMins1 and NumRowsMinus1
1213  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1214  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1215
1216  //create the TComTileArray
1217  pcPic->getPicSym()->xCreateTComTileArray();
1218
1219  if( pcSlice->getPPS()->getUniformSpacingFlag() )
1220  {
1221    //set the width for each tile
1222    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1223    {
1224      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1225      {
1226        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1227          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1228          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1229      }
1230    }
1231
1232    //set the height for each tile
1233    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1234    {
1235      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1236      {
1237        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1238          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1239          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1240      }
1241    }
1242  }
1243  else
1244  {
1245    //set the width for each tile
1246    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1247    {
1248      uiCummulativeTileWidth = 0;
1249      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1250      {
1251        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1252        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1253      }
1254      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1255    }
1256
1257    //set the height for each tile
1258    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1259    {
1260      uiCummulativeTileHeight = 0;
1261      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1262      { 
1263        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1264        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1265      }
1266      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1267    }
1268  }
1269
1270  pcPic->getPicSym()->xInitTiles();
1271
1272  //generate the Coding Order Map and Inverse Coding Order Map
1273  UInt uiEncCUAddr;
1274  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1275  {
1276    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1277    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1278  }
1279  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1280  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1281
1282  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1283  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1284  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1285  if(pcSlice->isNextSlice())
1286  {
1287    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1288    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1289  }
1290
1291  if (m_bFirstSliceInPicture) 
1292  {
1293    if(pcPic->getNumAllocatedSlice() != 1)
1294    {
1295      pcPic->clearSliceBuffer();
1296    }
1297  }
1298  else
1299  {
1300    pcPic->allocateNewSlice();
1301  }
1302  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1303  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1304  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1305
1306  pcPic->setTLayer(nalu.m_temporalId);
1307
1308#if SVC_EXTENSION
1309  pcPic->setLayerId(nalu.m_layerId);
1310  pcSlice->setLayerId(nalu.m_layerId);
1311  pcSlice->setPic(pcPic);
1312#endif
1313
1314  if (bNextSlice)
1315  {
1316    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1317    // Set reference list
1318#if SVC_EXTENSION
1319    if (m_layerId == 0)
1320#endif
1321    pcSlice->setRefPicList( m_cListPic, true );
1322
1323#if SVC_EXTENSION
1324    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1325    // Other slices might choose which reference pictures to be used for inter-layer prediction
1326    if( m_layerId > 0 && m_uiSliceIdx == 0 )
1327    {     
1328#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1329      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1330#endif
1331      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
1332      {
1333        UInt refLayerIdc = i;
1334#if AVC_BASE
1335        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1336        {         
1337          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1338
1339          if( pic )
1340          {
1341            pcSlice->setBaseColPic ( refLayerIdc, pic );
1342          }
1343          else
1344          {
1345            continue;
1346          }
1347#if AVC_SYNTAX
1348          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
1349          if( pcSlice->getPOC() == 0 )
1350          {
1351            // initialize partition order.
1352            UInt* piTmp = &g_auiZscanToRaster[0];
1353            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
1354            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
1355          }     
1356          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
1357          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
1358#endif
1359        }
1360        else
1361        {
1362#if VPS_EXTN_DIRECT_REF_LAYERS
1363          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1364#else
1365          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1366#endif
1367          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1368          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1369          {
1370            continue;
1371          }
1372        }
1373#else
1374#if VPS_EXTN_DIRECT_REF_LAYERS
1375        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1376#else
1377        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1378#endif
1379        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1380        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1381#endif
1382
1383#if O0098_SCALED_REF_LAYER_ID
1384        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
1385#else
1386        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1387#endif
1388
1389        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
1390        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
1391
1392        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1393        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1394
1395        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1396        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1397
1398        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1399        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1400
1401#if SVC_UPSAMPLING
1402        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
1403        {   
1404/*#if O0098_SCALED_REF_LAYER_ID
1405          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
1406#else
1407          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1408#endif*/
1409#if O0215_PHASE_ALIGNMENT
1410#if O0194_JOINT_US_BITSHIFT
1411          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1412#else
1413          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1414#endif
1415#else
1416#if O0194_JOINT_US_BITSHIFT
1417          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1418#else
1419          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1420#endif
1421#endif
1422        }
1423        else
1424        {
1425          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1426        }
1427        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1428#endif
1429      }
1430    }
1431
1432    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1433    {
1434      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1435      {
1436        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1437#if AVC_BASE
1438        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1439        {
1440          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1441#if AVC_SYNTAX
1442          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
1443          if( pcSlice->getPOC() == 0 )
1444          {
1445            // initialize partition order.
1446            UInt* piTmp = &g_auiZscanToRaster[0];
1447            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
1448            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
1449          }     
1450          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
1451          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
1452#endif
1453        }
1454        else
1455        {
1456#if VPS_EXTN_DIRECT_REF_LAYERS
1457          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1458#else
1459          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1460#endif
1461          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1462          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1463        }
1464#else
1465#if VPS_EXTN_DIRECT_REF_LAYERS
1466        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1467#else
1468        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1469#endif
1470        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1471        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1472#endif
1473
1474        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1475      }
1476
1477      pcSlice->setILRPic( m_cIlpPic );
1478
1479#if REF_IDX_MFM
1480#if M0457_COL_PICTURE_SIGNALING
1481      if( pcSlice->getMFMEnabledFlag() )
1482#else
1483      if( pcSlice->getSPS()->getMFMEnabledFlag() )
1484#endif
1485      {
1486        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
1487#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1488        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
1489#endif
1490      }
1491      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1492    }
1493#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1494    else if ( m_layerId > 0 )
1495    {
1496      pcSlice->setRefPicList( m_cListPic, false, NULL);
1497    }
1498#endif
1499#if MFM_ENCCONSTRAINT
1500    if( pcSlice->getMFMEnabledFlag() )
1501    {
1502      Int refLayerId = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() )->getLayerId();
1503      if( refLayerId != pcSlice->getLayerId() )
1504      {
1505        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
1506        assert( pColBasePic->checkSameRefInfo() == true );
1507      }
1508    }
1509#endif
1510#endif
1511   
1512#if N0147_IRAP_ALIGN_FLAG
1513    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
1514    {
1515#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1516      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1517#endif
1518      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1519      {
1520        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1521        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1522        if(refpicLayer && pcSlice->isIRAP())
1523        {                 
1524          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1525        }
1526      }
1527    }
1528#endif
1529#endif //SVC_EXTENSION
1530   
1531    // For generalized B
1532    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1533    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1534    {
1535      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1536      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1537
1538      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1539      {
1540        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1541      }
1542    }
1543    if (!pcSlice->isIntra())
1544    {
1545      Bool bLowDelay = true;
1546      Int  iCurrPOC  = pcSlice->getPOC();
1547      Int iRefIdx = 0;
1548
1549      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1550      {
1551        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1552        {
1553          bLowDelay = false;
1554        }
1555      }
1556      if (pcSlice->isInterB())
1557      {
1558        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1559        {
1560          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1561          {
1562            bLowDelay = false;
1563          }
1564        }       
1565      }
1566
1567      pcSlice->setCheckLDC(bLowDelay);           
1568    }
1569
1570    //---------------
1571    pcSlice->setRefPOCList();
1572  }
1573
1574  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1575  if(pcSlice->getSPS()->getScalingListFlag())
1576  {
1577    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1578    if(pcSlice->getPPS()->getScalingListPresentFlag())
1579    {
1580      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1581    }
1582#if SCALINGLIST_INFERRING
1583    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
1584#endif
1585    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1586    {
1587      pcSlice->setDefaultScalingList();
1588    }
1589    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1590    m_cTrQuant.setUseScalingList(true);
1591  }
1592  else
1593  {
1594    m_cTrQuant.setFlatScalingList();
1595    m_cTrQuant.setUseScalingList(false);
1596  }
1597
1598  //  Decode a picture
1599  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1600
1601  m_bFirstSliceInPicture = false;
1602  m_uiSliceIdx++;
1603
1604  return false;
1605}
1606
1607Void TDecTop::xDecodeVPS()
1608{
1609  TComVPS* vps = new TComVPS();
1610 
1611  m_cEntropyDecoder.decodeVPS( vps );
1612  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1613}
1614
1615Void TDecTop::xDecodeSPS()
1616{
1617  TComSPS* sps = new TComSPS();
1618#if SVC_EXTENSION
1619  sps->setLayerId(m_layerId);
1620  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
1621  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1622#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
1623  if(m_numLayer>0)
1624  {
1625    xInitILRP(sps);
1626  }
1627#endif
1628#else //SVC_EXTENSION
1629  m_cEntropyDecoder.decodeSPS( sps );
1630  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1631#endif //SVC_EXTENSION
1632}
1633
1634Void TDecTop::xDecodePPS()
1635{
1636  TComPPS* pps = new TComPPS();
1637
1638#if SCALINGLIST_INFERRING
1639  pps->setLayerId( m_layerId );
1640#endif
1641
1642  m_cEntropyDecoder.decodePPS( pps );
1643  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1644
1645  if( pps->getDependentSliceSegmentsEnabledFlag() )
1646  {
1647    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1648    m_cSliceDecoder.initCtxMem(NumCtx);
1649    for ( UInt st = 0; st < NumCtx; st++ )
1650    {
1651      TDecSbac* ctx = NULL;
1652      ctx = new TDecSbac;
1653      ctx->init( &m_cBinCABAC );
1654      m_cSliceDecoder.setCtxMem( ctx, st );
1655    }
1656  }
1657}
1658
1659Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1660{
1661#if SVC_EXTENSION
1662  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1663  {
1664#if RANDOM_ACCESS_SEI_FIX
1665    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
1666    {
1667      return;
1668    }
1669#endif
1670#if M0043_LAYERS_PRESENT_SEI
1671    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1672#else
1673    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1674#endif
1675  }
1676  else
1677  {
1678#if M0043_LAYERS_PRESENT_SEI
1679    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1680#else
1681    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1682#endif
1683    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1684    if (activeParamSets.size()>0)
1685    {
1686      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1687      m_parameterSetManagerDecoder.applyPrefetchedPS();
1688      assert(seiAps->activeSeqParamSetId.size()>0);
1689      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParamSetId[0] ) )
1690      {
1691        printf ("Warning SPS activation with Active parameter set SEI failed");
1692      }
1693    }
1694  }
1695#else
1696  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1697  {
1698#if M0043_LAYERS_PRESENT_SEI
1699    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1700#else
1701    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1702#endif
1703  }
1704  else
1705  {
1706#if M0043_LAYERS_PRESENT_SEI
1707    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1708#else
1709    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1710#endif
1711    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1712    if (activeParamSets.size()>0)
1713    {
1714      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1715      m_parameterSetManagerDecoder.applyPrefetchedPS();
1716      assert(seiAps->activeSeqParamSetId.size()>0);
1717      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1718      {
1719        printf ("Warning SPS activation with Active parameter set SEI failed");
1720      }
1721    }
1722  }
1723#endif
1724}
1725
1726#if SVC_EXTENSION
1727Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1728#else
1729Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1730#endif
1731{
1732  // Initialize entropy decoder
1733  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1734  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1735
1736  switch (nalu.m_nalUnitType)
1737  {
1738    case NAL_UNIT_VPS:
1739#if VPS_NUH_LAYER_ID
1740      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
1741#endif
1742      xDecodeVPS();
1743#if AVC_BASE
1744      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1745      {
1746        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1747        {
1748          printf( "Base layer YUV input reading error\n" );
1749          exit(EXIT_FAILURE);
1750        }       
1751#if AVC_SYNTAX
1752        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
1753        {
1754          printf( "Base layer syntax input reading error\n" );
1755          exit(EXIT_FAILURE);
1756        }
1757#endif
1758      }
1759      else
1760      {
1761        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1762        cListPic->clear();
1763      }
1764#endif
1765      return false;
1766     
1767    case NAL_UNIT_SPS:
1768      xDecodeSPS();
1769#if AVC_BASE
1770      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1771      {
1772        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1773        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1774        {
1775          // using EL SPS with spsId = 1
1776          TComSPS* sps = m_parameterSetManagerDecoder.getPrefetchedSPS(1);
1777          Int  numReorderPics[MAX_TLAYER];
1778          Window &conformanceWindow = sps->getConformanceWindow();
1779          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1780#if AUXILIARY_PICTURES
1781#if SVC_UPSAMPLING
1782#if AVC_SYNTAX
1783          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1784#else
1785          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1786#endif
1787#else
1788          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1789#endif
1790#else
1791#if SVC_UPSAMPLING
1792#if AVC_SYNTAX
1793          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1794#else
1795          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1796#endif
1797#else
1798          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1799#endif
1800#endif
1801
1802#if O0194_DIFFERENT_BITDEPTH_EL_BL
1803          // set AVC BL bit depth, can be an input parameter from the command line
1804          g_bitDepthYLayer[0] = 8;
1805          g_bitDepthCLayer[0] = 8;
1806#endif
1807        }
1808      }
1809#endif
1810      return false;
1811
1812    case NAL_UNIT_PPS:
1813      xDecodePPS();
1814      return false;
1815     
1816    case NAL_UNIT_PREFIX_SEI:
1817    case NAL_UNIT_SUFFIX_SEI:
1818      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1819      return false;
1820
1821    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1822    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1823    case NAL_UNIT_CODED_SLICE_TSA_R:
1824    case NAL_UNIT_CODED_SLICE_TSA_N:
1825    case NAL_UNIT_CODED_SLICE_STSA_R:
1826    case NAL_UNIT_CODED_SLICE_STSA_N:
1827    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1828    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1829    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1830    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1831    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1832    case NAL_UNIT_CODED_SLICE_CRA:
1833    case NAL_UNIT_CODED_SLICE_RADL_N:
1834    case NAL_UNIT_CODED_SLICE_RADL_R:
1835    case NAL_UNIT_CODED_SLICE_RASL_N:
1836    case NAL_UNIT_CODED_SLICE_RASL_R:
1837#if SVC_EXTENSION
1838      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1839#else
1840      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1841#endif
1842      break;
1843     
1844    case NAL_UNIT_EOS:
1845      m_associatedIRAPType = NAL_UNIT_INVALID;
1846      m_pocCRA = 0;
1847      m_pocRandomAccess = MAX_INT;
1848      m_prevPOC = MAX_INT;
1849      m_bFirstSliceInPicture = true;
1850      m_bFirstSliceInSequence = true;
1851      m_prevSliceSkipped = false;
1852      m_skippedPOC = 0;
1853      return false;
1854     
1855    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1856      // TODO: process AU delimiter
1857      return false;
1858     
1859    case NAL_UNIT_EOB:
1860      return false;
1861     
1862    default:
1863      assert (0);
1864  }
1865
1866  return false;
1867}
1868
1869/** Function for checking if picture should be skipped because of association with a previous BLA picture
1870 * \param iPOCLastDisplay POC of last picture displayed
1871 * \returns true if the picture should be skipped
1872 * This function skips all TFD pictures that follow a BLA picture
1873 * in decoding order and precede it in output order.
1874 */
1875Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1876{
1877  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
1878       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1879  {
1880    iPOCLastDisplay++;
1881    return true;
1882  }
1883  return false;
1884}
1885
1886/** Function for checking if picture should be skipped because of random access
1887 * \param iSkipFrame skip frame counter
1888 * \param iPOCLastDisplay POC of last picture displayed
1889 * \returns true if the picture shold be skipped in the random access.
1890 * This function checks the skipping of pictures in the case of -s option random access.
1891 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1892 * It also checks the type of Nal unit type at the random access point.
1893 * 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.
1894 * If the random access point is IDR all pictures after the random access point are decoded.
1895 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1896 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1897 * access point there is no guarantee that the decoder will not crash.
1898 */
1899Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1900{
1901  if (iSkipFrame) 
1902  {
1903    iSkipFrame--;   // decrement the counter
1904    return true;
1905  }
1906  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1907  {
1908    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1909        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1910        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1911        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1912    {
1913      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1914      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1915    }
1916    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1917    {
1918      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1919    }
1920    else 
1921    {
1922      static Bool warningMessage = false;
1923      if(!warningMessage)
1924      {
1925        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1926        warningMessage = true;
1927      }
1928      return true;
1929    }
1930  }
1931  // skip the reordered pictures, if necessary
1932  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1933  {
1934    iPOCLastDisplay++;
1935    return true;
1936  }
1937  // if we reach here, then the picture is not skipped.
1938  return false; 
1939}
1940
1941#if VPS_EXTN_DIRECT_REF_LAYERS
1942TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
1943{
1944  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
1945  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1946  {
1947    return (TDecTop *)getLayerDec( 0 );
1948  }
1949 
1950  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
1951}
1952#endif
1953
1954#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
1955
1956Void TDecTop::setRefLayerParams( TComVPS* vps )
1957{
1958  for(UInt layer = 0; layer < m_numLayer; layer++)
1959  {
1960    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
1961    decTop->setNumSamplePredRefLayers(0);
1962    decTop->setNumMotionPredRefLayers(0);
1963    decTop->setNumDirectRefLayers(0);
1964    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
1965    {
1966      decTop->setSamplePredEnabledFlag(i, false);
1967      decTop->setMotionPredEnabledFlag(i, false);
1968      decTop->setSamplePredRefLayerId(i, 0);
1969      decTop->setMotionPredRefLayerId(i, 0);
1970    }
1971    for(Int j = 0; j < layer; j++)
1972    {
1973      if (vps->getDirectDependencyFlag(layer, j))
1974      {
1975        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
1976        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
1977
1978        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
1979        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
1980        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
1981
1982        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
1983        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
1984        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
1985      }
1986    }
1987  }
1988  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
1989  {
1990    Int iNuhLId = vps->getLayerIdInNuh(i);
1991    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
1992    for ( Int j = 0; j < i; j++ )
1993    {
1994      if (decTop->getMotionPredEnabledFlag(j))
1995      {
1996        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
1997      }
1998      if (decTop->getSamplePredEnabledFlag(j))
1999      {
2000        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2001      }
2002    }
2003  }
2004}
2005
2006#endif
2007
2008#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
2009TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice)
2010{
2011  TComPic* ilpPic = NULL;
2012  Int activeMotionPredReflayerIdx = 0;
2013
2014  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
2015  {
2016    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
2017    if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
2018    {
2019      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
2020      {
2021        ilpPic = m_cIlpPic[refLayerIdc];
2022        break;
2023      }
2024      else
2025      {
2026        activeMotionPredReflayerIdx++;
2027      }
2028    }
2029  }
2030
2031  assert(ilpPic != NULL);
2032
2033  return ilpPic;
2034}
2035#endif
2036#if OUTPUT_LAYER_SET_INDEX
2037Void TDecTop::checkValueOfOutputLayerSetIdx(TComVPS *vps)
2038{
2039  CommonDecoderParams* params = this->getCommonDecoderParams();
2040  if( params->getValueCheckedFlag() )
2041  {
2042    return; // Already checked
2043  }
2044  if( params->getOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2045  {
2046    Bool layerSetMatchFound = false;
2047    // Output layer set index not assigned.
2048    // Based on the value of targetLayerId, check if any of the output layer matches
2049    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2050    // Check if any of the output layer sets match this description
2051    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
2052    {
2053      Bool layerSetMatchFlag = true;
2054      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2055      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
2056      {
2057        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2058        {
2059          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2060          {
2061            layerSetMatchFlag = false;
2062            break;
2063          }
2064        }
2065      }
2066      else
2067      {
2068        layerSetMatchFlag = false;
2069      }
2070     
2071      if( layerSetMatchFlag ) // Potential output layer set candidate found
2072      {
2073        // If target dec layer ID list is also included - check if they match
2074        if( params->getTargetDecLayerIdSet() )
2075        {
2076          if( params->getTargetDecLayerIdSet()->size() ) 
2077          {
2078            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2079            {
2080              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2081              {
2082                layerSetMatchFlag = false;
2083              }
2084            }
2085          }
2086        }
2087        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2088        {
2089          // Match found
2090          layerSetMatchFound = true;
2091          params->setOutputLayerSetIdx( i );
2092          params->setValueCheckedFlag( true );
2093          break;
2094        }
2095      }
2096    }
2097    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2098  }   
2099  else // Output layer set index is assigned - check if the values match
2100  {
2101    // Check if the target decoded layer is the highest layer in the list
2102    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getOutputLayerSetIdx() );  // Index to the layer set
2103    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2104
2105    Bool layerSetMatchFlag = true;
2106    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2107    {
2108      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2109      {
2110        layerSetMatchFlag = false;
2111        break;
2112      }
2113    }
2114
2115    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
2116   
2117    // Check if the targetdeclayerIdlist matches the output layer set
2118    if( params->getTargetDecLayerIdSet() )
2119    {
2120      if( params->getTargetDecLayerIdSet()->size() ) 
2121      {
2122        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2123        {
2124          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2125        }
2126      }
2127    }
2128    params->setValueCheckedFlag( true );
2129
2130  }
2131}
2132#endif
2133//! \}
Note: See TracBrowser for help on using the repository browser.