source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp @ 854

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

Integrated following MV-HEVC HLS 7 items:

H_MV_HLS7_GEN Stub for further integrations (not tested)
H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
Output layer sets, various

(VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
(VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
(VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).

H_MV_HLS_7_HRD_P0156_7 (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
H_MV_HLS_7_VPS_P0048_14
(VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
H_MV_HLS_7_VPS_P0076_15 (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
H_MV_HLS_7_SPS_P0155_16_32
(SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
H_MV_HLS_7_GEN_P0166_PPS_EXTENSION (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
H_MV_HLS_7_FIX_SET_DPB_SIZE
Fix derivation dpb size parameters
H_MV_HLS_7_RESERVED_FLAGS Added flags

(SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
(VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
(VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.

H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO Discard VPS with nuh_layer_Id > 0
H_MV_HLS_7_MISC_P0130_EOS
(MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
H_MV_HLS_7_MISC_P0182_13 (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
H_MV_HLS_7_MISC_P0068_21
(MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG Fix inference of cross_layer_irap_aligned_flag
H_MV_HLS_7_MISC_P0079_18
(MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.

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