source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 1198

Last change on this file since 1198 was 1196, checked in by tech, 10 years ago

Merged 14.0-dev0@1187.

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