source: 3DVCSoftware/branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.cpp @ 193

Last change on this file since 193 was 193, checked in by mitsubishi-htm, 12 years ago

A second release, as planned

  • Migrate to HTM 4.1
  • Move VSP related switches to cfg file instead of #define in the source code
  • A few bug fixes
  • For VC project files, only VC9 file is updated

TODO

  • Migrate to HTM 5.0, to be used as anchor for CE1 toward Geneva meeting
  • Property svn:eol-style set to native
File size: 59.5 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-2012, 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 "../../App/TAppDecoder/TAppDecTop.h"
40#include "TDecTop.h"
41
42//! \ingroup TLibDecoder
43//! \{
44
45
46CamParsCollector::CamParsCollector()
47: m_bInitialized( false )
48{
49  m_aaiCodedOffset         = new Int* [ MAX_VIEW_NUM ];
50  m_aaiCodedScale          = new Int* [ MAX_VIEW_NUM ];
51  m_aiViewOrderIndex       = new Int  [ MAX_VIEW_NUM ];
52  m_aiViewReceived         = new Int  [ MAX_VIEW_NUM ];
53  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_VIEW_NUM ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
57  }
58
59#if VSP_N
60  xCreateLUTs( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
61  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
62  m_uiBitDepthForLUT = 8; //fixed
63#if NTT_SUBPEL
64  xCreateLUTs_Subpel( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM,  m_aiBaseViewShiftLUT_ipel,  m_aiBaseViewShiftLUT_fpos);
65#endif
66#endif
67}
68
69CamParsCollector::~CamParsCollector()
70{
71  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
72  {
73    delete [] m_aaiCodedOffset      [ uiId ];
74    delete [] m_aaiCodedScale       [ uiId ];
75  }
76  delete [] m_aaiCodedOffset;
77  delete [] m_aaiCodedScale;
78  delete [] m_aiViewOrderIndex;
79  delete [] m_aiViewReceived;
80
81#if VSP_N
82  xDeleteArray( m_adBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
83  xDeleteArray( m_aiBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
84#if NTT_SUBPEL
85  xDeleteArray( m_aiBaseViewShiftLUT_ipel, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
86  xDeleteArray( m_aiBaseViewShiftLUT_fpos, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
87#endif
88#endif
89}
90
91Void
92CamParsCollector::init( FILE* pCodedScaleOffsetFile )
93{
94  m_bInitialized            = true;
95  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
96  m_uiCamParsCodedPrecision = 0;
97  m_bCamParsVaryOverTime    = false;
98  m_iLastViewId             = -1;
99  m_iLastPOC                = -1;
100  m_uiMaxViewId             = 0;
101}
102
103#if VSP_N
104Void
105CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
106{
107  //AOF( m_uiBitDepthForLUT == 8 );
108  //AOF(radLUT == NULL && raiLUT == NULL );
109
110  uiNumberSourceViews = Max( 1, uiNumberSourceViews );
111  uiNumberTargetViews = Max( 1, uiNumberTargetViews );
112
113  radLUT         = new Double***[ uiNumberSourceViews ];
114  raiLUT         = new Int   ***[ uiNumberSourceViews ];
115
116  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
117  {
118    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
119    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
120
121    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
122    {
123      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
124      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
125      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
126
127      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
128      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
129      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
130    }
131  }
132}
133
134Void
135CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
136{
137  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
138  Int     iLog2DivChroma = iLog2DivLuma + 1;
139
140  iOffset <<= m_uiBitDepthForLUT;
141
142  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
143  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
144
145  // offsets including rounding offsets
146  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
147  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
148
149
150  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
151  {
152
153    // real-valued look-up tables
154#if POZNAN_NONLINEAR_DEPTH
155    Double  dShiftLuma;
156    if( m_bUseNonlinearDepth )
157      dShiftLuma      = ( m_cNonlinearDepthModel.BackwardD( (Double)uiDepthValue, dScale) + dOffset ) * Double( 1 << m_iLog2Precision );
158    else
159      dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
160#else
161    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
162#endif
163    Double  dShiftChroma    = dShiftLuma / 2;
164    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
165    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
166
167    // integer-valued look-up tables
168#if POZNAN_NONLINEAR_DEPTH
169    Int64   iTempScale;
170    if( m_bUseNonlinearDepth )
171      iTempScale      = (Int64)m_cNonlinearDepthModel.BackwardI(uiDepthValue, iScale);
172    else
173      iTempScale      = (Int64)uiDepthValue * iScale;
174#else
175    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
176#endif
177    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
178    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
179    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
180    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
181
182    // maximum deviation
183    //dMaxDispDev     = Max( dMaxDispDev,    fabs( Double( (Int) iTestScale   ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) );
184    //dMaxRndDispDvL  = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma   ) - dShiftLuma   ) );
185    //dMaxRndDispDvC  = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) );
186  }
187
188  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
189  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
190  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
191  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
192}
193
194Bool
195CamParsCollector::getNearestBaseView( Int iSynthViewIdx, Int &riNearestViewIdx, Int &riRelDistToLeft, Bool& rbRenderFromLeft)
196{
197  /*
198  riNearestViewIdx = 0;
199
200  Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] );
201  Int  iFactor       = ( bDecencdingVN ? -1 : 1 );
202
203  if( ( m_aiBaseId2SortedId[iSynthViewIdx] - m_aiBaseId2SortedId[riNearestViewIdx] ) * iFactor  <= 0 )
204  {
205    rbRenderFromLeft = true;
206  }
207  else
208  {
209    rbRenderFromLeft = false;
210  }
211
212  riRelDistToLeft = 128; //Not used for now;
213//*/
214  return true;
215}
216
217#if NTT_SUBPEL
218Void
219CamParsCollector::xCreateLUTs_Subpel( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Int****& raiLUT0, Int****& raiLUT1 )
220{
221  uiNumberSourceViews = Max( 1, uiNumberSourceViews );
222  uiNumberTargetViews = Max( 1, uiNumberTargetViews );
223
224  raiLUT0         = new Int   ***[ uiNumberSourceViews ];
225  raiLUT1         = new Int   ***[ uiNumberSourceViews ];
226
227  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
228  {
229    raiLUT0        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
230    raiLUT1        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
231
232    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
233    {
234      raiLUT0        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
235      raiLUT0        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
236      raiLUT0        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
237      raiLUT1        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
238      raiLUT1        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
239      raiLUT1        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
240    }
241  }
242}
243Void
244CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Int****& raiLUT_ipel, Int****& raiLUT_fpos)
245{
246  Int   iLog2Div = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2Div > 0 );
247  Int64 iOffset64   = ( Int64(iOffset) << m_uiBitDepthForLUT ) + ( ( 1 << iLog2Div ) >> 1 );
248
249  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
250  {
251    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
252    Int     iShiftSubpel    = (Int) (( iTempScale + iOffset64 ) >> iLog2Div);
253    Int     iShiftPelLuma   = iShiftSubpel >> m_iLog2Precision; // better to have rounding ?
254    Int     iShiftPelChroma = iShiftPelLuma >> 1;
255
256    raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftPelLuma;
257    raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftPelChroma;
258    raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelLuma << m_iLog2Precision );
259    raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelChroma << (m_iLog2Precision+1) );
260
261#if 0 // NTT bugfix
262    if ( raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] < 0 )
263      raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = -4 - raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ];
264    if ( raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] < 0 )
265      raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = -8 - raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ];
266#endif
267
268#if _DEBUG
269    AOF( (raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ]>> m_iLog2Precision   ) == 0 );
270    AOF( (raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ]>>(m_iLog2Precision+1)) == 0 );
271#endif
272  }
273
274  raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
275  raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
276  raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
277  raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
278}
279#endif
280
281#endif
282
283Void
284CamParsCollector::uninit()
285{
286  m_bInitialized = false;
287}
288
289Void
290CamParsCollector::setSlice( TComSlice* pcSlice )
291{
292  if( pcSlice == 0 )
293  {
294    AOF( xIsComplete() );
295    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
296    {
297      xOutput( m_iLastPOC );
298    }
299    return;
300  }
301
302  AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
303  if ( pcSlice->getSPS()->isDepth  () )
304  {
305    return;
306  }
307  Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
308  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
309  Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
310  AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
311  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
312  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
313  AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
314  if ( !bFirstSliceInView )
315  {
316    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
317    {
318      UInt uiViewId = pcSlice->getSPS()->getViewId();
319      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
320      {
321        AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale    () [ uiBaseId ] );
322        AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset   () [ uiBaseId ] );
323        AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] );
324        AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] );
325      }
326    }
327    return;
328  }
329
330  if( bFirstSliceInAU )
331  {
332    if( !bFirstAU )
333    {
334      AOF( xIsComplete() );
335      xOutput( m_iLastPOC );
336    }
337    ::memset( m_aiViewReceived, 0x00, MAX_VIEW_NUM * sizeof( Int ) );
338  }
339
340  UInt uiViewId                 = pcSlice->getSPS()->getViewId();
341  m_aiViewReceived[ uiViewId ]  = 1;
342  if( bFirstAU )
343  {
344    m_uiMaxViewId                     = Max( m_uiMaxViewId, uiViewId );
345    m_aiViewOrderIndex[ uiViewId ]    = pcSlice->getSPS()->getViewOrderIdx();
346    if( uiViewId == 1 )
347    {
348      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
349      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
350    }
351    else if( uiViewId > 1 )
352    {
353      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
354      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
355    }
356    for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
357    {
358      if( m_bCamParsVaryOverTime )
359      {
360        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
361        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
362        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
363        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
364#if VSP_N
365        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
366        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
367#if NTT_SUBPEL
368        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
369        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
370#endif
371#endif 
372      }
373      else
374      {
375        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseId ];
376        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseId ];
377        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
378        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
379#if VSP_N
380        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
381        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
382#if NTT_SUBPEL
383        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
384        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
385#endif
386#endif
387      }
388    }
389  }
390  else
391  {
392    AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() );
393    if( m_bCamParsVaryOverTime )
394    {
395      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
396      {
397        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
398        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
399        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
400        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
401#if VSP_N
402        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
403        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
404#if NTT_SUBPEL
405        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
406        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
407#endif
408#endif
409      }
410    }
411  }
412  m_iLastViewId = (Int)pcSlice->getSPS()->getViewId();
413  m_iLastPOC    = (Int)pcSlice->getPOC();
414}
415
416Bool
417CamParsCollector::xIsComplete()
418{
419  for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ )
420  {
421    if( m_aiViewReceived[ uiView ] == 0 )
422    {
423      return false;
424    }
425  }
426  return true;
427}
428
429Void
430CamParsCollector::xOutput( Int iPOC )
431{
432  if( m_pCodedScaleOffsetFile )
433  {
434    if( iPOC == 0 )
435    {
436      fprintf( m_pCodedScaleOffsetFile, "#     ViewId ViewOrderIdx\n" );
437      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
438      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
439      {
440        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] );
441      }
442      fprintf( m_pCodedScaleOffsetFile, "\n\n");
443      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
444      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
445    }
446    if( iPOC == 0 || m_bCamParsVaryOverTime )
447    {
448      Int iS = iPOC;
449      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
450      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
451      {
452        for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ )
453        {
454          if( uiViewId != uiBaseId )
455          {
456            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
457              iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
458          }
459        }
460      }
461    }
462  }
463}
464
465TDecTop::TDecTop()
466: m_SEIs(0)
467, m_tAppDecTop( NULL )
468, m_nalUnitTypeBaseView( NAL_UNIT_INVALID )
469{
470  m_pcPic = 0;
471  m_iGopSize      = 0;
472  m_bGopSizeSet   = false;
473  m_iMaxRefPicNum = 0;
474  m_uiValidPS = 0;
475#if SONY_COLPIC_AVAILABILITY
476  m_iViewOrderIdx = 0;
477#endif
478#if ENC_DEC_TRACE
479  if(!g_hTrace) g_hTrace = fopen( "TraceDec.txt", "wb" );
480  g_bJustDoIt = g_bEncDecTraceDisable;
481  g_nSymbolCounter = 0;
482#endif
483  m_bRefreshPending = 0;
484  m_pocCRA = 0;
485  m_pocRandomAccess = MAX_INT;         
486  m_prevPOC                = MAX_INT;
487  m_bFirstSliceInPicture    = true;
488  m_bFirstSliceInSequence   = true;
489  m_pcCamParsCollector = 0;
490
491#if VSP_N
492  m_pcPicVSP = NULL;
493  m_pcPicAvail = NULL;
494#endif
495}
496
497TDecTop::~TDecTop()
498{
499#if ENC_DEC_TRACE
500  if(g_hTrace) fclose( g_hTrace );
501  g_hTrace=NULL;
502#endif
503}
504
505Void TDecTop::create()
506{
507  m_cGopDecoder.create();
508  m_apcSlicePilot = new TComSlice;
509  m_uiSliceIdx = m_uiLastSliceIdx = 0;
510}
511
512Void TDecTop::destroy()
513{
514  m_cGopDecoder.destroy();
515 
516  delete m_apcSlicePilot;
517  m_apcSlicePilot = NULL;
518 
519  m_cSliceDecoder.destroy();
520  m_tAppDecTop = NULL;
521
522#if DEPTH_MAP_GENERATION
523  m_cDepthMapGenerator.destroy();
524#endif
525#if HHI_INTER_VIEW_RESIDUAL_PRED
526  m_cResidualGenerator.destroy();
527#endif
528
529#if VSP_N
530  if( m_pcPicVSP )
531  {
532    m_pcPicVSP->destroy();
533    delete m_pcPicVSP;
534    m_pcPicVSP = NULL;
535  }
536  if( m_pcPicAvail )
537  {
538    m_pcPicAvail->destroy();
539    delete m_pcPicAvail;
540    m_pcPicAvail = NULL;
541  }
542#endif
543}
544
545Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
546{
547  // initialize ROM
548  if( bFirstInstance )
549  {
550  initROM();
551  }
552  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
553#if DEPTH_MAP_GENERATION
554                    , &m_cDepthMapGenerator
555#endif
556#if HHI_INTER_VIEW_RESIDUAL_PRED
557                    , &m_cResidualGenerator
558#endif
559    );
560  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
561  m_cEntropyDecoder.init(&m_cPrediction);
562  m_tAppDecTop = pcTAppDecTop;
563#if DEPTH_MAP_GENERATION
564#if VIDYO_VPS_INTEGRATION
565  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
566#else
567  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
568#endif
569#endif
570#if HHI_INTER_VIEW_RESIDUAL_PRED
571  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
572#endif
573}
574
575Void TDecTop::deletePicBuffer ( )
576{
577  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
578  Int iSize = Int( m_cListPic.size() );
579 
580  for (Int i = 0; i < iSize; i++ )
581  {
582    if( *iterPic )
583    {
584      TComPic* pcPic = *(iterPic++);
585      pcPic->destroy();
586   
587      delete pcPic;
588      pcPic = NULL;
589    }
590  }
591 
592  // destroy ALF temporary buffers
593  m_cAdaptiveLoopFilter.destroy();
594
595  m_cSAO.destroy();
596 
597  m_cLoopFilter.        destroy();
598 
599  // destroy ROM
600  if(m_viewId == 0 && m_isDepth == false)
601  {
602    destroyROM();
603  }
604}
605
606#if HHI_INTER_VIEW_RESIDUAL_PRED
607Void
608TDecTop::deleteExtraPicBuffers( Int iPoc )
609{
610  TComPic*                      pcPic = 0;
611  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
612  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
613  for( ; cIter != cEnd; cIter++ )
614  {
615    if( (*cIter)->getPOC() == iPoc )
616    {
617      pcPic = *cIter;
618      break;
619    }
620  }
621  //AOF( pcPic );
622  if ( pcPic )
623  {
624    pcPic->removeResidualBuffer   ();
625  }
626}
627#endif
628
629
630Void
631TDecTop::compressMotion( Int iPoc )
632{
633  TComPic*                      pcPic = 0;
634  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
635  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
636  for( ; cIter != cEnd; cIter++ )
637  {
638    if( (*cIter)->getPOC() == iPoc )
639    {
640      pcPic = *cIter;
641      break;
642    }
643  }
644//  AOF( pcPic );
645  if ( pcPic )
646  {
647    pcPic->compressMotion();
648  }
649}
650
651Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
652{
653  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
654  {
655    m_iGopSize    = pcSlice->getPOC();
656    m_bGopSizeSet = true;
657   
658    m_cGopDecoder.setGopSize(m_iGopSize);
659  }
660}
661
662Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
663{
664  xUpdateGopSize(pcSlice);
665 
666#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
667  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
668#else
669  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxNumberOfReferencePictures()+pcSlice->getSPS()->getNumReorderFrames() + 1; // +1 to have space for the picture currently being decoded
670#endif
671
672#if DEPTH_MAP_GENERATION
673  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
674  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
675#endif
676
677  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
678  {
679    rpcPic = new TComPic();
680   
681    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
682   
683#if DEPTH_MAP_GENERATION
684    if( bNeedPrdDepthMapBuffer )
685    {
686      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
687    }
688#endif
689   
690    m_cListPic.pushBack( rpcPic );
691   
692    return;
693  }
694 
695  Bool bBufferIsAvailable = false;
696  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
697  while (iterPic != m_cListPic.end())
698  {
699    rpcPic = *(iterPic++);
700    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
701    {
702      rpcPic->setOutputMark(false);
703      bBufferIsAvailable = true;
704      break;
705    }
706
707    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
708    {
709      rpcPic->setOutputMark(false);
710      rpcPic->setReconMark( false );
711      rpcPic->getPicYuvRec()->setBorderExtension( false );
712      bBufferIsAvailable = true;
713      break;
714    }
715  }
716 
717  if ( !bBufferIsAvailable )
718  {
719    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
720    m_iMaxRefPicNum++;
721    rpcPic = new TComPic();
722    m_cListPic.pushBack( rpcPic );
723  }
724  rpcPic->destroy(); 
725  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
726#if DEPTH_MAP_GENERATION
727  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
728  {
729    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
730  }
731#endif
732}
733
734Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
735{
736  if (!m_pcPic)
737  {
738    /* nothing to deblock */
739    return;
740  }
741 
742  TComPic*&   pcPic         = m_pcPic;
743
744  // Execute Deblock and ALF only + Cleanup
745
746  m_cGopDecoder.decompressGop(NULL, pcPic, true);
747
748  TComSlice::sortPicList( m_cListPic ); // sorting for application output
749  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
750  rpcListPic          = &m_cListPic; 
751  m_cCuDecoder.destroy();       
752  m_bFirstSliceInPicture  = true;
753
754  return;
755}
756
757Void TDecTop::xCreateLostPicture(Int iLostPoc) 
758{
759  printf("\ninserting lost poc : %d\n",iLostPoc);
760  TComSlice cFillSlice;
761  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
762  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
763  cFillSlice.initSlice();
764  cFillSlice.initTiles();
765  TComPic *cFillPic;
766  xGetNewPicBuffer(&cFillSlice,cFillPic);
767  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
768  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
769  cFillPic->getSlice(0)->initSlice();
770  cFillPic->getSlice(0)->initTiles();
771
772 
773 
774  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
775  Int closestPoc = 1000000;
776  while ( iterPic != m_cListPic.end())
777  {
778    TComPic * rpcPic = *(iterPic++);
779    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())
780    {
781      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
782    }
783  }
784  iterPic = m_cListPic.begin();
785  while ( iterPic != m_cListPic.end())
786  {
787    TComPic *rpcPic = *(iterPic++);
788    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
789    {
790      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
791      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
792      break;
793    }
794  }
795  cFillPic->setCurrSliceIdx(0);
796  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
797  {
798    cFillPic->getCU(i)->initCU(cFillPic,i);
799  }
800  cFillPic->getSlice(0)->setReferenced(true);
801  cFillPic->getSlice(0)->setPOC(iLostPoc);
802  cFillPic->setReconMark(true);
803  cFillPic->setOutputMark(true);
804  if(m_pocRandomAccess == MAX_INT)
805  {
806    m_pocRandomAccess = iLostPoc;
807  }
808}
809
810
811Void TDecTop::xActivateParameterSets()
812{
813  m_parameterSetManagerDecoder.applyPrefetchedPS();
814
815  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
816  assert (pps != 0);
817
818  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
819  assert (sps != 0);
820#if VIDYO_VPS_INTEGRATION
821  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
822  assert (vps != 0);
823  if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
824    // VPS can only be activated on IDR or CRA...
825    getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
826#endif
827  m_apcSlicePilot->setPPS(pps);
828  m_apcSlicePilot->setSPS(sps);
829#if VIDYO_VPS_INTEGRATION
830  m_apcSlicePilot->setVPS(vps);
831#endif
832  pps->setSPS(sps);
833
834  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
835  {
836    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
837  }
838  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
839
840  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
841  {
842    sps->setAMPAcc( i, sps->getUseAMP() );
843  }
844
845  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
846  {
847    sps->setAMPAcc( i, 0 );
848  }
849
850#if !LCU_SYNTAX_ALF
851  // create ALF temporary buffer
852  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
853#endif
854  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
855  m_cLoopFilter.        create( g_uiMaxCUDepth );
856}
857
858#if SKIPFRAME_BUGFIX
859Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
860#else
861Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
862#endif
863{
864  TComPic*&   pcPic         = m_pcPic;
865  m_apcSlicePilot->initSlice();
866
867  //!!!KS: DIRTY HACK
868  m_apcSlicePilot->setPPSId(0);
869  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
870  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
871#if VIDYO_VPS_INTEGRATION
872  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
873#endif
874  m_apcSlicePilot->initTiles();
875
876  if (m_bFirstSliceInPicture)
877  {
878    m_uiSliceIdx     = 0;
879    m_uiLastSliceIdx = 0;
880  }
881  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
882  if (!m_bFirstSliceInPicture)
883  {
884    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
885  }
886
887  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
888  if( m_bFirstSliceInPicture )
889  {
890#if VIDYO_VPS_INTEGRATION
891    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
892    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
893#else
894    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
895    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
896#endif
897   
898    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
899  }
900
901#if SONY_COLPIC_AVAILABILITY
902  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
903#endif
904
905#if NAL_REF_FLAG
906  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
907#else
908  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
909#endif
910  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
911
912  // ALF CU parameters should be part of the slice header -> needs to be fixed
913#if LCU_SYNTAX_ALF
914  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
915#else
916  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
917#endif
918  // byte align
919  {
920    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
921    if ( numBitsForByteAlignment > 0 )
922    {
923      UInt bitsForByteAlignment;
924      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
925      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
926    }
927  }
928
929  // exit when a new picture is found
930  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
931  {
932#if START_DECODING_AT_CRA
933    if (m_prevPOC >= m_pocRandomAccess)
934    {
935      m_prevPOC = m_apcSlicePilot->getPOC();
936      return true;
937    }
938    m_prevPOC = m_apcSlicePilot->getPOC();
939#else
940    m_prevPOC = m_apcSlicePilot->getPOC();
941    return true;
942#endif
943  }
944  // actual decoding starts here
945  xActivateParameterSets();
946  m_apcSlicePilot->initTiles();
947
948  if (m_apcSlicePilot->isNextSlice()) 
949  {
950    m_prevPOC = m_apcSlicePilot->getPOC();
951  }
952  m_bFirstSliceInSequence = false;
953  if (m_apcSlicePilot->isNextSlice())
954  {
955    // Skip pictures due to random access
956    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
957    {
958      return false;
959    }
960  }
961  //detect lost reference picture and insert copy of earlier frame.
962#if START_DECODING_AT_CRA
963  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
964#else
965  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
966#endif
967  {
968    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
969  }
970  if (m_bFirstSliceInPicture)
971  {
972    // Buffer initialize for prediction.
973    m_cPrediction.initTempBuff();
974    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
975    //  Get a new picture buffer
976    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
977#if VSP_N
978#if VSP_SLICE_HEADER
979    if( m_apcSlicePilot->getVspFlag() )
980#endif
981    {
982      if( m_pcPicVSP == NULL )
983      {
984        m_pcPicVSP = new TComPic;
985        m_pcPicVSP->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
986        m_pcPicVSP->setCurrSliceIdx(0);
987        m_pcPicVSP->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
988        m_pcPicVSP->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
989        m_pcPicVSP->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
990        m_pcPicVSP->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
991        m_pcPicVSP->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
992        m_pcPicVSP->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
993        m_pcPicVSP->getPicSym()->xCreateTComTileArray();
994        for (int i=0;i<m_pcPicVSP->getPicSym()->getNumberOfCUsInFrame();i++)
995        {
996          m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
997          m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
998        }
999#if DEPTH_MAP_GENERATION
1000        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1001        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1002        if( bNeedPrdDepthMapBuffer )
1003        {
1004          m_pcPicVSP->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1005        }
1006#endif
1007      }
1008      if( m_pcPicAvail == NULL )
1009      {
1010        m_pcPicAvail = new TComPic;
1011        m_pcPicAvail->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1012        m_pcPicAvail->setCurrSliceIdx(0);
1013        m_pcPicAvail->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
1014        m_pcPicAvail->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
1015        m_pcPicAvail->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
1016        m_pcPicAvail->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
1017        m_pcPicAvail->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
1018        m_pcPicAvail->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
1019        m_pcPicAvail->getPicSym()->xCreateTComTileArray();
1020        for (int i=0;i<m_pcPicAvail->getPicSym()->getNumberOfCUsInFrame();i++)
1021        {
1022          m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
1023          m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
1024        }
1025#if DEPTH_MAP_GENERATION
1026        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1027        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1028        if( bNeedPrdDepthMapBuffer )
1029        {
1030          m_pcPicAvail->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1031        }
1032#endif
1033      }
1034    }
1035#endif
1036
1037#if SONY_COLPIC_AVAILABILITY
1038    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
1039#endif
1040
1041    /* transfer any SEI messages that have been received to the picture */
1042    pcPic->setSEIs(m_SEIs);
1043    m_SEIs = NULL;
1044
1045    // Recursive structure
1046    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1047    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1048    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1049
1050    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1051#if DEPTH_MAP_GENERATION
1052    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1053    m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1054    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
1055    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
1056    {
1057      pcDMG0->create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1058    }
1059#endif
1060#if HHI_INTER_VIEW_RESIDUAL_PRED
1061    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
1062#endif
1063#if !QC_MULTI_DIS_CAN
1064#if VSP_N
1065#if VSP_SLICE_HEADER
1066    if( m_apcSlicePilot->getVspFlag() )
1067#endif
1068    {
1069      UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1070      Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1071      if( bNeedPrdDepthMapBuffer )
1072      {
1073        if( m_pcPicVSP && m_pcPicVSP->getPredDepthMap() )
1074        {
1075          m_cDepthMapGenerator.clearDepthMap( m_pcPicVSP );
1076        }
1077        if( m_pcPicAvail && m_pcPicAvail->getPredDepthMap() )
1078        {
1079          m_cDepthMapGenerator.clearDepthMap( m_pcPicAvail );
1080        }
1081      }
1082    }
1083#endif
1084#endif
1085  }
1086
1087  //  Set picture slice pointer
1088  TComSlice*  pcSlice = m_apcSlicePilot;
1089  Bool bNextSlice     = pcSlice->isNextSlice();
1090
1091  UInt uiCummulativeTileWidth;
1092  UInt uiCummulativeTileHeight;
1093  UInt i, j, p;
1094
1095#if !REMOVE_TILE_DEPENDENCE
1096  //set the TileBoundaryIndependenceIdr
1097  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
1098  {
1099    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
1100  }
1101  else
1102  {
1103    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
1104  }
1105#endif
1106
1107  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
1108  {
1109    //set NumColumnsMins1 and NumRowsMinus1
1110    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1111    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1112
1113    //create the TComTileArray
1114    pcPic->getPicSym()->xCreateTComTileArray();
1115
1116    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
1117    {
1118      //set the width for each tile
1119      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1120      {
1121        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1122        {
1123          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1124            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1125            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1126        }
1127      }
1128
1129      //set the height for each tile
1130      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1131      {
1132        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1133        {
1134          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1135            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1136            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1137        }
1138      }
1139    }
1140    else
1141    {
1142      //set the width for each tile
1143      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1144      {
1145        uiCummulativeTileWidth = 0;
1146        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1147        {
1148          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1149          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1150        }
1151        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1152      }
1153
1154      //set the height for each tile
1155      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1156      {
1157        uiCummulativeTileHeight = 0;
1158        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1159        { 
1160          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1161          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1162        }
1163        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1164      }
1165    }
1166  }
1167  else
1168  {
1169    //set NumColumnsMins1 and NumRowsMinus1
1170    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
1171    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
1172
1173    //create the TComTileArray
1174    pcPic->getPicSym()->xCreateTComTileArray();
1175
1176    //automatically set the column and row boundary if UniformSpacingIdr = 1
1177    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
1178    {
1179      //set the width for each tile
1180      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1181      {
1182        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1183        {
1184          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1185            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1186            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1187        }
1188      }
1189
1190      //set the height for each tile
1191      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1192      {
1193        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1194        {
1195          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1196            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1197            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1198        }
1199      }
1200    }
1201    else
1202    {
1203      //set the width for each tile
1204      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
1205      {
1206        uiCummulativeTileWidth = 0;
1207        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
1208        {
1209          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
1210          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
1211        }
1212        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1213      }
1214
1215      //set the height for each tile
1216      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
1217      {
1218        uiCummulativeTileHeight = 0;
1219        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
1220        { 
1221          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
1222          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
1223        }
1224        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1225      }
1226    }
1227  }
1228
1229  pcPic->getPicSym()->xInitTiles();
1230
1231  //generate the Coding Order Map and Inverse Coding Order Map
1232  UInt uiEncCUAddr;
1233  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1234  {
1235    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1236    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1237  }
1238  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1239  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1240
1241  //convert the start and end CU addresses of the slice and entropy slice into encoding order
1242  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
1243  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
1244  if(pcSlice->isNextSlice())
1245  {
1246    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1247    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1248  }
1249
1250  if (m_bFirstSliceInPicture) 
1251  {
1252    if(pcPic->getNumAllocatedSlice() != 1)
1253    {
1254      pcPic->clearSliceBuffer();
1255    }
1256  }
1257  else
1258  {
1259    pcPic->allocateNewSlice();
1260  }
1261  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1262  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1263  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1264
1265  pcPic->setTLayer(nalu.m_temporalId);
1266
1267  if (bNextSlice)
1268  {
1269    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
1270
1271    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
1272    {
1273      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
1274    }
1275
1276    // Set reference list
1277#if VIDYO_VPS_INTEGRATION
1278    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
1279    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
1280#else
1281    pcSlice->setViewId(m_viewId);
1282    pcSlice->setIsDepth(m_isDepth);
1283#endif
1284
1285#if SONY_COLPIC_AVAILABILITY
1286#if VIDYO_VPS_INTEGRATION
1287    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );
1288#else
1289    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
1290#endif
1291#endif
1292
1293    assert( m_tAppDecTop != NULL );
1294    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
1295    assert( !m_isDepth || pcTexturePic != NULL );
1296    pcSlice->setTexturePic( pcTexturePic );
1297
1298    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
1299#if VSP_N
1300    Bool bUseVsp = (m_viewId!=0);
1301#if VSP_CFG
1302    if( !pcSlice->getSPS()->getVspDepthPresentFlag() && m_isDepth ) bUseVsp = false;
1303#else
1304    if( pcSlice->getVspDepthDisableFlag() && m_isDepth ) bUseVsp = false;
1305#endif
1306#if VSP_SLICE_HEADER
1307    if( !pcSlice->getVspFlag() ) bUseVsp = false;
1308#endif
1309
1310#if VSP_SLICE_HEADER
1311    if( bUseVsp )
1312#endif
1313    {
1314      m_pcPicVSP->getCurrSlice()->setPOC( pcPic->getPOC() );
1315      m_pcPicVSP->getCurrSlice()->setViewId( pcPic->getViewId() );
1316    }
1317
1318    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics, bUseVsp ? m_pcPicVSP : NULL );
1319
1320#else
1321    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
1322#endif
1323
1324    // For generalized B
1325    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1326    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1327    {
1328      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1329      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1330
1331      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1332      {
1333        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1334      }
1335    }
1336    if (pcSlice->isInterB())
1337    {
1338      Bool bLowDelay = true;
1339      Int  iCurrPOC  = pcSlice->getPOC();
1340      Int iRefIdx = 0;
1341
1342      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1343      {
1344        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1345        {
1346          bLowDelay = false;
1347        }
1348      }
1349      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1350      {
1351        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1352        {
1353          bLowDelay = false;
1354        }
1355      }
1356
1357      pcSlice->setCheckLDC(bLowDelay);           
1358    }
1359
1360    //---------------
1361    pcSlice->setRefPOCnViewListsMvc();
1362
1363    if(!pcSlice->getRefPicListModificationFlagLC())
1364    {
1365      pcSlice->generateCombinedList();
1366    }
1367
1368    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
1369    {
1370      pcSlice->setWpParamforLC();
1371    }
1372    pcSlice->setNoBackPredFlag( false );
1373    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
1374    {
1375      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
1376      {
1377        pcSlice->setNoBackPredFlag( true );
1378        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1379        {
1380          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1381          {
1382            pcSlice->setNoBackPredFlag( false );
1383            break;
1384          }
1385        }
1386      }
1387    }
1388  }
1389
1390  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1391  if(pcSlice->getSPS()->getScalingListFlag())
1392  {
1393    if(pcSlice->getAPS()->getScalingListEnabled())
1394    {
1395      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1396      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1397      {
1398        pcSlice->setDefaultScalingList();
1399      }
1400      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1401    }
1402    m_cTrQuant.setUseScalingList(true);
1403  }
1404  else
1405  {
1406    m_cTrQuant.setFlatScalingList();
1407    m_cTrQuant.setUseScalingList(false);
1408  }
1409
1410#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1411  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1412  {
1413    initWedgeLists();
1414  }
1415#endif
1416
1417#if VSP_N
1418  if( m_pcCamParsCollector )
1419  {
1420    m_pcCamParsCollector->setSlice( pcSlice );
1421  }
1422#if VSP_SLICE_HEADER
1423  if( pcSlice->getVspFlag() )
1424#endif
1425  if( getTAppDecTop()->getUseDepth() )
1426  {
1427#if VSP_CFG
1428    if( pcSlice->getSPS()->getVspDepthPresentFlag() || !m_isDepth )
1429#else
1430    if( !pcSlice->getVspDepthDisableFlag() || !m_isDepth )
1431#endif
1432      getTAppDecTop()->storeVSPInBuffer( m_pcPicVSP, m_pcPicAvail, pcSlice->getViewId(), pcSlice->getSPS()->getViewOrderIdx(), pcSlice->getPOC(), m_isDepth );
1433#if VSP_N_DUMP
1434    if( m_pcPicVSP && pcSlice->getViewId() != 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)!=0){
1435        Char acFilenameBase[1024];
1436        ::sprintf(acFilenameBase,"ref_dec_%sv%d_%04d.yuv",(m_isDepth?"D":"T"),pcSlice->getViewId(), pcSlice->getPOC());
1437        pcSlice->getRefPic(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)-1)->getPicYuvRec()->dump(acFilenameBase,0);
1438    }
1439#endif
1440  }
1441#endif
1442
1443  //  Decode a picture
1444  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1445
1446  if( m_pcCamParsCollector )
1447  {
1448    m_pcCamParsCollector->setSlice( pcSlice );
1449  }
1450
1451  m_bFirstSliceInPicture = false;
1452  m_uiSliceIdx++;
1453
1454  return false;
1455}
1456
1457#if VIDYO_VPS_INTEGRATION
1458Void TDecTop::xDecodeVPS()
1459{
1460  TComVPS* vps = new TComVPS();
1461 
1462  m_cEntropyDecoder.decodeVPS( vps );
1463  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1464  getTAppDecTop()->getVPSAccess()->addVPS( vps );
1465}
1466#endif
1467
1468Void TDecTop::xDecodeSPS()
1469{
1470  TComSPS* sps = new TComSPS();
1471#if RPS_IN_SPS
1472  TComRPSList* rps = new TComRPSList();
1473  sps->setRPSList(rps);
1474#endif
1475#if HHI_MPI
1476  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1477#else
1478  m_cEntropyDecoder.decodeSPS( sps );
1479#endif
1480  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1481#if LCU_SYNTAX_ALF
1482  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1483#endif
1484
1485#if VSP_N
1486  if( !sps->isDepth() && sps->getViewId() == 0 && getTAppDecTop()->getVSPRendererTop() )
1487  {
1488#if NTT_SUBPEL
1489    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 5, 1, 0, 6 );
1490#else
1491    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
1492#endif
1493  }
1494#endif
1495}
1496
1497Void TDecTop::xDecodePPS()
1498{
1499#if !RPS_IN_SPS
1500  TComRPSList* rps = new TComRPSList();
1501#endif
1502  TComPPS* pps = new TComPPS();
1503#if !RPS_IN_SPS
1504  pps->setRPSList(rps);
1505#endif
1506#if TILES_OR_ENTROPY_SYNC_IDC
1507  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1508#else
1509  m_cEntropyDecoder.decodePPS( pps );
1510#endif
1511  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1512
1513  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1514  m_apcSlicePilot->setPPSId(pps->getPPSId());
1515  xActivateParameterSets();
1516  m_apcSlicePilot->initTiles();
1517}
1518
1519Void TDecTop::xDecodeAPS()
1520{
1521  TComAPS  *aps = new TComAPS();
1522  allocAPS (aps);
1523  decodeAPS(aps);
1524  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1525}
1526
1527Void TDecTop::xDecodeSEI()
1528{
1529  m_SEIs = new SEImessages;
1530  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1531}
1532
1533Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1534{
1535  // Initialize entropy decoder
1536  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1537  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1538
1539  switch (nalu.m_nalUnitType)
1540  {
1541#if VIDYO_VPS_INTEGRATION
1542    case NAL_UNIT_VPS:
1543      xDecodeVPS();
1544      return false;
1545#endif
1546    case NAL_UNIT_SPS:
1547      xDecodeSPS();
1548      return false;
1549
1550    case NAL_UNIT_PPS:
1551      xDecodePPS();
1552      return false;
1553    case NAL_UNIT_APS:
1554      xDecodeAPS();
1555      return false;
1556
1557    case NAL_UNIT_SEI:
1558      xDecodeSEI();
1559      return false;
1560
1561    case NAL_UNIT_CODED_SLICE:
1562    case NAL_UNIT_CODED_SLICE_IDR:
1563#if H0566_TLA
1564    case NAL_UNIT_CODED_SLICE_IDV:
1565    case NAL_UNIT_CODED_SLICE_CRA:
1566    case NAL_UNIT_CODED_SLICE_TLA:
1567#else
1568    case NAL_UNIT_CODED_SLICE_CDR:
1569#endif
1570      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1571      break;
1572    default:
1573      assert (1);
1574  }
1575
1576  return false;
1577}
1578
1579/** Function for checking if picture should be skipped because of random access
1580 * \param iSkipFrame skip frame counter
1581 * \param iPOCLastDisplay POC of last picture displayed
1582 * \returns true if the picture shold be skipped in the random access.
1583 * This function checks the skipping of pictures in the case of -s option random access.
1584 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1585 * It also checks the type of Nal unit type at the random access point.
1586 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1587 * If the random access point is IDR all pictures after the random access point are decoded.
1588 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1589 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1590 * access point there is no guarantee that the decoder will not crash.
1591 */
1592Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1593{
1594  if (iSkipFrame) 
1595  {
1596    iSkipFrame--;   // decrement the counter
1597    return true;
1598  }
1599  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1600  {
1601#if H0566_TLA
1602    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1603#else
1604    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
1605#endif
1606    {
1607      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1608    }
1609    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1610    {
1611      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1612    }
1613    else 
1614    {
1615#if START_DECODING_AT_CRA
1616      static bool warningMessage = false;
1617      if(!warningMessage)
1618      {
1619        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1620        warningMessage = true;
1621      }
1622      return true;
1623#else
1624      printf("\nUnsafe random access point. Decoder may crash.");
1625      m_pocRandomAccess = 0;
1626#endif
1627    }
1628  }
1629  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1630  {
1631    iPOCLastDisplay++;
1632    return true;
1633  }
1634  // if we reach here, then the picture is not skipped.
1635  return false; 
1636}
1637
1638Void TDecTop::allocAPS (TComAPS* pAPS)
1639{
1640  // we don't know the SPS before it has been activated. These fields could exist
1641  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1642  // have to be moved for that
1643  pAPS->createScalingList();
1644  pAPS->createSaoParam();
1645  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1646  pAPS->createAlfParam();
1647#if !LCU_SYNTAX_ALF
1648  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
1649#endif
1650}
1651
1652//! \}
Note: See TracBrowser for help on using the repository browser.