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

Last change on this file since 1314 was 1200, checked in by tech, 10 years ago

Update to HM-16.5.
Starting point for further re-activation of 3D-tools.

Includes:

active:

  • MV-HEVC
  • 3D-HLS (apart from DLT)
  • VSO

inactive:

  • remaining 3D-HEVC tools.
  • Property svn:eol-style set to native
File size: 57.0 KB
RevLine 
[5]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
[1200]4 * granted under this license.
[5]5 *
[1200]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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
[2]34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
[56]38#include "NALread.h"
[2]39#include "TDecTop.h"
[1200]40#if NH_MV
41ParameterSetManager TDecTop::m_parameterSetManager;
42#endif
[2]43
[56]44//! \ingroup TLibDecoder
45//! \{
[2]46
[1200]47#if NH_3D
[2]48CamParsCollector::CamParsCollector()
49: m_bInitialized( false )
50{
[608]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++ )
[2]54  {
[608]55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
[2]57  }
[296]58
[608]59  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
[296]60  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
61  m_uiBitDepthForLUT = 8; // fixed
[872]62  m_receivedIdc = NULL; 
63  m_vps         = NULL; 
[2]64}
65
66CamParsCollector::~CamParsCollector()
67{
[608]68  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
[2]69  {
70    delete [] m_aaiCodedOffset      [ uiId ];
71    delete [] m_aaiCodedScale       [ uiId ];
72  }
73  delete [] m_aaiCodedOffset;
74  delete [] m_aaiCodedScale;
[296]75
[608]76  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
[1179]78  xDeleteArray( m_receivedIdc, m_vps->getNumViews() );
[2]79}
80
[872]81
[2]82Void
[1200]83CamParsCollector::init( const TComVPS* vps)
[872]84{
85  assert( !isInitialized() ); // Only one initialization currently supported
86  m_bInitialized            = true;
87  m_vps                     = vps; 
[1200]88  m_bCamParsVaryOverTime    = false;   
[872]89  m_lastPoc                 = -1;   
90  m_firstReceivedPoc        = -2; 
91
[1179]92  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
93  {
94    Int curViewIdxInVps = m_vps->getVoiInVps( m_vps->getViewIndex( m_vps->getLayerIdInNuh( i ) ) ) ; 
95    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->getCpInSliceSegmentHeaderFlag( curViewIdxInVps );   
96  }
97
98  assert( m_receivedIdc == NULL ); 
99  m_receivedIdc = new Int*[ m_vps->getNumViews() ]; 
100  for (Int i = 0; i < m_vps->getNumViews(); i++)
101  {
102    m_receivedIdc[i] = new Int[ m_vps->getNumViews() ]; 
103  }
104
105  xResetReceivedIdc( true ); 
106
107  for (Int voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
108  {
109    if( !m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) 
110    {
111      for (Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
112      { 
113        if( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
114        {
115          m_receivedIdc   [ baseVoiInVps ][ voiInVps ] = -1; 
116          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] = m_vps->getCodedScale    (voiInVps) [ baseVoiInVps ];
117          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] = m_vps->getCodedOffset   (voiInVps) [ baseVoiInVps ];
118
119          m_receivedIdc   [ voiInVps ][ baseVoiInVps ] = -1; 
120          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedScale (voiInVps) [ baseVoiInVps ];
121          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedOffset(voiInVps) [ baseVoiInVps ];
122          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
123          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
124        }
125      }
126    }
127  }
128}
129
[872]130
131
132
133Void
134CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
135{
[1179]136  for (Int i = 0; i < m_vps->getNumViews(); i++)
137  { 
138    for (Int j = 0; j < m_vps->getNumViews(); j++)
139    {
[872]140      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
141      {
142        m_receivedIdc[i][j] = 0; 
143      }     
144    }
145  }
146}
[2]147
[872]148
[2]149Void
[296]150CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
151{
152
[608]153  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
154  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
[296]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{
[1179]180  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCpPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
[296]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
[2]217CamParsCollector::uninit()
218{
219  m_bInitialized = false;
220}
221
222Void
223CamParsCollector::setSlice( TComSlice* pcSlice )
224{
225  if( pcSlice == 0 )
226  {
[872]227    xOutput( m_lastPoc );
228    return;
229  }
230
[1084]231#if !H_3D_FCO
[872]232  if ( pcSlice->getIsDepth())
233  {
234    return;
235  }
[1066]236#endif
[872]237
238  Int curPoc = pcSlice->getPOC();
239  if( m_firstReceivedPoc == -2 )
240  {
241    m_firstReceivedPoc = curPoc; 
242  }
243
244  Bool newPocFlag = ( m_lastPoc != curPoc ); 
245
246  if ( newPocFlag )
247  {   
248    if( m_lastPoc != -1 )
249    {
250      xOutput( m_lastPoc );
251    }
252
253    xResetReceivedIdc( false ); 
254    m_lastPoc = pcSlice->getPOC();
255  }
256
[1179]257  UInt voiInVps          = m_vps->getVoiInVps(pcSlice->getViewIndex()); 
258  if( m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) // check consistency of slice parameters here
259  {   
260    for( Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
261    {       
262      if ( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
263      {
264        if ( m_receivedIdc[ voiInVps ][ baseVoiInVps ] != 0 )
265        {     
266          AOF( m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedScale () [ baseVoiInVps ] );
267          AOF( m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedOffset() [ baseVoiInVps ] );
268        }
269        else
270        {         
271          m_receivedIdc   [ voiInVps ][ baseVoiInVps ]  = 1; 
272          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedScale () [ baseVoiInVps ];
273          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedOffset() [ baseVoiInVps ];
274          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
275        }
276        if ( m_receivedIdc[ baseVoiInVps ][ voiInVps ] != 0 )
277        {     
278          AOF( m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedScale    () [ baseVoiInVps ] );
279          AOF( m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedOffset   () [ baseVoiInVps ] );
280        }
281        else
282        {       
283          m_receivedIdc   [ baseVoiInVps ][ voiInVps ]  = 1; 
284          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedScale    () [ baseVoiInVps ];
285          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedOffset   () [ baseVoiInVps ];
286          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
287        }
288      }
289    }
290  } 
[872]291}
292
293
[773]294#if H_3D_IV_MERGE
[724]295Void
296CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
297{
298  if( m_bCamParsVaryOverTime )
299  {
300    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
301  }
302}
303#endif
304
[2]305
306Void
307CamParsCollector::xOutput( Int iPOC )
308{
309  if( m_pCodedScaleOffsetFile )
310  {
[872]311    if( iPOC == m_firstReceivedPoc )
[2]312    {
[1179]313      fprintf( m_pCodedScaleOffsetFile, "#ViewOrderIdx     ViewIdVal\n" );
314      fprintf( m_pCodedScaleOffsetFile, "#------------ -------------\n" );
315     
316      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
317      {
318        fprintf( m_pCodedScaleOffsetFile, "%13d %13d\n", m_vps->getViewOIdxList( voiInVps ), m_vps->getViewIdVal( m_vps->getViewOIdxList( voiInVps ) ) );
319      }
320      fprintf( m_pCodedScaleOffsetFile, "\n\n");
321      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame    TargetVOI      BaseVOI   CodedScale  CodedOffset    Precision\n" );
322      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
323    }
324    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
325    {
326      Int iS = iPOC;
327      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
328      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
329      {
330        for( UInt baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
331        {
332          if( voiInVps != baseVoiInVps )
333          {
334            if ( m_receivedIdc[baseVoiInVps][voiInVps] != 0 )
335            {           
336              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
337                iS, iE, m_vps->getViewOIdxList( voiInVps ), m_vps->getViewOIdxList( baseVoiInVps ), 
338                m_aaiCodedScale [ baseVoiInVps ][ voiInVps ], 
339                m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_vps->getCpPrecision() );
[872]340            }           
[2]341          }
342        }
343      }
344    }
345  }
346}
[608]347#endif
[1196]348
[1200]349
[2]350TDecTop::TDecTop()
[1200]351  : m_iMaxRefPicNum(0)
352  , m_associatedIRAPType(NAL_UNIT_INVALID)
353  , m_pocCRA(0)
354  , m_pocRandomAccess(MAX_INT)
355  , m_cListPic()
356#if !NH_MV
357  , m_parameterSetManager()
358#endif
359  , m_apcSlicePilot(NULL)
360  , m_SEIs()
361  , m_cPrediction()
362  , m_cTrQuant()
363  , m_cGopDecoder()
364  , m_cSliceDecoder()
365  , m_cCuDecoder()
366  , m_cEntropyDecoder()
367  , m_cCavlcDecoder()
368  , m_cSbacDecoder()
369  , m_cBinCABAC()
370  , m_seiReader()
371  , m_cLoopFilter()
372  , m_cSAO()
373  , m_pcPic(NULL)
374  , m_prevPOC(MAX_INT)
375  , m_prevTid0POC(0)
376  , m_bFirstSliceInPicture(true)
377  , m_bFirstSliceInSequence(true)
378  , m_prevSliceSkipped(false)
379  , m_skippedPOC(0)
380  , m_bFirstSliceInBitstream(true)
381  , m_lastPOCNoOutputPriorPics(-1)
382  , m_isNoOutputPriorPics(false)
383  , m_craNoRaslOutputFlag(false)
384#if O0043_BEST_EFFORT_DECODING
385  , m_forceDecodeBitDepth(8)
386#endif
387  , m_pDecodedSEIOutputStream(NULL)
388  , m_warningMessageSkipPicture(false)
389  , m_prefixSEINALUs()
[2]390{
391#if ENC_DEC_TRACE
[1200]392#if NH_MV
[608]393  if ( g_hTrace == NULL )
394  {
395#endif
[1200]396  if (g_hTrace == NULL)
397  {
398    g_hTrace = fopen( "TraceDec.txt", "wb" );
399  }
[2]400  g_bJustDoIt = g_bEncDecTraceDisable;
401  g_nSymbolCounter = 0;
[1200]402#if NH_MV
[608]403  }
[2]404#endif
[608]405#endif
[1200]406#if NH_MV
[964]407  m_isLastNALWasEos = false;
[608]408  m_layerId = 0;
409  m_viewId = 0;
[1200]410#if NH_3D
[608]411  m_viewIndex = 0; 
412  m_isDepth = false;
[57]413  m_pcCamParsCollector = 0;
[210]414#endif
[1200]415#if NH_MV
416  m_targetOlsIdx = -1; 
[608]417#endif
[964]418#endif
[1200]419
[2]420}
421
422TDecTop::~TDecTop()
423{
424#if ENC_DEC_TRACE
[1200]425  if (g_hTrace != stdout)
426  {
427    fclose( g_hTrace );
428  }
[2]429#endif
[1200]430  while (!m_prefixSEINALUs.empty())
431  {
432    delete m_prefixSEINALUs.front();
433    m_prefixSEINALUs.pop_front();
434  }
[2]435}
436
437Void TDecTop::create()
438{
439  m_cGopDecoder.create();
440  m_apcSlicePilot = new TComSlice;
[608]441  m_uiSliceIdx = 0;
[2]442}
443
444Void TDecTop::destroy()
445{
446  m_cGopDecoder.destroy();
[1200]447
[2]448  delete m_apcSlicePilot;
449  m_apcSlicePilot = NULL;
[1200]450
[2]451  m_cSliceDecoder.destroy();
452}
453
[608]454Void TDecTop::init()
[2]455{
456  // initialize ROM
[1200]457#if !NH_MV
[56]458  initROM();
[5]459#endif
[1200]460#if NH_MV
[1179]461  m_cCavlcDecoder.setDecTop( this ); 
462#endif
[1200]463  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
[2]464  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
465  m_cEntropyDecoder.init(&m_cPrediction);
466}
467
468Void TDecTop::deletePicBuffer ( )
469{
470  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
471  Int iSize = Int( m_cListPic.size() );
[1200]472
[2]473  for (Int i = 0; i < iSize; i++ )
474  {
[608]475    TComPic* pcPic = *(iterPic++);
[1200]476#if NH_MV
[608]477    if( pcPic )
[56]478    {
[608]479#endif
480    pcPic->destroy();
[1200]481
[608]482    delete pcPic;
483    pcPic = NULL;
[1200]484#if NH_MV
[56]485    }
[608]486#endif
[2]487  }
[1200]488
[2]489  m_cSAO.destroy();
[1200]490
[2]491  m_cLoopFilter.        destroy();
[1200]492
493#if !NH_MV
[2]494  // destroy ROM
[608]495  destroyROM();
496#endif
[2]497}
498
[1200]499Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
[56]500{
[1200]501#if NH_MV
[872]502  if ( getLayerId() == 0 )
503  { 
[1200]504    m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[872]505  }
506  else
507  {
[1200]508    //GTCIC
509    //m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());   
510#if H_MV_HLS7_GEN
[872]511    TComVPS* vps         = pcSlice->getVPS();
512    TComDpbSize* dpbSize = vps->getDpbSize(); 
[964]513    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
[872]514    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
515    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
516    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
517#endif   
518  }
519#else
[1200]520  m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[872]521#endif
[2]522  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
523  {
[56]524    rpcPic = new TComPic();
[1200]525
526    rpcPic->create ( sps, pps, true);
527
[2]528    m_cListPic.pushBack( rpcPic );
[1200]529
[2]530    return;
531  }
[1200]532
[2]533  Bool bBufferIsAvailable = false;
534  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
535  while (iterPic != m_cListPic.end())
536  {
537    rpcPic = *(iterPic++);
[56]538    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
[2]539    {
[56]540      rpcPic->setOutputMark(false);
[1200]541#if NH_MV
[964]542      rpcPic->setPicOutputFlag(false); 
543#endif
[2]544      bBufferIsAvailable = true;
545      break;
546    }
[56]547
548    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
549    {
550      rpcPic->setOutputMark(false);
[1200]551#if NH_MV
[964]552      rpcPic->setPicOutputFlag(false); 
553#endif
[56]554      rpcPic->setReconMark( false );
555      rpcPic->getPicYuvRec()->setBorderExtension( false );
556      bBufferIsAvailable = true;
557      break;
558    }
[2]559  }
[1200]560
[2]561  if ( !bBufferIsAvailable )
562  {
[56]563    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
564    m_iMaxRefPicNum++;
565    rpcPic = new TComPic();
566    m_cListPic.pushBack( rpcPic );
[2]567  }
[608]568  rpcPic->destroy();
[1200]569  rpcPic->create ( sps, pps, true);
[2]570}
[1200]571#if NH_MV
[608]572Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
573#else
574Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
575#endif
[56]576{
577  if (!m_pcPic)
578  {
579    /* nothing to deblock */
580    return;
581  }
[2]582
[1200]583  TComPic*   pcPic         = m_pcPic;
584
[608]585  // Execute Deblock + Cleanup
[56]586
[608]587  m_cGopDecoder.filterPicture(pcPic);
[56]588
589  TComSlice::sortPicList( m_cListPic ); // sorting for application output
[608]590  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
[1200]591  rpcListPic          = &m_cListPic;
592  m_cCuDecoder.destroy();
593#if NH_MV
[622]594  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
[608]595  TComSlice::markCurrPic( pcPic ); 
596#endif
[56]597  m_bFirstSliceInPicture  = true;
598
599  return;
600}
601
[1200]602Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
[964]603{
[1200]604  if (!pcListPic || !m_isNoOutputPriorPics)
605  {
606    return;
607  }
[964]608
[1200]609  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
[964]610
[1200]611  while (iterPic != pcListPic->end())
[964]612  {
[1200]613    TComPic* pcPicTmp = *(iterPic++);
[964]614    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
615    {
616      pcPicTmp->setOutputMark(false);
[1200]617#if NH_MV
[964]618      pcPicTmp->setPicOutputFlag(false); 
619#endif
620    }
621  }
622}
623
[1200]624Void TDecTop::xCreateLostPicture(Int iLostPoc)
[2]625{
[56]626  printf("\ninserting lost poc : %d\n",iLostPoc);
627  TComPic *cFillPic;
[1200]628  xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
[56]629  cFillPic->getSlice(0)->initSlice();
[1200]630
[56]631  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
632  Int closestPoc = 1000000;
633  while ( iterPic != m_cListPic.end())
[2]634  {
[56]635    TComPic * rpcPic = *(iterPic++);
636    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())
[2]637    {
[56]638      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
639    }
640  }
641  iterPic = m_cListPic.begin();
642  while ( iterPic != m_cListPic.end())
643  {
644    TComPic *rpcPic = *(iterPic++);
645    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
646    {
647      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
648      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
[2]649      break;
650    }
651  }
[56]652  cFillPic->setCurrSliceIdx(0);
[1200]653  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
[2]654  {
[1200]655    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
[2]656  }
[56]657  cFillPic->getSlice(0)->setReferenced(true);
658  cFillPic->getSlice(0)->setPOC(iLostPoc);
[1200]659  xUpdatePreviousTid0POC(cFillPic->getSlice(0));
[56]660  cFillPic->setReconMark(true);
661  cFillPic->setOutputMark(true);
662  if(m_pocRandomAccess == MAX_INT)
663  {
664    m_pocRandomAccess = iLostPoc;
665  }
[2]666}
667
[56]668
669Void TDecTop::xActivateParameterSets()
[2]670{
[1200]671  if (m_bFirstSliceInPicture)
672  {
673    const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
674    assert (pps != 0);
[56]675
[1200]676    const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
677    assert (sps != 0);
[608]678
[1200]679    m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId());
680    m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId());
681#if NH_MV
682    const TComVPS* vps = m_parameterSetManager.getVPS(sps->getVPSId());
683    assert (vps != 0); 
684    if (!m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
[622]685#else
[1200]686    if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
[622]687#endif
[1200]688    {
689      printf ("Parameter set activation failed!");
690      assert (0);
691    }
[608]692
[1200]693#if NH_MV
[964]694  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
695  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
696  {
697    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
698    assert( sps->getUpdateRepFormatFlag() == false ); 
699  }
700  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
[1066]701
702  // It is a requirement of bitstream conformance that, when the SPS is referred to by
703  // any current picture that belongs to an independent non-base layer, the value of
704  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
705
706  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
707  { 
708    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
709  }
[1200]710#endif
[1066]711
[1200]712    xParsePrefixSEImessages();
713
714#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
715    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
716    {
717      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
718      assert (0);
719      exit(1);
720    }
[964]721#endif
722
[1200]723    // NOTE: globals were set up here originally. You can now use:
724    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
725    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
[608]726
[1200]727    //  Get a new picture buffer. This will also set up m_pcPic, and therefore give us a SPS and PPS pointer that we can use.
728    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
729    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
730#if NH_MV
731    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
732#endif
733
734    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
735    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
736    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
737
738    // we now have a real slice:
739    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
740
741    // Update the PPS and SPS pointers with the ones of the picture.
742    pps=pSlice->getPPS();
743    sps=pSlice->getSPS();
744
745#if NH_MV
746    vps=pSlice->getVPS(); 
747    // 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.
748    assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );   
749    // 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.
750    assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
751#endif
752
753#if NH_3D
754    if ( !m_pcCamParsCollector->isInitialized() )
[608]755    {
[1200]756      m_pcCamParsCollector->init( vps );
757    }
758#endif
759    // Initialise the various objects for the new set of settings
760    m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) );
761    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
762    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
763
764
765    Bool isField = false;
766    Bool isTopField = false;
767
768    if(!m_SEIs.empty())
769    {
770      // Check if any new Picture Timing SEI has arrived
771      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
772      if (pictureTimingSEIs.size()>0)
[608]773      {
[1200]774        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
775        isField    = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 10) || (pictureTiming->m_picStruct == 11) || (pictureTiming->m_picStruct == 12);
776        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
[608]777      }
778    }
[1200]779
780    //Set Field/Frame coding mode
781    m_pcPic->setField(isField);
782    m_pcPic->setTopField(isTopField);
783
784    // transfer any SEI messages that have been received to the picture
785    m_pcPic->setSEIs(m_SEIs);
786    m_SEIs.clear();
787
788    // Recursive structure
789    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
790    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
791    m_cTrQuant.init     ( sps->getMaxTrSize() );
792
793    m_cSliceDecoder.create();
[608]794  }
[1200]795  else
796  {
797    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
798    m_pcPic->allocateNewSlice();
799    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
800    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
[608]801
[1200]802    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
[1066]803
[1200]804    const TComSPS *sps = pSlice->getSPS();
805    const TComPPS *pps = pSlice->getPPS();
[56]806
[1200]807    // check that the current active PPS has not changed...
808    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
809    {
810      printf("Error - a new SPS has been decoded while processing a picture\n");
811      exit(1);
812    }
813    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
814    {
815      printf("Error - a new PPS has been decoded while processing a picture\n");
816      exit(1);
817    }
[608]818
[1200]819    xParsePrefixSEImessages();
820
821    // Check if any new SEI has arrived
822     if(!m_SEIs.empty())
823     {
824       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
825       SEIMessages &picSEI = m_pcPic->getSEIs();
826       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
827       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
828       deleteSEIs(m_SEIs);
829     }
830  }
831}
832Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
833{
834  while (!m_prefixSEINALUs.empty())
[2]835  {
[1200]836    // do nothing?
837    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
838    delete m_prefixSEINALUs.front();
[2]839  }
[1200]840  // TODO: discard following suffix SEIs as well?
841}
[56]842
[1200]843
844Void TDecTop::xParsePrefixSEImessages()
845{
846  while (!m_prefixSEINALUs.empty())
[56]847  {
[1200]848    InputNALUnit &nalu=*m_prefixSEINALUs.front();
849#if NH_MV
850    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
851#else
852    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
853#endif
854    delete m_prefixSEINALUs.front();
855    m_prefixSEINALUs.pop_front();
[56]856  }
[2]857}
[56]858
[1200]859
860#if NH_MV
[738]861Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
[608]862{
[1200]863  assert( nalu.m_nuhLayerId == m_layerId ); 
[608]864#else
[56]865Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
[2]866{
[608]867#endif
[1200]868  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
869                                // it is not associated with picture, sps or pps structures.
[2]870
[56]871  if (m_bFirstSliceInPicture)
[2]872  {
[1200]873    m_uiSliceIdx = 0;
[2]874  }
[872]875  else
[56]876  {
[1200]877    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
[56]878  }
[872]879  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
[2]880
[56]881  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
[608]882  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
883                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
884                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
885                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
886                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
887  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
888  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
[56]889  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
[42]890
[1200]891#if ENC_DEC_TRACE
892  const UInt64 originalSymbolCount = g_nSymbolCounter;
893#endif
894
895#if NH_MV
[622]896  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
[1200]897  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId );
[964]898#endif
[1200]899
900  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
901
[655]902  // set POC for dependent slices in skipped pictures
[1200]903  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
[655]904  {
905    m_apcSlicePilot->setPOC(m_skippedPOC);
906  }
907
[1200]908  xUpdatePreviousTid0POC(m_apcSlicePilot);
909
[655]910  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
911  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
[1200]912#if NH_MV 
913  const TComVPS* vps     = m_apcSlicePilot->getVPS();
914  Int layerId            = nalu.m_nuhLayerId;   
[622]915  setViewId   ( vps->getViewId   ( layerId )      ); 
[1200]916#if NH_3D
[622]917  setViewIndex( vps->getViewIndex( layerId )      ); 
918  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
919  m_ivPicLists->setVPS( vps ); 
920#endif
[608]921#endif
[738]922
[964]923  //For inference of NoOutputOfPriorPicsFlag
924  if (m_apcSlicePilot->getRapPicFlag())
925  {
926    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
927        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
928        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
929    {
930      m_apcSlicePilot->setNoRaslOutputFlag(true);
931    }
932    //the inference for NoOutputPriorPicsFlag
933    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
934    {
935      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
936      {
937        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
938      }
939    }
940    else
941    {
942      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
943    }
944
945    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
946    {
947      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
948    }
949  }
950  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
951  {
952    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
953    m_isNoOutputPriorPics = true;
954  }
955  else
956  {
957    m_isNoOutputPriorPics = false;
958  }
959
960  //For inference of PicOutputFlag
961  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
962  {
963    if ( m_craNoRaslOutputFlag )
964    {
965      m_apcSlicePilot->setPicOutputFlag(false);
966    }
967  }
968
969  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
970  {
[1200]971    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
972    assert (pps != 0);
973    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
974    assert (sps != 0);
975    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
[964]976    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
[1200]977    xUpdatePreviousTid0POC(m_apcSlicePilot);
[964]978  }
[1200]979#if NH_MV
[738]980    xCeckNoClrasOutput();
981#endif
[1200]982
983  // Skip pictures due to random access
984
985#if NH_MV
986  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay, vps))
987#else
988  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
989#endif
990  {
[655]991    m_prevSliceSkipped = true;
992    m_skippedPOC = m_apcSlicePilot->getPOC();
[1200]993#if NH_MV
[773]994    sliceSkippedFlag = true; 
[738]995#endif
[1200]996    return false;
997  }
998  // Skip TFD pictures associated with BLA/BLANT pictures
999  if (isSkipPictureForBLA(iPOCLastDisplay))
1000  {
[655]1001    m_prevSliceSkipped = true;
1002    m_skippedPOC = m_apcSlicePilot->getPOC();
[1200]1003#if NH_MV
[773]1004    sliceSkippedFlag = true; 
[738]1005#endif
[1200]1006    return false;
1007  }
[608]1008
[655]1009  // clear previous slice skipped flag
1010  m_prevSliceSkipped = false;
1011
[608]1012  //we should only get a different poc for a new picture (with CTU address==0)
[1200]1013  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0))
[608]1014  {
1015    printf ("Warning, the first slice of a picture might have been lost!\n");
[56]1016  }
[1200]1017
[56]1018  // exit when a new picture is found
[1200]1019  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
[56]1020  {
1021    if (m_prevPOC >= m_pocRandomAccess)
1022    {
1023      m_prevPOC = m_apcSlicePilot->getPOC();
[1200]1024#if ENC_DEC_TRACE
1025      //rewind the trace counter since we didn't actually decode the slice
1026      g_nSymbolCounter = originalSymbolCount;
1027#endif
[56]1028      return true;
1029    }
1030    m_prevPOC = m_apcSlicePilot->getPOC();
1031  }
[1200]1032#if NH_MV
[608]1033  if ( newLayerFlag )
1034  {
1035    return false; 
1036  }
1037#if ENC_DEC_TRACE
1038#if H_MV_ENC_DEC_TRAC
1039  // parse remainder of SH
1040   g_disableHLSTrace = false; 
1041#endif
1042#endif
1043#endif
[1200]1044
1045#if NH_MV
[622]1046   // This part needs further testing !
1047   if ( m_apcSlicePilot->getPocResetFlag() )
1048   {   
1049     xResetPocInPicBuffer();
1050   }
[1084]1051
1052   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
[1066]1053  {
1054    //update all pics in the DPB such that they cannot be used for TMPV ref
1055    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1056    while( iterRefPic != m_cListPic.end() )
1057    {
1058      TComPic *refPic = *iterRefPic;
1059      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1060      {
1061        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1062        {
1063
1064          TComSlice *refSlice = refPic->getSlice(i);
1065          refSlice->setAvailableForTMVPRefFlag( false );
1066        }
1067      }
1068      iterRefPic++;
1069    }
1070  }
1071  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1072#endif
1073
[1200]1074  //detect lost reference picture and insert copy of earlier frame.
[1179]1075  {
[1200]1076    Int lostPoc;
1077    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1078    {
1079      xCreateLostPicture(lostPoc-1);
1080    }
[1179]1081  }
1082
[1200]1083  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
[56]1084  {
1085    m_prevPOC = m_apcSlicePilot->getPOC();
1086  }
[1200]1087
1088  // actual decoding starts here
1089  xActivateParameterSets();
1090
[56]1091  m_bFirstSliceInSequence = false;
[964]1092  m_bFirstSliceInBitstream  = false;
[2]1093
[42]1094
[1200]1095  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
[42]1096
[1200]1097  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1098  // Now, having set up the maps, convert them to the correct form.
1099  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1100  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1101  if(!pcSlice->getDependentSliceSegmentFlag())
[608]1102  {
[1200]1103    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1104    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
[56]1105  }
[2]1106
[1200]1107  m_pcPic->setTLayer(nalu.m_temporalId);
[56]1108
[1200]1109#if NH_MV
1110  //Check Multiview Main profile constraint in G.11.1.1
1111  //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1
1112  //  for the layer with nuh_layer_id equal to i in subBitstream,
1113  //  inter_view_mv_vert_constraint_flag shall be equal to 1
1114  //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
1115  if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
1116      &&
1117      pcSlice->getVPS()->getViewOrderIdx(pcSlice->getVPS()->getLayerIdInNuh(getLayerId()))==1 
1118     )
[56]1119  {
[1200]1120    assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
[56]1121  }
[1200]1122#endif
1123#if NH_MV
1124  m_pcPic->setLayerId( nalu.m_nuhLayerId );
1125  m_pcPic->setViewId ( getViewId() );
1126#if NH_3D
1127  m_pcPic->setViewIndex( getViewIndex() );
1128  m_pcPic->setIsDepth  ( getIsDepth  () );
[1196]1129  pcSlice->setIvPicLists( m_ivPicLists );         
[608]1130#endif
1131#endif
[1179]1132
[1200]1133  if (!pcSlice->getDependentSliceSegmentFlag())
[56]1134  {
[655]1135    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
[608]1136    // Set reference list
[1200]1137#if NH_MV   
[622]1138    std::vector< TComPic* > tempRefPicLists[2];
1139    std::vector< Bool     > usedAsLongTerm [2];
1140    Int       numPocTotalCurr;
1141
1142    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1143    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
[1133]1144#if H_3D
[1124]1145    pcSlice->setDefaultRefView();
1146#endif
[608]1147#if H_3D_ARP
[724]1148    pcSlice->setARPStepNum(m_ivPicLists);
[608]1149    if( pcSlice->getARPStepNum() > 1 )
[56]1150    {
[622]1151      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
[1200]1152      for(Int iLayerId = 0; iLayerId < nalu.m_nuhLayerId; iLayerId ++ )
[608]1153      {
1154        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1155        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1156        if( iViewIdx<getViewIndex() && !bIsDepth )
1157        {
1158          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1159        }
1160      }
[56]1161    }
[77]1162#endif
1163#else
[608]1164    pcSlice->setRefPicList( m_cListPic, true );
[21]1165#endif
1166
[1200]1167#if NH_3D
[1179]1168    pcSlice->checkInCompPredRefLayers(); 
[655]1169#if H_3D_IV_MERGE
1170#if H_3D_FCO
1171    //assert( !getIsDepth() );
1172#else
[608]1173    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
[655]1174#endif
[608]1175#endif   
[210]1176#endif
[1200]1177#if NH_MV
[1066]1178    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1179    {
1180      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1181
1182      assert ( refPic );
1183      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
1184    }
1185#endif
1186
1187    // For generalized B
[56]1188    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1189    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1190    {
1191      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1192      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
[2]1193
[56]1194      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1195      {
1196        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1197      }
1198    }
[608]1199    if (!pcSlice->isIntra())
[56]1200    {
1201      Bool bLowDelay = true;
1202      Int  iCurrPOC  = pcSlice->getPOC();
1203      Int iRefIdx = 0;
1204
1205      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1206      {
1207        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
[21]1208        {
[56]1209          bLowDelay = false;
[21]1210        }
[2]1211      }
[608]1212      if (pcSlice->isInterB())
[56]1213      {
[608]1214        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
[56]1215        {
[608]1216          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1217          {
1218            bLowDelay = false;
1219          }
[1200]1220        }
[56]1221      }
[2]1222
[1200]1223      pcSlice->setCheckLDC(bLowDelay);
[56]1224    }
1225
1226    //---------------
[608]1227    pcSlice->setRefPOCList();
1228#if  H_3D_TMVP
1229    if(pcSlice->getLayerId())
[1196]1230    {
[608]1231      pcSlice->generateAlterRefforTMVP();
[1196]1232    }
[313]1233#endif
[56]1234  }
1235
[1200]1236  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
[56]1237  if(pcSlice->getSPS()->getScalingListFlag())
1238  {
[1200]1239    TComScalingList scalingList;
[608]1240    if(pcSlice->getPPS()->getScalingListPresentFlag())
[56]1241    {
[1200]1242      scalingList = pcSlice->getPPS()->getScalingList();
[56]1243    }
[1200]1244    else if (pcSlice->getSPS()->getScalingListPresentFlag())
[608]1245    {
[1200]1246      scalingList = pcSlice->getSPS()->getScalingList();
[608]1247    }
[1200]1248    else
1249    {
1250      scalingList.setDefaultScalingList();
1251    }
1252    m_cTrQuant.setScalingListDec(scalingList);
[56]1253    m_cTrQuant.setUseScalingList(true);
1254  }
1255  else
1256  {
[1200]1257    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1258    {
1259        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1260        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1261    };
1262    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
[56]1263    m_cTrQuant.setUseScalingList(false);
1264  }
[2]1265
[773]1266#if H_3D_IV_MERGE
[1084]1267#if H_3D_FCO
[1066]1268  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1269#else
[724]1270  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
[1066]1271#endif
[724]1272  {
1273    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1274  }
1275#endif
[1200]1276  //  Decode a picture
1277  m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
[724]1278
[1200]1279#if NH_3D
[57]1280  if( m_pcCamParsCollector )
1281  {
1282    m_pcCamParsCollector->setSlice( pcSlice );
1283  }
[758]1284#endif
[1200]1285
[56]1286  m_bFirstSliceInPicture = false;
1287  m_uiSliceIdx++;
1288
1289  return false;
1290}
1291
[1200]1292Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
[77]1293{
1294  TComVPS* vps = new TComVPS();
[1200]1295
[77]1296  m_cEntropyDecoder.decodeVPS( vps );
[1200]1297  m_parameterSetManager.storeVPS(vps, naluData);
[77]1298}
[56]1299
[1200]1300Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
[56]1301{
1302  TComSPS* sps = new TComSPS();
[1200]1303#if NH_MV
[608]1304  sps->setLayerId( getLayerId() ); 
1305#endif
[1200]1306#if O0043_BEST_EFFORT_DECODING
1307  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1308#endif
1309#if NH_3D
1310  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1311#endif
[1124]1312  m_cEntropyDecoder.decodeSPS( sps );
[1200]1313  m_parameterSetManager.storeSPS(sps, naluData);
[56]1314}
[2]1315
[1200]1316Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
[56]1317{
1318  TComPPS* pps = new TComPPS();
[1200]1319#if NH_MV
[622]1320  pps->setLayerId( getLayerId() ); 
1321#endif
[773]1322#if H_3D
[1200]1323  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1324#endif
[608]1325  m_cEntropyDecoder.decodePPS( pps );
[2]1326
[1200]1327  m_parameterSetManager.storePPS( pps, naluData);
[56]1328}
[2]1329
[1200]1330#if NH_MV
[738]1331Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1332#else
[56]1333Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
[608]1334#endif
[56]1335{
[1200]1336#if !NH_MV
1337  // ignore all NAL units of layers > 0
1338  if (nalu.m_nuhLayerId > 0)
1339  {
1340    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1341    return false;
1342  }
1343#endif
[56]1344  // Initialize entropy decoder
1345  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
[1200]1346  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
[2]1347
[56]1348  switch (nalu.m_nalUnitType)
1349  {
[77]1350    case NAL_UNIT_VPS:
[1200]1351      xDecodeVPS(nalu.getBitstream().getFifo());
1352#if NH_MV
[964]1353      m_isLastNALWasEos = false;
1354#endif
[77]1355      return false;
[1200]1356
[56]1357    case NAL_UNIT_SPS:
[1200]1358      xDecodeSPS(nalu.getBitstream().getFifo());
[56]1359      return false;
1360
1361    case NAL_UNIT_PPS:
[1200]1362      xDecodePPS(nalu.getBitstream().getFifo());
[56]1363      return false;
[1200]1364
[608]1365    case NAL_UNIT_PREFIX_SEI:
[1200]1366      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1367      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1368      return false;
1369
[608]1370    case NAL_UNIT_SUFFIX_SEI:
[1200]1371#if NH_MV
[964]1372      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1373      {
1374        assert( m_isLastNALWasEos == false );
1375      }
1376#endif
[1200]1377      if (m_pcPic)
1378      {
1379#if NH_MV
1380        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
1381#else
1382        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1383#endif
1384      }
1385      else
1386      {
1387        printf ("Note: received suffix SEI but no picture currently active.\n");
1388      }
[56]1389      return false;
1390
[608]1391    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1392    case NAL_UNIT_CODED_SLICE_TRAIL_N:
[872]1393    case NAL_UNIT_CODED_SLICE_TSA_R:
[608]1394    case NAL_UNIT_CODED_SLICE_TSA_N:
1395    case NAL_UNIT_CODED_SLICE_STSA_R:
1396    case NAL_UNIT_CODED_SLICE_STSA_N:
1397    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1398    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1399    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1400    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1401    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
[56]1402    case NAL_UNIT_CODED_SLICE_CRA:
[608]1403    case NAL_UNIT_CODED_SLICE_RADL_N:
1404    case NAL_UNIT_CODED_SLICE_RADL_R:
1405    case NAL_UNIT_CODED_SLICE_RASL_N:
1406    case NAL_UNIT_CODED_SLICE_RASL_R:
[1200]1407#if NH_MV
[964]1408      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1409          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1410          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1411          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1412          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1413      {
1414        assert( m_isLastNALWasEos == false );
1415      }
1416      else
1417      {
1418        m_isLastNALWasEos = false;
1419      }
[738]1420      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1421#else
[56]1422      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
[608]1423#endif
[2]1424      break;
[1200]1425
[872]1426    case NAL_UNIT_EOS:
[1200]1427#if NH_MV
[964]1428      assert( m_isLastNALWasEos == false );
1429      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
[1200]1430      if (nalu.m_nuhLayerId > 0)
[964]1431      {
1432        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1433        return false;
1434      }
1435      m_isLastNALWasEos = true;
1436#endif
[872]1437      m_associatedIRAPType = NAL_UNIT_INVALID;
1438      m_pocCRA = 0;
1439      m_pocRandomAccess = MAX_INT;
1440      m_prevPOC = MAX_INT;
1441      m_prevSliceSkipped = false;
1442      m_skippedPOC = 0;
1443      return false;
[1200]1444
[872]1445    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
[1200]1446      {
1447        AUDReader audReader;
1448        UInt picType;
1449        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1450        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
[872]1451      return false;
[1200]1452      }
1453
[872]1454    case NAL_UNIT_EOB:
1455      return false;
[1200]1456
[964]1457    case NAL_UNIT_FILLER_DATA:
[1200]1458      {
1459        FDReader fdReader;
1460        UInt size;
1461        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1462        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1463#if NH_MV
[964]1464      assert( m_isLastNALWasEos == false );
1465#endif
1466      return false;
[1200]1467      }
1468
[872]1469    case NAL_UNIT_RESERVED_VCL_N10:
1470    case NAL_UNIT_RESERVED_VCL_R11:
1471    case NAL_UNIT_RESERVED_VCL_N12:
1472    case NAL_UNIT_RESERVED_VCL_R13:
1473    case NAL_UNIT_RESERVED_VCL_N14:
1474    case NAL_UNIT_RESERVED_VCL_R15:
[1200]1475
[872]1476    case NAL_UNIT_RESERVED_IRAP_VCL22:
1477    case NAL_UNIT_RESERVED_IRAP_VCL23:
[1200]1478
[872]1479    case NAL_UNIT_RESERVED_VCL24:
1480    case NAL_UNIT_RESERVED_VCL25:
1481    case NAL_UNIT_RESERVED_VCL26:
1482    case NAL_UNIT_RESERVED_VCL27:
1483    case NAL_UNIT_RESERVED_VCL28:
1484    case NAL_UNIT_RESERVED_VCL29:
1485    case NAL_UNIT_RESERVED_VCL30:
1486    case NAL_UNIT_RESERVED_VCL31:
[1200]1487      printf ("Note: found reserved VCL NAL unit.\n");
1488      xParsePrefixSEIsForUnknownVCLNal();
1489      return false;
1490
[872]1491    case NAL_UNIT_RESERVED_NVCL41:
1492    case NAL_UNIT_RESERVED_NVCL42:
1493    case NAL_UNIT_RESERVED_NVCL43:
1494    case NAL_UNIT_RESERVED_NVCL44:
1495    case NAL_UNIT_RESERVED_NVCL45:
1496    case NAL_UNIT_RESERVED_NVCL46:
1497    case NAL_UNIT_RESERVED_NVCL47:
[1200]1498      printf ("Note: found reserved NAL unit.\n");
1499      return false;
[872]1500    case NAL_UNIT_UNSPECIFIED_48:
1501    case NAL_UNIT_UNSPECIFIED_49:
1502    case NAL_UNIT_UNSPECIFIED_50:
1503    case NAL_UNIT_UNSPECIFIED_51:
1504    case NAL_UNIT_UNSPECIFIED_52:
1505    case NAL_UNIT_UNSPECIFIED_53:
1506    case NAL_UNIT_UNSPECIFIED_54:
1507    case NAL_UNIT_UNSPECIFIED_55:
1508    case NAL_UNIT_UNSPECIFIED_56:
1509    case NAL_UNIT_UNSPECIFIED_57:
1510    case NAL_UNIT_UNSPECIFIED_58:
1511    case NAL_UNIT_UNSPECIFIED_59:
1512    case NAL_UNIT_UNSPECIFIED_60:
1513    case NAL_UNIT_UNSPECIFIED_61:
1514    case NAL_UNIT_UNSPECIFIED_62:
1515    case NAL_UNIT_UNSPECIFIED_63:
[1200]1516      printf ("Note: found unspecified NAL unit.\n");
1517      return false;
[2]1518    default:
[872]1519      assert (0);
[1200]1520      break;
[2]1521  }
1522
1523  return false;
1524}
1525
[608]1526/** Function for checking if picture should be skipped because of association with a previous BLA picture
1527 * \param iPOCLastDisplay POC of last picture displayed
1528 * \returns true if the picture should be skipped
1529 * This function skips all TFD pictures that follow a BLA picture
1530 * in decoding order and precede it in output order.
1531 */
1532Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
[210]1533{
[1200]1534  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) &&
[655]1535       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
[608]1536  {
1537    iPOCLastDisplay++;
1538    return true;
1539  }
1540  return false;
[210]1541}
1542
[2]1543/** Function for checking if picture should be skipped because of random access
1544 * \param iSkipFrame skip frame counter
1545 * \param iPOCLastDisplay POC of last picture displayed
1546 * \returns true if the picture shold be skipped in the random access.
1547 * This function checks the skipping of pictures in the case of -s option random access.
1548 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1549 * It also checks the type of Nal unit type at the random access point.
[608]1550 * 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.
[2]1551 * If the random access point is IDR all pictures after the random access point are decoded.
[1200]1552 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1553 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
[2]1554 * access point there is no guarantee that the decoder will not crash.
1555 */
[1200]1556#if NH_MV
1557Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps)
1558#else
1559Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1560#endif
[2]1561{
[1200]1562  if (iSkipFrame)
[2]1563  {
1564    iSkipFrame--;   // decrement the counter
1565    return true;
1566  }
[1200]1567#if NH_MV
[738]1568  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1569#else
[56]1570  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
[738]1571#endif
[2]1572  {
[608]1573    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1574        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1575        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1576        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
[2]1577    {
[738]1578
[1200]1579#if NH_MV
1580      if ( xAllRefLayersInitilized( vps ) )
[738]1581      {
1582        m_layerInitilizedFlag[ m_layerId ] = true; 
1583        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1584      }
1585      else
1586      {
1587        return true; 
1588      }
1589#else
[608]1590      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1591      m_pocRandomAccess = m_apcSlicePilot->getPOC();
[738]1592#endif
[2]1593    }
[608]1594    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
[2]1595    {
[1200]1596#if NH_MV
1597      if ( xAllRefLayersInitilized( vps) )
[738]1598      {
1599        m_layerInitilizedFlag[ m_layerId ] = true; 
[773]1600        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1601      }
1602      else 
1603      {
[738]1604        return true; 
1605      }
1606#else
1607      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1608#endif
1609    }
[1200]1610    else
[738]1611    {
[1200]1612#if NH_MV
[738]1613      static Bool warningMessage[MAX_NUM_LAYERS];
1614      static Bool warningInitFlag = false;
1615     
1616      if (!warningInitFlag)
1617      {
1618        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1619        {
1620          warningMessage[i] = true; 
1621        }
1622        warningInitFlag = true; 
1623      }
1624
1625      if ( warningMessage[getLayerId()] )
1626      {
1627        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1628        warningMessage[m_layerId] = false; 
1629      }
1630#else
[1200]1631      if(!m_warningMessageSkipPicture)
[56]1632      {
1633        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
[1200]1634        m_warningMessageSkipPicture = true;
[56]1635      }
[738]1636#endif
[56]1637      return true;
[2]1638    }
1639  }
[608]1640  // skip the reordered pictures, if necessary
1641  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))
[2]1642  {
1643    iPOCLastDisplay++;
1644    return true;
1645  }
[1200]1646  // if we reach here, then the picture is not skipped.
1647#if NH_MV
[738]1648  return !m_layerInitilizedFlag[ getLayerId() ]; 
1649#else
[1200]1650  return false;
[738]1651#endif
[2]1652}
[1200]1653#if NH_MV
[608]1654TComPic* TDecTop::getPic( Int poc )
[56]1655{
[608]1656  xGetPic( m_layerId, poc ); 
1657  TComList<TComPic*>* listPic = getListPic();
1658  TComPic* pcPic = NULL;
1659  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1660  {
1661    if( (*it)->getPOC() == poc )
1662    {
1663      pcPic = *it ;
1664      break ;
1665    }
1666  }
1667  return pcPic;
[56]1668}
[2]1669
[608]1670TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1671{ 
1672  return m_ivPicLists->getPic( layerId, poc ) ;
1673}
1674
[622]1675Void TDecTop::xResetPocInPicBuffer()
1676{
1677  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1678  while (iterPic != m_cListPic.end())
1679  {
1680    TComPic* pic = *(iterPic++);
1681    if ( pic->getReconMark() )
1682    {
1683      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1684      {
1685        TComSlice* slice = pic->getSlice( i ); 
1686        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1687      }         
1688    }     
1689  }
1690}
[738]1691
1692Void TDecTop::xCeckNoClrasOutput()
1693{
1694  // This part needs further testing!
1695  if ( getLayerId() == 0 )
1696  {   
1697    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1698
1699    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 ); 
1700    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1701    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1702
1703    if ( noClrasOutputFlag ) 
1704    {
1705      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1706      {
1707        m_layerInitilizedFlag[i] = false; 
1708      } 
1709    }
1710  }
1711}
1712
[1200]1713Bool TDecTop::xAllRefLayersInitilized( const TComVPS* vps )
[738]1714{
[1200]1715  Bool allRefLayersInitilizedFlag = true;   
[738]1716  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1717  {
[1066]1718    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
[738]1719    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1720  }
1721
1722  return allRefLayersInitilizedFlag;
1723}
[1196]1724
[1200]1725
1726Void TDecTop::initFromActiveVps( const TComVPS* vps )
[1196]1727{
[1200]1728  if ( m_targetOlsIdx == -1 )
1729  {
1730    // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1731    m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
1732  }
1733#if NH_3D
1734  // Set profile
1735  Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1736  Int lIdx = -1; 
1737  for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ); j++ )
1738  {
1739    if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
[1196]1740    {
[1200]1741      lIdx = j; 
1742      break; 
1743    }       
1744  }
1745  assert( lIdx != -1 ); 
[1196]1746
[1200]1747  Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1748  assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
1749  m_profileIdc = profileIdc;   
1750#endif
[1196]1751}
[608]1752#endif
[1200]1753
[56]1754//! \}
Note: See TracBrowser for help on using the repository browser.