source: 3DVCSoftware/branches/HTM-13.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp @ 1172

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

K0050: Camera paramters.

  • Property svn:eol-style set to native
File size: 62.3 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-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if H_MV
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
43#endif
44//! \ingroup TLibDecoder
45//! \{
46
47#if H_3D
48CamParsCollector::CamParsCollector()
49: m_bInitialized( false )
50{
51  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
52  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
53  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
57  }
58
59  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
60  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
61  m_uiBitDepthForLUT = 8; // fixed
62  m_receivedIdc = NULL; 
63  m_vps         = NULL; 
64}
65
66CamParsCollector::~CamParsCollector()
67{
68  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
69  {
70    delete [] m_aaiCodedOffset      [ uiId ];
71    delete [] m_aaiCodedScale       [ uiId ];
72  }
73  delete [] m_aaiCodedOffset;
74  delete [] m_aaiCodedScale;
75
76  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
78#if HHI_CAM_PARA_K0052
79  xDeleteArray( m_receivedIdc, m_vps->getNumViews() );
80#else
81  xDeleteArray( m_receivedIdc, m_uiMaxViewIndex + 1 );
82#endif
83}
84
85
86Void
87CamParsCollector::init( FILE* pCodedScaleOffsetFile, TComVPS* vps)
88{
89  assert( !isInitialized() ); // Only one initialization currently supported
90  m_bInitialized            = true;
91  m_vps                     = vps; 
92  m_bCamParsVaryOverTime    = false; 
93  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
94  m_lastPoc                 = -1;   
95  m_firstReceivedPoc        = -2; 
96
97#if HHI_CAM_PARA_K0052 
98  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
99  {
100    Int curViewIdxInVps = m_vps->getVoiInVps( m_vps->getViewIndex( m_vps->getLayerIdInNuh( i ) ) ) ; 
101    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->getCpInSliceSegmentHeaderFlag( curViewIdxInVps );   
102  }
103
104  assert( m_receivedIdc == NULL ); 
105  m_receivedIdc = new Int*[ m_vps->getNumViews() ]; 
106  for (Int i = 0; i < m_vps->getNumViews(); i++)
107  {
108    m_receivedIdc[i] = new Int[ m_vps->getNumViews() ]; 
109  }
110
111  xResetReceivedIdc( true ); 
112
113  for (Int voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
114  {
115    if( !m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) 
116    {
117      for (Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
118      { 
119        if( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
120        {
121          m_receivedIdc   [ baseVoiInVps ][ voiInVps ] = -1; 
122          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] = m_vps->getCodedScale    (voiInVps) [ baseVoiInVps ];
123          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] = m_vps->getCodedOffset   (voiInVps) [ baseVoiInVps ];
124
125          m_receivedIdc   [ voiInVps ][ baseVoiInVps ] = -1; 
126          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedScale (voiInVps) [ baseVoiInVps ];
127          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedOffset(voiInVps) [ baseVoiInVps ];
128          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
129          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
130        }
131      }
132    }
133  }
134}
135
136#else
137  m_uiMaxViewIndex            = -1; 
138  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
139  {
140    Int curViewIdx = m_vps->getViewIndex( m_vps->getLayerIdInNuh( i )); 
141    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->hasCamParInSliceHeader( curViewIdx );
142    m_uiMaxViewIndex = std::max( m_uiMaxViewIndex, curViewIdx  ) ; 
143  }
144  assert( m_receivedIdc == NULL ); 
145  m_receivedIdc = new Int*[ m_uiMaxViewIndex + 1]; 
146  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
147  {
148    m_receivedIdc[i] = new Int[ m_uiMaxViewIndex + 1 ]; 
149  }
150
151  xResetReceivedIdc( true ); 
152
153  for (Int viewIndex = 0; viewIndex <= m_uiMaxViewIndex ; viewIndex++ )
154  {
155    if (m_vps->getCamParPresent( viewIndex ) )
156    {   
157      if( !m_vps->hasCamParInSliceHeader( viewIndex ) ) 
158      {
159        for (Int baseViewIndex = 0; baseViewIndex < viewIndex ; baseViewIndex++ )
160        { 
161          m_receivedIdc   [ baseViewIndex ][ viewIndex ] = -1; 
162          m_aaiCodedScale [ baseViewIndex ][ viewIndex ] = m_vps->getCodedScale    (viewIndex) [ baseViewIndex ];
163          m_aaiCodedOffset[ baseViewIndex ][ viewIndex ] = m_vps->getCodedOffset   (viewIndex) [ baseViewIndex ];
164
165          m_receivedIdc   [ viewIndex ][ baseViewIndex ] = -1; 
166          m_aaiCodedScale [ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedScale (viewIndex) [ baseViewIndex ];
167          m_aaiCodedOffset[ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedOffset(viewIndex) [ baseViewIndex ];
168          xInitLUTs( baseViewIndex, viewIndex, m_aaiCodedScale[ baseViewIndex ][ viewIndex ], m_aaiCodedOffset[ baseViewIndex ][ viewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
169          xInitLUTs( viewIndex, baseViewIndex, m_aaiCodedScale[ viewIndex ][ baseViewIndex ], m_aaiCodedOffset[ viewIndex ][ baseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
170        }
171      }
172    }
173  }
174}
175
176#endif
177
178
179
180Void
181CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
182{
183#if HHI_CAM_PARA_K0052
184  for (Int i = 0; i < m_vps->getNumViews(); i++)
185  { 
186    for (Int j = 0; j < m_vps->getNumViews(); j++)
187    {
188#else
189  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
190  { 
191    for (Int j = 0; j <= m_uiMaxViewIndex; j++)
192    {
193#endif
194      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
195      {
196        m_receivedIdc[i][j] = 0; 
197      }     
198    }
199  }
200}
201
202
203Void
204CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
205{
206
207  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
208  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
209
210  radLUT         = new Double***[ uiNumberSourceViews ];
211  raiLUT         = new Int   ***[ uiNumberSourceViews ];
212
213  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
214  {
215    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
216    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
217
218    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
219    {
220      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
221      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
222      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
223
224      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
225      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
226      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
227    }
228  }
229}
230
231Void
232  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
233{
234#if HHI_CAM_PARA_K0052
235  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCpPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
236#else
237  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCamParPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
238#endif
239  Int     iLog2DivChroma = iLog2DivLuma + 1;
240
241  iOffset <<= m_uiBitDepthForLUT;
242
243  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
244  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
245
246  // offsets including rounding offsets
247  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
248  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
249
250
251  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
252  {
253
254    // real-valued look-up tables
255    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
256    Double  dShiftChroma    = dShiftLuma / 2;
257    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
258    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
259
260    // integer-valued look-up tables
261    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
262    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
263    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
264    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
265    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
266  }
267
268  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
269  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
270  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
271  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
272}
273
274Void
275CamParsCollector::uninit()
276{
277  m_bInitialized = false;
278}
279
280Void
281CamParsCollector::setSlice( TComSlice* pcSlice )
282{
283  if( pcSlice == 0 )
284  {
285    xOutput( m_lastPoc );
286    return;
287  }
288
289#if !H_3D_FCO
290  if ( pcSlice->getIsDepth())
291  {
292    return;
293  }
294#endif
295
296  Int curPoc = pcSlice->getPOC();
297  if( m_firstReceivedPoc == -2 )
298  {
299    m_firstReceivedPoc = curPoc; 
300  }
301
302  Bool newPocFlag = ( m_lastPoc != curPoc ); 
303
304  if ( newPocFlag )
305  {   
306    if( m_lastPoc != -1 )
307    {
308      xOutput( m_lastPoc );
309    }
310
311    xResetReceivedIdc( false ); 
312    m_lastPoc = pcSlice->getPOC();
313  }
314
315#if HHI_CAM_PARA_K0052
316  UInt voiInVps          = m_vps->getVoiInVps(pcSlice->getViewIndex()); 
317  if( m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) // check consistency of slice parameters here
318  {   
319    for( Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
320    {       
321      if ( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
322      {
323        if ( m_receivedIdc[ voiInVps ][ baseVoiInVps ] != 0 )
324        {     
325          AOF( m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedScale () [ baseVoiInVps ] );
326          AOF( m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedOffset() [ baseVoiInVps ] );
327        }
328        else
329        {         
330          m_receivedIdc   [ voiInVps ][ baseVoiInVps ]  = 1; 
331          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedScale () [ baseVoiInVps ];
332          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedOffset() [ baseVoiInVps ];
333          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
334        }
335        if ( m_receivedIdc[ baseVoiInVps ][ voiInVps ] != 0 )
336        {     
337          AOF( m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedScale    () [ baseVoiInVps ] );
338          AOF( m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedOffset   () [ baseVoiInVps ] );
339        }
340        else
341        {       
342          m_receivedIdc   [ baseVoiInVps ][ voiInVps ]  = 1; 
343          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedScale    () [ baseVoiInVps ];
344          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedOffset   () [ baseVoiInVps ];
345          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
346        }
347      }
348    }
349  } 
350#else
351  UInt uiViewIndex          = pcSlice->getViewIndex(); 
352  if( m_vps->getCamParPresent( uiViewIndex ) )
353  {   
354    if( m_vps->hasCamParInSliceHeader( uiViewIndex ) ) // check consistency of slice parameters here
355    {   
356      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
357      {       
358        if ( m_receivedIdc[ uiViewIndex ][ uiBaseViewIndex ] != 0 )
359        {     
360          AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
361          AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
362        }
363        else
364        {         
365          m_receivedIdc   [ uiViewIndex ][ uiBaseViewIndex ]  = 1; 
366          m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedScale () [ uiBaseViewIndex ];
367          m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseViewIndex ];
368          xInitLUTs( uiViewIndex, uiBaseViewIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseViewIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
369        }
370        if ( m_receivedIdc[ uiBaseViewIndex ][ uiViewIndex ] != 0 )
371        {     
372          AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
373          AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
374        }
375        else
376        {       
377          m_receivedIdc   [ uiBaseViewIndex ][ uiViewIndex ]  = 1; 
378          m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseViewIndex ];
379          m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseViewIndex ];
380          xInitLUTs( uiBaseViewIndex, uiViewIndex, m_aaiCodedScale[ uiBaseViewIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
381        }
382      }
383    }
384  }
385#endif
386
387
388}
389
390
391#if H_3D_IV_MERGE
392Void
393CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
394{
395  if( m_bCamParsVaryOverTime )
396  {
397    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
398  }
399}
400#endif
401
402
403Void
404CamParsCollector::xOutput( Int iPOC )
405{
406  if( m_pCodedScaleOffsetFile )
407  {
408    if( iPOC == m_firstReceivedPoc )
409    {
410#if HHI_CAM_PARA_K0052
411      fprintf( m_pCodedScaleOffsetFile, "#ViewOrderIdx     ViewIdVal\n" );
412      fprintf( m_pCodedScaleOffsetFile, "#------------ -------------\n" );
413     
414      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
415      {
416        fprintf( m_pCodedScaleOffsetFile, "%13d %13d\n", m_vps->getViewOIdxList( voiInVps ), m_vps->getViewIdVal( m_vps->getViewOIdxList( voiInVps ) ) );
417      }
418      fprintf( m_pCodedScaleOffsetFile, "\n\n");
419      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame    TargetVOI      BaseVOI   CodedScale  CodedOffset    Precision\n" );
420      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
421    }
422    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
423    {
424      Int iS = iPOC;
425      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
426      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
427      {
428        for( UInt baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
429        {
430          if( voiInVps != baseVoiInVps )
431          {
432            if ( m_receivedIdc[baseVoiInVps][voiInVps] != 0 )
433            {           
434              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
435                iS, iE, m_vps->getViewOIdxList( voiInVps ), m_vps->getViewOIdxList( baseVoiInVps ), 
436                m_aaiCodedScale [ baseVoiInVps ][ voiInVps ], 
437                m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_vps->getCpPrecision() );
438#else
439      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
440      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
441      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
442      {
443        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_vps->getViewIdVal( uiViewIndex ) );
444      }
445      fprintf( m_pCodedScaleOffsetFile, "\n\n");
446      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
447      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
448    }
449    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
450    {
451      Int iS = iPOC;
452      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
453#if HHI_CAM_PARA_K0052
454      for( UInt uiViewIndex = 0; uiViewIndex < m_vps->getNumViews(); uiViewIndex++ )
455      {
456        for( UInt uiBaseIndex = 0; uiBaseIndex < m_vps->getNumViews(); uiBaseIndex++ )
457#else
458      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
459      {
460        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
461#endif
462        {
463          if( uiViewIndex != uiBaseIndex )
464          {
465            if ( m_receivedIdc[uiBaseIndex][uiViewIndex] != 0 )
466            {           
467#if HHI_CAM_PARA_K0052
468              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
469                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCpPrecision() );
470#else
471              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
472                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCamParPrecision() );
473#endif
474#endif
475            }           
476          }
477        }
478      }
479    }
480  }
481}
482#endif
483TDecTop::TDecTop()
484{
485  m_pcPic = 0;
486  m_iMaxRefPicNum = 0;
487#if ENC_DEC_TRACE
488#if H_MV
489  if ( g_hTrace == NULL )
490  {
491#endif
492  g_hTrace = fopen( "TraceDec.txt", "wb" );
493  g_bJustDoIt = g_bEncDecTraceDisable;
494  g_nSymbolCounter = 0;
495#if H_MV
496  }
497#endif
498#endif
499  m_associatedIRAPType = NAL_UNIT_INVALID;
500  m_pocCRA = 0;
501  m_pocRandomAccess = MAX_INT; 
502  m_prevPOC                = MAX_INT;
503  m_bFirstSliceInPicture    = true;
504  m_bFirstSliceInSequence   = true;
505  m_prevSliceSkipped = false;
506  m_skippedPOC = 0;
507#if SETTING_NO_OUT_PIC_PRIOR
508  m_bFirstSliceInBitstream  = true;
509  m_lastPOCNoOutputPriorPics = -1;
510  m_craNoRaslOutputFlag = false;
511  m_isNoOutputPriorPics = false;
512#endif
513#if H_MV
514  m_isLastNALWasEos = false;
515  m_layerId = 0;
516  m_viewId = 0;
517#if H_3D
518  m_viewIndex = 0; 
519  m_isDepth = false;
520  m_pcCamParsCollector = 0;
521#endif
522#if H_MV
523  m_targetOptLayerSetIdx = -1; 
524#endif
525#endif
526}
527
528TDecTop::~TDecTop()
529{
530#if ENC_DEC_TRACE
531  fclose( g_hTrace );
532#endif
533}
534
535Void TDecTop::create()
536{
537  m_cGopDecoder.create();
538  m_apcSlicePilot = new TComSlice;
539  m_uiSliceIdx = 0;
540}
541
542Void TDecTop::destroy()
543{
544  m_cGopDecoder.destroy();
545 
546  delete m_apcSlicePilot;
547  m_apcSlicePilot = NULL;
548 
549  m_cSliceDecoder.destroy();
550}
551
552Void TDecTop::init()
553{
554  // initialize ROM
555#if !H_MV
556  initROM();
557#endif
558#if H_3D_ANNEX_SELECTION_FIX
559  m_cCavlcDecoder.setDecTop( this ); 
560#endif
561  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
562  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
563  m_cEntropyDecoder.init(&m_cPrediction);
564}
565
566Void TDecTop::deletePicBuffer ( )
567{
568  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
569  Int iSize = Int( m_cListPic.size() );
570 
571  for (Int i = 0; i < iSize; i++ )
572  {
573    TComPic* pcPic = *(iterPic++);
574#if H_MV
575    if( pcPic )
576    {
577#endif
578    pcPic->destroy();
579   
580    delete pcPic;
581    pcPic = NULL;
582#if H_MV
583    }
584#endif
585  }
586 
587  m_cSAO.destroy();
588 
589  m_cLoopFilter.        destroy();
590 
591#if !H_MV
592  // destroy ROM
593  destroyROM();
594#endif
595}
596
597Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
598{
599  Int  numReorderPics[MAX_TLAYER];
600  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
601  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
602
603#if H_MV
604    assert( conformanceWindow   .getScaledFlag() ); 
605    assert( defaultDisplayWindow.getScaledFlag() );
606#endif
607  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
608  {
609#if H_MV
610    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
611#else
612    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
613#endif
614  }
615#if H_MV
616  if ( getLayerId() == 0 )
617  { 
618    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
619  }
620  else
621  {
622    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
623#if H_MV_HLS7_GEN
624    TComVPS* vps         = pcSlice->getVPS();
625    TComDpbSize* dpbSize = vps->getDpbSize(); 
626    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
627    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
628    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
629    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
630#endif   
631  }
632#else
633  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
634#endif
635  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
636  {
637    rpcPic = new TComPic();
638   
639    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
640                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
641    m_cListPic.pushBack( rpcPic );
642   
643    return;
644  }
645 
646  Bool bBufferIsAvailable = false;
647  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
648  while (iterPic != m_cListPic.end())
649  {
650    rpcPic = *(iterPic++);
651    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
652    {
653      rpcPic->setOutputMark(false);
654#if H_MV
655      rpcPic->setPicOutputFlag(false); 
656#endif
657      bBufferIsAvailable = true;
658      break;
659    }
660
661    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
662    {
663      rpcPic->setOutputMark(false);
664#if H_MV
665      rpcPic->setPicOutputFlag(false); 
666#endif
667      rpcPic->setReconMark( false );
668      rpcPic->getPicYuvRec()->setBorderExtension( false );
669      bBufferIsAvailable = true;
670      break;
671    }
672  }
673 
674  if ( !bBufferIsAvailable )
675  {
676    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
677    m_iMaxRefPicNum++;
678    rpcPic = new TComPic();
679    m_cListPic.pushBack( rpcPic );
680  }
681  rpcPic->destroy();
682  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
683                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
684}
685
686#if H_MV
687Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
688#else
689Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
690#endif
691{
692  if (!m_pcPic)
693  {
694    /* nothing to deblock */
695    return;
696  }
697 
698  TComPic*&   pcPic         = m_pcPic;
699
700  // Execute Deblock + Cleanup
701
702  m_cGopDecoder.filterPicture(pcPic);
703
704  TComSlice::sortPicList( m_cListPic ); // sorting for application output
705  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
706  rpcListPic          = &m_cListPic; 
707  m_cCuDecoder.destroy();       
708#if H_MV
709  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
710  TComSlice::markCurrPic( pcPic ); 
711#endif
712  m_bFirstSliceInPicture  = true;
713
714  return;
715}
716
717#if SETTING_NO_OUT_PIC_PRIOR
718Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
719{
720  if (!rpcListPic || !m_isNoOutputPriorPics) return;
721
722  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
723
724  while (iterPic != rpcListPic->end())
725  {
726    TComPic*& pcPicTmp = *(iterPic++);
727    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
728    {
729      pcPicTmp->setOutputMark(false);
730#if H_MV
731      pcPicTmp->setPicOutputFlag(false); 
732#endif
733    }
734  }
735}
736#endif
737
738Void TDecTop::xCreateLostPicture(Int iLostPoc) 
739{
740  printf("\ninserting lost poc : %d\n",iLostPoc);
741  TComSlice cFillSlice;
742  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
743  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
744  cFillSlice.initSlice();
745  TComPic *cFillPic;
746  xGetNewPicBuffer(&cFillSlice,cFillPic);
747  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
748  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
749  cFillPic->getSlice(0)->initSlice();
750 
751  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
752  Int closestPoc = 1000000;
753  while ( iterPic != m_cListPic.end())
754  {
755    TComPic * rpcPic = *(iterPic++);
756    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())
757    {
758      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
759    }
760  }
761  iterPic = m_cListPic.begin();
762  while ( iterPic != m_cListPic.end())
763  {
764    TComPic *rpcPic = *(iterPic++);
765    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
766    {
767      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
768      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
769      break;
770    }
771  }
772  cFillPic->setCurrSliceIdx(0);
773  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
774  {
775    cFillPic->getCU(i)->initCU(cFillPic,i);
776  }
777  cFillPic->getSlice(0)->setReferenced(true);
778  cFillPic->getSlice(0)->setPOC(iLostPoc);
779  cFillPic->setReconMark(true);
780  cFillPic->setOutputMark(true);
781  if(m_pocRandomAccess == MAX_INT)
782  {
783    m_pocRandomAccess = iLostPoc;
784  }
785}
786
787
788Void TDecTop::xActivateParameterSets()
789{
790  m_parameterSetManagerDecoder.applyPrefetchedPS();
791 
792  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
793  assert (pps != 0);
794
795  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
796  assert (sps != 0);
797
798#if H_MV
799  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
800  assert (vps != 0); 
801  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
802#else
803  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
804#endif
805  {
806    printf ("Parameter set activation failed!");
807    assert (0);
808  }
809
810#if H_MV
811  sps->inferSpsMaxDecPicBufferingMinus1( vps, m_targetOptLayerSetIdx, getLayerId(), false ); 
812  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
813  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
814  {
815    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
816    assert( sps->getUpdateRepFormatFlag() == false ); 
817  }
818  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
819
820  if( sps->getLayerId() != 0 )
821  {
822    sps->inferSpsMaxSubLayersMinus1( true, vps ); 
823  }
824
825  // It is a requirement of bitstream conformance that, when the SPS is referred to by
826  // any current picture that belongs to an independent non-base layer, the value of
827  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
828
829  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
830  { 
831    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
832  }
833
834  if( sps->getMultiLayerExtSpsFlag() )
835  {
836    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
837  }
838#endif
839
840  if( pps->getDependentSliceSegmentsEnabledFlag() )
841  {
842    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
843
844    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
845    {
846      m_cSliceDecoder.initCtxMem(NumCtx);
847      for ( UInt st = 0; st < NumCtx; st++ )
848      {
849        TDecSbac* ctx = NULL;
850        ctx = new TDecSbac;
851        ctx->init( &m_cBinCABAC );
852        m_cSliceDecoder.setCtxMem( ctx, st );
853      }
854    }
855  }
856
857  m_apcSlicePilot->setPPS(pps);
858  m_apcSlicePilot->setSPS(sps);
859#if H_MV
860  m_apcSlicePilot->setVPS(vps); 
861  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
862  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );   
863  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
864  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
865  sps->inferRepFormat  ( vps , m_layerId ); 
866  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
867
868#endif
869#if H_3D
870#if !HHI_INTER_COMP_PRED_K0052
871  m_apcSlicePilot->init3dToolParameters();
872#endif
873#endif
874  pps->setSPS(sps);
875  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
876  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
877
878  g_bitDepthY     = sps->getBitDepthY();
879  g_bitDepthC     = sps->getBitDepthC();
880  g_uiMaxCUWidth  = sps->getMaxCUWidth();
881  g_uiMaxCUHeight = sps->getMaxCUHeight();
882  g_uiMaxCUDepth  = sps->getMaxCUDepth();
883  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
884
885  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
886  {
887    sps->setAMPAcc( i, sps->getUseAMP() );
888  }
889
890  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
891  {
892    sps->setAMPAcc( i, 0 );
893  }
894
895  m_cSAO.destroy();
896  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
897  m_cLoopFilter.create( sps->getMaxCUDepth() );
898}
899
900#if H_MV
901Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
902{
903  assert( nalu.m_layerId == m_layerId ); 
904#else
905Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
906{
907#endif
908  TComPic*&   pcPic         = m_pcPic;
909  m_apcSlicePilot->initSlice();
910
911  if (m_bFirstSliceInPicture)
912  {
913    m_uiSliceIdx     = 0;
914  }
915  else
916  {
917    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
918  }
919  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
920
921  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
922  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
923                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
924                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
925                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
926                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
927  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
928 
929  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
930  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
931
932#if H_MV
933  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
934  m_apcSlicePilot->setLayerId( nalu.m_layerId );
935  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
936#else
937  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
938#endif
939  // set POC for dependent slices in skipped pictures
940  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
941  {
942    m_apcSlicePilot->setPOC(m_skippedPOC);
943  }
944
945  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
946  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
947
948#if H_MV 
949  TComVPS* vps     = m_apcSlicePilot->getVPS();
950  Int layerId  = nalu.m_layerId;   
951  setViewId   ( vps->getViewId   ( layerId )      ); 
952#if H_3D
953  setViewIndex( vps->getViewIndex( layerId )      ); 
954  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
955  m_ivPicLists->setVPS( vps ); 
956#endif
957#endif
958
959#if SETTING_NO_OUT_PIC_PRIOR
960  //For inference of NoOutputOfPriorPicsFlag
961  if (m_apcSlicePilot->getRapPicFlag())
962  {
963    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
964        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
965        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
966    {
967      m_apcSlicePilot->setNoRaslOutputFlag(true);
968    }
969    //the inference for NoOutputPriorPicsFlag
970    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
971    {
972      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
973      {
974        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
975      }
976    }
977    else
978    {
979      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
980    }
981
982    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
983    {
984      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
985    }
986  }
987  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
988  {
989    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
990    m_isNoOutputPriorPics = true;
991  }
992  else
993  {
994    m_isNoOutputPriorPics = false;
995  }
996
997  //For inference of PicOutputFlag
998  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
999  {
1000    if ( m_craNoRaslOutputFlag )
1001    {
1002      m_apcSlicePilot->setPicOutputFlag(false);
1003    }
1004  }
1005#endif
1006
1007#if FIX_POC_CRA_NORASL_OUTPUT
1008  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
1009  {
1010    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1011    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
1012  }
1013#endif
1014#if H_MV
1015    xCeckNoClrasOutput();
1016#endif
1017    // Skip pictures due to random access
1018    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
1019    {
1020    m_prevSliceSkipped = true;
1021    m_skippedPOC = m_apcSlicePilot->getPOC();
1022#if H_MV
1023    sliceSkippedFlag = true; 
1024#endif
1025      return false;
1026    }
1027    // Skip TFD pictures associated with BLA/BLANT pictures
1028    if (isSkipPictureForBLA(iPOCLastDisplay))
1029    {
1030    m_prevSliceSkipped = true;
1031    m_skippedPOC = m_apcSlicePilot->getPOC();
1032#if H_MV
1033    sliceSkippedFlag = true; 
1034#endif
1035      return false;
1036    }
1037
1038  // clear previous slice skipped flag
1039  m_prevSliceSkipped = false;
1040
1041  //we should only get a different poc for a new picture (with CTU address==0)
1042  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
1043  {
1044    printf ("Warning, the first slice of a picture might have been lost!\n");
1045  }
1046  // exit when a new picture is found
1047  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
1048  {
1049    if (m_prevPOC >= m_pocRandomAccess)
1050    {
1051      m_prevPOC = m_apcSlicePilot->getPOC();
1052      return true;
1053    }
1054    m_prevPOC = m_apcSlicePilot->getPOC();
1055  }
1056#if H_MV
1057  if ( newLayerFlag )
1058  {
1059    return false; 
1060  }
1061#if ENC_DEC_TRACE
1062#if H_MV_ENC_DEC_TRAC
1063  // parse remainder of SH
1064   g_disableHLSTrace = false; 
1065#endif
1066#endif
1067#endif
1068  // actual decoding starts here
1069#if H_MV
1070   // This part needs further testing !
1071   if ( m_apcSlicePilot->getPocResetFlag() )
1072   {   
1073     xResetPocInPicBuffer();
1074   }
1075
1076   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1077  {
1078    //update all pics in the DPB such that they cannot be used for TMPV ref
1079    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1080    while( iterRefPic != m_cListPic.end() )
1081    {
1082      TComPic *refPic = *iterRefPic;
1083      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1084      {
1085        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1086        {
1087
1088          TComSlice *refSlice = refPic->getSlice(i);
1089          refSlice->setAvailableForTMVPRefFlag( false );
1090        }
1091      }
1092      iterRefPic++;
1093    }
1094  }
1095  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1096#endif
1097
1098  xActivateParameterSets();
1099
1100#if SONY_MV_V_CONST_C0078
1101  //Check Multiview Main profile constraint in G.11.1.1
1102  //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1
1103  //  for the layer with nuh_layer_id equal to i in subBitstream,
1104  //  inter_view_mv_vert_constraint_flag shall be equal to 1
1105  //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
1106  if( m_apcSlicePilot->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
1107      &&
1108      m_apcSlicePilot->getVPS()->getViewOrderIdx(m_apcSlicePilot->getVPS()->getLayerIdInNuh(getLayerId()))==1 
1109     )
1110  {
1111    assert( m_apcSlicePilot->getSPS()->getInterViewMvVertConstraintFlag()==1 );
1112  }
1113#endif
1114
1115  if (m_apcSlicePilot->isNextSlice()) 
1116  {
1117    m_prevPOC = m_apcSlicePilot->getPOC();
1118  }
1119  m_bFirstSliceInSequence = false;
1120#if SETTING_NO_OUT_PIC_PRIOR 
1121  m_bFirstSliceInBitstream  = false;
1122#endif
1123  //detect lost reference picture and insert copy of earlier frame.
1124  Int lostPoc;
1125  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1126  {
1127    xCreateLostPicture(lostPoc-1);
1128  }
1129  if (m_bFirstSliceInPicture)
1130  {
1131    // Buffer initialize for prediction.
1132    m_cPrediction.initTempBuff();
1133    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1134#if H_MV
1135    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
1136#endif
1137    //  Get a new picture buffer
1138    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1139
1140    Bool isField = false;
1141    Bool isTff = false;
1142   
1143    if(!m_SEIs.empty())
1144    {
1145      // Check if any new Picture Timing SEI has arrived
1146      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1147      if (pictureTimingSEIs.size()>0)
1148      {
1149        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
1150        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
1151        isTff =  (pictureTiming->m_picStruct == 1);
1152      }
1153    }
1154   
1155    //Set Field/Frame coding mode
1156    m_pcPic->setField(isField);
1157    m_pcPic->setTopField(isTff);
1158   
1159    // transfer any SEI messages that have been received to the picture
1160    pcPic->setSEIs(m_SEIs);
1161    m_SEIs.clear();
1162
1163    // Recursive structure
1164    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1165    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1166    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1167
1168    m_cSliceDecoder.create();
1169  }
1170  else
1171  {
1172    // Check if any new SEI has arrived
1173    if(!m_SEIs.empty())
1174    {
1175      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
1176      SEIMessages &picSEI = pcPic->getSEIs();
1177      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1178      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1179      deleteSEIs(m_SEIs);
1180    }
1181  }
1182 
1183  //  Set picture slice pointer
1184  TComSlice*  pcSlice = m_apcSlicePilot;
1185  Bool bNextSlice     = pcSlice->isNextSlice();
1186
1187  UInt i;
1188  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
1189
1190  //generate the Coding Order Map and Inverse Coding Order Map
1191  UInt uiEncCUAddr;
1192  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1193  {
1194    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1195    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1196  }
1197  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1198  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1199
1200  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1201  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1202  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1203  if(pcSlice->isNextSlice())
1204  {
1205    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1206    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1207  }
1208
1209  if (m_bFirstSliceInPicture) 
1210  {
1211    if(pcPic->getNumAllocatedSlice() != 1)
1212    {
1213      pcPic->clearSliceBuffer();
1214    }
1215  }
1216  else
1217  {
1218    pcPic->allocateNewSlice();
1219  }
1220  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1221  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1222  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1223
1224  pcPic->setTLayer(nalu.m_temporalId);
1225
1226#if H_MV
1227  pcPic->setLayerId( nalu.m_layerId );
1228  pcPic->setViewId ( getViewId() );
1229#if H_3D
1230  pcPic->setViewIndex( getViewIndex() );
1231  pcPic->setIsDepth  ( getIsDepth  () );
1232#endif
1233#endif
1234#if HHI_RES_PRED_K0052
1235  pcSlice->setIvPicLists( m_ivPicLists );         
1236#endif
1237
1238  if (bNextSlice)
1239  {
1240    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1241    // Set reference list
1242#if H_MV   
1243    std::vector< TComPic* > tempRefPicLists[2];
1244    std::vector< Bool     > usedAsLongTerm [2];
1245    Int       numPocTotalCurr;
1246
1247    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1248    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
1249#if H_3D
1250    pcSlice->setDefaultRefView();
1251#endif
1252#if H_3D_ARP
1253    pcSlice->setARPStepNum(m_ivPicLists);
1254    if( pcSlice->getARPStepNum() > 1 )
1255    {
1256      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
1257      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
1258      {
1259        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1260        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1261        if( iViewIdx<getViewIndex() && !bIsDepth )
1262        {
1263          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1264        }
1265      }
1266    }
1267#endif
1268#else
1269    pcSlice->setRefPicList( m_cListPic, true );
1270#endif
1271
1272#if H_3D
1273#if !HHI_RES_PRED_K0052
1274    pcSlice->setIvPicLists( m_ivPicLists );         
1275#endif
1276
1277#if HHI_INTER_COMP_PRED_K0052
1278    pcSlice->checkInCompPredRefLayers(); 
1279#if H_3D_IV_MERGE
1280#if H_3D_FCO
1281    //assert( !getIsDepth() );
1282#else
1283    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1284#endif
1285#endif   
1286#else
1287#if H_3D_IV_MERGE
1288#if H_3D_FCO
1289    //assert( !getIsDepth() );
1290#else
1291    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1292#endif
1293#endif   
1294#endif
1295#endif
1296#if H_MV
1297    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1298    {
1299      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1300
1301      assert ( refPic );
1302      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
1303    }
1304#endif
1305
1306    // For generalized B
1307    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1308    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1309    {
1310      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1311      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1312
1313      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1314      {
1315        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1316      }
1317    }
1318    if (!pcSlice->isIntra())
1319    {
1320      Bool bLowDelay = true;
1321      Int  iCurrPOC  = pcSlice->getPOC();
1322      Int iRefIdx = 0;
1323
1324      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1325      {
1326        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1327        {
1328          bLowDelay = false;
1329        }
1330      }
1331      if (pcSlice->isInterB())
1332      {
1333        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1334        {
1335          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1336          {
1337            bLowDelay = false;
1338          }
1339        }       
1340      }
1341
1342      pcSlice->setCheckLDC(bLowDelay);           
1343    }
1344
1345    //---------------
1346    pcSlice->setRefPOCList();
1347#if  H_3D_TMVP
1348    if(pcSlice->getLayerId())
1349      pcSlice->generateAlterRefforTMVP();
1350#endif
1351  }
1352
1353  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1354  if(pcSlice->getSPS()->getScalingListFlag())
1355  {
1356    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1357    if(pcSlice->getPPS()->getScalingListPresentFlag())
1358    {
1359      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1360    }
1361    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1362    {
1363      pcSlice->setDefaultScalingList();
1364    }
1365    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1366    m_cTrQuant.setUseScalingList(true);
1367  }
1368  else
1369  {
1370    m_cTrQuant.setFlatScalingList();
1371    m_cTrQuant.setUseScalingList(false);
1372  }
1373
1374#if H_3D_IV_MERGE
1375#if H_3D_FCO
1376  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1377#else
1378  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1379#endif
1380  {
1381    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1382  }
1383#endif
1384
1385  //  Decode a picture
1386  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1387#if H_3D
1388  if( m_pcCamParsCollector )
1389  {
1390    m_pcCamParsCollector->setSlice( pcSlice );
1391  }
1392#endif
1393  m_bFirstSliceInPicture = false;
1394  m_uiSliceIdx++;
1395
1396  return false;
1397}
1398
1399Void TDecTop::xDecodeVPS()
1400{
1401  TComVPS* vps = new TComVPS();
1402 
1403  m_cEntropyDecoder.decodeVPS( vps );
1404  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1405}
1406
1407Void TDecTop::xDecodeSPS()
1408{
1409  TComSPS* sps = new TComSPS();
1410#if H_MV
1411  sps->setLayerId( getLayerId() ); 
1412#endif
1413#if H_3D
1414  // Preliminary fix. assuming that all sps refer to the same VPS.
1415  // Parsing dependency should be resolved!
1416  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1417  assert( vps != 0 );
1418  m_cEntropyDecoder.decodeSPS( sps );
1419#else
1420  m_cEntropyDecoder.decodeSPS( sps );
1421#endif
1422  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1423}
1424
1425Void TDecTop::xDecodePPS()
1426{
1427  TComPPS* pps = new TComPPS();
1428#if H_MV
1429  pps->setLayerId( getLayerId() ); 
1430#endif
1431#if H_3D
1432  // Assuming that all PPS indirectly refer to the same VPS via different SPS
1433  // There is no parsing dependency in decoding DLT in PPS.
1434  // The VPS information passed to decodePPS() is used to arrange the decoded DLT tables to their corresponding layers.
1435  // This is equivalent to the process of
1436  //   Step 1) decoding DLT tables based on the number of depth layers, and
1437  //   Step 2) mapping DLT tables to the depth layers
1438  // as described in the 3D-HEVC WD.
1439  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
1440  m_cEntropyDecoder.decodePPS( pps, vps );
1441#else
1442  m_cEntropyDecoder.decodePPS( pps );
1443#endif
1444  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1445}
1446
1447Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1448{
1449  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1450  {
1451#if H_MV
1452    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1453#else
1454    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1455#endif
1456  }
1457  else
1458  {
1459#if H_MV
1460    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1461#else
1462    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1463#endif
1464    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1465    if (activeParamSets.size()>0)
1466    {
1467      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1468      m_parameterSetManagerDecoder.applyPrefetchedPS();
1469      assert(seiAps->activeSeqParameterSetId.size()>0);
1470#if H_MV
1471      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
1472#else
1473      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
1474#endif
1475      {
1476        printf ("Warning SPS activation with Active parameter set SEI failed");
1477      }
1478    }
1479  }
1480}
1481
1482#if H_MV
1483Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1484#else
1485Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1486#endif
1487{
1488  // Initialize entropy decoder
1489  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1490  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1491
1492  switch (nalu.m_nalUnitType)
1493  {
1494    case NAL_UNIT_VPS:
1495      xDecodeVPS();
1496#if H_MV
1497      m_isLastNALWasEos = false;
1498#endif
1499      return false;
1500     
1501    case NAL_UNIT_SPS:
1502      xDecodeSPS();
1503      return false;
1504
1505    case NAL_UNIT_PPS:
1506      xDecodePPS();
1507      return false;
1508     
1509    case NAL_UNIT_PREFIX_SEI:
1510    case NAL_UNIT_SUFFIX_SEI:
1511#if H_MV
1512      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1513      {
1514        assert( m_isLastNALWasEos == false );
1515      }
1516#endif
1517      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1518      return false;
1519
1520    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1521    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1522    case NAL_UNIT_CODED_SLICE_TSA_R:
1523    case NAL_UNIT_CODED_SLICE_TSA_N:
1524    case NAL_UNIT_CODED_SLICE_STSA_R:
1525    case NAL_UNIT_CODED_SLICE_STSA_N:
1526    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1527    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1528    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1529    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1530    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1531    case NAL_UNIT_CODED_SLICE_CRA:
1532    case NAL_UNIT_CODED_SLICE_RADL_N:
1533    case NAL_UNIT_CODED_SLICE_RADL_R:
1534    case NAL_UNIT_CODED_SLICE_RASL_N:
1535    case NAL_UNIT_CODED_SLICE_RASL_R:
1536#if H_MV
1537      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1538          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1539          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1540          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1541          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1542      {
1543        assert( m_isLastNALWasEos == false );
1544      }
1545      else
1546      {
1547        m_isLastNALWasEos = false;
1548      }
1549
1550      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1551#else
1552      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1553#endif
1554      break;
1555    case NAL_UNIT_EOS:
1556#if H_MV
1557      assert( m_isLastNALWasEos == false );
1558      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1559      if (nalu.m_layerId > 0)
1560      {
1561        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1562        return false;
1563      }
1564      m_isLastNALWasEos = true;
1565#endif
1566      m_associatedIRAPType = NAL_UNIT_INVALID;
1567      m_pocCRA = 0;
1568      m_pocRandomAccess = MAX_INT;
1569      m_prevPOC = MAX_INT;
1570      m_bFirstSliceInPicture = true;
1571      m_bFirstSliceInSequence = true;
1572      m_prevSliceSkipped = false;
1573      m_skippedPOC = 0;
1574      return false;
1575     
1576    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1577      // TODO: process AU delimiter
1578      return false;
1579     
1580    case NAL_UNIT_EOB:
1581      return false;
1582     
1583    case NAL_UNIT_FILLER_DATA:
1584#if H_MV
1585      assert( m_isLastNALWasEos == false );
1586#endif
1587      return false;
1588     
1589    case NAL_UNIT_RESERVED_VCL_N10:
1590    case NAL_UNIT_RESERVED_VCL_R11:
1591    case NAL_UNIT_RESERVED_VCL_N12:
1592    case NAL_UNIT_RESERVED_VCL_R13:
1593    case NAL_UNIT_RESERVED_VCL_N14:
1594    case NAL_UNIT_RESERVED_VCL_R15:
1595     
1596    case NAL_UNIT_RESERVED_IRAP_VCL22:
1597    case NAL_UNIT_RESERVED_IRAP_VCL23:
1598     
1599    case NAL_UNIT_RESERVED_VCL24:
1600    case NAL_UNIT_RESERVED_VCL25:
1601    case NAL_UNIT_RESERVED_VCL26:
1602    case NAL_UNIT_RESERVED_VCL27:
1603    case NAL_UNIT_RESERVED_VCL28:
1604    case NAL_UNIT_RESERVED_VCL29:
1605    case NAL_UNIT_RESERVED_VCL30:
1606    case NAL_UNIT_RESERVED_VCL31:
1607     
1608    case NAL_UNIT_RESERVED_NVCL41:
1609    case NAL_UNIT_RESERVED_NVCL42:
1610    case NAL_UNIT_RESERVED_NVCL43:
1611    case NAL_UNIT_RESERVED_NVCL44:
1612    case NAL_UNIT_RESERVED_NVCL45:
1613    case NAL_UNIT_RESERVED_NVCL46:
1614    case NAL_UNIT_RESERVED_NVCL47:
1615    case NAL_UNIT_UNSPECIFIED_48:
1616    case NAL_UNIT_UNSPECIFIED_49:
1617    case NAL_UNIT_UNSPECIFIED_50:
1618    case NAL_UNIT_UNSPECIFIED_51:
1619    case NAL_UNIT_UNSPECIFIED_52:
1620    case NAL_UNIT_UNSPECIFIED_53:
1621    case NAL_UNIT_UNSPECIFIED_54:
1622    case NAL_UNIT_UNSPECIFIED_55:
1623    case NAL_UNIT_UNSPECIFIED_56:
1624    case NAL_UNIT_UNSPECIFIED_57:
1625    case NAL_UNIT_UNSPECIFIED_58:
1626    case NAL_UNIT_UNSPECIFIED_59:
1627    case NAL_UNIT_UNSPECIFIED_60:
1628    case NAL_UNIT_UNSPECIFIED_61:
1629    case NAL_UNIT_UNSPECIFIED_62:
1630    case NAL_UNIT_UNSPECIFIED_63:
1631    default:
1632      assert (0);
1633  }
1634
1635  return false;
1636}
1637
1638/** Function for checking if picture should be skipped because of association with a previous BLA picture
1639 * \param iPOCLastDisplay POC of last picture displayed
1640 * \returns true if the picture should be skipped
1641 * This function skips all TFD pictures that follow a BLA picture
1642 * in decoding order and precede it in output order.
1643 */
1644Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1645{
1646  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
1647       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1648  {
1649    iPOCLastDisplay++;
1650    return true;
1651  }
1652  return false;
1653}
1654
1655/** Function for checking if picture should be skipped because of random access
1656 * \param iSkipFrame skip frame counter
1657 * \param iPOCLastDisplay POC of last picture displayed
1658 * \returns true if the picture shold be skipped in the random access.
1659 * This function checks the skipping of pictures in the case of -s option random access.
1660 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1661 * It also checks the type of Nal unit type at the random access point.
1662 * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped.
1663 * If the random access point is IDR all pictures after the random access point are decoded.
1664 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1665 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1666 * access point there is no guarantee that the decoder will not crash.
1667 */
1668Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1669{
1670  if (iSkipFrame) 
1671  {
1672    iSkipFrame--;   // decrement the counter
1673    return true;
1674  }
1675#if H_MV
1676  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1677#else
1678  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1679#endif
1680  {
1681    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1682        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1683        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1684        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1685    {
1686
1687#if H_MV
1688      if ( xAllRefLayersInitilized() )
1689      {
1690        m_layerInitilizedFlag[ m_layerId ] = true; 
1691        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1692      }
1693      else
1694      {
1695        return true; 
1696      }
1697#else
1698      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1699      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1700#endif
1701    }
1702    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1703    {
1704#if H_MV
1705      if ( xAllRefLayersInitilized() )
1706      {
1707        m_layerInitilizedFlag[ m_layerId ] = true; 
1708        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1709      }
1710      else 
1711      {
1712        return true; 
1713      }
1714#else
1715      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1716#endif
1717    }
1718    else 
1719    {
1720#if H_MV
1721      static Bool warningMessage[MAX_NUM_LAYERS];
1722      static Bool warningInitFlag = false;
1723     
1724      if (!warningInitFlag)
1725      {
1726        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1727        {
1728          warningMessage[i] = true; 
1729        }
1730        warningInitFlag = true; 
1731      }
1732
1733      if ( warningMessage[getLayerId()] )
1734      {
1735        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1736        warningMessage[m_layerId] = false; 
1737      }
1738#else
1739      static Bool warningMessage = false;
1740      if(!warningMessage)
1741      {
1742        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1743        warningMessage = true;
1744      }
1745#endif
1746      return true;
1747    }
1748  }
1749  // skip the reordered pictures, if necessary
1750  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1751  {
1752    iPOCLastDisplay++;
1753    return true;
1754  }
1755#if H_MV
1756  return !m_layerInitilizedFlag[ getLayerId() ]; 
1757#else
1758  // if we reach here, then the picture is not skipped.
1759  return false; 
1760#endif
1761}
1762
1763#if H_MV
1764TComPic* TDecTop::getPic( Int poc )
1765{
1766  xGetPic( m_layerId, poc ); 
1767  TComList<TComPic*>* listPic = getListPic();
1768  TComPic* pcPic = NULL;
1769  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1770  {
1771    if( (*it)->getPOC() == poc )
1772    {
1773      pcPic = *it ;
1774      break ;
1775    }
1776  }
1777  return pcPic;
1778}
1779
1780TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1781{ 
1782  return m_ivPicLists->getPic( layerId, poc ) ;
1783}
1784
1785Void TDecTop::xResetPocInPicBuffer()
1786{
1787  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1788  while (iterPic != m_cListPic.end())
1789  {
1790    TComPic* pic = *(iterPic++);
1791    if ( pic->getReconMark() )
1792    {
1793      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1794      {
1795        TComSlice* slice = pic->getSlice( i ); 
1796        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1797      }         
1798    }     
1799  }
1800}
1801
1802#if H_MV
1803Void TDecTop::xCeckNoClrasOutput()
1804{
1805  // This part needs further testing!
1806  if ( getLayerId() == 0 )
1807  {   
1808    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1809
1810    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1811    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1812    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1813
1814    if ( noClrasOutputFlag ) 
1815    {
1816      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1817      {
1818        m_layerInitilizedFlag[i] = false; 
1819      } 
1820    }
1821  }
1822}
1823
1824Bool TDecTop::xAllRefLayersInitilized()
1825{
1826  Bool allRefLayersInitilizedFlag = true; 
1827  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1828  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1829  {
1830    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1831    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1832  }
1833
1834  return allRefLayersInitilizedFlag;
1835}
1836#endif
1837#endif
1838//! \}
Note: See TracBrowser for help on using the repository browser.