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

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

Initial integration of VSP into HTM 4.0.1. The version used for JCT3V-B0102 at Shanghai meeting.

  • VC9 project/solution files updated. Other Visual C++ project/solution files are not updated.
  • Linux make file updated.

TODO

  • A second release is expected to include some bug fix and improvements on the interface, e.g. to move switches from macro definition to the configuration file.
  • A third release is expected after being integrated within HTM 5.x, which is to be used for CE1.h anchor.
  • Property svn:eol-style set to native
File size: 58.9 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}
545
546Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
547{
548  // initialize ROM
549  if( bFirstInstance )
550  {
551  initROM();
552  }
553  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
554#if DEPTH_MAP_GENERATION
555                    , &m_cDepthMapGenerator
556#endif
557#if HHI_INTER_VIEW_RESIDUAL_PRED
558                    , &m_cResidualGenerator
559#endif
560    );
561  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
562  m_cEntropyDecoder.init(&m_cPrediction);
563  m_tAppDecTop = pcTAppDecTop;
564#if DEPTH_MAP_GENERATION
565#if VIDYO_VPS_INTEGRATION
566  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
567#else
568  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
569#endif
570#endif
571#if HHI_INTER_VIEW_RESIDUAL_PRED
572  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
573#endif
574}
575
576Void TDecTop::deletePicBuffer ( )
577{
578  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
579  Int iSize = Int( m_cListPic.size() );
580 
581  for (Int i = 0; i < iSize; i++ )
582  {
583    if( *iterPic )
584    {
585      TComPic* pcPic = *(iterPic++);
586      pcPic->destroy();
587   
588      delete pcPic;
589      pcPic = NULL;
590    }
591  }
592 
593  // destroy ALF temporary buffers
594  m_cAdaptiveLoopFilter.destroy();
595
596  m_cSAO.destroy();
597 
598  m_cLoopFilter.        destroy();
599 
600  // destroy ROM
601  if(m_viewId == 0 && m_isDepth == false)
602  {
603    destroyROM();
604  }
605}
606
607#if HHI_INTER_VIEW_RESIDUAL_PRED
608Void
609TDecTop::deleteExtraPicBuffers( Int iPoc )
610{
611  TComPic*                      pcPic = 0;
612  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
613  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
614  for( ; cIter != cEnd; cIter++ )
615  {
616    if( (*cIter)->getPOC() == iPoc )
617    {
618      pcPic = *cIter;
619      break;
620    }
621  }
622  //AOF( pcPic );
623  if ( pcPic )
624  {
625    pcPic->removeResidualBuffer   ();
626  }
627}
628#endif
629
630
631Void
632TDecTop::compressMotion( Int iPoc )
633{
634  TComPic*                      pcPic = 0;
635  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
636  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
637  for( ; cIter != cEnd; cIter++ )
638  {
639    if( (*cIter)->getPOC() == iPoc )
640    {
641      pcPic = *cIter;
642      break;
643    }
644  }
645//  AOF( pcPic );
646  if ( pcPic )
647  {
648    pcPic->compressMotion();
649  }
650}
651
652Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
653{
654  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
655  {
656    m_iGopSize    = pcSlice->getPOC();
657    m_bGopSizeSet = true;
658   
659    m_cGopDecoder.setGopSize(m_iGopSize);
660  }
661}
662
663Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
664{
665  xUpdateGopSize(pcSlice);
666 
667#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
668  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
669#else
670  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxNumberOfReferencePictures()+pcSlice->getSPS()->getNumReorderFrames() + 1; // +1 to have space for the picture currently being decoded
671#endif
672
673#if DEPTH_MAP_GENERATION
674  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
675  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
676#endif
677
678  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
679  {
680    rpcPic = new TComPic();
681   
682    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
683   
684#if DEPTH_MAP_GENERATION
685    if( bNeedPrdDepthMapBuffer )
686    {
687      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
688    }
689#endif
690   
691    m_cListPic.pushBack( rpcPic );
692   
693    return;
694  }
695 
696  Bool bBufferIsAvailable = false;
697  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
698  while (iterPic != m_cListPic.end())
699  {
700    rpcPic = *(iterPic++);
701    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
702    {
703      rpcPic->setOutputMark(false);
704      bBufferIsAvailable = true;
705      break;
706    }
707
708    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
709    {
710      rpcPic->setOutputMark(false);
711      rpcPic->setReconMark( false );
712      rpcPic->getPicYuvRec()->setBorderExtension( false );
713      bBufferIsAvailable = true;
714      break;
715    }
716  }
717 
718  if ( !bBufferIsAvailable )
719  {
720    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
721    m_iMaxRefPicNum++;
722    rpcPic = new TComPic();
723    m_cListPic.pushBack( rpcPic );
724  }
725  rpcPic->destroy(); 
726  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
727#if DEPTH_MAP_GENERATION
728  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
729  {
730    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
731  }
732#endif
733}
734
735Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
736{
737  if (!m_pcPic)
738  {
739    /* nothing to deblock */
740    return;
741  }
742 
743  TComPic*&   pcPic         = m_pcPic;
744
745  // Execute Deblock and ALF only + Cleanup
746
747  m_cGopDecoder.decompressGop(NULL, pcPic, true);
748
749  TComSlice::sortPicList( m_cListPic ); // sorting for application output
750  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
751  rpcListPic          = &m_cListPic; 
752  m_cCuDecoder.destroy();       
753  m_bFirstSliceInPicture  = true;
754
755  return;
756}
757
758Void TDecTop::xCreateLostPicture(Int iLostPoc) 
759{
760  printf("\ninserting lost poc : %d\n",iLostPoc);
761  TComSlice cFillSlice;
762  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
763  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
764  cFillSlice.initSlice();
765  cFillSlice.initTiles();
766  TComPic *cFillPic;
767  xGetNewPicBuffer(&cFillSlice,cFillPic);
768  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
769  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
770  cFillPic->getSlice(0)->initSlice();
771  cFillPic->getSlice(0)->initTiles();
772
773 
774 
775  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
776  Int closestPoc = 1000000;
777  while ( iterPic != m_cListPic.end())
778  {
779    TComPic * rpcPic = *(iterPic++);
780    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())
781    {
782      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
783    }
784  }
785  iterPic = m_cListPic.begin();
786  while ( iterPic != m_cListPic.end())
787  {
788    TComPic *rpcPic = *(iterPic++);
789    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
790    {
791      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
792      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
793      break;
794    }
795  }
796  cFillPic->setCurrSliceIdx(0);
797  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
798  {
799    cFillPic->getCU(i)->initCU(cFillPic,i);
800  }
801  cFillPic->getSlice(0)->setReferenced(true);
802  cFillPic->getSlice(0)->setPOC(iLostPoc);
803  cFillPic->setReconMark(true);
804  cFillPic->setOutputMark(true);
805  if(m_pocRandomAccess == MAX_INT)
806  {
807    m_pocRandomAccess = iLostPoc;
808  }
809}
810
811
812Void TDecTop::xActivateParameterSets()
813{
814  m_parameterSetManagerDecoder.applyPrefetchedPS();
815
816  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
817  assert (pps != 0);
818
819  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
820  assert (sps != 0);
821#if VIDYO_VPS_INTEGRATION
822  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
823  assert (vps != 0);
824  if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
825    // VPS can only be activated on IDR or CRA...
826    getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
827#endif
828  m_apcSlicePilot->setPPS(pps);
829  m_apcSlicePilot->setSPS(sps);
830#if VIDYO_VPS_INTEGRATION
831  m_apcSlicePilot->setVPS(vps);
832#endif
833  pps->setSPS(sps);
834
835  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
836  {
837    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
838  }
839  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
840
841  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
842  {
843    sps->setAMPAcc( i, sps->getUseAMP() );
844  }
845
846  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
847  {
848    sps->setAMPAcc( i, 0 );
849  }
850
851#if !LCU_SYNTAX_ALF
852  // create ALF temporary buffer
853  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
854#endif
855  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
856  m_cLoopFilter.        create( g_uiMaxCUDepth );
857}
858
859#if SKIPFRAME_BUGFIX
860Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
861#else
862Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
863#endif
864{
865  TComPic*&   pcPic         = m_pcPic;
866  m_apcSlicePilot->initSlice();
867
868  //!!!KS: DIRTY HACK
869  m_apcSlicePilot->setPPSId(0);
870  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
871  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
872#if VIDYO_VPS_INTEGRATION
873  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
874#endif
875  m_apcSlicePilot->initTiles();
876
877  if (m_bFirstSliceInPicture)
878  {
879    m_uiSliceIdx     = 0;
880    m_uiLastSliceIdx = 0;
881  }
882  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
883  if (!m_bFirstSliceInPicture)
884  {
885    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
886  }
887
888  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
889  if( m_bFirstSliceInPicture )
890  {
891#if VIDYO_VPS_INTEGRATION
892    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
893    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
894#else
895    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
896    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
897#endif
898   
899    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
900  }
901
902#if SONY_COLPIC_AVAILABILITY
903  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
904#endif
905
906#if NAL_REF_FLAG
907  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
908#else
909  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
910#endif
911  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
912
913  // ALF CU parameters should be part of the slice header -> needs to be fixed
914#if LCU_SYNTAX_ALF
915  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
916#else
917  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
918#endif
919  // byte align
920  {
921    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
922    if ( numBitsForByteAlignment > 0 )
923    {
924      UInt bitsForByteAlignment;
925      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
926      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
927    }
928  }
929
930  // exit when a new picture is found
931  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
932  {
933#if START_DECODING_AT_CRA
934    if (m_prevPOC >= m_pocRandomAccess)
935    {
936      m_prevPOC = m_apcSlicePilot->getPOC();
937      return true;
938    }
939    m_prevPOC = m_apcSlicePilot->getPOC();
940#else
941    m_prevPOC = m_apcSlicePilot->getPOC();
942    return true;
943#endif
944  }
945  // actual decoding starts here
946  xActivateParameterSets();
947  m_apcSlicePilot->initTiles();
948
949  if (m_apcSlicePilot->isNextSlice()) 
950  {
951    m_prevPOC = m_apcSlicePilot->getPOC();
952  }
953  m_bFirstSliceInSequence = false;
954  if (m_apcSlicePilot->isNextSlice())
955  {
956    // Skip pictures due to random access
957    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
958    {
959      return false;
960    }
961  }
962  //detect lost reference picture and insert copy of earlier frame.
963#if START_DECODING_AT_CRA
964  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
965#else
966  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
967#endif
968  {
969    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
970  }
971  if (m_bFirstSliceInPicture)
972  {
973    // Buffer initialize for prediction.
974    m_cPrediction.initTempBuff();
975    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
976    //  Get a new picture buffer
977    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
978#if VSP_N
979#if VSP_SLICE_HEADER
980    if( m_apcSlicePilot->getVspFlag() )
981#endif
982    {
983      if( m_pcPicVSP == NULL )
984      {
985        m_pcPicVSP = new TComPic;
986        m_pcPicVSP->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
987        m_pcPicVSP->setCurrSliceIdx(0);
988        m_pcPicVSP->getCurrSlice()->setViewId( NUM_VIEW_VSP );
989        m_pcPicVSP->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
990        m_pcPicVSP->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
991        m_pcPicVSP->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
992        m_pcPicVSP->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
993        m_pcPicVSP->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
994        m_pcPicVSP->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
995        m_pcPicVSP->getPicSym()->xCreateTComTileArray();
996        for (int i=0;i<m_pcPicVSP->getPicSym()->getNumberOfCUsInFrame();i++)
997        {
998          m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
999          m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
1000        }
1001#if DEPTH_MAP_GENERATION
1002        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1003        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1004        if( bNeedPrdDepthMapBuffer )
1005        {
1006          m_pcPicVSP->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1007        }
1008#endif
1009      }
1010      if( m_pcPicAvail == NULL )
1011      {
1012        m_pcPicAvail = new TComPic;
1013        m_pcPicAvail->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1014        m_pcPicAvail->setCurrSliceIdx(0);
1015        m_pcPicAvail->getCurrSlice()->setViewId( 99 );
1016        m_pcPicAvail->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
1017        m_pcPicAvail->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
1018        m_pcPicAvail->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
1019        m_pcPicAvail->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
1020        m_pcPicAvail->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
1021        m_pcPicAvail->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
1022        m_pcPicAvail->getPicSym()->xCreateTComTileArray();
1023        for (int i=0;i<m_pcPicAvail->getPicSym()->getNumberOfCUsInFrame();i++)
1024        {
1025          m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
1026          m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
1027        }
1028#if DEPTH_MAP_GENERATION
1029        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1030        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1031        if( bNeedPrdDepthMapBuffer )
1032        {
1033          m_pcPicAvail->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
1034        }
1035#endif
1036      }
1037    }
1038#endif
1039
1040#if SONY_COLPIC_AVAILABILITY
1041    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
1042#endif
1043
1044    /* transfer any SEI messages that have been received to the picture */
1045    pcPic->setSEIs(m_SEIs);
1046    m_SEIs = NULL;
1047
1048    // Recursive structure
1049    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1050    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1051    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1052
1053    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1054#if DEPTH_MAP_GENERATION
1055    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1056    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) );
1057    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
1058    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
1059    {
1060      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) );
1061    }
1062#endif
1063#if HHI_INTER_VIEW_RESIDUAL_PRED
1064    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
1065#endif
1066#if !QC_MULTI_DIS_CAN
1067#if VSP_N
1068#if VSP_SLICE_HEADER
1069    if( m_apcSlicePilot->getVspFlag() )
1070#endif
1071    {
1072      UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
1073      Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
1074      if( bNeedPrdDepthMapBuffer )
1075      {
1076        if( m_pcPicVSP && m_pcPicVSP->getPredDepthMap() )
1077        {
1078          m_cDepthMapGenerator.clearDepthMap( m_pcPicVSP );
1079        }
1080        if( m_pcPicAvail && m_pcPicAvail->getPredDepthMap() )
1081        {
1082          m_cDepthMapGenerator.clearDepthMap( m_pcPicAvail );
1083        }
1084      }
1085    }
1086#endif
1087#endif
1088  }
1089
1090  //  Set picture slice pointer
1091  TComSlice*  pcSlice = m_apcSlicePilot;
1092  Bool bNextSlice     = pcSlice->isNextSlice();
1093
1094  UInt uiCummulativeTileWidth;
1095  UInt uiCummulativeTileHeight;
1096  UInt i, j, p;
1097
1098#if !REMOVE_TILE_DEPENDENCE
1099  //set the TileBoundaryIndependenceIdr
1100  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
1101  {
1102    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
1103  }
1104  else
1105  {
1106    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
1107  }
1108#endif
1109
1110  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
1111  {
1112    //set NumColumnsMins1 and NumRowsMinus1
1113    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1114    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1115
1116    //create the TComTileArray
1117    pcPic->getPicSym()->xCreateTComTileArray();
1118
1119    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
1120    {
1121      //set the width for each tile
1122      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1123      {
1124        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1125        {
1126          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1127            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1128            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1129        }
1130      }
1131
1132      //set the height for each tile
1133      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1134      {
1135        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1136        {
1137          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1138            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1139            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1140        }
1141      }
1142    }
1143    else
1144    {
1145      //set the width for each tile
1146      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1147      {
1148        uiCummulativeTileWidth = 0;
1149        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1150        {
1151          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1152          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1153        }
1154        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1155      }
1156
1157      //set the height for each tile
1158      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1159      {
1160        uiCummulativeTileHeight = 0;
1161        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1162        { 
1163          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1164          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1165        }
1166        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1167      }
1168    }
1169  }
1170  else
1171  {
1172    //set NumColumnsMins1 and NumRowsMinus1
1173    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
1174    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
1175
1176    //create the TComTileArray
1177    pcPic->getPicSym()->xCreateTComTileArray();
1178
1179    //automatically set the column and row boundary if UniformSpacingIdr = 1
1180    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
1181    {
1182      //set the width for each tile
1183      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1184      {
1185        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1186        {
1187          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1188            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1189            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1190        }
1191      }
1192
1193      //set the height for each tile
1194      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1195      {
1196        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1197        {
1198          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1199            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1200            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1201        }
1202      }
1203    }
1204    else
1205    {
1206      //set the width for each tile
1207      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
1208      {
1209        uiCummulativeTileWidth = 0;
1210        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
1211        {
1212          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
1213          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
1214        }
1215        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1216      }
1217
1218      //set the height for each tile
1219      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
1220      {
1221        uiCummulativeTileHeight = 0;
1222        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
1223        { 
1224          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
1225          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
1226        }
1227        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1228      }
1229    }
1230  }
1231
1232  pcPic->getPicSym()->xInitTiles();
1233
1234  //generate the Coding Order Map and Inverse Coding Order Map
1235  UInt uiEncCUAddr;
1236  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1237  {
1238    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1239    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1240  }
1241  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1242  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1243
1244  //convert the start and end CU addresses of the slice and entropy slice into encoding order
1245  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
1246  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
1247  if(pcSlice->isNextSlice())
1248  {
1249    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1250    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1251  }
1252
1253  if (m_bFirstSliceInPicture) 
1254  {
1255    if(pcPic->getNumAllocatedSlice() != 1)
1256    {
1257      pcPic->clearSliceBuffer();
1258    }
1259  }
1260  else
1261  {
1262    pcPic->allocateNewSlice();
1263  }
1264  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1265  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1266  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1267
1268  pcPic->setTLayer(nalu.m_temporalId);
1269
1270  if (bNextSlice)
1271  {
1272    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
1273
1274    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
1275    {
1276      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
1277    }
1278
1279    // Set reference list
1280#if VIDYO_VPS_INTEGRATION
1281    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
1282    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
1283#else
1284    pcSlice->setViewId(m_viewId);
1285    pcSlice->setIsDepth(m_isDepth);
1286#endif
1287
1288#if SONY_COLPIC_AVAILABILITY
1289#if VIDYO_VPS_INTEGRATION
1290    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );
1291#else
1292    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
1293#endif
1294#endif
1295
1296    assert( m_tAppDecTop != NULL );
1297    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
1298    assert( !m_isDepth || pcTexturePic != NULL );
1299    pcSlice->setTexturePic( pcTexturePic );
1300
1301    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
1302#if VSP_N
1303    Bool bUseVsp = (m_viewId!=0);
1304#if VSP_TEXT_ONLY
1305    if( m_isDepth ) bUseVsp = false;
1306#endif
1307#if VSP_SLICE_HEADER
1308    if( !pcSlice->getVspFlag() ) bUseVsp = false;
1309#endif
1310
1311#if VSP_SLICE_HEADER
1312    if( bUseVsp )
1313#endif
1314      m_pcPicVSP->getCurrSlice()->setPOC( pcPic->getPOC() );
1315
1316    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics, bUseVsp ? m_pcPicVSP : NULL );
1317
1318#else
1319    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
1320#endif
1321
1322    // For generalized B
1323    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1324    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1325    {
1326      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1327      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1328
1329      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1330      {
1331        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1332      }
1333    }
1334    if (pcSlice->isInterB())
1335    {
1336      Bool bLowDelay = true;
1337      Int  iCurrPOC  = pcSlice->getPOC();
1338      Int iRefIdx = 0;
1339
1340      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1341      {
1342        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1343        {
1344          bLowDelay = false;
1345        }
1346      }
1347      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1348      {
1349        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1350        {
1351          bLowDelay = false;
1352        }
1353      }
1354
1355      pcSlice->setCheckLDC(bLowDelay);           
1356    }
1357
1358    //---------------
1359    pcSlice->setRefPOCnViewListsMvc();
1360
1361    if(!pcSlice->getRefPicListModificationFlagLC())
1362    {
1363      pcSlice->generateCombinedList();
1364    }
1365
1366    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
1367    {
1368      pcSlice->setWpParamforLC();
1369    }
1370    pcSlice->setNoBackPredFlag( false );
1371    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
1372    {
1373      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
1374      {
1375        pcSlice->setNoBackPredFlag( true );
1376        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1377        {
1378          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1379          {
1380            pcSlice->setNoBackPredFlag( false );
1381            break;
1382          }
1383        }
1384      }
1385    }
1386  }
1387
1388  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1389  if(pcSlice->getSPS()->getScalingListFlag())
1390  {
1391    if(pcSlice->getAPS()->getScalingListEnabled())
1392    {
1393      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1394      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1395      {
1396        pcSlice->setDefaultScalingList();
1397      }
1398      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1399    }
1400    m_cTrQuant.setUseScalingList(true);
1401  }
1402  else
1403  {
1404    m_cTrQuant.setFlatScalingList();
1405    m_cTrQuant.setUseScalingList(false);
1406  }
1407
1408#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1409  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1410  {
1411    initWedgeLists();
1412  }
1413#endif
1414
1415#if VSP_N
1416  if( m_pcCamParsCollector )
1417  {
1418    m_pcCamParsCollector->setSlice( pcSlice );
1419  }
1420#if VSP_SLICE_HEADER
1421  if( pcSlice->getVspFlag() )
1422#endif
1423  if( getTAppDecTop()->getUseDepth() )
1424  {
1425    getTAppDecTop()->storeVSPInBuffer( m_pcPicVSP, m_pcPicAvail, pcSlice->getViewId(), pcSlice->getSPS()->getViewOrderIdx(), pcSlice->getPOC(), m_isDepth );
1426  }
1427#endif
1428
1429  //  Decode a picture
1430  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1431
1432  if( m_pcCamParsCollector )
1433  {
1434    m_pcCamParsCollector->setSlice( pcSlice );
1435  }
1436
1437  m_bFirstSliceInPicture = false;
1438  m_uiSliceIdx++;
1439
1440  return false;
1441}
1442
1443#if VIDYO_VPS_INTEGRATION
1444Void TDecTop::xDecodeVPS()
1445{
1446  TComVPS* vps = new TComVPS();
1447 
1448  m_cEntropyDecoder.decodeVPS( vps );
1449  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1450  getTAppDecTop()->getVPSAccess()->addVPS( vps );
1451}
1452#endif
1453
1454Void TDecTop::xDecodeSPS()
1455{
1456  TComSPS* sps = new TComSPS();
1457#if RPS_IN_SPS
1458  TComRPSList* rps = new TComRPSList();
1459  sps->setRPSList(rps);
1460#endif
1461#if HHI_MPI
1462  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1463#else
1464  m_cEntropyDecoder.decodeSPS( sps );
1465#endif
1466  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1467#if LCU_SYNTAX_ALF
1468  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1469#endif
1470
1471#if VSP_N
1472  if( !sps->isDepth() && sps->getViewId() == 0 && getTAppDecTop()->getVSPRendererTop() )
1473  {
1474#if NTT_SUBPEL
1475    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 5, 1, 0, 6 );
1476#else
1477    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
1478#endif
1479  }
1480#endif
1481}
1482
1483Void TDecTop::xDecodePPS()
1484{
1485#if !RPS_IN_SPS
1486  TComRPSList* rps = new TComRPSList();
1487#endif
1488  TComPPS* pps = new TComPPS();
1489#if !RPS_IN_SPS
1490  pps->setRPSList(rps);
1491#endif
1492#if TILES_OR_ENTROPY_SYNC_IDC
1493  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1494#else
1495  m_cEntropyDecoder.decodePPS( pps );
1496#endif
1497  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1498
1499  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1500  m_apcSlicePilot->setPPSId(pps->getPPSId());
1501  xActivateParameterSets();
1502  m_apcSlicePilot->initTiles();
1503}
1504
1505Void TDecTop::xDecodeAPS()
1506{
1507  TComAPS  *aps = new TComAPS();
1508  allocAPS (aps);
1509  decodeAPS(aps);
1510  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1511}
1512
1513Void TDecTop::xDecodeSEI()
1514{
1515  m_SEIs = new SEImessages;
1516  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1517}
1518
1519Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1520{
1521  // Initialize entropy decoder
1522  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1523  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1524
1525  switch (nalu.m_nalUnitType)
1526  {
1527#if VIDYO_VPS_INTEGRATION
1528    case NAL_UNIT_VPS:
1529      xDecodeVPS();
1530      return false;
1531#endif
1532    case NAL_UNIT_SPS:
1533      xDecodeSPS();
1534      return false;
1535
1536    case NAL_UNIT_PPS:
1537      xDecodePPS();
1538      return false;
1539    case NAL_UNIT_APS:
1540      xDecodeAPS();
1541      return false;
1542
1543    case NAL_UNIT_SEI:
1544      xDecodeSEI();
1545      return false;
1546
1547    case NAL_UNIT_CODED_SLICE:
1548    case NAL_UNIT_CODED_SLICE_IDR:
1549#if H0566_TLA
1550    case NAL_UNIT_CODED_SLICE_IDV:
1551    case NAL_UNIT_CODED_SLICE_CRA:
1552    case NAL_UNIT_CODED_SLICE_TLA:
1553#else
1554    case NAL_UNIT_CODED_SLICE_CDR:
1555#endif
1556      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1557      break;
1558    default:
1559      assert (1);
1560  }
1561
1562  return false;
1563}
1564
1565/** Function for checking if picture should be skipped because of random access
1566 * \param iSkipFrame skip frame counter
1567 * \param iPOCLastDisplay POC of last picture displayed
1568 * \returns true if the picture shold be skipped in the random access.
1569 * This function checks the skipping of pictures in the case of -s option random access.
1570 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1571 * It also checks the type of Nal unit type at the random access point.
1572 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1573 * If the random access point is IDR all pictures after the random access point are decoded.
1574 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1575 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1576 * access point there is no guarantee that the decoder will not crash.
1577 */
1578Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1579{
1580  if (iSkipFrame) 
1581  {
1582    iSkipFrame--;   // decrement the counter
1583    return true;
1584  }
1585  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1586  {
1587#if H0566_TLA
1588    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1589#else
1590    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
1591#endif
1592    {
1593      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1594    }
1595    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1596    {
1597      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1598    }
1599    else 
1600    {
1601#if START_DECODING_AT_CRA
1602      static bool warningMessage = false;
1603      if(!warningMessage)
1604      {
1605        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1606        warningMessage = true;
1607      }
1608      return true;
1609#else
1610      printf("\nUnsafe random access point. Decoder may crash.");
1611      m_pocRandomAccess = 0;
1612#endif
1613    }
1614  }
1615  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1616  {
1617    iPOCLastDisplay++;
1618    return true;
1619  }
1620  // if we reach here, then the picture is not skipped.
1621  return false; 
1622}
1623
1624Void TDecTop::allocAPS (TComAPS* pAPS)
1625{
1626  // we don't know the SPS before it has been activated. These fields could exist
1627  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1628  // have to be moved for that
1629  pAPS->createScalingList();
1630  pAPS->createSaoParam();
1631  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1632  pAPS->createAlfParam();
1633#if !LCU_SYNTAX_ALF
1634  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
1635#endif
1636}
1637
1638//! \}
Note: See TracBrowser for help on using the repository browser.