source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.cpp @ 534

Last change on this file since 534 was 534, checked in by tech, 11 years ago

MergeMerged tags/HTM-DEV-1.0.

  • Property svn:eol-style set to native
File size: 42.6 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_pocCRA = 0;
350  m_prevRAPisBLA = false;
351  m_pocRandomAccess = MAX_INT; 
352  m_prevPOC                = MAX_INT;
353  m_bFirstSliceInPicture    = true;
354  m_bFirstSliceInSequence   = true;
355#if H_MV
356  m_layerId = 0;
357  m_viewId = 0;
358#if H_3D
359  m_viewIndex = 0; 
360  m_isDepth = false;
361  m_pcCamParsCollector = 0;
362#endif
363#endif
364}
365
366TDecTop::~TDecTop()
367{
368#if ENC_DEC_TRACE
369  fclose( g_hTrace );
370#endif
371}
372
373Void TDecTop::create()
374{
375  m_cGopDecoder.create();
376  m_apcSlicePilot = new TComSlice;
377  m_uiSliceIdx = 0;
378}
379
380Void TDecTop::destroy()
381{
382  m_cGopDecoder.destroy();
383 
384  delete m_apcSlicePilot;
385  m_apcSlicePilot = NULL;
386 
387  m_cSliceDecoder.destroy();
388}
389
390Void TDecTop::init()
391{
392  // initialize ROM
393#if !H_MV
394  initROM();
395#endif
396  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
397  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
398  m_cEntropyDecoder.init(&m_cPrediction);
399}
400
401Void TDecTop::deletePicBuffer ( )
402{
403  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
404  Int iSize = Int( m_cListPic.size() );
405 
406  for (Int i = 0; i < iSize; i++ )
407  {
408    TComPic* pcPic = *(iterPic++);
409#if H_MV
410    if( pcPic )
411    {
412#endif
413    pcPic->destroy();
414   
415    delete pcPic;
416    pcPic = NULL;
417#if H_MV
418    }
419#endif
420  }
421 
422  m_cSAO.destroy();
423 
424  m_cLoopFilter.        destroy();
425 
426#if !H_MV
427  // destroy ROM
428  destroyROM();
429#endif
430}
431
432Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
433{
434  Int  numReorderPics[MAX_TLAYER];
435  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
436  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
437
438  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
439  {
440    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
441  }
442
443#if L0323_DPB
444  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
445#else
446  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
447#endif
448  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
449  {
450    rpcPic = new TComPic();
451   
452    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
453                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
454    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
455    m_cListPic.pushBack( rpcPic );
456   
457    return;
458  }
459 
460  Bool bBufferIsAvailable = false;
461  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
462  while (iterPic != m_cListPic.end())
463  {
464    rpcPic = *(iterPic++);
465    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
466    {
467      rpcPic->setOutputMark(false);
468      bBufferIsAvailable = true;
469      break;
470    }
471
472    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
473    {
474      rpcPic->setOutputMark(false);
475      rpcPic->setReconMark( false );
476      rpcPic->getPicYuvRec()->setBorderExtension( false );
477      bBufferIsAvailable = true;
478      break;
479    }
480  }
481 
482  if ( !bBufferIsAvailable )
483  {
484    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
485    m_iMaxRefPicNum++;
486    rpcPic = new TComPic();
487    m_cListPic.pushBack( rpcPic );
488  }
489  rpcPic->destroy();
490  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
491                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
492  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
493}
494
495#if H_MV
496Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
497#else
498Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
499#endif
500{
501  if (!m_pcPic)
502  {
503    /* nothing to deblock */
504    return;
505  }
506 
507  TComPic*&   pcPic         = m_pcPic;
508
509  // Execute Deblock + Cleanup
510
511  m_cGopDecoder.filterPicture(pcPic);
512
513  TComSlice::sortPicList( m_cListPic ); // sorting for application output
514  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
515  rpcListPic          = &m_cListPic; 
516  m_cCuDecoder.destroy();       
517#if H_MV
518  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
519  TComSlice::markCurrPic( pcPic ); 
520  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
521#endif
522  m_bFirstSliceInPicture  = true;
523
524  return;
525}
526
527Void TDecTop::xCreateLostPicture(Int iLostPoc) 
528{
529  printf("\ninserting lost poc : %d\n",iLostPoc);
530  TComSlice cFillSlice;
531  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
532  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
533  cFillSlice.initSlice();
534  TComPic *cFillPic;
535  xGetNewPicBuffer(&cFillSlice,cFillPic);
536  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
537  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
538  cFillPic->getSlice(0)->initSlice();
539 
540  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
541  Int closestPoc = 1000000;
542  while ( iterPic != m_cListPic.end())
543  {
544    TComPic * rpcPic = *(iterPic++);
545    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())
546    {
547      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
548    }
549  }
550  iterPic = m_cListPic.begin();
551  while ( iterPic != m_cListPic.end())
552  {
553    TComPic *rpcPic = *(iterPic++);
554    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
555    {
556      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
557      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
558      break;
559    }
560  }
561  cFillPic->setCurrSliceIdx(0);
562  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
563  {
564    cFillPic->getCU(i)->initCU(cFillPic,i);
565  }
566  cFillPic->getSlice(0)->setReferenced(true);
567  cFillPic->getSlice(0)->setPOC(iLostPoc);
568  cFillPic->setReconMark(true);
569  cFillPic->setOutputMark(true);
570  if(m_pocRandomAccess == MAX_INT)
571  {
572    m_pocRandomAccess = iLostPoc;
573  }
574}
575
576
577Void TDecTop::xActivateParameterSets()
578{
579  m_parameterSetManagerDecoder.applyPrefetchedPS();
580 
581  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
582  assert (pps != 0);
583
584  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
585  assert (sps != 0);
586
587  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
588  {
589    printf ("Parameter set activation failed!");
590    assert (0);
591  }
592
593  if( pps->getDependentSliceSegmentsEnabledFlag() )
594  {
595    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
596
597    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
598    {
599      m_cSliceDecoder.initCtxMem(NumCtx);
600      for ( UInt st = 0; st < NumCtx; st++ )
601      {
602        TDecSbac* ctx = NULL;
603        ctx = new TDecSbac;
604        ctx->init( &m_cBinCABAC );
605        m_cSliceDecoder.setCtxMem( ctx, st );
606      }
607    }
608  }
609
610  m_apcSlicePilot->setPPS(pps);
611  m_apcSlicePilot->setSPS(sps);
612#if H_MV
613  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
614#endif
615  pps->setSPS(sps);
616  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
617  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
618
619  g_bitDepthY     = sps->getBitDepthY();
620  g_bitDepthC     = sps->getBitDepthC();
621  g_uiMaxCUWidth  = sps->getMaxCUWidth();
622  g_uiMaxCUHeight = sps->getMaxCUHeight();
623  g_uiMaxCUDepth  = sps->getMaxCUDepth();
624  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
625
626  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
627  {
628    sps->setAMPAcc( i, sps->getUseAMP() );
629  }
630
631  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
632  {
633    sps->setAMPAcc( i, 0 );
634  }
635
636  m_cSAO.destroy();
637  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
638  m_cLoopFilter.create( sps->getMaxCUDepth() );
639}
640
641#if H_MV
642Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
643{
644  assert( nalu.m_layerId == m_layerId ); 
645
646#else
647Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
648{
649#endif
650  TComPic*&   pcPic         = m_pcPic;
651  m_apcSlicePilot->initSlice();
652
653  if (m_bFirstSliceInPicture)
654  {
655    m_uiSliceIdx     = 0;
656  }
657  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
658  if (!m_bFirstSliceInPicture)
659  {
660    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
661  }
662
663  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
664  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
665                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
666                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
667                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
668                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
669  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
670 
671  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
672  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
673
674#if H_MV
675  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
676  m_apcSlicePilot->setLayerId( nalu.m_layerId );
677#endif
678  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
679
680#if H_MV 
681  TComVPS* vps     = m_apcSlicePilot->getVPS();
682  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); 
683  setViewId   ( vps->getViewId   ( layerIdInVps )      ); 
684#if H_3D
685  setViewIndex( vps->getViewIndex( layerIdInVps )      ); 
686  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 ); 
687  m_ivPicLists->setVPS( vps ); 
688#endif
689#endif
690    // Skip pictures due to random access
691    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
692    {
693      return false;
694    }
695    // Skip TFD pictures associated with BLA/BLANT pictures
696    if (isSkipPictureForBLA(iPOCLastDisplay))
697    {
698      return false;
699    }
700
701  //we should only get a different poc for a new picture (with CTU address==0)
702  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
703  {
704    printf ("Warning, the first slice of a picture might have been lost!\n");
705  }
706  // exit when a new picture is found
707  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
708  {
709    if (m_prevPOC >= m_pocRandomAccess)
710    {
711      m_prevPOC = m_apcSlicePilot->getPOC();
712      return true;
713    }
714    m_prevPOC = m_apcSlicePilot->getPOC();
715  }
716#if H_MV
717  if ( newLayerFlag )
718  {
719    return false; 
720  }
721#if ENC_DEC_TRACE
722#if H_MV_ENC_DEC_TRAC
723  // parse remainder of SH
724   g_disableHLSTrace = false; 
725#endif
726#endif
727#endif
728  // actual decoding starts here
729  xActivateParameterSets();
730
731  if (m_apcSlicePilot->isNextSlice()) 
732  {
733    m_prevPOC = m_apcSlicePilot->getPOC();
734  }
735  m_bFirstSliceInSequence = false;
736  //detect lost reference picture and insert copy of earlier frame.
737  Int lostPoc;
738  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
739  {
740    xCreateLostPicture(lostPoc-1);
741  }
742  if (m_bFirstSliceInPicture)
743  {
744    // Buffer initialize for prediction.
745    m_cPrediction.initTempBuff();
746    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
747#if H_MV
748    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
749#endif
750    //  Get a new picture buffer
751    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
752
753    // transfer any SEI messages that have been received to the picture
754    pcPic->setSEIs(m_SEIs);
755    m_SEIs.clear();
756
757    // Recursive structure
758    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
759    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
760    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
761
762    m_cSliceDecoder.create();
763  }
764  else
765  {
766    // Check if any new SEI has arrived
767    if(!m_SEIs.empty())
768    {
769      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
770      SEIMessages &picSEI = pcPic->getSEIs();
771      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
772      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
773      deleteSEIs(m_SEIs);
774    }
775  }
776 
777  //  Set picture slice pointer
778  TComSlice*  pcSlice = m_apcSlicePilot;
779  Bool bNextSlice     = pcSlice->isNextSlice();
780
781  UInt uiCummulativeTileWidth;
782  UInt uiCummulativeTileHeight;
783  UInt i, j, p;
784
785  //set NumColumnsMins1 and NumRowsMinus1
786  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
787  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
788
789  //create the TComTileArray
790  pcPic->getPicSym()->xCreateTComTileArray();
791
792  if( pcSlice->getPPS()->getUniformSpacingFlag() )
793  {
794    //set the width for each tile
795    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
796    {
797      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
798      {
799        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
800          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
801          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
802      }
803    }
804
805    //set the height for each tile
806    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
807    {
808      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
809      {
810        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
811          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
812          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
813      }
814    }
815  }
816  else
817  {
818    //set the width for each tile
819    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
820    {
821      uiCummulativeTileWidth = 0;
822      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
823      {
824        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
825        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
826      }
827      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
828    }
829
830    //set the height for each tile
831    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
832    {
833      uiCummulativeTileHeight = 0;
834      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
835      { 
836        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
837        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
838      }
839      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
840    }
841  }
842
843  pcPic->getPicSym()->xInitTiles();
844
845  //generate the Coding Order Map and Inverse Coding Order Map
846  UInt uiEncCUAddr;
847  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
848  {
849    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
850    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
851  }
852  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
853  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
854
855  //convert the start and end CU addresses of the slice and dependent slice into encoding order
856  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
857  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
858  if(pcSlice->isNextSlice())
859  {
860    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
861    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
862  }
863
864  if (m_bFirstSliceInPicture) 
865  {
866    if(pcPic->getNumAllocatedSlice() != 1)
867    {
868      pcPic->clearSliceBuffer();
869    }
870  }
871  else
872  {
873    pcPic->allocateNewSlice();
874  }
875  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
876  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
877  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
878
879  pcPic->setTLayer(nalu.m_temporalId);
880
881#if H_MV
882  pcPic->setLayerId( nalu.m_layerId );
883  pcPic->setViewId ( getViewId() );
884#if H_3D
885  pcPic->setViewIndex( getViewIndex() );
886  pcPic->setIsDepth  ( getIsDepth  () );
887#endif
888#endif
889  if (bNextSlice)
890  {
891    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
892    // Set reference list
893#if H_MV   
894    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
895#if H_3D_ARP
896    pcSlice->setARPStepNum();
897    if( pcSlice->getARPStepNum() > 1 )
898    {
899      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
900      {
901        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
902        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
903        if( iViewIdx<getViewIndex() && !bIsDepth )
904        {
905          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
906        }
907      }
908    }
909#endif
910#else
911#if FIX1071
912    pcSlice->setRefPicList( m_cListPic, true );
913#else
914    pcSlice->setRefPicList( m_cListPic );
915#endif
916
917#endif
918
919#if H_3D_GEN
920    pcSlice->setIvPicLists( m_ivPicLists );         
921#if H_3D_IV_MERGE   
922    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
923#endif   
924#endif
925    // For generalized B
926    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
927    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
928    {
929      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
930      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
931
932      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
933      {
934        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
935      }
936    }
937    if (!pcSlice->isIntra())
938    {
939      Bool bLowDelay = true;
940      Int  iCurrPOC  = pcSlice->getPOC();
941      Int iRefIdx = 0;
942
943      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
944      {
945        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
946        {
947          bLowDelay = false;
948        }
949      }
950      if (pcSlice->isInterB())
951      {
952        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
953        {
954          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
955          {
956            bLowDelay = false;
957          }
958        }       
959      }
960
961      pcSlice->setCheckLDC(bLowDelay);           
962    }
963
964    //---------------
965    pcSlice->setRefPOCList();
966#if !L0034_COMBINED_LIST_CLEANUP
967    pcSlice->setNoBackPredFlag( false );
968    if ( pcSlice->getSliceType() == B_SLICE )
969    {
970      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
971      {
972        pcSlice->setNoBackPredFlag( true );
973        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
974        {
975          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
976          {
977            pcSlice->setNoBackPredFlag( false );
978            break;
979          }
980        }
981      }
982    }
983#endif
984#if  H_3D_TMVP
985    if(pcSlice->getLayerId())
986      pcSlice->generateAlterRefforTMVP();
987#endif
988  }
989
990  pcPic->setCurrSliceIdx(m_uiSliceIdx);
991  if(pcSlice->getSPS()->getScalingListFlag())
992  {
993    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
994    if(pcSlice->getPPS()->getScalingListPresentFlag())
995    {
996      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
997    }
998    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
999    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1000    {
1001      pcSlice->setDefaultScalingList();
1002    }
1003    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1004    m_cTrQuant.setUseScalingList(true);
1005  }
1006  else
1007  {
1008    m_cTrQuant.setFlatScalingList();
1009    m_cTrQuant.setUseScalingList(false);
1010  }
1011
1012  //  Decode a picture
1013  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1014#if H_3D
1015  if( m_pcCamParsCollector )
1016  {
1017    m_pcCamParsCollector->setSlice( pcSlice );
1018  }
1019#endif
1020  m_bFirstSliceInPicture = false;
1021  m_uiSliceIdx++;
1022
1023  return false;
1024}
1025
1026Void TDecTop::xDecodeVPS()
1027{
1028  TComVPS* vps = new TComVPS();
1029 
1030  m_cEntropyDecoder.decodeVPS( vps );
1031  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1032}
1033
1034Void TDecTop::xDecodeSPS()
1035{
1036  TComSPS* sps = new TComSPS();
1037#if H_MV
1038  sps->setLayerId( getLayerId() ); 
1039#endif
1040#if H_3D
1041  // Preliminary fix. assuming that all sps refer to the same SPS.
1042  // Parsing dependency should be resolved!
1043  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1044  assert( vps != 0 ); 
1045  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1046  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
1047#else
1048  m_cEntropyDecoder.decodeSPS( sps );
1049#endif
1050  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1051}
1052
1053Void TDecTop::xDecodePPS()
1054{
1055  TComPPS* pps = new TComPPS();
1056  m_cEntropyDecoder.decodePPS( pps );
1057  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1058}
1059
1060Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1061{
1062  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1063  {
1064    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1065  }
1066  else
1067  {
1068    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1069    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1070    if (activeParamSets.size()>0)
1071    {
1072      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1073      m_parameterSetManagerDecoder.applyPrefetchedPS();
1074      assert(seiAps->activeSeqParamSetId.size()>0);
1075      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1076      {
1077        printf ("Warning SPS activation with Active parameter set SEI failed");
1078      }
1079    }
1080  }
1081}
1082
1083#if H_MV
1084Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1085#else
1086Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1087#endif
1088{
1089  // Initialize entropy decoder
1090  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1091  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1092
1093  switch (nalu.m_nalUnitType)
1094  {
1095    case NAL_UNIT_VPS:
1096      xDecodeVPS();
1097      return false;
1098     
1099    case NAL_UNIT_SPS:
1100      xDecodeSPS();
1101      return false;
1102
1103    case NAL_UNIT_PPS:
1104      xDecodePPS();
1105      return false;
1106     
1107    case NAL_UNIT_PREFIX_SEI:
1108    case NAL_UNIT_SUFFIX_SEI:
1109      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1110      return false;
1111
1112    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1113    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1114    case NAL_UNIT_CODED_SLICE_TLA_R:
1115    case NAL_UNIT_CODED_SLICE_TSA_N:
1116    case NAL_UNIT_CODED_SLICE_STSA_R:
1117    case NAL_UNIT_CODED_SLICE_STSA_N:
1118    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1119    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1120    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1121    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1122    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1123    case NAL_UNIT_CODED_SLICE_CRA:
1124    case NAL_UNIT_CODED_SLICE_RADL_N:
1125    case NAL_UNIT_CODED_SLICE_RADL_R:
1126    case NAL_UNIT_CODED_SLICE_RASL_N:
1127    case NAL_UNIT_CODED_SLICE_RASL_R:
1128#if H_MV
1129      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1130#else
1131      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1132#endif
1133      break;
1134    default:
1135      assert (1);
1136  }
1137
1138  return false;
1139}
1140
1141/** Function for checking if picture should be skipped because of association with a previous BLA picture
1142 * \param iPOCLastDisplay POC of last picture displayed
1143 * \returns true if the picture should be skipped
1144 * This function skips all TFD pictures that follow a BLA picture
1145 * in decoding order and precede it in output order.
1146 */
1147Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1148{
1149  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1150  {
1151    iPOCLastDisplay++;
1152    return true;
1153  }
1154  return false;
1155}
1156
1157/** Function for checking if picture should be skipped because of random access
1158 * \param iSkipFrame skip frame counter
1159 * \param iPOCLastDisplay POC of last picture displayed
1160 * \returns true if the picture shold be skipped in the random access.
1161 * This function checks the skipping of pictures in the case of -s option random access.
1162 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1163 * It also checks the type of Nal unit type at the random access point.
1164 * 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.
1165 * If the random access point is IDR all pictures after the random access point are decoded.
1166 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1167 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1168 * access point there is no guarantee that the decoder will not crash.
1169 */
1170Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1171{
1172  if (iSkipFrame) 
1173  {
1174    iSkipFrame--;   // decrement the counter
1175    return true;
1176  }
1177  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1178  {
1179    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1180        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1181        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1182        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1183    {
1184      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1185      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1186    }
1187    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1188    {
1189      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1190    }
1191    else 
1192    {
1193      static Bool warningMessage = false;
1194      if(!warningMessage)
1195      {
1196        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1197        warningMessage = true;
1198      }
1199      return true;
1200    }
1201  }
1202  // skip the reordered pictures, if necessary
1203  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))
1204  {
1205    iPOCLastDisplay++;
1206    return true;
1207  }
1208  // if we reach here, then the picture is not skipped.
1209  return false; 
1210}
1211
1212#if H_MV
1213TComPic* TDecTop::getPic( Int poc )
1214{
1215  xGetPic( m_layerId, poc ); 
1216  TComList<TComPic*>* listPic = getListPic();
1217  TComPic* pcPic = NULL;
1218  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1219  {
1220    if( (*it)->getPOC() == poc )
1221    {
1222      pcPic = *it ;
1223      break ;
1224    }
1225  }
1226  return pcPic;
1227}
1228
1229TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1230{ 
1231  return m_ivPicLists->getPic( layerId, poc ) ;
1232}
1233
1234#endif
1235//! \}
Note: See TracBrowser for help on using the repository browser.