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

Last change on this file since 1296 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
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if H_MV
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
43#endif
44//! \ingroup TLibDecoder
45//! \{
46
47#if H_3D
48CamParsCollector::CamParsCollector()
49: m_bInitialized( false )
50{
51  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
52  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
53  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
57  }
58
59  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
60  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
61  m_uiBitDepthForLUT = 8; // fixed
62  m_receivedIdc = NULL; 
63  m_vps         = NULL; 
64}
65
66CamParsCollector::~CamParsCollector()
67{
68  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
69  {
70    delete [] m_aaiCodedOffset      [ uiId ];
71    delete [] m_aaiCodedScale       [ uiId ];
72  }
73  delete [] m_aaiCodedOffset;
74  delete [] m_aaiCodedScale;
75
76  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
78  xDeleteArray( m_receivedIdc, m_vps->getNumViews() );
79}
80
81
82Void
83CamParsCollector::init( FILE* pCodedScaleOffsetFile, TComVPS* vps)
84{
85  assert( !isInitialized() ); // Only one initialization currently supported
86  m_bInitialized            = true;
87  m_vps                     = vps; 
88  m_bCamParsVaryOverTime    = false; 
89  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
90  m_lastPoc                 = -1;   
91  m_firstReceivedPoc        = -2; 
92
93  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
131
132
133
134Void
135CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
136{
137  for (Int i = 0; i < m_vps->getNumViews(); i++)
138  { 
139    for (Int j = 0; j < m_vps->getNumViews(); j++)
140    {
141      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
142      {
143        m_receivedIdc[i][j] = 0; 
144      }     
145    }
146  }
147}
148
149
150Void
151CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
152{
153
154  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
155  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
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{
181  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCpPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
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
218CamParsCollector::uninit()
219{
220  m_bInitialized = false;
221}
222
223Void
224CamParsCollector::setSlice( TComSlice* pcSlice )
225{
226  if( pcSlice == 0 )
227  {
228    xOutput( m_lastPoc );
229    return;
230  }
231
232#if !H_3D_FCO
233  if ( pcSlice->getIsDepth())
234  {
235    return;
236  }
237#endif
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
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  } 
292}
293
294
295#if H_3D_IV_MERGE
296Void
297CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
298{
299  if( m_bCamParsVaryOverTime )
300  {
301    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
302  }
303}
304#endif
305
306
307Void
308CamParsCollector::xOutput( Int iPOC )
309{
310  if( m_pCodedScaleOffsetFile )
311  {
312    if( iPOC == m_firstReceivedPoc )
313    {
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() );
341            }           
342          }
343        }
344      }
345    }
346  }
347}
348#endif
349
350TDecTop::TDecTop()
351{
352  m_pcPic = 0;
353  m_iMaxRefPicNum = 0;
354#if ENC_DEC_TRACE
355#if H_MV
356  if ( g_hTrace == NULL )
357  {
358#endif
359  g_hTrace = fopen( "TraceDec.txt", "wb" );
360  g_bJustDoIt = g_bEncDecTraceDisable;
361  g_nSymbolCounter = 0;
362#if H_MV
363  }
364#endif
365#endif
366  m_associatedIRAPType = NAL_UNIT_INVALID;
367  m_pocCRA = 0;
368  m_pocRandomAccess = MAX_INT; 
369  m_prevPOC                = MAX_INT;
370  m_bFirstSliceInPicture    = true;
371  m_bFirstSliceInSequence   = true;
372  m_prevSliceSkipped = false;
373  m_skippedPOC = 0;
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
380#if H_MV
381  m_isLastNALWasEos = false;
382  m_layerId = 0;
383  m_viewId = 0;
384#if H_3D
385  m_viewIndex = 0; 
386  m_isDepth = false;
387  m_pcCamParsCollector = 0;
388#endif
389#if H_MV
390  m_targetOptLayerSetIdx = -1; 
391#endif
392#endif
393}
394
395TDecTop::~TDecTop()
396{
397#if ENC_DEC_TRACE
398  fclose( g_hTrace );
399#endif
400}
401
402Void TDecTop::create()
403{
404  m_cGopDecoder.create();
405  m_apcSlicePilot = new TComSlice;
406  m_uiSliceIdx = 0;
407}
408
409Void TDecTop::destroy()
410{
411  m_cGopDecoder.destroy();
412 
413  delete m_apcSlicePilot;
414  m_apcSlicePilot = NULL;
415 
416  m_cSliceDecoder.destroy();
417}
418
419Void TDecTop::init()
420{
421  // initialize ROM
422#if !H_MV
423  initROM();
424#endif
425#if H_3D
426  m_cCavlcDecoder.setDecTop( this ); 
427#endif
428  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
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() );
437 
438  for (Int i = 0; i < iSize; i++ )
439  {
440    TComPic* pcPic = *(iterPic++);
441#if H_MV
442    if( pcPic )
443    {
444#endif
445    pcPic->destroy();
446   
447    delete pcPic;
448    pcPic = NULL;
449#if H_MV
450    }
451#endif
452  }
453 
454  m_cSAO.destroy();
455 
456  m_cLoopFilter.        destroy();
457 
458#if !H_MV
459  // destroy ROM
460  destroyROM();
461#endif
462}
463
464Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
465{
466  Int  numReorderPics[MAX_TLAYER];
467  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
468  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
469
470#if H_MV
471    assert( conformanceWindow   .getScaledFlag() ); 
472    assert( defaultDisplayWindow.getScaledFlag() );
473#endif
474  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
475  {
476#if H_MV
477    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
478#else
479    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
480#endif
481  }
482#if H_MV
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(); 
493    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
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
500  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
501#endif
502  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
503  {
504    rpcPic = new TComPic();
505   
506    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
507                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
508    m_cListPic.pushBack( rpcPic );
509   
510    return;
511  }
512 
513  Bool bBufferIsAvailable = false;
514  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
515  while (iterPic != m_cListPic.end())
516  {
517    rpcPic = *(iterPic++);
518    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
519    {
520      rpcPic->setOutputMark(false);
521#if H_MV
522      rpcPic->setPicOutputFlag(false); 
523#endif
524      bBufferIsAvailable = true;
525      break;
526    }
527
528    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
529    {
530      rpcPic->setOutputMark(false);
531#if H_MV
532      rpcPic->setPicOutputFlag(false); 
533#endif
534      rpcPic->setReconMark( false );
535      rpcPic->getPicYuvRec()->setBorderExtension( false );
536      bBufferIsAvailable = true;
537      break;
538    }
539  }
540 
541  if ( !bBufferIsAvailable )
542  {
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 );
547  }
548  rpcPic->destroy();
549  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
550                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
551}
552
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
558{
559  if (!m_pcPic)
560  {
561    /* nothing to deblock */
562    return;
563  }
564 
565  TComPic*&   pcPic         = m_pcPic;
566
567  // Execute Deblock + Cleanup
568
569  m_cGopDecoder.filterPicture(pcPic);
570
571  TComSlice::sortPicList( m_cListPic ); // sorting for application output
572  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
573  rpcListPic          = &m_cListPic; 
574  m_cCuDecoder.destroy();       
575#if H_MV
576  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
577  TComSlice::markCurrPic( pcPic ); 
578#endif
579  m_bFirstSliceInPicture  = true;
580
581  return;
582}
583
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);
597#if H_MV
598      pcPicTmp->setPicOutputFlag(false); 
599#endif
600    }
601  }
602}
603#endif
604
605Void TDecTop::xCreateLostPicture(Int iLostPoc) 
606{
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())
621  {
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())
624    {
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());
636      break;
637    }
638  }
639  cFillPic->setCurrSliceIdx(0);
640  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
641  {
642    cFillPic->getCU(i)->initCU(cFillPic,i);
643  }
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  }
652}
653
654
655Void TDecTop::xActivateParameterSets()
656{
657  m_parameterSetManagerDecoder.applyPrefetchedPS();
658 
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);
664
665#if H_MV
666  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
667  assert (vps != 0); 
668  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
669#else
670  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
671#endif
672  {
673    printf ("Parameter set activation failed!");
674    assert (0);
675  }
676
677#if H_MV
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() ); 
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  }
705#endif
706
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
724  m_apcSlicePilot->setPPS(pps);
725  m_apcSlicePilot->setSPS(sps);
726#if H_MV
727  m_apcSlicePilot->setVPS(vps); 
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.
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() ) );
732  sps->inferRepFormat  ( vps , m_layerId ); 
733  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
734
735#endif
736  pps->setSPS(sps);
737  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
738  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
739
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++)
748  {
749    sps->setAMPAcc( i, sps->getUseAMP() );
750  }
751
752  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
753  {
754    sps->setAMPAcc( i, 0 );
755  }
756
757  m_cSAO.destroy();
758  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
759  m_cLoopFilter.create( sps->getMaxCUDepth() );
760}
761
762#if H_MV
763Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
764{
765  assert( nalu.m_layerId == m_layerId ); 
766#else
767Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
768{
769#endif
770  TComPic*&   pcPic         = m_pcPic;
771  m_apcSlicePilot->initSlice();
772
773  if (m_bFirstSliceInPicture)
774  {
775    m_uiSliceIdx     = 0;
776  }
777  else
778  {
779    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
780  }
781  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
782
783  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
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
792  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
793
794#if H_MV
795  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
796  m_apcSlicePilot->setLayerId( nalu.m_layerId );
797  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
798#else
799  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
800#endif
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
810#if H_MV 
811  TComVPS* vps     = m_apcSlicePilot->getVPS();
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
819#endif
820
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
876#if H_MV
877    xCeckNoClrasOutput();
878#endif
879    // Skip pictures due to random access
880    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
881    {
882    m_prevSliceSkipped = true;
883    m_skippedPOC = m_apcSlicePilot->getPOC();
884#if H_MV
885    sliceSkippedFlag = true; 
886#endif
887      return false;
888    }
889    // Skip TFD pictures associated with BLA/BLANT pictures
890    if (isSkipPictureForBLA(iPOCLastDisplay))
891    {
892    m_prevSliceSkipped = true;
893    m_skippedPOC = m_apcSlicePilot->getPOC();
894#if H_MV
895    sliceSkippedFlag = true; 
896#endif
897      return false;
898    }
899
900  // clear previous slice skipped flag
901  m_prevSliceSkipped = false;
902
903  //we should only get a different poc for a new picture (with CTU address==0)
904  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
905  {
906    printf ("Warning, the first slice of a picture might have been lost!\n");
907  }
908  // exit when a new picture is found
909  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
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  }
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
930  // actual decoding starts here
931#if H_MV
932   // This part needs further testing !
933   if ( m_apcSlicePilot->getPocResetFlag() )
934   {   
935     xResetPocInPicBuffer();
936   }
937
938   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
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
960  xActivateParameterSets();
961
962#if H_MV
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
977  if (m_apcSlicePilot->isNextSlice()) 
978  {
979    m_prevPOC = m_apcSlicePilot->getPOC();
980  }
981  m_bFirstSliceInSequence = false;
982#if SETTING_NO_OUT_PIC_PRIOR 
983  m_bFirstSliceInBitstream  = false;
984#endif
985  //detect lost reference picture and insert copy of earlier frame.
986  Int lostPoc;
987  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
988  {
989    xCreateLostPicture(lostPoc-1);
990  }
991  if (m_bFirstSliceInPicture)
992  {
993    // Buffer initialize for prediction.
994    m_cPrediction.initTempBuff();
995    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
996#if H_MV
997    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
998#endif
999    //  Get a new picture buffer
1000    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1001
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   
1021    // transfer any SEI messages that have been received to the picture
1022    pcPic->setSEIs(m_SEIs);
1023    m_SEIs.clear();
1024
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());
1029
1030    m_cSliceDecoder.create();
1031  }
1032  else
1033  {
1034    // Check if any new SEI has arrived
1035    if(!m_SEIs.empty())
1036    {
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);
1042    }
1043  }
1044 
1045  //  Set picture slice pointer
1046  TComSlice*  pcSlice = m_apcSlicePilot;
1047  Bool bNextSlice     = pcSlice->isNextSlice();
1048
1049  UInt i;
1050  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
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
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()) );
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
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  () );
1094  pcSlice->setIvPicLists( m_ivPicLists );         
1095#endif
1096#endif
1097
1098
1099
1100
1101  if (bNextSlice)
1102  {
1103    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1104    // Set reference list
1105#if H_MV   
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 ); 
1112#if H_3D
1113    pcSlice->setDefaultRefView();
1114#endif
1115#if H_3D_ARP
1116    pcSlice->setARPStepNum(m_ivPicLists);
1117    if( pcSlice->getARPStepNum() > 1 )
1118    {
1119      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
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      }
1129    }
1130#endif
1131#else
1132    pcSlice->setRefPicList( m_cListPic, true );
1133#endif
1134
1135#if H_3D
1136    pcSlice->checkInCompPredRefLayers(); 
1137#if H_3D_IV_MERGE
1138#if H_3D_FCO
1139    //assert( !getIsDepth() );
1140#else
1141    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1142#endif
1143#endif   
1144#endif
1145#if H_MV
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
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 );
1161
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    }
1167    if (!pcSlice->isIntra())
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 )
1176        {
1177          bLowDelay = false;
1178        }
1179      }
1180      if (pcSlice->isInterB())
1181      {
1182        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1183        {
1184          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1185          {
1186            bLowDelay = false;
1187          }
1188        }       
1189      }
1190
1191      pcSlice->setCheckLDC(bLowDelay);           
1192    }
1193
1194    //---------------
1195    pcSlice->setRefPOCList();
1196#if  H_3D_TMVP
1197    if(pcSlice->getLayerId())
1198    {
1199      pcSlice->generateAlterRefforTMVP();
1200    }
1201#endif
1202  }
1203
1204  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1205  if(pcSlice->getSPS()->getScalingListFlag())
1206  {
1207    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1208    if(pcSlice->getPPS()->getScalingListPresentFlag())
1209    {
1210      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1211    }
1212    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1213    {
1214      pcSlice->setDefaultScalingList();
1215    }
1216    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1217    m_cTrQuant.setUseScalingList(true);
1218  }
1219  else
1220  {
1221    m_cTrQuant.setFlatScalingList();
1222    m_cTrQuant.setUseScalingList(false);
1223  }
1224
1225#if H_3D_IV_MERGE
1226#if H_3D_FCO
1227  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1228#else
1229  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1230#endif
1231  {
1232    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1233  }
1234#endif
1235
1236  //  Decode a picture
1237  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1238#if H_3D
1239  if( m_pcCamParsCollector )
1240  {
1241    m_pcCamParsCollector->setSlice( pcSlice );
1242  }
1243#endif
1244  m_bFirstSliceInPicture = false;
1245  m_uiSliceIdx++;
1246
1247  return false;
1248}
1249
1250Void TDecTop::xDecodeVPS()
1251{
1252  TComVPS* vps = new TComVPS();
1253 
1254  m_cEntropyDecoder.decodeVPS( vps );
1255  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1256}
1257
1258Void TDecTop::xDecodeSPS()
1259{
1260  TComSPS* sps = new TComSPS();
1261#if H_MV
1262  sps->setLayerId( getLayerId() ); 
1263#endif
1264#if H_3D
1265  // Preliminary fix. assuming that all sps refer to the same VPS.
1266  // Parsing dependency should be resolved!
1267  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1268  assert( vps != 0 );
1269  m_cEntropyDecoder.decodeSPS( sps );
1270#else
1271  m_cEntropyDecoder.decodeSPS( sps );
1272#endif
1273  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1274}
1275
1276Void TDecTop::xDecodePPS()
1277{
1278  TComPPS* pps = new TComPPS();
1279#if H_MV
1280  pps->setLayerId( getLayerId() ); 
1281#endif
1282#if H_3D
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
1289  // as described in the 3D-HEVC WD.
1290  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
1291  m_cEntropyDecoder.decodePPS( pps, vps );
1292#else
1293  m_cEntropyDecoder.decodePPS( pps );
1294#endif
1295  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1296}
1297
1298Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1299{
1300  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1301  {
1302#if H_MV
1303    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1304#else
1305    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1306#endif
1307  }
1308  else
1309  {
1310#if H_MV
1311    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1312#else
1313    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1314#endif
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();
1320      assert(seiAps->activeSeqParameterSetId.size()>0);
1321#if H_MV
1322      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
1323#else
1324      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
1325#endif
1326      {
1327        printf ("Warning SPS activation with Active parameter set SEI failed");
1328      }
1329    }
1330  }
1331}
1332
1333#if H_MV
1334Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1335#else
1336Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1337#endif
1338{
1339  // Initialize entropy decoder
1340  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1341  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1342
1343  switch (nalu.m_nalUnitType)
1344  {
1345    case NAL_UNIT_VPS:
1346      xDecodeVPS();
1347#if H_MV
1348      m_isLastNALWasEos = false;
1349#endif
1350      return false;
1351     
1352    case NAL_UNIT_SPS:
1353      xDecodeSPS();
1354      return false;
1355
1356    case NAL_UNIT_PPS:
1357      xDecodePPS();
1358      return false;
1359     
1360    case NAL_UNIT_PREFIX_SEI:
1361    case NAL_UNIT_SUFFIX_SEI:
1362#if H_MV
1363      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1364      {
1365        assert( m_isLastNALWasEos == false );
1366      }
1367#endif
1368      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1369      return false;
1370
1371    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1372    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1373    case NAL_UNIT_CODED_SLICE_TSA_R:
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:
1382    case NAL_UNIT_CODED_SLICE_CRA:
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:
1387#if H_MV
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      }
1400
1401      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1402#else
1403      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1404#endif
1405      break;
1406    case NAL_UNIT_EOS:
1407#if H_MV
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
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     
1434    case NAL_UNIT_FILLER_DATA:
1435#if H_MV
1436      assert( m_isLastNALWasEos == false );
1437#endif
1438      return false;
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:
1482    default:
1483      assert (0);
1484  }
1485
1486  return false;
1487}
1488
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)
1496{
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))
1499  {
1500    iPOCLastDisplay++;
1501    return true;
1502  }
1503  return false;
1504}
1505
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.
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.
1514 * If the random access point is IDR all pictures after the random access point are decoded.
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
1517 * access point there is no guarantee that the decoder will not crash.
1518 */
1519Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1520{
1521  if (iSkipFrame) 
1522  {
1523    iSkipFrame--;   // decrement the counter
1524    return true;
1525  }
1526#if H_MV
1527  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1528#else
1529  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1530#endif
1531  {
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 )
1536    {
1537
1538#if H_MV
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
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();
1551#endif
1552    }
1553    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1554    {
1555#if H_MV
1556      if ( xAllRefLayersInitilized() )
1557      {
1558        m_layerInitilizedFlag[ m_layerId ] = true; 
1559        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1560      }
1561      else 
1562      {
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    {
1571#if H_MV
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
1590      static Bool warningMessage = false;
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      }
1596#endif
1597      return true;
1598    }
1599  }
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))
1602  {
1603    iPOCLastDisplay++;
1604    return true;
1605  }
1606#if H_MV
1607  return !m_layerInitilizedFlag[ getLayerId() ]; 
1608#else
1609  // if we reach here, then the picture is not skipped.
1610  return false; 
1611#endif
1612}
1613
1614#if H_MV
1615TComPic* TDecTop::getPic( Int poc )
1616{
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;
1629}
1630
1631TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1632{ 
1633  return m_ivPicLists->getPic( layerId, poc ) ;
1634}
1635
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}
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  {
1680    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1681    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1682  }
1683
1684  return allRefLayersInitilizedFlag;
1685}
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}
1710#endif
1711#endif
1712//! \}
Note: See TracBrowser for help on using the repository browser.