source: 3DVCSoftware/branches/HTM-11.0-dev0-Qualcomm/source/Lib/TLibDecoder/TDecTop.cpp @ 1314

Last change on this file since 1314 was 960, checked in by qualcomm, 11 years ago

Implementation of JCT3V_H0056 -- Inference of sps_temporal_id_nesting_flag when it is not present.

Macro: H0056_SPS_TEMP_NESTING_FIX

Submitted by Hendry (fhendry@…)

  • Property svn:eol-style set to native
File size: 52.9 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-2014, 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 H_MV
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
43#endif
44//! \ingroup TLibDecoder
45//! \{
46
47#if H_3D
48CamParsCollector::CamParsCollector()
49: m_bInitialized( false )
50{
51  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
52  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
53  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
57  }
58
59  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
60  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
61  m_uiBitDepthForLUT = 8; // fixed
62  m_receivedIdc = NULL; 
63  m_vps         = NULL; 
64}
65
66CamParsCollector::~CamParsCollector()
67{
68  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
69  {
70    delete [] m_aaiCodedOffset      [ uiId ];
71    delete [] m_aaiCodedScale       [ uiId ];
72  }
73  delete [] m_aaiCodedOffset;
74  delete [] m_aaiCodedScale;
75
76  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
78  xDeleteArray( m_receivedIdc, m_uiMaxViewIndex + 1 );
79}
80
81
82Void
83CamParsCollector::init( FILE* pCodedScaleOffsetFile, TComVPS* vps)
84{
85  assert( !isInitialized() ); // Only one initialization currently supported
86  m_bInitialized            = true;
87  m_vps                     = vps; 
88  m_bCamParsVaryOverTime    = false; 
89  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
90  m_lastPoc                 = -1;   
91  m_firstReceivedPoc        = -2; 
92
93  m_uiMaxViewIndex            = -1; 
94  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
95  {
96    Int curViewIdx = m_vps->getViewIndex( m_vps->getLayerIdInNuh( i )); 
97    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->hasCamParInSliceHeader( curViewIdx );
98    m_uiMaxViewIndex = std::max( m_uiMaxViewIndex, curViewIdx  ) ; 
99  }
100
101  assert( m_receivedIdc == NULL ); 
102  m_receivedIdc = new Int*[ m_uiMaxViewIndex + 1]; 
103  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
104  {
105    m_receivedIdc[i] = new Int[ m_uiMaxViewIndex + 1 ]; 
106  }
107
108  xResetReceivedIdc( true ); 
109
110  for (Int viewIndex = 0; viewIndex <= m_uiMaxViewIndex ; viewIndex++ )
111  {
112    if (m_vps->getCamParPresent( viewIndex ) )
113    {   
114      if( !m_vps->hasCamParInSliceHeader( viewIndex ) ) 
115      {
116        for (Int baseViewIndex = 0; baseViewIndex < viewIndex ; baseViewIndex++ )
117        { 
118          m_receivedIdc   [ baseViewIndex ][ viewIndex ] = -1; 
119          m_aaiCodedScale [ baseViewIndex ][ viewIndex ] = m_vps->getCodedScale    (viewIndex) [ baseViewIndex ];
120          m_aaiCodedOffset[ baseViewIndex ][ viewIndex ] = m_vps->getCodedOffset   (viewIndex) [ baseViewIndex ];
121
122          m_receivedIdc   [ viewIndex ][ baseViewIndex ] = -1; 
123          m_aaiCodedScale [ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedScale (viewIndex) [ baseViewIndex ];
124          m_aaiCodedOffset[ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedOffset(viewIndex) [ baseViewIndex ];
125          xInitLUTs( baseViewIndex, viewIndex, m_aaiCodedScale[ baseViewIndex ][ viewIndex ], m_aaiCodedOffset[ baseViewIndex ][ viewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
126          xInitLUTs( viewIndex, baseViewIndex, m_aaiCodedScale[ viewIndex ][ baseViewIndex ], m_aaiCodedOffset[ viewIndex ][ baseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
127        }
128      }
129    }
130  }
131}
132
133Void
134CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
135{
136  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
137  { 
138    for (Int j = 0; j <= m_uiMaxViewIndex; j++)
139    {
140      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
141      {
142        m_receivedIdc[i][j] = 0; 
143      }     
144    }
145  }
146}
147
148
149Void
150CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
151{
152
153  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
154  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
155
156  radLUT         = new Double***[ uiNumberSourceViews ];
157  raiLUT         = new Int   ***[ uiNumberSourceViews ];
158
159  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
160  {
161    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
162    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
163
164    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
165    {
166      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
167      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
168      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
169
170      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
171      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
172      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
173    }
174  }
175}
176
177Void
178  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
179{
180  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCamParPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
181  Int     iLog2DivChroma = iLog2DivLuma + 1;
182
183  iOffset <<= m_uiBitDepthForLUT;
184
185  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
186  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
187
188  // offsets including rounding offsets
189  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
190  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
191
192
193  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
194  {
195
196    // real-valued look-up tables
197    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
198    Double  dShiftChroma    = dShiftLuma / 2;
199    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
200    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
201
202    // integer-valued look-up tables
203    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
204    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
205    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
206    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
207    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
208  }
209
210  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
211  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
212  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
213  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
214}
215
216Void
217CamParsCollector::uninit()
218{
219  m_bInitialized = false;
220}
221
222Void
223CamParsCollector::setSlice( TComSlice* pcSlice )
224{
225  if( pcSlice == 0 )
226  {
227    xOutput( m_lastPoc );
228    return;
229  }
230
231  if ( pcSlice->getIsDepth())
232  {
233    return;
234  }
235
236  Int curPoc = pcSlice->getPOC();
237  if( m_firstReceivedPoc == -2 )
238  {
239    m_firstReceivedPoc = curPoc; 
240  }
241
242  Bool newPocFlag = ( m_lastPoc != curPoc ); 
243
244  if ( newPocFlag )
245  {   
246    if( m_lastPoc != -1 )
247    {
248      xOutput( m_lastPoc );
249    }
250
251    xResetReceivedIdc( false ); 
252    m_lastPoc = pcSlice->getPOC();
253  }
254
255  UInt uiViewIndex          = pcSlice->getViewIndex(); 
256  if( m_vps->getCamParPresent( uiViewIndex ) )
257  {   
258    if( m_vps->hasCamParInSliceHeader( uiViewIndex ) ) // check consistency of slice parameters here
259    {   
260      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
261      {       
262        if ( m_receivedIdc[ uiViewIndex ][ uiBaseViewIndex ] != 0 )
263        {     
264          AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
265          AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
266        }
267        else
268        {         
269          m_receivedIdc   [ uiViewIndex ][ uiBaseViewIndex ]  = 1; 
270          m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedScale () [ uiBaseViewIndex ];
271          m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseViewIndex ];
272          xInitLUTs( uiViewIndex, uiBaseViewIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseViewIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
273        }
274        if ( m_receivedIdc[ uiBaseViewIndex ][ uiViewIndex ] != 0 )
275        {     
276          AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
277          AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
278        }
279        else
280        {       
281          m_receivedIdc   [ uiBaseViewIndex ][ uiViewIndex ]  = 1; 
282          m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseViewIndex ];
283          m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseViewIndex ];
284          xInitLUTs( uiBaseViewIndex, uiViewIndex, m_aaiCodedScale[ uiBaseViewIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
285        }
286      }
287    }
288  }
289}
290
291
292#if H_3D_IV_MERGE
293Void
294CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
295{
296  if( m_bCamParsVaryOverTime )
297  {
298    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
299  }
300}
301#endif
302
303
304Void
305CamParsCollector::xOutput( Int iPOC )
306{
307  if( m_pCodedScaleOffsetFile )
308  {
309    if( iPOC == m_firstReceivedPoc )
310    {
311      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
312      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
313      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
314      {
315        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_vps->getViewIdVal( uiViewIndex ) );
316      }
317      fprintf( m_pCodedScaleOffsetFile, "\n\n");
318      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
319      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
320    }
321    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
322    {
323      Int iS = iPOC;
324      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
325      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
326      {
327        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
328        {
329          if( uiViewIndex != uiBaseIndex )
330          {
331            if ( m_receivedIdc[uiBaseIndex][uiViewIndex] != 0 )
332            {           
333              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
334                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCamParPrecision() );
335            }           
336          }
337        }
338      }
339    }
340  }
341}
342#endif
343TDecTop::TDecTop()
344{
345  m_pcPic = 0;
346  m_iMaxRefPicNum = 0;
347#if ENC_DEC_TRACE
348#if H_MV
349  if ( g_hTrace == NULL )
350  {
351#endif
352  g_hTrace = fopen( "TraceDec.txt", "wb" );
353  g_bJustDoIt = g_bEncDecTraceDisable;
354  g_nSymbolCounter = 0;
355#if H_MV
356  }
357#endif
358#endif
359  m_associatedIRAPType = NAL_UNIT_INVALID;
360  m_pocCRA = 0;
361  m_pocRandomAccess = MAX_INT; 
362  m_prevPOC                = MAX_INT;
363  m_bFirstSliceInPicture    = true;
364  m_bFirstSliceInSequence   = true;
365  m_prevSliceSkipped = false;
366  m_skippedPOC = 0;
367#if H0056_EOS_CHECKS
368  m_isLastNALWasEos = false;
369#endif
370#if H_MV
371  m_layerId = 0;
372  m_viewId = 0;
373#if H_3D
374  m_viewIndex = 0; 
375  m_isDepth = false;
376  m_pcCamParsCollector = 0;
377#endif
378#endif
379}
380
381TDecTop::~TDecTop()
382{
383#if ENC_DEC_TRACE
384  fclose( g_hTrace );
385#endif
386}
387
388Void TDecTop::create()
389{
390  m_cGopDecoder.create();
391  m_apcSlicePilot = new TComSlice;
392  m_uiSliceIdx = 0;
393}
394
395Void TDecTop::destroy()
396{
397  m_cGopDecoder.destroy();
398 
399  delete m_apcSlicePilot;
400  m_apcSlicePilot = NULL;
401 
402  m_cSliceDecoder.destroy();
403}
404
405Void TDecTop::init()
406{
407  // initialize ROM
408#if !H_MV
409  initROM();
410#endif
411  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
412  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
413  m_cEntropyDecoder.init(&m_cPrediction);
414}
415
416Void TDecTop::deletePicBuffer ( )
417{
418  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
419  Int iSize = Int( m_cListPic.size() );
420 
421  for (Int i = 0; i < iSize; i++ )
422  {
423    TComPic* pcPic = *(iterPic++);
424#if H_MV
425    if( pcPic )
426    {
427#endif
428    pcPic->destroy();
429   
430    delete pcPic;
431    pcPic = NULL;
432#if H_MV
433    }
434#endif
435  }
436 
437  m_cSAO.destroy();
438 
439  m_cLoopFilter.        destroy();
440 
441#if !H_MV
442  // destroy ROM
443  destroyROM();
444#endif
445}
446
447Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
448{
449  Int  numReorderPics[MAX_TLAYER];
450  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
451  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
452
453#if H_MV
454    assert( conformanceWindow   .getScaledFlag() ); 
455    assert( defaultDisplayWindow.getScaledFlag() );
456#endif
457  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
458  {
459#if H_MV
460    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
461#else
462    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
463#endif
464  }
465#if H_MV
466  if ( getLayerId() == 0 )
467  { 
468    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
469  }
470  else
471  {
472    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
473#if H_MV_HLS7_GEN
474    TComVPS* vps         = pcSlice->getVPS();
475    TComDpbSize* dpbSize = vps->getDpbSize(); 
476    Int lsIdx            = vps->getLayerSetIdxForOutputLayerSet( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
477    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
478    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
479    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
480#endif   
481  }
482#else
483  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
484#endif
485  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
486  {
487    rpcPic = new TComPic();
488   
489    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
490                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
491    m_cListPic.pushBack( rpcPic );
492   
493    return;
494  }
495 
496  Bool bBufferIsAvailable = false;
497  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
498  while (iterPic != m_cListPic.end())
499  {
500    rpcPic = *(iterPic++);
501    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
502    {
503      rpcPic->setOutputMark(false);
504      bBufferIsAvailable = true;
505      break;
506    }
507
508    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
509    {
510      rpcPic->setOutputMark(false);
511      rpcPic->setReconMark( false );
512      rpcPic->getPicYuvRec()->setBorderExtension( false );
513      bBufferIsAvailable = true;
514      break;
515    }
516  }
517 
518  if ( !bBufferIsAvailable )
519  {
520    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
521    m_iMaxRefPicNum++;
522    rpcPic = new TComPic();
523    m_cListPic.pushBack( rpcPic );
524  }
525  rpcPic->destroy();
526  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
527                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
528}
529
530#if H_MV
531Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
532#else
533Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
534#endif
535{
536  if (!m_pcPic)
537  {
538    /* nothing to deblock */
539    return;
540  }
541 
542  TComPic*&   pcPic         = m_pcPic;
543
544  // Execute Deblock + Cleanup
545
546  m_cGopDecoder.filterPicture(pcPic);
547
548  TComSlice::sortPicList( m_cListPic ); // sorting for application output
549  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
550  rpcListPic          = &m_cListPic; 
551  m_cCuDecoder.destroy();       
552#if H_MV
553  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
554  TComSlice::markCurrPic( pcPic ); 
555  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
556#endif
557  m_bFirstSliceInPicture  = true;
558
559  return;
560}
561
562Void TDecTop::xCreateLostPicture(Int iLostPoc) 
563{
564  printf("\ninserting lost poc : %d\n",iLostPoc);
565  TComSlice cFillSlice;
566  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
567  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
568  cFillSlice.initSlice();
569  TComPic *cFillPic;
570  xGetNewPicBuffer(&cFillSlice,cFillPic);
571  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
572  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
573  cFillPic->getSlice(0)->initSlice();
574 
575  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
576  Int closestPoc = 1000000;
577  while ( iterPic != m_cListPic.end())
578  {
579    TComPic * rpcPic = *(iterPic++);
580    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())
581    {
582      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
583    }
584  }
585  iterPic = m_cListPic.begin();
586  while ( iterPic != m_cListPic.end())
587  {
588    TComPic *rpcPic = *(iterPic++);
589    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
590    {
591      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
592      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
593      break;
594    }
595  }
596  cFillPic->setCurrSliceIdx(0);
597  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
598  {
599    cFillPic->getCU(i)->initCU(cFillPic,i);
600  }
601  cFillPic->getSlice(0)->setReferenced(true);
602  cFillPic->getSlice(0)->setPOC(iLostPoc);
603  cFillPic->setReconMark(true);
604  cFillPic->setOutputMark(true);
605  if(m_pocRandomAccess == MAX_INT)
606  {
607    m_pocRandomAccess = iLostPoc;
608  }
609}
610
611
612Void TDecTop::xActivateParameterSets()
613{
614  m_parameterSetManagerDecoder.applyPrefetchedPS();
615 
616  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
617  assert (pps != 0);
618
619  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
620  assert (sps != 0);
621
622#if H_MV
623  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
624  assert (vps != 0); 
625  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
626#else
627  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
628#endif
629  {
630    printf ("Parameter set activation failed!");
631    assert (0);
632  }
633
634#if H0056_SPS_TEMP_NESTING_FIX
635  if( m_layerId > 0 )
636  {
637    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
638  }
639#endif
640
641  if( pps->getDependentSliceSegmentsEnabledFlag() )
642  {
643    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
644
645    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
646    {
647      m_cSliceDecoder.initCtxMem(NumCtx);
648      for ( UInt st = 0; st < NumCtx; st++ )
649      {
650        TDecSbac* ctx = NULL;
651        ctx = new TDecSbac;
652        ctx->init( &m_cBinCABAC );
653        m_cSliceDecoder.setCtxMem( ctx, st );
654      }
655    }
656  }
657
658  m_apcSlicePilot->setPPS(pps);
659  m_apcSlicePilot->setSPS(sps);
660#if H_MV
661  m_apcSlicePilot->setVPS(vps); 
662  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
663  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, pps->getLayerId() ) );   
664  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
665  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, sps->getLayerId() ) );
666  sps->inferRepFormat  ( vps , m_layerId ); 
667  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
668#endif
669  pps->setSPS(sps);
670  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
671  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
672
673  g_bitDepthY     = sps->getBitDepthY();
674  g_bitDepthC     = sps->getBitDepthC();
675  g_uiMaxCUWidth  = sps->getMaxCUWidth();
676  g_uiMaxCUHeight = sps->getMaxCUHeight();
677  g_uiMaxCUDepth  = sps->getMaxCUDepth();
678  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
679
680  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
681  {
682    sps->setAMPAcc( i, sps->getUseAMP() );
683  }
684
685  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
686  {
687    sps->setAMPAcc( i, 0 );
688  }
689
690  m_cSAO.destroy();
691  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
692  m_cLoopFilter.create( sps->getMaxCUDepth() );
693}
694
695#if H_MV
696Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
697{
698  assert( nalu.m_layerId == m_layerId ); 
699#else
700Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
701{
702#endif
703  TComPic*&   pcPic         = m_pcPic;
704  m_apcSlicePilot->initSlice();
705
706  if (m_bFirstSliceInPicture)
707  {
708    m_uiSliceIdx     = 0;
709  }
710  else
711  {
712    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
713  }
714  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
715
716  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
717  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
718                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
719                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
720                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
721                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
722  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
723 
724  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
725  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
726
727#if H_MV
728  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
729  m_apcSlicePilot->setLayerId( nalu.m_layerId );
730#endif
731  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
732
733  // set POC for dependent slices in skipped pictures
734  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
735  {
736    m_apcSlicePilot->setPOC(m_skippedPOC);
737  }
738
739  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
740  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
741
742#if H_MV 
743  TComVPS* vps     = m_apcSlicePilot->getVPS();
744  Int layerId  = nalu.m_layerId;   
745  setViewId   ( vps->getViewId   ( layerId )      ); 
746#if H_3D
747  setViewIndex( vps->getViewIndex( layerId )      ); 
748  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
749  m_ivPicLists->setVPS( vps ); 
750#endif
751#endif
752
753#if H_MV
754    xCeckNoClrasOutput();
755#endif
756    // Skip pictures due to random access
757    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
758    {
759    m_prevSliceSkipped = true;
760    m_skippedPOC = m_apcSlicePilot->getPOC();
761#if H_MV
762    sliceSkippedFlag = true; 
763#endif
764      return false;
765    }
766    // Skip TFD pictures associated with BLA/BLANT pictures
767    if (isSkipPictureForBLA(iPOCLastDisplay))
768    {
769    m_prevSliceSkipped = true;
770    m_skippedPOC = m_apcSlicePilot->getPOC();
771#if H_MV
772    sliceSkippedFlag = true; 
773#endif
774      return false;
775    }
776
777  // clear previous slice skipped flag
778  m_prevSliceSkipped = false;
779
780  //we should only get a different poc for a new picture (with CTU address==0)
781  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
782  {
783    printf ("Warning, the first slice of a picture might have been lost!\n");
784  }
785  // exit when a new picture is found
786  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
787  {
788    if (m_prevPOC >= m_pocRandomAccess)
789    {
790      m_prevPOC = m_apcSlicePilot->getPOC();
791      return true;
792    }
793    m_prevPOC = m_apcSlicePilot->getPOC();
794  }
795#if H_MV
796  if ( newLayerFlag )
797  {
798    return false; 
799  }
800#if ENC_DEC_TRACE
801#if H_MV_ENC_DEC_TRAC
802  // parse remainder of SH
803   g_disableHLSTrace = false; 
804#endif
805#endif
806#endif
807  // actual decoding starts here
808#if H_MV
809   // This part needs further testing !
810   if ( m_apcSlicePilot->getPocResetFlag() )
811   {   
812     xResetPocInPicBuffer();
813   }
814#endif
815  xActivateParameterSets();
816
817  if (m_apcSlicePilot->isNextSlice()) 
818  {
819    m_prevPOC = m_apcSlicePilot->getPOC();
820  }
821  m_bFirstSliceInSequence = false;
822  //detect lost reference picture and insert copy of earlier frame.
823  Int lostPoc;
824  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
825  {
826    xCreateLostPicture(lostPoc-1);
827  }
828  if (m_bFirstSliceInPicture)
829  {
830    // Buffer initialize for prediction.
831    m_cPrediction.initTempBuff();
832    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
833#if H_MV
834    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
835#endif
836    //  Get a new picture buffer
837    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
838
839    Bool isField = false;
840    Bool isTff = false;
841   
842    if(!m_SEIs.empty())
843    {
844      // Check if any new Picture Timing SEI has arrived
845      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
846      if (pictureTimingSEIs.size()>0)
847      {
848        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
849        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
850        isTff =  (pictureTiming->m_picStruct == 1);
851      }
852    }
853   
854    //Set Field/Frame coding mode
855    m_pcPic->setField(isField);
856    m_pcPic->setTopField(isTff);
857   
858    // transfer any SEI messages that have been received to the picture
859    pcPic->setSEIs(m_SEIs);
860    m_SEIs.clear();
861
862    // Recursive structure
863    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
864    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
865    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
866
867    m_cSliceDecoder.create();
868  }
869  else
870  {
871    // Check if any new SEI has arrived
872    if(!m_SEIs.empty())
873    {
874      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
875      SEIMessages &picSEI = pcPic->getSEIs();
876      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
877      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
878      deleteSEIs(m_SEIs);
879    }
880  }
881 
882  //  Set picture slice pointer
883  TComSlice*  pcSlice = m_apcSlicePilot;
884  Bool bNextSlice     = pcSlice->isNextSlice();
885
886  UInt uiCummulativeTileWidth;
887  UInt uiCummulativeTileHeight;
888  UInt i, j, p;
889
890  //set NumColumnsMins1 and NumRowsMinus1
891  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
892  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
893
894  //create the TComTileArray
895  pcPic->getPicSym()->xCreateTComTileArray();
896
897  if( pcSlice->getPPS()->getUniformSpacingFlag() )
898  {
899    //set the width for each tile
900    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
901    {
902      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
903      {
904        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
905          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
906          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
907      }
908    }
909
910    //set the height for each tile
911    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
912    {
913      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
914      {
915        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
916          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
917          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
918      }
919    }
920  }
921  else
922  {
923    //set the width for each tile
924    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
925    {
926      uiCummulativeTileWidth = 0;
927      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
928      {
929        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
930        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
931      }
932      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
933    }
934
935    //set the height for each tile
936    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
937    {
938      uiCummulativeTileHeight = 0;
939      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
940      { 
941        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
942        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
943      }
944      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
945    }
946  }
947
948  pcPic->getPicSym()->xInitTiles();
949
950  //generate the Coding Order Map and Inverse Coding Order Map
951  UInt uiEncCUAddr;
952  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
953  {
954    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
955    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
956  }
957  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
958  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
959
960  //convert the start and end CU addresses of the slice and dependent slice into encoding order
961  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
962  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
963  if(pcSlice->isNextSlice())
964  {
965    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
966    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
967  }
968
969  if (m_bFirstSliceInPicture) 
970  {
971    if(pcPic->getNumAllocatedSlice() != 1)
972    {
973      pcPic->clearSliceBuffer();
974    }
975  }
976  else
977  {
978    pcPic->allocateNewSlice();
979  }
980  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
981  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
982  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
983
984  pcPic->setTLayer(nalu.m_temporalId);
985
986#if H_MV
987  pcPic->setLayerId( nalu.m_layerId );
988  pcPic->setViewId ( getViewId() );
989#if H_3D
990  pcPic->setViewIndex( getViewIndex() );
991  pcPic->setIsDepth  ( getIsDepth  () );
992#endif
993#endif
994  if (bNextSlice)
995  {
996    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
997    // Set reference list
998#if H_MV   
999    std::vector< TComPic* > tempRefPicLists[2];
1000    std::vector< Bool     > usedAsLongTerm [2];
1001    Int       numPocTotalCurr;
1002
1003    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1004    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
1005#if H_3D_ARP
1006    pcSlice->setARPStepNum(m_ivPicLists);
1007    if( pcSlice->getARPStepNum() > 1 )
1008    {
1009      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
1010      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
1011      {
1012        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1013        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1014        if( iViewIdx<getViewIndex() && !bIsDepth )
1015        {
1016          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1017        }
1018      }
1019    }
1020#endif
1021#else
1022    pcSlice->setRefPicList( m_cListPic, true );
1023#endif
1024
1025#if H_3D
1026    pcSlice->setIvPicLists( m_ivPicLists );         
1027#if H_3D_IV_MERGE
1028#if H_3D_FCO
1029    //assert( !getIsDepth() );
1030#else
1031    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1032#endif
1033#endif   
1034#endif
1035    // For generalized B
1036    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1037    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1038    {
1039      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1040      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1041
1042      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1043      {
1044        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1045      }
1046    }
1047    if (!pcSlice->isIntra())
1048    {
1049      Bool bLowDelay = true;
1050      Int  iCurrPOC  = pcSlice->getPOC();
1051      Int iRefIdx = 0;
1052
1053      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1054      {
1055        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1056        {
1057          bLowDelay = false;
1058        }
1059      }
1060      if (pcSlice->isInterB())
1061      {
1062        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1063        {
1064          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1065          {
1066            bLowDelay = false;
1067          }
1068        }       
1069      }
1070
1071      pcSlice->setCheckLDC(bLowDelay);           
1072    }
1073
1074    //---------------
1075    pcSlice->setRefPOCList();
1076#if  H_3D_TMVP
1077    if(pcSlice->getLayerId())
1078      pcSlice->generateAlterRefforTMVP();
1079#endif
1080  }
1081
1082  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1083  if(pcSlice->getSPS()->getScalingListFlag())
1084  {
1085    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1086    if(pcSlice->getPPS()->getScalingListPresentFlag())
1087    {
1088      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1089    }
1090    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1091    {
1092      pcSlice->setDefaultScalingList();
1093    }
1094    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1095    m_cTrQuant.setUseScalingList(true);
1096  }
1097  else
1098  {
1099    m_cTrQuant.setFlatScalingList();
1100    m_cTrQuant.setUseScalingList(false);
1101  }
1102
1103#if H_3D_IV_MERGE
1104  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1105  {
1106    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1107  }
1108#endif
1109
1110  //  Decode a picture
1111  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1112#if H_3D
1113  if( m_pcCamParsCollector )
1114  {
1115    m_pcCamParsCollector->setSlice( pcSlice );
1116  }
1117#endif
1118  m_bFirstSliceInPicture = false;
1119  m_uiSliceIdx++;
1120
1121  return false;
1122}
1123
1124Void TDecTop::xDecodeVPS()
1125{
1126  TComVPS* vps = new TComVPS();
1127 
1128  m_cEntropyDecoder.decodeVPS( vps );
1129  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1130}
1131
1132Void TDecTop::xDecodeSPS()
1133{
1134  TComSPS* sps = new TComSPS();
1135#if H_MV
1136  sps->setLayerId( getLayerId() ); 
1137#endif
1138#if H_3D
1139  // Preliminary fix. assuming that all sps refer to the same SPS.
1140  // Parsing dependency should be resolved!
1141  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1142  assert( vps != 0 ); 
1143  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1144#else
1145  m_cEntropyDecoder.decodeSPS( sps );
1146#endif
1147  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1148}
1149
1150Void TDecTop::xDecodePPS()
1151{
1152  TComPPS* pps = new TComPPS();
1153#if H_MV
1154  pps->setLayerId( getLayerId() ); 
1155#endif
1156#if H_3D
1157  // Assuming that all PPS indirectly refer to the same VPS via different SPS
1158  // There is no parsing dependency in decoding DLT in PPS.
1159  // The VPS information passed to decodePPS() is used to arrange the decoded DLT tables to their corresponding layers.
1160  // This is equivalent to the process of
1161  //   Step 1) decoding DLT tables based on the number of depth layers, and
1162  //   Step 2) mapping DLT tables to the depth layers
1163  // as described in the 3D-HEVC WD.
1164  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
1165  m_cEntropyDecoder.decodePPS( pps, vps );
1166#else
1167  m_cEntropyDecoder.decodePPS( pps );
1168#endif
1169  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1170}
1171
1172Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1173{
1174  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1175  {
1176#if H_MV
1177    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1178#else
1179    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1180#endif
1181  }
1182  else
1183  {
1184#if H_MV
1185    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1186#else
1187    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1188#endif
1189    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1190    if (activeParamSets.size()>0)
1191    {
1192      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1193      m_parameterSetManagerDecoder.applyPrefetchedPS();
1194      assert(seiAps->activeSeqParamSetId.size()>0);
1195#if H_MV
1196      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
1197#else
1198      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1199#endif
1200      {
1201        printf ("Warning SPS activation with Active parameter set SEI failed");
1202      }
1203    }
1204  }
1205}
1206
1207#if H_MV
1208Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1209#else
1210Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1211#endif
1212{
1213  // Initialize entropy decoder
1214  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1215  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1216
1217  switch (nalu.m_nalUnitType)
1218  {
1219    case NAL_UNIT_VPS:
1220      xDecodeVPS();
1221#if H0056_EOS_CHECKS
1222      m_isLastNALWasEos = false;
1223#endif
1224      return false;
1225     
1226    case NAL_UNIT_SPS:
1227      xDecodeSPS();
1228      return false;
1229
1230    case NAL_UNIT_PPS:
1231      xDecodePPS();
1232      return false;
1233     
1234    case NAL_UNIT_PREFIX_SEI:
1235    case NAL_UNIT_SUFFIX_SEI:
1236#if H0056_EOS_CHECKS
1237      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1238      {
1239        assert( m_isLastNALWasEos == false );
1240      }
1241#endif
1242      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1243      return false;
1244
1245    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1246    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1247    case NAL_UNIT_CODED_SLICE_TSA_R:
1248    case NAL_UNIT_CODED_SLICE_TSA_N:
1249    case NAL_UNIT_CODED_SLICE_STSA_R:
1250    case NAL_UNIT_CODED_SLICE_STSA_N:
1251    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1252    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1253    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1254    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1255    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1256    case NAL_UNIT_CODED_SLICE_CRA:
1257    case NAL_UNIT_CODED_SLICE_RADL_N:
1258    case NAL_UNIT_CODED_SLICE_RADL_R:
1259    case NAL_UNIT_CODED_SLICE_RASL_N:
1260    case NAL_UNIT_CODED_SLICE_RASL_R:
1261#if H0056_EOS_CHECKS
1262      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1263          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1264          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1265          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1266          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1267      {
1268        assert( m_isLastNALWasEos == false );
1269      }
1270      else
1271      {
1272        m_isLastNALWasEos = false;
1273      }
1274#endif
1275#if H_MV
1276      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1277#else
1278      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1279#endif
1280      break;
1281    case NAL_UNIT_EOS:
1282#if H0056_EOS_CHECKS
1283      assert( m_isLastNALWasEos == false );
1284      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1285      if (nalu.m_layerId > 0)
1286      {
1287        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1288        return false;
1289      }
1290      m_isLastNALWasEos = true;
1291#endif
1292      m_associatedIRAPType = NAL_UNIT_INVALID;
1293      m_pocCRA = 0;
1294      m_pocRandomAccess = MAX_INT;
1295      m_prevPOC = MAX_INT;
1296      m_bFirstSliceInPicture = true;
1297      m_bFirstSliceInSequence = true;
1298      m_prevSliceSkipped = false;
1299      m_skippedPOC = 0;
1300      return false;
1301     
1302    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1303      // TODO: process AU delimiter
1304      return false;
1305     
1306    case NAL_UNIT_EOB:
1307      return false;
1308     
1309#if H0056_EOS_CHECKS
1310    case NAL_UNIT_FILLER_DATA:
1311      assert( m_isLastNALWasEos == false );
1312      return false;
1313#endif
1314     
1315    case NAL_UNIT_RESERVED_VCL_N10:
1316    case NAL_UNIT_RESERVED_VCL_R11:
1317    case NAL_UNIT_RESERVED_VCL_N12:
1318    case NAL_UNIT_RESERVED_VCL_R13:
1319    case NAL_UNIT_RESERVED_VCL_N14:
1320    case NAL_UNIT_RESERVED_VCL_R15:
1321     
1322    case NAL_UNIT_RESERVED_IRAP_VCL22:
1323    case NAL_UNIT_RESERVED_IRAP_VCL23:
1324     
1325    case NAL_UNIT_RESERVED_VCL24:
1326    case NAL_UNIT_RESERVED_VCL25:
1327    case NAL_UNIT_RESERVED_VCL26:
1328    case NAL_UNIT_RESERVED_VCL27:
1329    case NAL_UNIT_RESERVED_VCL28:
1330    case NAL_UNIT_RESERVED_VCL29:
1331    case NAL_UNIT_RESERVED_VCL30:
1332    case NAL_UNIT_RESERVED_VCL31:
1333     
1334#if !H0056_EOS_CHECKS
1335    case NAL_UNIT_FILLER_DATA:
1336#endif
1337    case NAL_UNIT_RESERVED_NVCL41:
1338    case NAL_UNIT_RESERVED_NVCL42:
1339    case NAL_UNIT_RESERVED_NVCL43:
1340    case NAL_UNIT_RESERVED_NVCL44:
1341    case NAL_UNIT_RESERVED_NVCL45:
1342    case NAL_UNIT_RESERVED_NVCL46:
1343    case NAL_UNIT_RESERVED_NVCL47:
1344    case NAL_UNIT_UNSPECIFIED_48:
1345    case NAL_UNIT_UNSPECIFIED_49:
1346    case NAL_UNIT_UNSPECIFIED_50:
1347    case NAL_UNIT_UNSPECIFIED_51:
1348    case NAL_UNIT_UNSPECIFIED_52:
1349    case NAL_UNIT_UNSPECIFIED_53:
1350    case NAL_UNIT_UNSPECIFIED_54:
1351    case NAL_UNIT_UNSPECIFIED_55:
1352    case NAL_UNIT_UNSPECIFIED_56:
1353    case NAL_UNIT_UNSPECIFIED_57:
1354    case NAL_UNIT_UNSPECIFIED_58:
1355    case NAL_UNIT_UNSPECIFIED_59:
1356    case NAL_UNIT_UNSPECIFIED_60:
1357    case NAL_UNIT_UNSPECIFIED_61:
1358    case NAL_UNIT_UNSPECIFIED_62:
1359    case NAL_UNIT_UNSPECIFIED_63:
1360    default:
1361      assert (0);
1362  }
1363
1364  return false;
1365}
1366
1367/** Function for checking if picture should be skipped because of association with a previous BLA picture
1368 * \param iPOCLastDisplay POC of last picture displayed
1369 * \returns true if the picture should be skipped
1370 * This function skips all TFD pictures that follow a BLA picture
1371 * in decoding order and precede it in output order.
1372 */
1373Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1374{
1375  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) && 
1376       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1377  {
1378    iPOCLastDisplay++;
1379    return true;
1380  }
1381  return false;
1382}
1383
1384/** Function for checking if picture should be skipped because of random access
1385 * \param iSkipFrame skip frame counter
1386 * \param iPOCLastDisplay POC of last picture displayed
1387 * \returns true if the picture shold be skipped in the random access.
1388 * This function checks the skipping of pictures in the case of -s option random access.
1389 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1390 * It also checks the type of Nal unit type at the random access point.
1391 * 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.
1392 * If the random access point is IDR all pictures after the random access point are decoded.
1393 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1394 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1395 * access point there is no guarantee that the decoder will not crash.
1396 */
1397Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1398{
1399  if (iSkipFrame) 
1400  {
1401    iSkipFrame--;   // decrement the counter
1402    return true;
1403  }
1404#if H_MV
1405  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1406#else
1407  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1408#endif
1409  {
1410    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1411        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1412        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1413        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1414    {
1415
1416#if H_MV
1417      if ( xAllRefLayersInitilized() )
1418      {
1419        m_layerInitilizedFlag[ m_layerId ] = true; 
1420        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1421      }
1422      else
1423      {
1424        return true; 
1425      }
1426#else
1427      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1428      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1429#endif
1430    }
1431    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1432    {
1433#if H_MV
1434      if ( xAllRefLayersInitilized() )
1435      {
1436        m_layerInitilizedFlag[ m_layerId ] = true; 
1437        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1438      }
1439      else 
1440      {
1441        return true; 
1442      }
1443#else
1444      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1445#endif
1446    }
1447    else 
1448    {
1449#if H_MV
1450      static Bool warningMessage[MAX_NUM_LAYERS];
1451      static Bool warningInitFlag = false;
1452     
1453      if (!warningInitFlag)
1454      {
1455        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1456        {
1457          warningMessage[i] = true; 
1458        }
1459        warningInitFlag = true; 
1460      }
1461
1462      if ( warningMessage[getLayerId()] )
1463      {
1464        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1465        warningMessage[m_layerId] = false; 
1466      }
1467#else
1468      static Bool warningMessage = false;
1469      if(!warningMessage)
1470      {
1471        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1472        warningMessage = true;
1473      }
1474#endif
1475      return true;
1476    }
1477  }
1478  // skip the reordered pictures, if necessary
1479  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))
1480  {
1481    iPOCLastDisplay++;
1482    return true;
1483  }
1484#if H_MV
1485  return !m_layerInitilizedFlag[ getLayerId() ]; 
1486#else
1487  // if we reach here, then the picture is not skipped.
1488  return false; 
1489#endif
1490}
1491
1492#if H_MV
1493TComPic* TDecTop::getPic( Int poc )
1494{
1495  xGetPic( m_layerId, poc ); 
1496  TComList<TComPic*>* listPic = getListPic();
1497  TComPic* pcPic = NULL;
1498  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1499  {
1500    if( (*it)->getPOC() == poc )
1501    {
1502      pcPic = *it ;
1503      break ;
1504    }
1505  }
1506  return pcPic;
1507}
1508
1509TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1510{ 
1511  return m_ivPicLists->getPic( layerId, poc ) ;
1512}
1513
1514Void TDecTop::xResetPocInPicBuffer()
1515{
1516  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1517  while (iterPic != m_cListPic.end())
1518  {
1519    TComPic* pic = *(iterPic++);
1520    if ( pic->getReconMark() )
1521    {
1522      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1523      {
1524        TComSlice* slice = pic->getSlice( i ); 
1525        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1526      }         
1527    }     
1528  }
1529}
1530
1531#if H_MV
1532Void TDecTop::xCeckNoClrasOutput()
1533{
1534  // This part needs further testing!
1535  if ( getLayerId() == 0 )
1536  {   
1537    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1538
1539    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1540    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1541    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1542
1543    if ( noClrasOutputFlag ) 
1544    {
1545      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1546      {
1547        m_layerInitilizedFlag[i] = false; 
1548      } 
1549    }
1550  }
1551}
1552
1553Bool TDecTop::xAllRefLayersInitilized()
1554{
1555  Bool allRefLayersInitilizedFlag = true; 
1556  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1557  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1558  {
1559    Int refLayerId = vps->getRefLayerId( m_layerId, i ); 
1560    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1561  }
1562
1563  return allRefLayersInitilizedFlag;
1564}
1565#endif
1566#endif
1567//! \}
Note: See TracBrowser for help on using the repository browser.