source: 3DVCSoftware/branches/HTM-8.2-dev1-Sharp/source/Lib/TLibDecoder/TDecTop.cpp @ 693

Last change on this file since 693 was 693, checked in by sharpjp-htm, 11 years ago

Integration of F0105

  • Property svn:eol-style set to native
File size: 45.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if 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  m_aiViewId               = new Int  [ MAX_NUM_LAYERS ];
54
55  m_bViewReceived          = new Bool [ MAX_NUM_LAYERS ];
56  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
57  {
58    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
59    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
60  }
61
62  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
63  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
64  m_uiBitDepthForLUT = 8; // fixed
65}
66
67CamParsCollector::~CamParsCollector()
68{
69  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
70  {
71    delete [] m_aaiCodedOffset      [ uiId ];
72    delete [] m_aaiCodedScale       [ uiId ];
73  }
74  delete [] m_aaiCodedOffset;
75  delete [] m_aaiCodedScale;
76  delete [] m_aiViewId; 
77  delete [] m_bViewReceived;
78
79  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
80  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
81}
82
83Void
84CamParsCollector::init( FILE* pCodedScaleOffsetFile )
85{
86  m_bInitialized            = true;
87  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
88  m_uiCamParsCodedPrecision = 0;
89  m_bCamParsVaryOverTime    = false;
90  m_iLastViewIndex             = -1;
91  m_iLastPOC                = -1;
92  m_uiMaxViewIndex             = 0;
93}
94
95Void
96CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
97{
98
99  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
100  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
101
102  radLUT         = new Double***[ uiNumberSourceViews ];
103  raiLUT         = new Int   ***[ uiNumberSourceViews ];
104
105  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
106  {
107    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
108    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
109
110    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
111    {
112      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
113      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
114      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
115
116      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
117      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
118      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
119    }
120  }
121}
122
123Void
124  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
125{
126  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
127  Int     iLog2DivChroma = iLog2DivLuma + 1;
128
129  iOffset <<= m_uiBitDepthForLUT;
130
131  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
132  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
133
134  // offsets including rounding offsets
135  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
136  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
137
138
139  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
140  {
141
142    // real-valued look-up tables
143    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
144    Double  dShiftChroma    = dShiftLuma / 2;
145    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
146    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
147
148    // integer-valued look-up tables
149    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
150    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
151    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
152    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
153    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
154  }
155
156  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
157  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
158  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
159  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
160}
161
162Void
163CamParsCollector::uninit()
164{
165  m_bInitialized = false;
166}
167
168Void
169CamParsCollector::setSlice( TComSlice* pcSlice )
170{
171
172  if( pcSlice == 0 )
173  {
174    AOF( xIsComplete() );
175    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
176    {
177      xOutput( m_iLastPOC );
178    }
179    return;
180  }
181 
182  if ( pcSlice->getIsDepth())
183  {
184    return;
185  }
186
187  Bool  bFirstAU          = ( pcSlice->getPOC()     == 0 );
188  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()     != Int ( m_iLastPOC ) );
189  Bool  bFirstSliceInView = ( pcSlice->getViewIndex()  != UInt( m_iLastViewIndex ) || bFirstSliceInAU );
190
191  AOT(  bFirstSliceInAU  &&   pcSlice->getViewIndex()  != 0 );
192  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   < UInt( m_iLastViewIndex ) );
193 
194  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   > UInt( m_iLastViewIndex + 1 ) );
195 
196  AOT( !bFirstAU         &&   pcSlice->getViewIndex()   > m_uiMaxViewIndex );
197
198  if ( !bFirstSliceInView )
199  {
200    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
201    {
202      UInt uiViewIndex = pcSlice->getViewIndex();
203      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
204      {
205        AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
206        AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
207        AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
208        AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
209      }
210    }
211    return;
212  }
213
214  if( bFirstSliceInAU )
215  {
216    if( !bFirstAU )
217    {
218      AOF( xIsComplete() );
219      xOutput( m_iLastPOC );
220    }
221    ::memset( m_bViewReceived, false, MAX_NUM_LAYERS * sizeof( Bool ) );
222  }
223
224  UInt uiViewIndex                       = pcSlice->getViewIndex();
225  m_bViewReceived[ uiViewIndex ]         = true;
226  if( bFirstAU )
227  {
228    m_uiMaxViewIndex                     = std::max( m_uiMaxViewIndex, uiViewIndex );
229    m_aiViewId[ uiViewIndex ]            = pcSlice->getViewId();
230    if( uiViewIndex == 1 )
231    {
232      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
233      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
234    }
235    else if( uiViewIndex > 1 )
236    {
237      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
238      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
239    }
240    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
241    {
242      if( m_bCamParsVaryOverTime )
243      {
244        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
245        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
246        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
247        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
248        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
249        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
250      }
251      else
252      {
253        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseIndex ];
254        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseIndex ];
255        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseIndex ];
256        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseIndex ];
257        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
258        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
259      }
260    }
261  }
262  else
263  {
264    AOF( m_aiViewId[ uiViewIndex ] == pcSlice->getViewId() );
265    if( m_bCamParsVaryOverTime )
266    {
267      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
268      {
269        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
270        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
271        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
272        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
273
274        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
275        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
276      }
277    }
278  }
279 
280  m_iLastViewIndex = (Int)pcSlice->getViewIndex(); 
281  m_iLastPOC       = (Int)pcSlice->getPOC();
282}
283
284Bool
285CamParsCollector::xIsComplete()
286{
287  for( UInt uiView = 0; uiView <= m_uiMaxViewIndex; uiView++ )
288  {
289    if( m_bViewReceived[ uiView ] == 0 )
290    {
291      return false;
292    }
293  }
294  return true;
295}
296
297Void
298CamParsCollector::xOutput( Int iPOC )
299{
300  if( m_pCodedScaleOffsetFile )
301  {
302    if( iPOC == 0 )
303    {
304      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
305      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
306      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
307      {
308        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
309      }
310      fprintf( m_pCodedScaleOffsetFile, "\n\n");
311      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
312      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
313    }
314    if( iPOC == 0 || m_bCamParsVaryOverTime )
315    {
316      Int iS = iPOC;
317      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
318      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
319      {
320        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
321        {
322          if( uiViewIndex != uiBaseIndex )
323          {
324            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
325              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
326          }
327        }
328      }
329    }
330  }
331}
332#endif
333TDecTop::TDecTop()
334{
335  m_pcPic = 0;
336  m_iMaxRefPicNum = 0;
337#if ENC_DEC_TRACE
338#if H_MV
339  if ( g_hTrace == NULL )
340  {
341#endif
342  g_hTrace = fopen( "TraceDec.txt", "wb" );
343  g_bJustDoIt = g_bEncDecTraceDisable;
344  g_nSymbolCounter = 0;
345#if H_MV
346  }
347#endif
348#endif
349  m_associatedIRAPType = NAL_UNIT_INVALID;
350  m_pocCRA = 0;
351  m_pocRandomAccess = MAX_INT; 
352  m_prevPOC                = MAX_INT;
353  m_bFirstSliceInPicture    = true;
354  m_bFirstSliceInSequence   = true;
355  m_prevSliceSkipped = false;
356  m_skippedPOC = 0;
357#if H_MV
358  m_layerId = 0;
359  m_viewId = 0;
360#if H_3D
361  m_viewIndex = 0; 
362  m_isDepth = false;
363  m_pcCamParsCollector = 0;
364#endif
365#endif
366}
367
368TDecTop::~TDecTop()
369{
370#if ENC_DEC_TRACE
371  fclose( g_hTrace );
372#endif
373}
374
375Void TDecTop::create()
376{
377  m_cGopDecoder.create();
378  m_apcSlicePilot = new TComSlice;
379  m_uiSliceIdx = 0;
380}
381
382Void TDecTop::destroy()
383{
384  m_cGopDecoder.destroy();
385 
386  delete m_apcSlicePilot;
387  m_apcSlicePilot = NULL;
388 
389  m_cSliceDecoder.destroy();
390}
391
392Void TDecTop::init()
393{
394  // initialize ROM
395#if !H_MV
396  initROM();
397#endif
398  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
399  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
400  m_cEntropyDecoder.init(&m_cPrediction);
401}
402
403Void TDecTop::deletePicBuffer ( )
404{
405  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
406  Int iSize = Int( m_cListPic.size() );
407 
408  for (Int i = 0; i < iSize; i++ )
409  {
410    TComPic* pcPic = *(iterPic++);
411#if H_MV
412    if( pcPic )
413    {
414#endif
415    pcPic->destroy();
416   
417    delete pcPic;
418    pcPic = NULL;
419#if H_MV
420    }
421#endif
422  }
423 
424  m_cSAO.destroy();
425 
426  m_cLoopFilter.        destroy();
427 
428#if !H_MV
429  // destroy ROM
430  destroyROM();
431#endif
432}
433
434Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
435{
436  Int  numReorderPics[MAX_TLAYER];
437  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
438  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
439
440#if H_MV
441    assert( conformanceWindow   .getScaledFlag() ); 
442    assert( defaultDisplayWindow.getScaledFlag() );
443#endif
444  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
445  {
446    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
447  }
448
449  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
450  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
451  {
452    rpcPic = new TComPic();
453   
454    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
455                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
456    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
457    m_cListPic.pushBack( rpcPic );
458   
459    return;
460  }
461 
462  Bool bBufferIsAvailable = false;
463  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
464  while (iterPic != m_cListPic.end())
465  {
466    rpcPic = *(iterPic++);
467    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
468    {
469      rpcPic->setOutputMark(false);
470      bBufferIsAvailable = true;
471      break;
472    }
473
474    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
475    {
476      rpcPic->setOutputMark(false);
477      rpcPic->setReconMark( false );
478      rpcPic->getPicYuvRec()->setBorderExtension( false );
479      bBufferIsAvailable = true;
480      break;
481    }
482  }
483 
484  if ( !bBufferIsAvailable )
485  {
486    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
487    m_iMaxRefPicNum++;
488    rpcPic = new TComPic();
489    m_cListPic.pushBack( rpcPic );
490  }
491  rpcPic->destroy();
492  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
493                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
494  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
495}
496
497#if H_MV
498Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
499#else
500Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
501#endif
502{
503  if (!m_pcPic)
504  {
505    /* nothing to deblock */
506    return;
507  }
508 
509  TComPic*&   pcPic         = m_pcPic;
510
511  // Execute Deblock + Cleanup
512
513  m_cGopDecoder.filterPicture(pcPic);
514
515  TComSlice::sortPicList( m_cListPic ); // sorting for application output
516  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
517  rpcListPic          = &m_cListPic; 
518  m_cCuDecoder.destroy();       
519#if H_MV
520  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
521  TComSlice::markCurrPic( pcPic ); 
522  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
523#endif
524  m_bFirstSliceInPicture  = true;
525
526  return;
527}
528
529Void TDecTop::xCreateLostPicture(Int iLostPoc) 
530{
531  printf("\ninserting lost poc : %d\n",iLostPoc);
532  TComSlice cFillSlice;
533  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
534  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
535  cFillSlice.initSlice();
536  TComPic *cFillPic;
537  xGetNewPicBuffer(&cFillSlice,cFillPic);
538  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
539  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
540  cFillPic->getSlice(0)->initSlice();
541 
542  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
543  Int closestPoc = 1000000;
544  while ( iterPic != m_cListPic.end())
545  {
546    TComPic * rpcPic = *(iterPic++);
547    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())
548    {
549      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
550    }
551  }
552  iterPic = m_cListPic.begin();
553  while ( iterPic != m_cListPic.end())
554  {
555    TComPic *rpcPic = *(iterPic++);
556    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
557    {
558      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
559      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
560      break;
561    }
562  }
563  cFillPic->setCurrSliceIdx(0);
564  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
565  {
566    cFillPic->getCU(i)->initCU(cFillPic,i);
567  }
568  cFillPic->getSlice(0)->setReferenced(true);
569  cFillPic->getSlice(0)->setPOC(iLostPoc);
570  cFillPic->setReconMark(true);
571  cFillPic->setOutputMark(true);
572  if(m_pocRandomAccess == MAX_INT)
573  {
574    m_pocRandomAccess = iLostPoc;
575  }
576}
577
578
579Void TDecTop::xActivateParameterSets()
580{
581  m_parameterSetManagerDecoder.applyPrefetchedPS();
582 
583  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
584  assert (pps != 0);
585
586  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
587  assert (sps != 0);
588
589#if H_MV
590  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
591  assert (vps != 0); 
592  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
593#else
594  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
595#endif
596  {
597    printf ("Parameter set activation failed!");
598    assert (0);
599  }
600
601  if( pps->getDependentSliceSegmentsEnabledFlag() )
602  {
603    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
604
605    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
606    {
607      m_cSliceDecoder.initCtxMem(NumCtx);
608      for ( UInt st = 0; st < NumCtx; st++ )
609      {
610        TDecSbac* ctx = NULL;
611        ctx = new TDecSbac;
612        ctx->init( &m_cBinCABAC );
613        m_cSliceDecoder.setCtxMem( ctx, st );
614      }
615    }
616  }
617
618  m_apcSlicePilot->setPPS(pps);
619  m_apcSlicePilot->setSPS(sps);
620#if H_MV
621  m_apcSlicePilot->setVPS(vps); 
622  sps->inferRepFormat  ( vps , m_layerId ); 
623  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
624#endif
625  pps->setSPS(sps);
626  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
627  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
628
629  g_bitDepthY     = sps->getBitDepthY();
630  g_bitDepthC     = sps->getBitDepthC();
631  g_uiMaxCUWidth  = sps->getMaxCUWidth();
632  g_uiMaxCUHeight = sps->getMaxCUHeight();
633  g_uiMaxCUDepth  = sps->getMaxCUDepth();
634  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
635
636  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
637  {
638    sps->setAMPAcc( i, sps->getUseAMP() );
639  }
640
641  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
642  {
643    sps->setAMPAcc( i, 0 );
644  }
645
646  m_cSAO.destroy();
647  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
648  m_cLoopFilter.create( sps->getMaxCUDepth() );
649}
650
651#if H_MV
652Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
653{
654  assert( nalu.m_layerId == m_layerId ); 
655
656#else
657Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
658{
659#endif
660  TComPic*&   pcPic         = m_pcPic;
661  m_apcSlicePilot->initSlice();
662
663  if (m_bFirstSliceInPicture)
664  {
665    m_uiSliceIdx     = 0;
666  }
667  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
668  if (!m_bFirstSliceInPicture)
669  {
670    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
671  }
672
673  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
674  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
675                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
676                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
677                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
678                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
679  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
680 
681  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
682  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
683
684#if H_MV
685  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
686  m_apcSlicePilot->setLayerId( nalu.m_layerId );
687#endif
688  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
689
690  // set POC for dependent slices in skipped pictures
691  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
692  {
693    m_apcSlicePilot->setPOC(m_skippedPOC);
694  }
695
696  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
697  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
698
699#if H_MV 
700  TComVPS* vps     = m_apcSlicePilot->getVPS();
701  Int layerId  = nalu.m_layerId;   
702  setViewId   ( vps->getViewId   ( layerId )      ); 
703#if H_3D
704  setViewIndex( vps->getViewIndex( layerId )      ); 
705  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
706  m_ivPicLists->setVPS( vps ); 
707#endif
708#endif
709    // Skip pictures due to random access
710    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
711    {
712    m_prevSliceSkipped = true;
713    m_skippedPOC = m_apcSlicePilot->getPOC();
714      return false;
715    }
716    // Skip TFD pictures associated with BLA/BLANT pictures
717    if (isSkipPictureForBLA(iPOCLastDisplay))
718    {
719    m_prevSliceSkipped = true;
720    m_skippedPOC = m_apcSlicePilot->getPOC();
721      return false;
722    }
723
724  // clear previous slice skipped flag
725  m_prevSliceSkipped = false;
726
727  //we should only get a different poc for a new picture (with CTU address==0)
728  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
729  {
730    printf ("Warning, the first slice of a picture might have been lost!\n");
731  }
732  // exit when a new picture is found
733  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
734  {
735    if (m_prevPOC >= m_pocRandomAccess)
736    {
737      m_prevPOC = m_apcSlicePilot->getPOC();
738      return true;
739    }
740    m_prevPOC = m_apcSlicePilot->getPOC();
741  }
742#if H_MV
743  if ( newLayerFlag )
744  {
745    return false; 
746  }
747#if ENC_DEC_TRACE
748#if H_MV_ENC_DEC_TRAC
749  // parse remainder of SH
750   g_disableHLSTrace = false; 
751#endif
752#endif
753#endif
754  // actual decoding starts here
755#if H_MV
756   // This part needs further testing !
757   if ( m_apcSlicePilot->getPocResetFlag() )
758   {   
759     xResetPocInPicBuffer();
760   }
761#endif
762  xActivateParameterSets();
763
764  if (m_apcSlicePilot->isNextSlice()) 
765  {
766    m_prevPOC = m_apcSlicePilot->getPOC();
767  }
768  m_bFirstSliceInSequence = false;
769  //detect lost reference picture and insert copy of earlier frame.
770  Int lostPoc;
771  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
772  {
773    xCreateLostPicture(lostPoc-1);
774  }
775  if (m_bFirstSliceInPicture)
776  {
777    // Buffer initialize for prediction.
778    m_cPrediction.initTempBuff();
779    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
780#if H_MV
781    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
782#endif
783    //  Get a new picture buffer
784    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
785
786    Bool isField = false;
787    Bool isTff = false;
788   
789    if(!m_SEIs.empty())
790    {
791      // Check if any new Picture Timing SEI has arrived
792      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
793      if (pictureTimingSEIs.size()>0)
794      {
795        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
796        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
797        isTff =  (pictureTiming->m_picStruct == 1);
798      }
799    }
800   
801    //Set Field/Frame coding mode
802    m_pcPic->setField(isField);
803    m_pcPic->setTopField(isTff);
804   
805    // transfer any SEI messages that have been received to the picture
806    pcPic->setSEIs(m_SEIs);
807    m_SEIs.clear();
808
809    // Recursive structure
810    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
811    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
812    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
813
814    m_cSliceDecoder.create();
815  }
816  else
817  {
818    // Check if any new SEI has arrived
819    if(!m_SEIs.empty())
820    {
821      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
822      SEIMessages &picSEI = pcPic->getSEIs();
823      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
824      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
825      deleteSEIs(m_SEIs);
826    }
827  }
828 
829  //  Set picture slice pointer
830  TComSlice*  pcSlice = m_apcSlicePilot;
831  Bool bNextSlice     = pcSlice->isNextSlice();
832
833  UInt uiCummulativeTileWidth;
834  UInt uiCummulativeTileHeight;
835  UInt i, j, p;
836
837  //set NumColumnsMins1 and NumRowsMinus1
838  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
839  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
840
841  //create the TComTileArray
842  pcPic->getPicSym()->xCreateTComTileArray();
843
844  if( pcSlice->getPPS()->getUniformSpacingFlag() )
845  {
846    //set the width for each tile
847    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
848    {
849      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
850      {
851        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
852          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
853          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
854      }
855    }
856
857    //set the height for each tile
858    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
859    {
860      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
861      {
862        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
863          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
864          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
865      }
866    }
867  }
868  else
869  {
870    //set the width for each tile
871    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
872    {
873      uiCummulativeTileWidth = 0;
874      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
875      {
876        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
877        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
878      }
879      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
880    }
881
882    //set the height for each tile
883    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
884    {
885      uiCummulativeTileHeight = 0;
886      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
887      { 
888        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
889        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
890      }
891      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
892    }
893  }
894
895  pcPic->getPicSym()->xInitTiles();
896
897  //generate the Coding Order Map and Inverse Coding Order Map
898  UInt uiEncCUAddr;
899  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
900  {
901    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
902    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
903  }
904  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
905  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
906
907  //convert the start and end CU addresses of the slice and dependent slice into encoding order
908  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
909  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
910  if(pcSlice->isNextSlice())
911  {
912    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
913    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
914  }
915
916  if (m_bFirstSliceInPicture) 
917  {
918    if(pcPic->getNumAllocatedSlice() != 1)
919    {
920      pcPic->clearSliceBuffer();
921    }
922  }
923  else
924  {
925    pcPic->allocateNewSlice();
926  }
927  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
928  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
929  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
930
931  pcPic->setTLayer(nalu.m_temporalId);
932
933#if H_MV
934  pcPic->setLayerId( nalu.m_layerId );
935  pcPic->setViewId ( getViewId() );
936#if H_3D
937  pcPic->setViewIndex( getViewIndex() );
938  pcPic->setIsDepth  ( getIsDepth  () );
939#endif
940#endif
941  if (bNextSlice)
942  {
943    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
944    // Set reference list
945#if H_MV   
946    std::vector< TComPic* > tempRefPicLists[2];
947    std::vector< Bool     > usedAsLongTerm [2];
948    Int       numPocTotalCurr;
949
950    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
951    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
952#if H_3D_ARP
953#if SHARP_ARP_REF_CHECK_F0105
954    pcSlice->setARPStepNum(m_ivPicLists);
955#else
956    pcSlice->setARPStepNum();
957#endif
958    if( pcSlice->getARPStepNum() > 1 )
959    {
960      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
961      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
962      {
963        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
964        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
965        if( iViewIdx<getViewIndex() && !bIsDepth )
966        {
967          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
968        }
969      }
970    }
971#endif
972#else
973#if FIX1071
974    pcSlice->setRefPicList( m_cListPic, true );
975#else
976    pcSlice->setRefPicList( m_cListPic );
977#endif
978
979#endif
980
981#if H_3D
982    pcSlice->setIvPicLists( m_ivPicLists );         
983#if H_3D_IV_MERGE
984#if H_3D_FCO
985    //assert( !getIsDepth() );
986#else
987    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
988#endif
989#endif   
990#endif
991    // For generalized B
992    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
993    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
994    {
995      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
996      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
997
998      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
999      {
1000        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1001      }
1002    }
1003    if (!pcSlice->isIntra())
1004    {
1005      Bool bLowDelay = true;
1006      Int  iCurrPOC  = pcSlice->getPOC();
1007      Int iRefIdx = 0;
1008
1009      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1010      {
1011        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1012        {
1013          bLowDelay = false;
1014        }
1015      }
1016      if (pcSlice->isInterB())
1017      {
1018        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1019        {
1020          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1021          {
1022            bLowDelay = false;
1023          }
1024        }       
1025      }
1026
1027      pcSlice->setCheckLDC(bLowDelay);           
1028    }
1029
1030    //---------------
1031    pcSlice->setRefPOCList();
1032#if  H_3D_TMVP
1033    if(pcSlice->getLayerId())
1034      pcSlice->generateAlterRefforTMVP();
1035#endif
1036  }
1037
1038  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1039  if(pcSlice->getSPS()->getScalingListFlag())
1040  {
1041    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1042    if(pcSlice->getPPS()->getScalingListPresentFlag())
1043    {
1044      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1045    }
1046    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1047    {
1048      pcSlice->setDefaultScalingList();
1049    }
1050    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1051    m_cTrQuant.setUseScalingList(true);
1052  }
1053  else
1054  {
1055    m_cTrQuant.setFlatScalingList();
1056    m_cTrQuant.setUseScalingList(false);
1057  }
1058
1059  //  Decode a picture
1060  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1061#if H_3D
1062  if( m_pcCamParsCollector )
1063  {
1064    m_pcCamParsCollector->setSlice( pcSlice );
1065  }
1066#endif
1067  m_bFirstSliceInPicture = false;
1068  m_uiSliceIdx++;
1069
1070  return false;
1071}
1072
1073Void TDecTop::xDecodeVPS()
1074{
1075  TComVPS* vps = new TComVPS();
1076 
1077  m_cEntropyDecoder.decodeVPS( vps );
1078  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1079}
1080
1081Void TDecTop::xDecodeSPS()
1082{
1083  TComSPS* sps = new TComSPS();
1084#if H_MV
1085  sps->setLayerId( getLayerId() ); 
1086#endif
1087#if H_3D
1088  // Preliminary fix. assuming that all sps refer to the same SPS.
1089  // Parsing dependency should be resolved!
1090  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1091  assert( vps != 0 ); 
1092  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1093#else
1094  m_cEntropyDecoder.decodeSPS( sps );
1095#endif
1096  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1097}
1098
1099Void TDecTop::xDecodePPS()
1100{
1101  TComPPS* pps = new TComPPS();
1102#if H_MV
1103  pps->setLayerId( getLayerId() ); 
1104#endif
1105  m_cEntropyDecoder.decodePPS( pps );
1106  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1107}
1108
1109Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1110{
1111  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1112  {
1113#if H_MV
1114    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1115#else
1116    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1117#endif
1118  }
1119  else
1120  {
1121#if H_MV
1122    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1123#else
1124    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1125#endif
1126    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1127    if (activeParamSets.size()>0)
1128    {
1129      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1130      m_parameterSetManagerDecoder.applyPrefetchedPS();
1131      assert(seiAps->activeSeqParamSetId.size()>0);
1132#if H_MV
1133      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
1134#else
1135      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1136#endif
1137      {
1138        printf ("Warning SPS activation with Active parameter set SEI failed");
1139      }
1140    }
1141  }
1142}
1143
1144#if H_MV
1145Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1146#else
1147Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1148#endif
1149{
1150  // Initialize entropy decoder
1151  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1152  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1153
1154  switch (nalu.m_nalUnitType)
1155  {
1156    case NAL_UNIT_VPS:
1157      xDecodeVPS();
1158      return false;
1159     
1160    case NAL_UNIT_SPS:
1161      xDecodeSPS();
1162      return false;
1163
1164    case NAL_UNIT_PPS:
1165      xDecodePPS();
1166      return false;
1167     
1168    case NAL_UNIT_PREFIX_SEI:
1169    case NAL_UNIT_SUFFIX_SEI:
1170      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1171      return false;
1172
1173    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1174    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1175    case NAL_UNIT_CODED_SLICE_TLA_R:
1176    case NAL_UNIT_CODED_SLICE_TSA_N:
1177    case NAL_UNIT_CODED_SLICE_STSA_R:
1178    case NAL_UNIT_CODED_SLICE_STSA_N:
1179    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1180    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1181    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1182    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1183    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1184    case NAL_UNIT_CODED_SLICE_CRA:
1185    case NAL_UNIT_CODED_SLICE_RADL_N:
1186    case NAL_UNIT_CODED_SLICE_RADL_R:
1187    case NAL_UNIT_CODED_SLICE_RASL_N:
1188    case NAL_UNIT_CODED_SLICE_RASL_R:
1189#if H_MV
1190      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1191#else
1192      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1193#endif
1194      break;
1195    default:
1196      assert (1);
1197  }
1198
1199  return false;
1200}
1201
1202/** Function for checking if picture should be skipped because of association with a previous BLA picture
1203 * \param iPOCLastDisplay POC of last picture displayed
1204 * \returns true if the picture should be skipped
1205 * This function skips all TFD pictures that follow a BLA picture
1206 * in decoding order and precede it in output order.
1207 */
1208Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1209{
1210  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) && 
1211       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1212  {
1213    iPOCLastDisplay++;
1214    return true;
1215  }
1216  return false;
1217}
1218
1219/** Function for checking if picture should be skipped because of random access
1220 * \param iSkipFrame skip frame counter
1221 * \param iPOCLastDisplay POC of last picture displayed
1222 * \returns true if the picture shold be skipped in the random access.
1223 * This function checks the skipping of pictures in the case of -s option random access.
1224 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1225 * It also checks the type of Nal unit type at the random access point.
1226 * 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.
1227 * If the random access point is IDR all pictures after the random access point are decoded.
1228 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1229 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1230 * access point there is no guarantee that the decoder will not crash.
1231 */
1232Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1233{
1234  if (iSkipFrame) 
1235  {
1236    iSkipFrame--;   // decrement the counter
1237    return true;
1238  }
1239  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1240  {
1241    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1242        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1243        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1244        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1245    {
1246      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1247      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1248    }
1249    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1250    {
1251      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1252    }
1253    else 
1254    {
1255      static Bool warningMessage = false;
1256      if(!warningMessage)
1257      {
1258        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1259        warningMessage = true;
1260      }
1261      return true;
1262    }
1263  }
1264  // skip the reordered pictures, if necessary
1265  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))
1266  {
1267    iPOCLastDisplay++;
1268    return true;
1269  }
1270  // if we reach here, then the picture is not skipped.
1271  return false; 
1272}
1273
1274#if H_MV
1275TComPic* TDecTop::getPic( Int poc )
1276{
1277  xGetPic( m_layerId, poc ); 
1278  TComList<TComPic*>* listPic = getListPic();
1279  TComPic* pcPic = NULL;
1280  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1281  {
1282    if( (*it)->getPOC() == poc )
1283    {
1284      pcPic = *it ;
1285      break ;
1286    }
1287  }
1288  return pcPic;
1289}
1290
1291TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1292{ 
1293  return m_ivPicLists->getPic( layerId, poc ) ;
1294}
1295
1296Void TDecTop::xResetPocInPicBuffer()
1297{
1298  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1299  while (iterPic != m_cListPic.end())
1300  {
1301    TComPic* pic = *(iterPic++);
1302    if ( pic->getReconMark() )
1303    {
1304      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1305      {
1306        TComSlice* slice = pic->getSlice( i ); 
1307        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1308      }         
1309    }     
1310  }
1311}
1312#endif
1313//! \}
Note: See TracBrowser for help on using the repository browser.