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

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

Merged HTM-9.0-dev0@731. (MV-HEVC 6 HLS)

  • Property svn:eol-style set to native
File size: 49.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
284#if QC_DEPTH_IV_MRG_F0125
285Void
286CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
287{
288  UInt uiViewIndex = pcSlice->getViewIndex();
289
290  pcSlice->getSPS()->initCamParaSPS( uiViewIndex, m_uiCamParsCodedPrecision, m_bCamParsVaryOverTime, m_aaiCodedScale, m_aaiCodedOffset );
291
292  if( m_bCamParsVaryOverTime )
293  {
294    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
295  }
296}
297#endif
298
299Bool
300CamParsCollector::xIsComplete()
301{
302  for( UInt uiView = 0; uiView <= m_uiMaxViewIndex; uiView++ )
303  {
304    if( m_bViewReceived[ uiView ] == 0 )
305    {
306      return false;
307    }
308  }
309  return true;
310}
311
312Void
313CamParsCollector::xOutput( Int iPOC )
314{
315  if( m_pCodedScaleOffsetFile )
316  {
317    if( iPOC == 0 )
318    {
319      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
320      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
321      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
322      {
323        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
324      }
325      fprintf( m_pCodedScaleOffsetFile, "\n\n");
326      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
327      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
328    }
329    if( iPOC == 0 || m_bCamParsVaryOverTime )
330    {
331      Int iS = iPOC;
332      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
333      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
334      {
335        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
336        {
337          if( uiViewIndex != uiBaseIndex )
338          {
339            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
340              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
341          }
342        }
343      }
344    }
345  }
346}
347#endif
348TDecTop::TDecTop()
349{
350  m_pcPic = 0;
351  m_iMaxRefPicNum = 0;
352#if ENC_DEC_TRACE
353#if H_MV
354  if ( g_hTrace == NULL )
355  {
356#endif
357  g_hTrace = fopen( "TraceDec.txt", "wb" );
358  g_bJustDoIt = g_bEncDecTraceDisable;
359  g_nSymbolCounter = 0;
360#if H_MV
361  }
362#endif
363#endif
364  m_associatedIRAPType = NAL_UNIT_INVALID;
365  m_pocCRA = 0;
366  m_pocRandomAccess = MAX_INT; 
367  m_prevPOC                = MAX_INT;
368  m_bFirstSliceInPicture    = true;
369  m_bFirstSliceInSequence   = true;
370  m_prevSliceSkipped = false;
371  m_skippedPOC = 0;
372#if H_MV
373  m_layerId = 0;
374  m_viewId = 0;
375#if H_3D
376  m_viewIndex = 0; 
377  m_isDepth = false;
378  m_pcCamParsCollector = 0;
379#endif
380#endif
381}
382
383TDecTop::~TDecTop()
384{
385#if ENC_DEC_TRACE
386  fclose( g_hTrace );
387#endif
388}
389
390Void TDecTop::create()
391{
392  m_cGopDecoder.create();
393  m_apcSlicePilot = new TComSlice;
394  m_uiSliceIdx = 0;
395}
396
397Void TDecTop::destroy()
398{
399  m_cGopDecoder.destroy();
400 
401  delete m_apcSlicePilot;
402  m_apcSlicePilot = NULL;
403 
404  m_cSliceDecoder.destroy();
405}
406
407Void TDecTop::init()
408{
409  // initialize ROM
410#if !H_MV
411  initROM();
412#endif
413  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
414  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
415  m_cEntropyDecoder.init(&m_cPrediction);
416}
417
418Void TDecTop::deletePicBuffer ( )
419{
420  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
421  Int iSize = Int( m_cListPic.size() );
422 
423  for (Int i = 0; i < iSize; i++ )
424  {
425    TComPic* pcPic = *(iterPic++);
426#if H_MV
427    if( pcPic )
428    {
429#endif
430    pcPic->destroy();
431   
432    delete pcPic;
433    pcPic = NULL;
434#if H_MV
435    }
436#endif
437  }
438 
439  m_cSAO.destroy();
440 
441  m_cLoopFilter.        destroy();
442 
443#if !H_MV
444  // destroy ROM
445  destroyROM();
446#endif
447}
448
449Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
450{
451  Int  numReorderPics[MAX_TLAYER];
452  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
453  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
454
455#if H_MV
456    assert( conformanceWindow   .getScaledFlag() ); 
457    assert( defaultDisplayWindow.getScaledFlag() );
458#endif
459  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
460  {
461    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
462  }
463
464  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
465  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
466  {
467    rpcPic = new TComPic();
468   
469    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
470                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
471    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
472    m_cListPic.pushBack( rpcPic );
473   
474    return;
475  }
476 
477  Bool bBufferIsAvailable = false;
478  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
479  while (iterPic != m_cListPic.end())
480  {
481    rpcPic = *(iterPic++);
482    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
483    {
484      rpcPic->setOutputMark(false);
485      bBufferIsAvailable = true;
486      break;
487    }
488
489    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
490    {
491      rpcPic->setOutputMark(false);
492      rpcPic->setReconMark( false );
493      rpcPic->getPicYuvRec()->setBorderExtension( false );
494      bBufferIsAvailable = true;
495      break;
496    }
497  }
498 
499  if ( !bBufferIsAvailable )
500  {
501    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
502    m_iMaxRefPicNum++;
503    rpcPic = new TComPic();
504    m_cListPic.pushBack( rpcPic );
505  }
506  rpcPic->destroy();
507  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
508                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
509  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
510}
511
512#if H_MV
513Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
514#else
515Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
516#endif
517{
518  if (!m_pcPic)
519  {
520    /* nothing to deblock */
521    return;
522  }
523 
524  TComPic*&   pcPic         = m_pcPic;
525
526  // Execute Deblock + Cleanup
527
528  m_cGopDecoder.filterPicture(pcPic);
529
530  TComSlice::sortPicList( m_cListPic ); // sorting for application output
531  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
532  rpcListPic          = &m_cListPic; 
533  m_cCuDecoder.destroy();       
534#if H_MV
535  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
536  TComSlice::markCurrPic( pcPic ); 
537  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
538#endif
539  m_bFirstSliceInPicture  = true;
540
541  return;
542}
543
544Void TDecTop::xCreateLostPicture(Int iLostPoc) 
545{
546  printf("\ninserting lost poc : %d\n",iLostPoc);
547  TComSlice cFillSlice;
548  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
549  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
550  cFillSlice.initSlice();
551  TComPic *cFillPic;
552  xGetNewPicBuffer(&cFillSlice,cFillPic);
553  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
554  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
555  cFillPic->getSlice(0)->initSlice();
556 
557  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
558  Int closestPoc = 1000000;
559  while ( iterPic != m_cListPic.end())
560  {
561    TComPic * rpcPic = *(iterPic++);
562    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())
563    {
564      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
565    }
566  }
567  iterPic = m_cListPic.begin();
568  while ( iterPic != m_cListPic.end())
569  {
570    TComPic *rpcPic = *(iterPic++);
571    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
572    {
573      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
574      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
575      break;
576    }
577  }
578  cFillPic->setCurrSliceIdx(0);
579  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
580  {
581    cFillPic->getCU(i)->initCU(cFillPic,i);
582  }
583  cFillPic->getSlice(0)->setReferenced(true);
584  cFillPic->getSlice(0)->setPOC(iLostPoc);
585  cFillPic->setReconMark(true);
586  cFillPic->setOutputMark(true);
587  if(m_pocRandomAccess == MAX_INT)
588  {
589    m_pocRandomAccess = iLostPoc;
590  }
591}
592
593
594Void TDecTop::xActivateParameterSets()
595{
596  m_parameterSetManagerDecoder.applyPrefetchedPS();
597 
598  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
599  assert (pps != 0);
600
601  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
602  assert (sps != 0);
603
604#if H_MV
605  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
606  assert (vps != 0); 
607  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
608#else
609  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
610#endif
611  {
612    printf ("Parameter set activation failed!");
613    assert (0);
614  }
615
616  if( pps->getDependentSliceSegmentsEnabledFlag() )
617  {
618    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
619
620    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
621    {
622      m_cSliceDecoder.initCtxMem(NumCtx);
623      for ( UInt st = 0; st < NumCtx; st++ )
624      {
625        TDecSbac* ctx = NULL;
626        ctx = new TDecSbac;
627        ctx->init( &m_cBinCABAC );
628        m_cSliceDecoder.setCtxMem( ctx, st );
629      }
630    }
631  }
632
633  m_apcSlicePilot->setPPS(pps);
634  m_apcSlicePilot->setSPS(sps);
635#if H_MV
636  m_apcSlicePilot->setVPS(vps); 
637#if H_MV_6_PS_0092_17
638  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
639  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, pps->getLayerId() ) );   
640  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
641  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, sps->getLayerId() ) );
642#endif
643  sps->inferRepFormat  ( vps , m_layerId ); 
644  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
645#endif
646  pps->setSPS(sps);
647  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
648  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
649
650  g_bitDepthY     = sps->getBitDepthY();
651  g_bitDepthC     = sps->getBitDepthC();
652  g_uiMaxCUWidth  = sps->getMaxCUWidth();
653  g_uiMaxCUHeight = sps->getMaxCUHeight();
654  g_uiMaxCUDepth  = sps->getMaxCUDepth();
655  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
656
657  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
658  {
659    sps->setAMPAcc( i, sps->getUseAMP() );
660  }
661
662  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
663  {
664    sps->setAMPAcc( i, 0 );
665  }
666
667  m_cSAO.destroy();
668  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
669  m_cLoopFilter.create( sps->getMaxCUDepth() );
670}
671
672#if H_MV
673#if H_MV_FIX_SKIP_PICTURES
674Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
675#else
676Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
677#endif
678{
679  assert( nalu.m_layerId == m_layerId ); 
680
681#else
682Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
683{
684#endif
685  TComPic*&   pcPic         = m_pcPic;
686  m_apcSlicePilot->initSlice();
687
688  if (m_bFirstSliceInPicture)
689  {
690    m_uiSliceIdx     = 0;
691  }
692  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
693  if (!m_bFirstSliceInPicture)
694  {
695    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
696  }
697
698  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
699  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
700                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
701                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
702                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
703                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
704  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
705 
706  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
707  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
708
709#if H_MV
710  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
711  m_apcSlicePilot->setLayerId( nalu.m_layerId );
712#endif
713  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
714
715  // set POC for dependent slices in skipped pictures
716  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
717  {
718    m_apcSlicePilot->setPOC(m_skippedPOC);
719  }
720
721  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
722  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
723
724#if H_MV 
725  TComVPS* vps     = m_apcSlicePilot->getVPS();
726  Int layerId  = nalu.m_layerId;   
727  setViewId   ( vps->getViewId   ( layerId )      ); 
728#if H_3D
729  setViewIndex( vps->getViewIndex( layerId )      ); 
730  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
731  m_ivPicLists->setVPS( vps ); 
732#endif
733#endif
734
735#if H_MV_LAYER_WISE_STARTUP
736    xCeckNoClrasOutput();
737#endif
738    // Skip pictures due to random access
739    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
740    {
741    m_prevSliceSkipped = true;
742    m_skippedPOC = m_apcSlicePilot->getPOC();
743#if H_MV_FIX_SKIP_PICTURES
744      sliceSkippedFlag = true; 
745#endif
746      return false;
747    }
748    // Skip TFD pictures associated with BLA/BLANT pictures
749    if (isSkipPictureForBLA(iPOCLastDisplay))
750    {
751    m_prevSliceSkipped = true;
752    m_skippedPOC = m_apcSlicePilot->getPOC();
753#if H_MV_FIX_SKIP_PICTURES
754      sliceSkippedFlag = true; 
755#endif
756      return false;
757    }
758
759  // clear previous slice skipped flag
760  m_prevSliceSkipped = false;
761
762  //we should only get a different poc for a new picture (with CTU address==0)
763  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
764  {
765    printf ("Warning, the first slice of a picture might have been lost!\n");
766  }
767  // exit when a new picture is found
768  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
769  {
770    if (m_prevPOC >= m_pocRandomAccess)
771    {
772      m_prevPOC = m_apcSlicePilot->getPOC();
773      return true;
774    }
775    m_prevPOC = m_apcSlicePilot->getPOC();
776  }
777#if H_MV
778  if ( newLayerFlag )
779  {
780    return false; 
781  }
782#if ENC_DEC_TRACE
783#if H_MV_ENC_DEC_TRAC
784  // parse remainder of SH
785   g_disableHLSTrace = false; 
786#endif
787#endif
788#endif
789  // actual decoding starts here
790#if H_MV
791   // This part needs further testing !
792   if ( m_apcSlicePilot->getPocResetFlag() )
793   {   
794     xResetPocInPicBuffer();
795   }
796#endif
797  xActivateParameterSets();
798
799  if (m_apcSlicePilot->isNextSlice()) 
800  {
801    m_prevPOC = m_apcSlicePilot->getPOC();
802  }
803  m_bFirstSliceInSequence = false;
804  //detect lost reference picture and insert copy of earlier frame.
805  Int lostPoc;
806  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
807  {
808    xCreateLostPicture(lostPoc-1);
809  }
810  if (m_bFirstSliceInPicture)
811  {
812    // Buffer initialize for prediction.
813    m_cPrediction.initTempBuff();
814    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
815#if H_MV
816    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
817#endif
818    //  Get a new picture buffer
819    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
820
821    Bool isField = false;
822    Bool isTff = false;
823   
824    if(!m_SEIs.empty())
825    {
826      // Check if any new Picture Timing SEI has arrived
827      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
828      if (pictureTimingSEIs.size()>0)
829      {
830        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
831        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
832        isTff =  (pictureTiming->m_picStruct == 1);
833      }
834    }
835   
836    //Set Field/Frame coding mode
837    m_pcPic->setField(isField);
838    m_pcPic->setTopField(isTff);
839   
840    // transfer any SEI messages that have been received to the picture
841    pcPic->setSEIs(m_SEIs);
842    m_SEIs.clear();
843
844    // Recursive structure
845    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
846    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
847    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
848
849    m_cSliceDecoder.create();
850  }
851  else
852  {
853    // Check if any new SEI has arrived
854    if(!m_SEIs.empty())
855    {
856      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
857      SEIMessages &picSEI = pcPic->getSEIs();
858      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
859      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
860      deleteSEIs(m_SEIs);
861    }
862  }
863 
864  //  Set picture slice pointer
865  TComSlice*  pcSlice = m_apcSlicePilot;
866  Bool bNextSlice     = pcSlice->isNextSlice();
867
868  UInt uiCummulativeTileWidth;
869  UInt uiCummulativeTileHeight;
870  UInt i, j, p;
871
872  //set NumColumnsMins1 and NumRowsMinus1
873  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
874  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
875
876  //create the TComTileArray
877  pcPic->getPicSym()->xCreateTComTileArray();
878
879  if( pcSlice->getPPS()->getUniformSpacingFlag() )
880  {
881    //set the width for each tile
882    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
883    {
884      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
885      {
886        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
887          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
888          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
889      }
890    }
891
892    //set the height for each tile
893    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
894    {
895      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
896      {
897        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
898          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
899          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
900      }
901    }
902  }
903  else
904  {
905    //set the width for each tile
906    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
907    {
908      uiCummulativeTileWidth = 0;
909      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
910      {
911        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
912        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
913      }
914      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
915    }
916
917    //set the height for each tile
918    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
919    {
920      uiCummulativeTileHeight = 0;
921      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
922      { 
923        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
924        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
925      }
926      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
927    }
928  }
929
930  pcPic->getPicSym()->xInitTiles();
931
932  //generate the Coding Order Map and Inverse Coding Order Map
933  UInt uiEncCUAddr;
934  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
935  {
936    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
937    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
938  }
939  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
940  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
941
942  //convert the start and end CU addresses of the slice and dependent slice into encoding order
943  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
944  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
945  if(pcSlice->isNextSlice())
946  {
947    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
948    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
949  }
950
951  if (m_bFirstSliceInPicture) 
952  {
953    if(pcPic->getNumAllocatedSlice() != 1)
954    {
955      pcPic->clearSliceBuffer();
956    }
957  }
958  else
959  {
960    pcPic->allocateNewSlice();
961  }
962  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
963  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
964  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
965
966  pcPic->setTLayer(nalu.m_temporalId);
967
968#if H_MV
969  pcPic->setLayerId( nalu.m_layerId );
970  pcPic->setViewId ( getViewId() );
971#if H_3D
972  pcPic->setViewIndex( getViewIndex() );
973  pcPic->setIsDepth  ( getIsDepth  () );
974#endif
975#endif
976  if (bNextSlice)
977  {
978    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
979    // Set reference list
980#if H_MV   
981    std::vector< TComPic* > tempRefPicLists[2];
982    std::vector< Bool     > usedAsLongTerm [2];
983    Int       numPocTotalCurr;
984
985    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
986    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
987#if H_3D_ARP
988#if SHARP_ARP_REF_CHECK_F0105
989    pcSlice->setARPStepNum(m_ivPicLists);
990#else
991    pcSlice->setARPStepNum();
992#endif
993    if( pcSlice->getARPStepNum() > 1 )
994    {
995      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
996      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
997      {
998        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
999        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1000        if( iViewIdx<getViewIndex() && !bIsDepth )
1001        {
1002          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1003        }
1004      }
1005    }
1006#endif
1007#else
1008#if FIX1071
1009    pcSlice->setRefPicList( m_cListPic, true );
1010#else
1011    pcSlice->setRefPicList( m_cListPic );
1012#endif
1013
1014#endif
1015
1016#if H_3D
1017    pcSlice->setIvPicLists( m_ivPicLists );         
1018#if H_3D_IV_MERGE
1019#if H_3D_FCO
1020    //assert( !getIsDepth() );
1021#else
1022    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1023#endif
1024#endif   
1025#endif
1026    // For generalized B
1027    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1028    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1029    {
1030      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1031      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1032
1033      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1034      {
1035        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1036      }
1037    }
1038    if (!pcSlice->isIntra())
1039    {
1040      Bool bLowDelay = true;
1041      Int  iCurrPOC  = pcSlice->getPOC();
1042      Int iRefIdx = 0;
1043
1044      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1045      {
1046        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1047        {
1048          bLowDelay = false;
1049        }
1050      }
1051      if (pcSlice->isInterB())
1052      {
1053        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1054        {
1055          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1056          {
1057            bLowDelay = false;
1058          }
1059        }       
1060      }
1061
1062      pcSlice->setCheckLDC(bLowDelay);           
1063    }
1064
1065    //---------------
1066    pcSlice->setRefPOCList();
1067#if  H_3D_TMVP
1068    if(pcSlice->getLayerId())
1069      pcSlice->generateAlterRefforTMVP();
1070#endif
1071  }
1072
1073  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1074  if(pcSlice->getSPS()->getScalingListFlag())
1075  {
1076    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1077    if(pcSlice->getPPS()->getScalingListPresentFlag())
1078    {
1079      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1080    }
1081    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1082    {
1083      pcSlice->setDefaultScalingList();
1084    }
1085    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1086    m_cTrQuant.setUseScalingList(true);
1087  }
1088  else
1089  {
1090    m_cTrQuant.setFlatScalingList();
1091    m_cTrQuant.setUseScalingList(false);
1092  }
1093
1094#if QC_DEPTH_IV_MRG_F0125
1095  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1096  {
1097    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1098  }
1099#endif
1100
1101  //  Decode a picture
1102  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1103#if H_3D
1104  if( m_pcCamParsCollector )
1105  {
1106    m_pcCamParsCollector->setSlice( pcSlice );
1107  }
1108#if QC_DEPTH_IV_MRG_F0125
1109  if( pcSlice->getIsDepth() )
1110  {
1111    pcSlice->getSPS()->setHasCamParInSliceHeader( false );
1112  }
1113#endif
1114#endif
1115  m_bFirstSliceInPicture = false;
1116  m_uiSliceIdx++;
1117
1118  return false;
1119}
1120
1121Void TDecTop::xDecodeVPS()
1122{
1123  TComVPS* vps = new TComVPS();
1124 
1125  m_cEntropyDecoder.decodeVPS( vps );
1126  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1127}
1128
1129Void TDecTop::xDecodeSPS()
1130{
1131  TComSPS* sps = new TComSPS();
1132#if H_MV
1133  sps->setLayerId( getLayerId() ); 
1134#endif
1135#if H_3D
1136  // Preliminary fix. assuming that all sps refer to the same SPS.
1137  // Parsing dependency should be resolved!
1138  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1139  assert( vps != 0 ); 
1140  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1141#else
1142  m_cEntropyDecoder.decodeSPS( sps );
1143#endif
1144  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1145}
1146
1147Void TDecTop::xDecodePPS()
1148{
1149  TComPPS* pps = new TComPPS();
1150#if H_MV
1151  pps->setLayerId( getLayerId() ); 
1152#endif
1153  m_cEntropyDecoder.decodePPS( pps );
1154  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1155}
1156
1157Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1158{
1159  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1160  {
1161#if H_MV
1162    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1163#else
1164    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1165#endif
1166  }
1167  else
1168  {
1169#if H_MV
1170    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1171#else
1172    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1173#endif
1174    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1175    if (activeParamSets.size()>0)
1176    {
1177      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1178      m_parameterSetManagerDecoder.applyPrefetchedPS();
1179      assert(seiAps->activeSeqParamSetId.size()>0);
1180#if H_MV
1181      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
1182#else
1183      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1184#endif
1185      {
1186        printf ("Warning SPS activation with Active parameter set SEI failed");
1187      }
1188    }
1189  }
1190}
1191
1192#if H_MV
1193#if H_MV_FIX_SKIP_PICTURES
1194Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1195#else
1196Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1197#endif
1198#else
1199Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1200#endif
1201{
1202  // Initialize entropy decoder
1203  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1204  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1205
1206  switch (nalu.m_nalUnitType)
1207  {
1208    case NAL_UNIT_VPS:
1209      xDecodeVPS();
1210      return false;
1211     
1212    case NAL_UNIT_SPS:
1213      xDecodeSPS();
1214      return false;
1215
1216    case NAL_UNIT_PPS:
1217      xDecodePPS();
1218      return false;
1219     
1220    case NAL_UNIT_PREFIX_SEI:
1221    case NAL_UNIT_SUFFIX_SEI:
1222      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1223      return false;
1224
1225    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1226    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1227    case NAL_UNIT_CODED_SLICE_TLA_R:
1228    case NAL_UNIT_CODED_SLICE_TSA_N:
1229    case NAL_UNIT_CODED_SLICE_STSA_R:
1230    case NAL_UNIT_CODED_SLICE_STSA_N:
1231    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1232    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1233    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1234    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1235    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1236    case NAL_UNIT_CODED_SLICE_CRA:
1237    case NAL_UNIT_CODED_SLICE_RADL_N:
1238    case NAL_UNIT_CODED_SLICE_RADL_R:
1239    case NAL_UNIT_CODED_SLICE_RASL_N:
1240    case NAL_UNIT_CODED_SLICE_RASL_R:
1241#if H_MV
1242#if H_MV_FIX_SKIP_PICTURES
1243      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1244#else
1245      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1246#endif
1247#else
1248      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1249#endif
1250      break;
1251    default:
1252      assert (1);
1253  }
1254
1255  return false;
1256}
1257
1258/** Function for checking if picture should be skipped because of association with a previous BLA picture
1259 * \param iPOCLastDisplay POC of last picture displayed
1260 * \returns true if the picture should be skipped
1261 * This function skips all TFD pictures that follow a BLA picture
1262 * in decoding order and precede it in output order.
1263 */
1264Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1265{
1266  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) && 
1267       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1268  {
1269    iPOCLastDisplay++;
1270    return true;
1271  }
1272  return false;
1273}
1274
1275/** Function for checking if picture should be skipped because of random access
1276 * \param iSkipFrame skip frame counter
1277 * \param iPOCLastDisplay POC of last picture displayed
1278 * \returns true if the picture shold be skipped in the random access.
1279 * This function checks the skipping of pictures in the case of -s option random access.
1280 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1281 * It also checks the type of Nal unit type at the random access point.
1282 * 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.
1283 * If the random access point is IDR all pictures after the random access point are decoded.
1284 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1285 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1286 * access point there is no guarantee that the decoder will not crash.
1287 */
1288Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1289{
1290  if (iSkipFrame) 
1291  {
1292    iSkipFrame--;   // decrement the counter
1293    return true;
1294  }
1295#if H_MV_LAYER_WISE_STARTUP
1296  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1297#else
1298  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1299#endif
1300  {
1301    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1302        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1303        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1304        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1305    {
1306
1307#if H_MV_LAYER_WISE_STARTUP
1308      if ( xAllRefLayersInitilized() )
1309      {
1310        m_layerInitilizedFlag[ m_layerId ] = true; 
1311        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1312      }
1313      else
1314      {
1315        return true; 
1316      }
1317#else
1318      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1319      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1320#endif
1321    }
1322    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1323    {
1324#if H_MV_LAYER_WISE_STARTUP
1325      if ( xAllRefLayersInitilized() )
1326      {
1327        m_layerInitilizedFlag[ m_layerId ] = true; 
1328      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1329    }
1330    else 
1331    {
1332        return true; 
1333      }
1334#else
1335      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1336#endif
1337    }
1338    else 
1339    {
1340#if H_MV_FIX_SKIP_PICTURES
1341      static Bool warningMessage[MAX_NUM_LAYERS];
1342      static Bool warningInitFlag = false;
1343     
1344      if (!warningInitFlag)
1345      {
1346        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1347        {
1348          warningMessage[i] = true; 
1349        }
1350        warningInitFlag = true; 
1351      }
1352
1353      if ( warningMessage[getLayerId()] )
1354      {
1355        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1356        warningMessage[m_layerId] = false; 
1357      }
1358#else
1359      static Bool warningMessage = false;
1360      if(!warningMessage)
1361      {
1362        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1363        warningMessage = true;
1364      }
1365#endif
1366      return true;
1367    }
1368  }
1369  // skip the reordered pictures, if necessary
1370  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))
1371  {
1372    iPOCLastDisplay++;
1373    return true;
1374  }
1375#if H_MV_LAYER_WISE_STARTUP
1376  return !m_layerInitilizedFlag[ getLayerId() ]; 
1377#else
1378  // if we reach here, then the picture is not skipped.
1379  return false; 
1380#endif
1381}
1382
1383#if H_MV
1384TComPic* TDecTop::getPic( Int poc )
1385{
1386  xGetPic( m_layerId, poc ); 
1387  TComList<TComPic*>* listPic = getListPic();
1388  TComPic* pcPic = NULL;
1389  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1390  {
1391    if( (*it)->getPOC() == poc )
1392    {
1393      pcPic = *it ;
1394      break ;
1395    }
1396  }
1397  return pcPic;
1398}
1399
1400TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1401{ 
1402  return m_ivPicLists->getPic( layerId, poc ) ;
1403}
1404
1405Void TDecTop::xResetPocInPicBuffer()
1406{
1407  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1408  while (iterPic != m_cListPic.end())
1409  {
1410    TComPic* pic = *(iterPic++);
1411    if ( pic->getReconMark() )
1412    {
1413      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1414      {
1415        TComSlice* slice = pic->getSlice( i ); 
1416        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1417      }         
1418    }     
1419  }
1420}
1421
1422#if H_MV_LAYER_WISE_STARTUP
1423Void TDecTop::xCeckNoClrasOutput()
1424{
1425  // This part needs further testing!
1426  if ( getLayerId() == 0 )
1427  {   
1428    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1429
1430    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1431    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1432    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1433
1434    if ( noClrasOutputFlag ) 
1435    {
1436      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1437      {
1438        m_layerInitilizedFlag[i] = false; 
1439      } 
1440    }
1441  }
1442}
1443
1444Bool TDecTop::xAllRefLayersInitilized()
1445{
1446  Bool allRefLayersInitilizedFlag = true; 
1447  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1448  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1449  {
1450    Int refLayerId = vps->getRefLayerId( m_layerId, i ); 
1451    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1452  }
1453
1454  return allRefLayersInitilizedFlag;
1455}
1456#endif
1457#endif
1458//! \}
Note: See TracBrowser for help on using the repository browser.