source: 3DVCSoftware/branches/HTM-10.2-dev2-MediaTek/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 912

Last change on this file since 912 was 912, checked in by mediatek-htm, 10 years ago

H0091 integration

  • Property svn:eol-style set to native
File size: 114.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     TDecCAVLC.cpp
35\brief    CAVLC decoder class
36*/
37
38#include "TDecCAVLC.h"
39#include "SEIread.h"
40#include "TDecSlice.h"
41
42//! \ingroup TLibDecoder
43//! \{
44
45#if ENC_DEC_TRACE
46
47Void  xTraceSPSHeader (TComSPS *pSPS)
48{
49#if H_MV_ENC_DEC_TRAC
50  if ( g_disableHLSTrace )
51  {
52    return; 
53  }
54  // To avoid mismatches
55  fprintf( g_hTrace, "=========== Sequence Parameter Set ===========\n" );
56#else
57  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
58#endif
59}
60
61Void  xTracePPSHeader (TComPPS *pPPS)
62{
63#if H_MV_ENC_DEC_TRAC
64  if ( g_disableHLSTrace )
65  {
66    return; 
67  }
68  fprintf( g_hTrace, "=========== Picture Parameter Set ===========\n" );
69#else
70  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
71#endif
72}
73
74Void  xTraceSliceHeader (TComSlice *pSlice)
75{
76#if H_MV_ENC_DEC_TRAC
77  if ( g_disableHLSTrace )
78  {
79    return; 
80  }
81#endif
82  fprintf( g_hTrace, "=========== Slice ===========\n");
83}
84
85#endif
86
87// ====================================================================================================================
88// Constructor / destructor / create / destroy
89// ====================================================================================================================
90
91TDecCavlc::TDecCavlc()
92{
93#if H_3D
94  m_aaiTempScale            = new Int* [ MAX_NUM_LAYERS ];
95  m_aaiTempOffset           = new Int* [ MAX_NUM_LAYERS ];
96  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
97  {
98    m_aaiTempScale            [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
99    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
100  }
101#endif
102}
103
104TDecCavlc::~TDecCavlc()
105{
106#if H_3D
107  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
108  {
109    delete [] m_aaiTempScale            [ uiVId ];
110    delete [] m_aaiTempOffset           [ uiVId ];
111  }
112  delete [] m_aaiTempScale;
113  delete [] m_aaiTempOffset;
114#endif
115}
116
117// ====================================================================================================================
118// Public member functions
119// ====================================================================================================================
120
121void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
122{
123  UInt code;
124  UInt interRPSPred;
125  if (idx > 0)
126  {
127    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
128  }
129  else
130  {
131    interRPSPred = false;
132    rps->setInterRPSPrediction(false);
133  }
134
135  if (interRPSPred) 
136  {
137    UInt bit;
138    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
139    {
140      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
141    }
142    else
143    {
144      code = 0;
145    }
146    assert(code <= idx-1); // delta_idx_minus1 shall not be larger than idx-1, otherwise we will predict from a negative row position that does not exist. When idx equals 0 there is no legal value and interRPSPred must be zero. See J0185-r2
147    Int rIdx =  idx - 1 - code;
148    assert (rIdx <= idx-1 && rIdx >= 0); // Made assert tighter; if rIdx = idx then prediction is done from itself. rIdx must belong to range 0, idx-1, inclusive, see J0185-r2
149    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
150    Int k = 0, k0 = 0, k1 = 0;
151    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
152    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
153    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
154    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
155    {
156      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
157      Int refIdc = bit;
158      if (refIdc == 0) 
159      {
160        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
161        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
162      }
163      if (refIdc == 1 || refIdc == 2)
164      {
165        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
166        rps->setDeltaPOC(k, deltaPOC);
167        rps->setUsed(k, (refIdc == 1));
168
169        if (deltaPOC < 0)
170        {
171          k0++;
172        }
173        else 
174        {
175          k1++;
176        }
177        k++;
178      } 
179      rps->setRefIdc(j,refIdc); 
180    }
181    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
182    rps->setNumberOfPictures(k);
183    rps->setNumberOfNegativePictures(k0);
184    rps->setNumberOfPositivePictures(k1);
185    rps->sortDeltaPOC();
186  }
187  else
188  {
189    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
190    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
191    Int prev = 0;
192    Int poc;
193    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
194    {
195      READ_UVLC(code, "delta_poc_s0_minus1");
196      poc = prev-code-1;
197      prev = poc;
198      rps->setDeltaPOC(j,poc);
199      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
200    }
201    prev = 0;
202    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
203    {
204      READ_UVLC(code, "delta_poc_s1_minus1");
205      poc = prev+code+1;
206      prev = poc;
207      rps->setDeltaPOC(j,poc);
208      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
209    }
210    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
211  }
212#if PRINT_RPS_INFO
213  rps->printDeltaPOC();
214#endif
215}
216
217#if H_3D
218Void TDecCavlc::parsePPS(TComPPS* pcPPS, TComVPS* pcVPS )
219#else
220Void TDecCavlc::parsePPS(TComPPS* pcPPS)
221#endif
222{
223#if ENC_DEC_TRACE 
224  xTracePPSHeader (pcPPS);
225#endif
226  UInt  uiCode;
227
228  Int   iCode;
229
230  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
231  assert(uiCode <= 63);
232  pcPPS->setPPSId (uiCode);
233 
234  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
235  assert(uiCode <= 15);
236  pcPPS->setSPSId (uiCode);
237 
238  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
239  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
240
241  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
242  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
243
244  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
245
246  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
247  assert(uiCode <= 14);
248  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
249 
250  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
251  assert(uiCode <= 14);
252  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
253 
254  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
255  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
256  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
257  pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
258
259  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
260  if( pcPPS->getUseDQP() )
261  {
262    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
263    pcPPS->setMaxCuDQPDepth( uiCode );
264  }
265  else
266  {
267    pcPPS->setMaxCuDQPDepth( 0 );
268  }
269  READ_SVLC( iCode, "pps_cb_qp_offset");
270  pcPPS->setChromaCbQpOffset(iCode);
271  assert( pcPPS->getChromaCbQpOffset() >= -12 );
272  assert( pcPPS->getChromaCbQpOffset() <=  12 );
273
274  READ_SVLC( iCode, "pps_cr_qp_offset");
275  pcPPS->setChromaCrQpOffset(iCode);
276  assert( pcPPS->getChromaCrQpOffset() >= -12 );
277  assert( pcPPS->getChromaCrQpOffset() <=  12 );
278
279  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
280  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
281
282  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
283  pcPPS->setUseWP( uiCode==1 );
284  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
285  pcPPS->setWPBiPred( uiCode==1 );
286
287  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
288  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
289  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
290  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
291 
292  if( pcPPS->getTilesEnabledFlag() )
293  {
294    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode ); 
295    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode ); 
296    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
297
298    if( !pcPPS->getUniformSpacingFlag())
299    {
300      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
301      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
302      { 
303        READ_UVLC( uiCode, "column_width_minus1" ); 
304        columnWidth[i] = uiCode+1;
305      }
306      pcPPS->setColumnWidth(columnWidth);
307      free(columnWidth);
308
309      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
310      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
311      {
312        READ_UVLC( uiCode, "row_height_minus1" );
313        rowHeight[i] = uiCode + 1;
314      }
315      pcPPS->setRowHeight(rowHeight);
316      free(rowHeight); 
317    }
318
319    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
320    {
321      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
322    }
323  }
324  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
325  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
326  if(pcPPS->getDeblockingFilterControlPresentFlag())
327  {
328    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
329    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
330    if(!pcPPS->getPicDisableDeblockingFilterFlag())
331    {
332      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
333      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
334    }
335  }
336#if H_MV
337  if ( pcPPS->getLayerId() > 0 )
338  {
339    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );   
340  }
341
342  if( pcPPS->getPpsInferScalingListFlag( ) ) 
343  {
344    READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
345  }
346  else
347  { 
348#endif
349  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
350  if(pcPPS->getScalingListPresentFlag ())
351  {
352    parseScalingList( pcPPS->getScalingList() );
353  }
354#if H_MV
355  }
356#endif
357
358  READ_FLAG( uiCode, "lists_modification_present_flag");
359  pcPPS->setListsModificationPresentFlag(uiCode);
360
361  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
362  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
363
364  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
365  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
366
367  READ_FLAG( uiCode, "pps_extension_flag");
368  if (uiCode)
369  {
370#if H_MV
371    for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
372    {
373      READ_FLAG( uiCode, "pps_extension_type_flag" ); pcPPS->setPpsExtensionTypeFlag( i, uiCode == 1 );
374#if H_3D
375      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_3D || i == PPS_EX_T_ESC ); 
376#else
377      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_ESC ); 
378#endif
379    }
380   
381
382    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_MV ) )
383    {
384      READ_FLAG( uiCode, "poc_reset_info_present_flag" ); pcPPS->setPocResetInfoPresentFlag( uiCode == 1 );
385    }
386
387#if H_3D
388    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_3D ) ) // This probably needs to be aligned with Rext and SHVC
389    {
390      parsePPSExtension( pcPPS, pcVPS );
391    }
392#endif
393
394    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_ESC ) )
395    {
396#endif
397      while ( xMoreRbspData() )
398      {
399        READ_FLAG( uiCode, "pps_extension_data_flag");
400      }
401#if H_MV
402    }
403#endif
404  }
405}
406
407#if H_3D
408Void TDecCavlc::parsePPSExtension( TComPPS* pcPPS, TComVPS* pcVPS )
409{
410  //Ed.(GT): pcVPS should not be used here. Needs to be fixed.
411  UInt uiCode = 0; 
412  TComDLT* pcDLT = new TComDLT;
413
414  READ_FLAG(uiCode, "dlt_present_flag");
415  pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
416
417  if ( pcDLT->getDltPresentFlag() )
418  {
419    READ_CODE(6, uiCode, "pps_depth_layers_minus1");
420    pcDLT->setNumDepthViews( uiCode );
421
422    READ_CODE(4, uiCode, "pps_bit_depth_for_depth_views_minus8");
423    pcDLT->setDepthViewBitDepth( (uiCode+8) );
424
425
426
427    for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
428    {
429      if ( i != 0 )
430      {
431        if( pcVPS->getDepthId( i ) == 1 ) 
432        {
433          READ_FLAG(uiCode, "dlt_flag[i]");
434          pcDLT->setUseDLTFlag(i, (uiCode == 1) ? true : false);
435
436          if ( pcDLT->getUseDLTFlag( i ) )
437          {
438            Bool bDltBitMapRepFlag    = false;
439            UInt uiMaxDiff            = 0xffffffff;
440            UInt uiMinDiff            = 0;
441            UInt uiCodeLength         = 0;
442
443            READ_FLAG(uiCode, "inter_view_dlt_pred_enable_flag[ i ]"); 
444
445#if  MTK_DLT_CODING_FIX_H0091
446            if( uiCode )
447            {
448                assert( pcDLT->getUseDLTFlag( 1 ));
449            }
450#endif
451
452            pcDLT->setInterViewDltPredEnableFlag( i, (uiCode == 1) ? true : false );
453
454            if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
455            {
456              READ_FLAG(uiCode, "dlt_bit_map_rep_flag[ layerId ]");
457              bDltBitMapRepFlag = (uiCode == 1) ? true : false; 
458            }
459            else
460            {
461              bDltBitMapRepFlag = false;
462            }
463           
464            UInt uiNumDepthValues = 0;
465            Int  aiIdx2DepthValue[256];
466
467            // Bit map
468            if ( bDltBitMapRepFlag )
469            {
470              for (UInt d=0; d<256; d++)
471              {
472                READ_FLAG(uiCode, "dlt_bit_map_flag[ layerId ][ j ]");
473                if (uiCode == 1)
474                {
475                  aiIdx2DepthValue[uiNumDepthValues] = d;
476                  uiNumDepthValues++;
477                }
478              }
479            }
480            // Diff Coding
481            else
482            {
483              READ_CODE(8, uiNumDepthValues, "num_depth_values_in_dlt[i]");   // num_entry
484
485#if !H_3D_DELTA_DLT
486              if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )       // Single-view DLT Diff Coding
487#endif
488              {
489                // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
490
491                if (uiNumDepthValues > 1)
492                {
493                  READ_CODE(8, uiCode, "max_diff[ layerId ]"); 
494                  uiMaxDiff = uiCode;
495                }
496                else
497                {
498                  uiMaxDiff = 0;           // when there is only one value in DLT
499                }
500
501                if (uiNumDepthValues > 2)
502                {
503                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff + 1));
504                  READ_CODE(uiCodeLength, uiCode, "min_diff_minus1[ layerId ]");
505                  uiMinDiff = uiCode + 1;
506                }
507                else
508                {
509                  uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
510                }
511
512                READ_CODE(8, uiCode, "dlt_depth_value0[layerId]");   // entry0
513                aiIdx2DepthValue[0] = uiCode;
514
515                if (uiMaxDiff == uiMinDiff)
516                {
517                  for (UInt d=1; d<uiNumDepthValues; d++)
518                  {
519                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
520                  }
521                }
522                else
523                {
524                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
525                  for (UInt d=1; d<uiNumDepthValues; d++)
526                  {
527                    READ_CODE(uiCodeLength, uiCode, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");
528                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
529                  }
530                }
531
532              }
533            }
534           
535#if H_3D_DELTA_DLT
536            if( pcDLT->getInterViewDltPredEnableFlag( i ) )
537            {
538              // interpret decoded values as delta DLT
539              AOF( pcVPS->getDepthId( 1 ) == 1 );
540              AOF( i > 1 );
541              // assumes ref layer id to be 1
542              Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
543              UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
544              pcDLT->setDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
545            }
546            else
547            {
548              // store final DLT
549              pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
550            }
551#else
552            // store final DLT
553            pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
554#endif
555          }
556        }
557      }
558    }
559  }
560
561  pcPPS->setDLT( pcDLT );
562}
563#endif
564
565Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
566{
567#if ENC_DEC_TRACE
568  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
569#endif
570  UInt  uiCode;
571
572  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
573  if (pcVUI->getAspectRatioInfoPresentFlag())
574  {
575    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
576    if (pcVUI->getAspectRatioIdc() == 255)
577    {
578      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
579      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
580    }
581  }
582
583  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
584  if (pcVUI->getOverscanInfoPresentFlag())
585  {
586    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
587  }
588
589  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
590#if H_MV
591  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() ); 
592#endif
593  if (pcVUI->getVideoSignalTypePresentFlag())
594  {
595    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
596    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
597    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
598    if (pcVUI->getColourDescriptionPresentFlag())
599    {
600      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
601      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
602      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
603    }
604  }
605
606  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
607  if (pcVUI->getChromaLocInfoPresentFlag())
608  {
609    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
610    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
611  }
612
613  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
614
615  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
616
617  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
618
619  READ_FLAG(     uiCode, "default_display_window_flag");
620  if (uiCode != 0)
621  {
622    Window &defDisp = pcVUI->getDefaultDisplayWindow();
623#if H_MV
624    defDisp.setScaledFlag( false ); 
625    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
626    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
627    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
628    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
629#else
630    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
631    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
632    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
633    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
634#endif
635  }
636  TimingInfo *timingInfo = pcVUI->getTimingInfo();
637  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
638  if(timingInfo->getTimingInfoPresentFlag())
639  {
640    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
641    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
642    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
643    if(timingInfo->getPocProportionalToTimingFlag())
644    {
645      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
646    }
647  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
648  if( pcVUI->getHrdParametersPresentFlag() )
649  {
650    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
651  }
652  }
653  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
654  if (pcVUI->getBitstreamRestrictionFlag())
655  {
656    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
657    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
658    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
659    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
660    assert(uiCode < 4096);
661    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
662    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
663    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
664    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
665  }
666}
667
668Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
669{
670  UInt  uiCode;
671  if( commonInfPresentFlag )
672  {
673    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
674    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
675    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
676    {
677      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
678      if( hrd->getSubPicCpbParamsPresentFlag() )
679      {
680        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
681        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
682        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
683        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
684      }
685      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
686      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
687      if( hrd->getSubPicCpbParamsPresentFlag() )
688      {
689        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
690      }
691      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
692      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
693      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
694    }
695  }
696  Int i, j, nalOrVcl;
697  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
698  {
699    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
700    if( !hrd->getFixedPicRateFlag( i ) )
701    {
702      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
703    }
704    else
705    {
706      hrd->setFixedPicRateWithinCvsFlag( i, true );
707    }
708    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
709    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
710    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
711    {
712      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
713    }
714    else
715    {     
716      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
717    }
718    if (!hrd->getLowDelayHrdFlag( i ))
719    {
720      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
721    }
722    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
723    {
724      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
725          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
726      {
727        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
728        {
729          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
730          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
731          if( hrd->getSubPicCpbParamsPresentFlag() )
732          {
733            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
734            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
735          }
736          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
737        }
738      }
739    }
740  }
741}
742
743#if H_3D
744Void TDecCavlc::parseSPS(TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
745#else
746Void TDecCavlc::parseSPS(TComSPS* pcSPS)
747#endif
748{
749#if ENC_DEC_TRACE 
750  xTraceSPSHeader (pcSPS);
751#endif
752
753  UInt  uiCode;
754  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
755#if H_MV
756  if ( pcSPS->getLayerId() == 0 )
757  {
758#endif
759  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
760  assert(uiCode <= 6);
761 
762  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
763  if ( pcSPS->getMaxTLayers() == 1 )
764  {
765    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
766    assert( uiCode == 1 );
767  }
768 
769  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
770#if H_MV
771  }
772#endif
773  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
774  assert(uiCode <= 15);
775#if H_MV
776  if ( pcSPS->getLayerId() > 0 )
777  {
778    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
779    if ( pcSPS->getUpdateRepFormatFlag() )
780    { 
781      READ_CODE( 8, uiCode, "sps_rep_format_idx" );                pcSPS->setSpsRepFormatIdx( uiCode );
782    }
783  }
784  else
785  {
786#endif
787  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
788  assert(uiCode <= 3);
789  // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
790  assert (uiCode == 1);
791  if( uiCode == 3 )
792  {
793    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
794  }
795
796  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
797  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
798#if H_MV
799  }
800#endif
801  READ_FLAG(     uiCode, "conformance_window_flag");
802  if (uiCode != 0)
803  {
804    Window &conf = pcSPS->getConformanceWindow();
805#if H_MV
806    // Needs to be scaled later, when ChromaFormatIdc is known.
807    conf.setScaledFlag( false ); 
808    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
809    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
810    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
811    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );   
812#else
813    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
814    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
815    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
816    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
817#endif
818  }
819
820#if H_MV
821  if ( pcSPS->getLayerId() == 0 )
822  { 
823#endif
824  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
825  assert(uiCode <= 6);
826  pcSPS->setBitDepthY( uiCode + 8 );
827  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
828
829  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
830  assert(uiCode <= 6);
831  pcSPS->setBitDepthC( uiCode + 8 );
832  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
833#if H_MV
834  }
835#endif
836
837  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
838  assert(uiCode <= 12);
839
840#if H_MV
841  if ( pcSPS->getLayerId() == 0 ) 
842  { 
843#endif
844  UInt subLayerOrderingInfoPresentFlag;
845  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
846 
847  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
848  {
849#if H_MV
850    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
851#else
852    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
853#endif
854    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
855#if H_MV
856    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
857#else
858    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
859#endif
860    pcSPS->setNumReorderPics(uiCode, i);
861#if H_MV
862    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
863#else
864    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
865#endif
866    pcSPS->setMaxLatencyIncrease( uiCode, i );
867
868    if (!subLayerOrderingInfoPresentFlag)
869    {
870      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
871      {
872        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
873        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
874        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
875      }
876      break;
877    }
878  }
879#if H_MV
880  }
881#endif
882
883  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
884  Int log2MinCUSize = uiCode + 3;
885  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
886  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
887  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
888 
889  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
890  {
891    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
892  }
893 
894  Int maxCUDepthDelta = uiCode;
895  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
896  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
897  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
898
899  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
900  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
901
902  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
903  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
904
905  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
906  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
907
908  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
909  if(pcSPS->getScalingListFlag())
910  {
911#if H_MV
912    if ( pcSPS->getLayerId() > 0 )
913    {   
914      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
915    }
916
917    if ( pcSPS->getSpsInferScalingListFlag() )
918    {
919      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
920    }
921    else
922    {   
923#endif
924    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
925    if(pcSPS->getScalingListPresentFlag ())
926    {
927      parseScalingList( pcSPS->getScalingList() );
928    }
929#if H_MV
930    }
931#endif
932  }
933  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
934  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
935
936  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
937  if( pcSPS->getUsePCM() )
938  {
939    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
940    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
941    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
942    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
943    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
944  }
945
946  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
947  assert(uiCode <= 64);
948  pcSPS->createRPSList(uiCode);
949
950  TComRPSList* rpsList = pcSPS->getRPSList();
951  TComReferencePictureSet* rps;
952
953  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
954  {
955    rps = rpsList->getReferencePictureSet(i);
956    parseShortTermRefPicSet(pcSPS,rps,i);
957  }
958  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
959  if (pcSPS->getLongTermRefsPresent()) 
960  {
961    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
962    pcSPS->setNumLongTermRefPicSPS(uiCode);
963    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
964    {
965      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
966      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
967      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
968      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
969    }
970  }
971  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
972
973  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
974
975  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
976
977  if (pcSPS->getVuiParametersPresentFlag())
978  {
979    parseVUI(pcSPS->getVuiParameters(), pcSPS);
980  }
981
982  READ_FLAG( uiCode, "sps_extension_flag");
983#if H_MV
984  pcSPS->setSpsExtensionFlag( uiCode ); 
985  if (pcSPS->getSpsExtensionFlag( ) )
986#else
987  if (uiCode)
988#endif
989  {
990#if H_MV
991    for (Int i = 0; i < PS_EX_T_MAX_NUM; i++)
992    {
993      READ_FLAG( uiCode, "sps_extension_type_flag" ); pcSPS->setSpsExtensionTypeFlag( i, uiCode );
994#if H_3D
995      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV || i == PS_EX_T_3D || i == PS_EX_T_ESC ); 
996#else
997      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV || i == PS_EX_T_ESC ); 
998#endif
999    } 
1000
1001    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_MV ))
1002    {
1003      parseSPSExtension( pcSPS ); 
1004    }
1005
1006#if H_3D
1007    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_3D ))
1008    {
1009      parseSPSExtension2( pcSPS, viewIndex, depthFlag  ); 
1010    }
1011#endif
1012
1013    if ( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_ESC ))
1014    {   
1015#endif
1016        while ( xMoreRbspData() )
1017        {
1018          READ_FLAG( uiCode, "sps_extension_data_flag");
1019        }
1020#if H_MV
1021    }
1022#endif
1023  }
1024}
1025
1026#if H_MV
1027Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
1028{
1029  UInt uiCode; 
1030  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
1031 
1032  READ_UVLC( uiCode, "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets( uiCode );
1033
1034  for( Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets( ); i++)
1035  {   
1036    READ_CODE( 6, uiCode, "scaled_ref_layer_id" ); pcSPS->setScaledRefLayerId( i, uiCode ); 
1037
1038    Int j = pcSPS->getScaledRefLayerId( i ); 
1039    Int iCode; 
1040    READ_SVLC( iCode, "scaled_ref_layer_left_offset" ); pcSPS->setScaledRefLayerLeftOffset( j, iCode );
1041    READ_SVLC( iCode, "scaled_ref_layer_top_offset" ); pcSPS->setScaledRefLayerTopOffset( j, iCode );
1042    READ_SVLC( iCode, "scaled_ref_layer_right_offset" ); pcSPS->setScaledRefLayerRightOffset( j, iCode );
1043    READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" ); pcSPS->setScaledRefLayerBottomOffset( j, iCode );
1044    READ_FLAG( uiCode, "sps_multilayer_ext_reserved_zero_flag[ i ]" );
1045  }
1046}
1047
1048#if H_3D
1049Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
1050{ 
1051  UInt uiCode; 
1052#if H_3D_QTLPC
1053  //GT: This has to go to VPS
1054  if( depthFlag )
1055  {
1056    READ_FLAG( uiCode, "use_qtl_flag" );
1057    pcSPS->setUseQTL( uiCode );
1058    READ_FLAG( uiCode, "use_pc_flag" );
1059    pcSPS->setUsePC( uiCode );
1060  }
1061#endif
1062}
1063#endif
1064#endif
1065
1066Void TDecCavlc::parseVPS(TComVPS* pcVPS)
1067{
1068  UInt  uiCode;
1069 
1070  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
1071  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
1072#if H_MV
1073  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
1074#else
1075  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
1076#endif
1077  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
1078  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
1079  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
1080
1081  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
1082  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
1083  UInt subLayerOrderingInfoPresentFlag;
1084  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
1085  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
1086  {
1087    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
1088    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
1089    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
1090
1091    if (!subLayerOrderingInfoPresentFlag)
1092    {
1093      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
1094      {
1095        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
1096        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
1097        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
1098      }
1099      break;
1100    }
1101  }
1102
1103  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
1104#if H_MV
1105  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
1106  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
1107
1108  READ_UVLC(    uiCode, "vps_max_num_layer_sets_minus1" );               pcVPS->setVpsNumLayerSetsMinus1( uiCode );
1109  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
1110  {
1111    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
1112#else
1113  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
1114  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
1115  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
1116  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
1117  {
1118    // Operation point set
1119    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
1120#endif
1121    {
1122      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
1123    }
1124  }
1125#if H_MV
1126  pcVPS->deriveLayerSetLayerIdList(); 
1127#endif
1128  TimingInfo *timingInfo = pcVPS->getTimingInfo();
1129  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
1130  if(timingInfo->getTimingInfoPresentFlag())
1131  {
1132    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
1133    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
1134    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
1135    if(timingInfo->getPocProportionalToTimingFlag())
1136    {
1137      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
1138    }
1139    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1140
1141    if( pcVPS->getNumHrdParameters() > 0 )
1142    {
1143      pcVPS->createHrdParamBuffer();
1144    }
1145    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1146    {
1147      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1148      if( i > 0 )
1149      {
1150        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1151      }
1152      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1153    }
1154  }
1155  READ_FLAG( uiCode,  "vps_extension_flag" );
1156  if (uiCode)
1157  {
1158#if H_MV
1159    m_pcBitstream->readOutTrailingBits();
1160    parseVPSExtension( pcVPS );   
1161    READ_FLAG( uiCode,  "vps_extension2_flag" );
1162    if (uiCode)
1163    {
1164#if H_3D
1165      m_pcBitstream->readOutTrailingBits();
1166      pcVPS->createCamPars(pcVPS->getNumViews());
1167      parseVPSExtension2( pcVPS );   
1168      READ_FLAG( uiCode,  "vps_extension3_flag" );
1169      if (uiCode)
1170      {     
1171#endif
1172#endif 
1173        while ( xMoreRbspData() )
1174        {
1175          READ_FLAG( uiCode, "vps_extension_data_flag");
1176        }
1177#if H_MV
1178#if H_3D
1179      }
1180#endif
1181    }
1182#endif
1183  }
1184  return; 
1185}
1186
1187#if H_MV
1188Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
1189{
1190  UInt uiCode; 
1191  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
1192
1193  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
1194
1195  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
1196  {
1197    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );     
1198  }
1199
1200  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
1201  {
1202    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
1203  }
1204
1205  if ( pcVPS->getSplittingFlag() )
1206  {
1207    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
1208  }
1209
1210  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
1211
1212  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1213  {
1214    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
1215    {
1216      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
1217    }
1218    else
1219    {
1220      pcVPS->setLayerIdInNuh( i, i );; 
1221    }
1222
1223    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
1224
1225    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
1226    {
1227      if ( !pcVPS->getSplittingFlag() )
1228      {
1229        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
1230      }
1231      else
1232      {
1233        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
1234      }
1235    }
1236  }
1237
1238  READ_CODE( 4, uiCode, "view_id_len" ); pcVPS->setViewIdLen( uiCode );
1239
1240  if ( pcVPS->getViewIdLen( ) > 0 )
1241  {   
1242    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1243    {
1244      READ_CODE( pcVPS->getViewIdLen( ), uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
1245    }
1246  }
1247  else
1248  {
1249    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1250    {
1251      pcVPS->setViewIdVal( i, 0 ); 
1252    }
1253  }
1254
1255
1256  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1257  {
1258    for( Int j = 0; j < i; j++ )
1259    {
1260      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
1261    }
1262  }
1263  pcVPS->setRefLayers(); 
1264  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag" ); pcVPS->setVpsSubLayersMaxMinus1PresentFlag( uiCode == 1 );
1265  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
1266  {
1267    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1268    {
1269      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1" ); pcVPS->setSubLayersVpsMaxMinus1( i, uiCode );   
1270      pcVPS->checkSubLayersVpsMaxMinus1( i ); 
1271
1272    }
1273  } 
1274  else
1275  {
1276    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1277    {
1278      pcVPS->setSubLayersVpsMaxMinus1( i, pcVPS->getMaxTLayers( ) - 1);   
1279    }
1280  }
1281  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
1282
1283  if ( pcVPS->getMaxTidRefPresentFlag() )
1284  {   
1285    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
1286    {
1287      for( Int j = i + 1; j <= pcVPS->getMaxLayersMinus1(); j++ )
1288      {
1289        if ( pcVPS->getDirectDependencyFlag(j,i) )
1290        {
1291          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1" ); pcVPS->setMaxTidIlRefPicsPlus1( i, j, uiCode );
1292        }
1293      }
1294    }
1295  }
1296
1297  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
1298
1299  READ_UVLC( uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode ); 
1300
1301  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
1302  {
1303    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
1304    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
1305    if( !pcVPS->getVpsProfilePresentFlag( i ) )
1306    {
1307      TComPTL temp = *pcVPS->getPTL( i );
1308      *pcVPS->getPTL( i ) = *pcVPS->getPTL( i - 1 );
1309      pcVPS->getPTL( i )->copyLevelFrom( &temp );
1310    }
1311  }
1312
1313  READ_UVLC( uiCode, "num_add_output_layer_sets"      ); pcVPS->setNumAddOutputLayerSets( uiCode );
1314  pcVPS->initTargetLayerIdLists( ); 
1315  if( pcVPS->getNumOutputLayerSets() > 1)
1316  {
1317    READ_CODE( 2, uiCode, "default_target_output_layer_idc" ); pcVPS->setDefaultTargetOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );   
1318  } 
1319
1320  pcVPS->setOutputLayerFlag(0, 0, pcVPS->inferOutputLayerFlag( 0, 0 )); 
1321  pcVPS->setOutputLayerSetIdxMinus1(0, -1); 
1322
1323  pcVPS->deriveTargetLayerIdList( 0 ); 
1324  for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
1325  {
1326    if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )   
1327    {       
1328      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
1329    }
1330
1331    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
1332    {       
1333      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
1334      {
1335        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1336      }
1337    }
1338    else
1339    { 
1340      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
1341      {             
1342        pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j )); 
1343      }
1344    }
1345    pcVPS->deriveTargetLayerIdList( i ); 
1346
1347    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
1348    {     
1349      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
1350    }
1351
1352    if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
1353    {
1354      READ_FLAG( uiCode, "alt_output_layer_flag[ i ]" ); pcVPS->setAltOutputLayerFlag( i, uiCode == 1 );
1355    }
1356  }
1357
1358  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
1359  if ( pcVPS->getRepFormatIdxPresentFlag() )
1360  {
1361    READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
1362  }
1363
1364  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
1365  { 
1366    assert( pcVPS->getRepFormat(i) == NULL ); 
1367    TComRepFormat* curRepFormat = new TComRepFormat(); 
1368    TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL; 
1369    parseRepFormat( i, curRepFormat ,  prevRepFormat); 
1370    pcVPS->setRepFormat(i, curRepFormat ); 
1371  }
1372
1373  if( pcVPS->getRepFormatIdxPresentFlag() ) 
1374  {
1375    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1376    {
1377      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
1378      {
1379        READ_CODE( pcVPS->getVpsRepFormatIdxLen(), uiCode, "vps_rep_format_idx[i]" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1380      }
1381    }
1382  }
1383
1384  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
1385#if H_MV_HLS7_GEN
1386  READ_FLAG( uiCode, "vps_poc_lsb_aligned_flag" ); pcVPS->setVpsPocLsbAlignedFlag( uiCode == 1 );
1387#endif
1388  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1389  {
1390    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) )  ==  0 )
1391    {     
1392      READ_FLAG( uiCode, "poc_lsb_not_present_flag" ); pcVPS->setPocLsbNotPresentFlag( i, uiCode == 1 );
1393    }
1394  }
1395
1396  READ_FLAG( uiCode, "vps_reserved_zero_flag" ); 
1397  parseDpbSize( pcVPS ); 
1398
1399  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
1400
1401  READ_FLAG( uiCode, "default_direct_dependency_flag" ); pcVPS->setDefaultDirectDependencyFlag( uiCode == 1 );
1402  if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1403  { 
1404    READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2, uiCode, "default_direct_dependency_type" ); pcVPS->setDefaultDirectDependencyType( uiCode );
1405  }
1406
1407  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1408  {
1409    for( Int j = 0; j < i; j++ )
1410    {
1411      if (pcVPS->getDirectDependencyFlag( i, j) )
1412      {       
1413        if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1414        { 
1415          pcVPS->setDirectDependencyType( i, j , pcVPS->getDefaultDirectDependencyType( ) );
1416        }
1417        else
1418        {
1419          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1420        }
1421      }
1422    }
1423  } 
1424
1425  READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode ); 
1426  for ( Int i = 1; i <= pcVPS->getVpsNonVuiExtensionLength(); i++ )
1427  {
1428    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" );
1429  }
1430  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
1431  if( pcVPS->getVpsVuiPresentFlag() )
1432  {
1433    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
1434    parseVPSVUI( pcVPS ); 
1435  }     
1436  {
1437    TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1438    assert( pcVPSVUI ); 
1439    pcVPSVUI->inferVpsVui( false ); 
1440  }
1441
1442  pcVPS->checkVPSExtensionSyntax(); 
1443}
1444
1445Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
1446{
1447  assert( pcRepFormat ); 
1448
1449  UInt uiCode; 
1450
1451  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
1452  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
1453  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" ); pcRepFormat->setChromaAndBitDepthVpsPresentFlag( uiCode == 1 );
1454
1455  pcRepFormat->checkChromaAndBitDepthVpsPresentFlag( i ); 
1456
1457  if ( pcRepFormat->getChromaAndBitDepthVpsPresentFlag() )
1458  { 
1459  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
1460  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
1461  {
1462    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
1463  }
1464  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
1465  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
1466  }
1467  else
1468  {
1469    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false ); 
1470  }
1471}
1472
1473
1474Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
1475{
1476  assert( pcVPS ); 
1477
1478  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1479
1480  assert( pcVPSVUI ); 
1481
1482  UInt uiCode; 
1483  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
1484  if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
1485  { 
1486    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
1487  }
1488  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
1489  {
1490    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
1491  }
1492  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
1493  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
1494  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1495  {
1496    for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
1497    {
1498      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
1499      {
1500        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
1501        {
1502          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
1503        }
1504        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
1505        {
1506          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
1507        }
1508        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
1509        {
1510          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
1511          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
1512        }
1513        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
1514        {
1515          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
1516          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
1517        }
1518      }
1519    }
1520  }
1521
1522  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1523  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1524  {
1525    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1526  }
1527  else
1528  {
1529    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
1530  }
1531
1532  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1533  {
1534    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1535    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1536    parseVideoSignalInfo( curVideoSignalInfo ); 
1537    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1538  }
1539
1540  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1541  {
1542    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1543    {
1544      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1545      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
1546    }
1547  }
1548  else
1549  {
1550    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1551    {
1552      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ); 
1553    }
1554  }
1555
1556  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
1557  if( !pcVPSVUI->getTilesNotInUseFlag() ) 
1558  {     
1559    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1560    {
1561      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
1562      if( pcVPSVUI->getTilesInUseFlag( i ) ) 
1563      {
1564        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
1565      }
1566    } 
1567
1568    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1569    {
1570      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
1571      { 
1572        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getRefLayerId(pcVPS->getLayerIdInNuh( i ) , j  )); 
1573        if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
1574        {
1575          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
1576        }
1577      } 
1578    }
1579  } 
1580 
1581  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
1582 
1583  if( !pcVPSVUI->getWppNotInUseFlag( ))
1584  {
1585    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1586    {
1587      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
1588    }
1589  }
1590
1591  READ_CODE( 3, uiCode, "vps_vui_reserved_zero_3bits" ); 
1592  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
1593
1594  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1595  {
1596    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1597    {
1598      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
1599      {
1600        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
1601        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1602        {
1603          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
1604          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1605          {
1606            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
1607          }
1608        }
1609      }
1610    }
1611  }
1612
1613  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
1614  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
1615  {
1616    parseVpsVuiBspHrdParameters( pcVPS ); 
1617}
1618  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1619  {
1620    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 ) 
1621    {
1622      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
1623    }
1624  }
1625}
1626
1627Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
1628{
1629  assert( pcVPS ); 
1630
1631  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1632
1633  assert( pcVPSVUI ); 
1634
1635  TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters(); 
1636 
1637  assert ( vpsVuiBspHrdP );
1638
1639  UInt uiCode; 
1640  READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vpsVuiBspHrdP->setVpsNumBspHrdParametersMinus1( uiCode );
1641  for( Int i = 0; i <= vpsVuiBspHrdP->getVpsNumBspHrdParametersMinus1( ); i++ )
1642  { 
1643    if( i > 0 )
1644    {
1645      READ_FLAG( uiCode, "bsp_cprms_present_flag" ); vpsVuiBspHrdP->setBspCprmsPresentFlag( i, uiCode == 1 );
1646    }
1647    TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i ); 
1648    parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getBspCprmsPresentFlag( i ), pcVPS->getMaxSubLayersMinus1() );     
1649  } 
1650  for( Int h = 1; h <= pcVPS->getVpsNumLayerSetsMinus1(); h++ )
1651  { 
1652    READ_UVLC( uiCode, "num_bitstream_partitions" ); vpsVuiBspHrdP->setNumBitstreamPartitions( h, uiCode );
1653    for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ ) 
1654    {
1655      for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ ) 
1656      {
1657        if( pcVPS->getLayerIdIncludedFlag( h ,j ) )
1658        {
1659          READ_FLAG( uiCode, "layer_in_bsp_flag" ); vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, uiCode == 1 );
1660        }
1661        else
1662        {
1663          vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec
1664        }
1665      }
1666    }
1667    vpsVuiBspHrdP->checkLayerInBspFlag( pcVPS, h ); 
1668   
1669    if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
1670    { 
1671      READ_UVLC( uiCode, "num_bsp_sched_combinations" ); vpsVuiBspHrdP->setNumBspSchedCombinations( h, uiCode );
1672      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
1673      {
1674        for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
1675        { 
1676          READ_UVLC( uiCode, "bsp_comb_hrd_idx" ); vpsVuiBspHrdP->setBspCombHrdIdx( h, i, j, uiCode );
1677          READ_UVLC( uiCode, "bsp_comb_sched_idx" ); vpsVuiBspHrdP->setBspCombSchedIdx( h, i, j, uiCode );
1678        } 
1679      }
1680    } 
1681  } 
1682} 
1683
1684Void TDecCavlc::parseVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo ) 
1685{
1686  UInt uiCode; 
1687  READ_CODE( 3, uiCode, "video_vps_format" );             pcVideoSignalInfo->setVideoVpsFormat( uiCode );
1688  READ_FLAG( uiCode, "video_full_range_vps_flag" );       pcVideoSignalInfo->setVideoFullRangeVpsFlag( uiCode == 1 );
1689  READ_CODE( 8, uiCode, "colour_primaries_vps" );         pcVideoSignalInfo->setColourPrimariesVps( uiCode );
1690  READ_CODE( 8, uiCode, "transfer_characteristics_vps" ); pcVideoSignalInfo->setTransferCharacteristicsVps( uiCode );
1691  READ_CODE( 8, uiCode, "matrix_coeffs_vps" );            pcVideoSignalInfo->setMatrixCoeffsVps( uiCode );
1692}
1693
1694Void TDecCavlc::parseDpbSize( TComVPS* vps )
1695{
1696  UInt uiCode; 
1697  TComDpbSize* dpbSize = vps->getDpbSize(); 
1698  assert ( dpbSize != 0 ); 
1699
1700  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
1701  { 
1702    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
1703    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
1704    { 
1705      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
1706      {
1707        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
1708      }
1709      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
1710      { 
1711        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
1712        {
1713          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
1714        }
1715        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
1716#if H_MV_HLS7_GEN
1717        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) ) 
1718        {
1719          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
1720          {
1721            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1" ); dpbSize->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode );
1722          }
1723        }
1724#endif
1725        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
1726      }
1727      else
1728      {
1729        if ( j > 0 )
1730        {
1731          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
1732          {
1733            dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
1734          }
1735          dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
1736          dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
1737        }
1738      }
1739    } 
1740  } 
1741}
1742#endif
1743
1744#if H_3D
1745Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
1746{
1747  UInt uiCode; 
1748  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1749  {
1750#if H_3D_ARP
1751    pcVPS->setUseAdvRP  ( i, 0 );
1752    pcVPS->setARPStepNum( i, 1 );
1753#endif 
1754#if H_3D_SPIVMP
1755    pcVPS->setSubPULog2Size(i, 0);
1756#endif
1757    if ( i != 0 )
1758    {
1759      if( !( pcVPS->getDepthId( i ) == 1 ) )
1760      {
1761#if H_3D_IV_MERGE
1762        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1763#if H_3D_SPIVMP
1764        READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1765#endif
1766#endif
1767#if H_3D_ARP
1768        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1769
1770#endif
1771#if H_3D_NBDV_REF
1772        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1773#endif
1774#if H_3D_VSP
1775        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1776#endif
1777#if H_3D_DBBP
1778          READ_FLAG( uiCode, "use_dbbp_flag[i]" ); pcVPS->setUseDBBP( i, uiCode == 1 ? true : false );
1779#endif
1780      }
1781      else
1782      {
1783#if H_3D_IV_MERGE
1784        if(i!=1)
1785        {
1786          READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1787        }
1788#endif
1789#if H_3D_SPIVMP
1790        if (i!=1)
1791        {
1792          READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1793        }
1794#endif
1795#if H_3D_IV_MERGE
1796        READ_FLAG( uiCode, "mpi_flag[i]" );             pcVPS->setMPIFlag( i, uiCode == 1 ? true : false );
1797#endif
1798        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1799        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
1800#if H_3D_INTER_SDC
1801            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
1802#endif
1803      }
1804    }
1805  }
1806
1807  UInt uiCamParPrecision = 0; 
1808  Bool bCamParSlice      = false; 
1809  Bool bCamParPresentFlag = false;
1810
1811  READ_UVLC( uiCamParPrecision, "cp_precision" );
1812  for (UInt viewIndex=0; viewIndex<pcVPS->getNumViews(); viewIndex++)
1813  {
1814    pcVPS->setCamParPresent         ( viewIndex, false );
1815    pcVPS->setHasCamParInSliceHeader( viewIndex, false );
1816    READ_FLAG( uiCode, "cp_present_flag[i]" );                  bCamParPresentFlag = ( uiCode == 1);
1817    if ( bCamParPresentFlag )
1818    {
1819      READ_FLAG( uiCode, "cp_in_slice_segment_header_flag[i]" );          bCamParSlice = ( uiCode == 1);
1820      if ( !bCamParSlice )
1821      {
1822        for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
1823        {
1824          Int iCode; 
1825          READ_SVLC( iCode, "vps_cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
1826          READ_SVLC( iCode, "vps_cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
1827          READ_SVLC( iCode, "vps_cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
1828          READ_SVLC( iCode, "vps_cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
1829        }
1830      }
1831      pcVPS->initCamParaVPS( viewIndex, bCamParPresentFlag, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
1832    }
1833  }
1834  READ_UVLC (uiCode, "log2_sub_PU_MPI_size_minus3");              pcVPS->setSubPUMPILog2Size( uiCode + 3 ); 
1835  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
1836}
1837#endif
1838
1839Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
1840{
1841  UInt  uiCode;
1842  Int   iCode;
1843
1844#if ENC_DEC_TRACE
1845  xTraceSliceHeader(rpcSlice);
1846#endif
1847  TComPPS* pps = NULL;
1848  TComSPS* sps = NULL;
1849#if H_MV
1850  TComVPS* vps = NULL;
1851#endif
1852
1853  UInt firstSliceSegmentInPic;
1854  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1855  if( rpcSlice->getRapPicFlag())
1856  { 
1857    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
1858  }
1859  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1860  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1861  //!KS: need to add error handling code here, if PPS is not available
1862  assert(pps!=0);
1863  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1864  //!KS: need to add error handling code here, if SPS is not available
1865  assert(sps!=0);
1866#if H_MV
1867  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
1868  assert( vps != NULL );
1869 
1870  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
1871  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
1872  if ( sps->getVuiParametersPresentFlag() )
1873  {
1874    sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() ); 
1875  }
1876  rpcSlice->setVPS(vps);     
1877  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
1878  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
1879#if H_3D 
1880  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
1881#endif
1882#endif
1883  rpcSlice->setSPS(sps);
1884  rpcSlice->setPPS(pps);
1885  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1886  {
1887    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1888  }
1889  else
1890  {
1891    rpcSlice->setDependentSliceSegmentFlag(false);
1892  }
1893  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1894  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
1895  UInt sliceSegmentAddress = 0;
1896  Int bitsSliceSegmentAddress = 0;
1897  while(numCTUs>(1<<bitsSliceSegmentAddress))
1898  {
1899    bitsSliceSegmentAddress++;
1900  }
1901
1902  if(!firstSliceSegmentInPic)
1903  {
1904    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
1905  }
1906  //set uiCode to equal slice start address (or dependent slice start address)
1907  Int startCuAddress = maxParts*sliceSegmentAddress;
1908  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
1909  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
1910
1911  if (rpcSlice->getDependentSliceSegmentFlag())
1912  {
1913    rpcSlice->setNextSlice          ( false );
1914    rpcSlice->setNextSliceSegment ( true  );
1915  }
1916  else
1917  {
1918    rpcSlice->setNextSlice          ( true  );
1919    rpcSlice->setNextSliceSegment ( false );
1920
1921    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
1922    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
1923  }
1924 
1925  if(!rpcSlice->getDependentSliceSegmentFlag())
1926  {
1927#if H_MV   
1928    Int esb = 0; //Don't use i, otherwise will shadow something below
1929
1930    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
1931    {
1932      esb++; 
1933      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
1934    }
1935
1936    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
1937    {
1938      esb++; 
1939      READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
1940    }
1941    rpcSlice->checkCrossLayerBlaFlag( ); 
1942
1943#if !H_MV_HLS7_GEN
1944    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
1945    {
1946      esb++; 
1947      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
1948    }
1949#endif
1950
1951    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
1952#else
1953    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1954#endif     
1955    {
1956      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1957    }
1958
1959    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
1960    if( pps->getOutputFlagPresentFlag() )
1961    {
1962      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
1963    }
1964    else
1965    {
1966      rpcSlice->setPicOutputFlag( true );
1967    }
1968    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
1969    assert (sps->getChromaFormatIdc() == 1 );
1970    // if( separate_colour_plane_flag  ==  1 )
1971    //   colour_plane_id                                      u(2)
1972
1973
1974#if H_MV
1975    UInt slicePicOrderCntLsb = 0;
1976    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
1977    if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
1978    {
1979      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
1980    }   
1981
1982    Bool picOrderCntMSBZeroFlag = false;     
1983
1984    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
1985    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ); 
1986    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1987    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ); 
1988    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag(); 
1989
1990    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
1991
1992    Int picOrderCntMSB = 0; 
1993
1994    if ( !picOrderCntMSBZeroFlag )
1995    {
1996      Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
1997      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
1998      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
1999      Int prevPicOrderCntMsb = prevPicOrderCnt - prevPicOrderCntLsb;
2000           
2001      if( ( slicePicOrderCntLsb  <  prevPicOrderCntLsb ) && ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
2002      {
2003        picOrderCntMSB = prevPicOrderCntMsb + maxPicOrderCntLsb;
2004      }
2005      else if( (slicePicOrderCntLsb  >  prevPicOrderCntLsb )  && ( (slicePicOrderCntLsb - prevPicOrderCntLsb )  >  ( maxPicOrderCntLsb / 2 ) ) ) 
2006      {
2007        picOrderCntMSB = prevPicOrderCntMsb - maxPicOrderCntLsb;
2008      }
2009      else
2010      {
2011        picOrderCntMSB = prevPicOrderCntMsb;
2012      }   
2013    }
2014     
2015    rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
2016    if ( rpcSlice->getPocResetFlag() ) 
2017    {
2018      rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
2019      rpcSlice->setPOC              ( 0 );
2020    }     
2021#endif
2022
2023    if( rpcSlice->getIdrPicFlag() )
2024    {
2025#if !H_MV
2026      rpcSlice->setPOC(0);
2027#endif
2028      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2029      rps->setNumberOfNegativePictures(0);
2030      rps->setNumberOfPositivePictures(0);
2031      rps->setNumberOfLongtermPictures(0);
2032      rps->setNumberOfPictures(0);
2033      rpcSlice->setRPS(rps);
2034#if H_MV
2035      rpcSlice->setEnableTMVPFlag(false);
2036#endif
2037    }
2038    else
2039    {
2040#if !H_MV
2041      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
2042      Int iPOClsb = uiCode;
2043      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2044      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2045      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2046      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2047      Int iPOCmsb;
2048      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2049      {
2050        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2051      }
2052      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
2053      {
2054        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2055      }
2056      else
2057      {
2058        iPOCmsb = iPrevPOCmsb;
2059      }
2060      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2061        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2062        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2063      {
2064        // For BLA picture types, POCmsb is set to 0.
2065        iPOCmsb = 0;
2066      }
2067      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2068#endif
2069      TComReferencePictureSet* rps;
2070      rps = rpcSlice->getLocalRPS();
2071      rpcSlice->setRPS(rps);
2072      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2073      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2074      {
2075        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2076      }
2077      else // use reference to short-term reference picture set in PPS
2078      {
2079        Int numBits = 0;
2080        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2081        {
2082          numBits++;
2083        }
2084        if (numBits > 0)
2085        {
2086          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2087        }
2088        else
2089        {
2090          uiCode = 0;
2091        }
2092        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2093      }
2094      if(sps->getLongTermRefsPresent())
2095      {
2096        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2097        UInt numOfLtrp = 0;
2098        UInt numLtrpInSPS = 0;
2099        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2100        {
2101          READ_UVLC( uiCode, "num_long_term_sps");
2102          numLtrpInSPS = uiCode;
2103          numOfLtrp += numLtrpInSPS;
2104          rps->setNumberOfLongtermPictures(numOfLtrp);
2105        }
2106        Int bitsForLtrpInSPS = 0;
2107        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2108        {
2109          bitsForLtrpInSPS++;
2110        }
2111        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2112        numOfLtrp += uiCode;
2113        rps->setNumberOfLongtermPictures(numOfLtrp);
2114        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2115        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2116        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2117        {
2118          Int pocLsbLt;
2119          if (k < numLtrpInSPS)
2120          {
2121            uiCode = 0;
2122            if (bitsForLtrpInSPS > 0)
2123            {
2124              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2125            }
2126            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2127
2128            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2129            rps->setUsed(j,usedByCurrFromSPS);
2130          }
2131          else
2132          {
2133            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2134            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2135          }
2136          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2137          Bool mSBPresentFlag = uiCode ? true : false;
2138          if(mSBPresentFlag)                 
2139          {
2140            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2141            Bool deltaFlag = false;
2142            //            First LTRP                               || First LTRP from SH
2143            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2144            {
2145              deltaFlag = true;
2146            }
2147            if(deltaFlag)
2148            {
2149              deltaPocMSBCycleLT = uiCode;
2150            }
2151            else
2152            {
2153              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
2154            }
2155
2156            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2157                                        - iPOClsb + pocLsbLt;
2158            rps->setPOC     (j, pocLTCurr); 
2159            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2160            rps->setCheckLTMSBPresent(j,true); 
2161          }
2162          else
2163          {
2164            rps->setPOC     (j, pocLsbLt);
2165            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2166            rps->setCheckLTMSBPresent(j,false); 
2167           
2168            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2169            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2170            {
2171              deltaPocMSBCycleLT = 0;
2172            }
2173          }
2174          prevDeltaMSB = deltaPocMSBCycleLT;
2175        }
2176        offset += rps->getNumberOfLongtermPictures();
2177        rps->setNumberOfPictures(offset);       
2178      } 
2179      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2180        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2181        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2182      {
2183        // In the case of BLA picture types, rps data is read from slice header but ignored
2184        rps = rpcSlice->getLocalRPS();
2185        rps->setNumberOfNegativePictures(0);
2186        rps->setNumberOfPositivePictures(0);
2187        rps->setNumberOfLongtermPictures(0);
2188        rps->setNumberOfPictures(0);
2189        rpcSlice->setRPS(rps);
2190      }
2191      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2192      {
2193        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2194        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
2195      }
2196      else
2197      {
2198        rpcSlice->setEnableTMVPFlag(false);
2199      }
2200    }
2201#if H_MV
2202    Bool interLayerPredLayerIdcPresentFlag = false; 
2203    Int layerId       = rpcSlice->getLayerId(); 
2204    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
2205    {   
2206      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
2207      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
2208      {           
2209        if( !vps->getMaxOneActiveRefLayerFlag()) 
2210        {
2211          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
2212        }
2213        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
2214        {
2215          interLayerPredLayerIdcPresentFlag = true; 
2216          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
2217          {
2218            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
2219          }
2220        }
2221      } 
2222    }
2223    if ( !interLayerPredLayerIdcPresentFlag )
2224    {
2225      for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
2226      {
2227        rpcSlice->setInterLayerPredLayerIdc( i, rpcSlice->getRefLayerPicIdc( i ) );
2228      }
2229    }
2230#endif
2231    if(sps->getUseSAO())
2232    {
2233      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2234      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2235    }
2236
2237    if (rpcSlice->getIdrPicFlag())
2238    {
2239      rpcSlice->setEnableTMVPFlag(false);
2240    }
2241    if (!rpcSlice->isIntra())
2242    {
2243
2244      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2245      if (uiCode)
2246      {
2247        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2248        if (rpcSlice->isInterB())
2249        {
2250          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2251        }
2252        else
2253        {
2254          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2255        }
2256      }
2257      else
2258      {
2259        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2260        if (rpcSlice->isInterB())
2261        {
2262          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2263        }
2264        else
2265        {
2266          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2267        }
2268      }
2269    }
2270    // }
2271    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2272    if(!rpcSlice->isIntra())
2273    {
2274      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2275      {
2276        refPicListModification->setRefPicListModificationFlagL0( 0 );
2277      }
2278      else
2279      {
2280        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2281      }
2282
2283      if(refPicListModification->getRefPicListModificationFlagL0())
2284      { 
2285        uiCode = 0;
2286        Int i = 0;
2287        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2288        if ( numRpsCurrTempList0 > 1 )
2289        {
2290          Int length = 1;
2291          numRpsCurrTempList0 --;
2292          while ( numRpsCurrTempList0 >>= 1) 
2293          {
2294            length ++;
2295          }
2296          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2297          {
2298            READ_CODE( length, uiCode, "list_entry_l0" );
2299            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2300          }
2301        }
2302        else
2303        {
2304          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2305          {
2306            refPicListModification->setRefPicSetIdxL0(i, 0 );
2307          }
2308        }
2309      }
2310    }
2311    else
2312    {
2313      refPicListModification->setRefPicListModificationFlagL0(0);
2314    }
2315    if(rpcSlice->isInterB())
2316    {
2317      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2318      {
2319        refPicListModification->setRefPicListModificationFlagL1( 0 );
2320      }
2321      else
2322      {
2323        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2324      }
2325      if(refPicListModification->getRefPicListModificationFlagL1())
2326      {
2327        uiCode = 0;
2328        Int i = 0;
2329        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
2330        if ( numRpsCurrTempList1 > 1 )
2331        {
2332          Int length = 1;
2333          numRpsCurrTempList1 --;
2334          while ( numRpsCurrTempList1 >>= 1) 
2335          {
2336            length ++;
2337          }
2338          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2339          {
2340            READ_CODE( length, uiCode, "list_entry_l1" );
2341            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2342          }
2343        }
2344        else
2345        {
2346          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2347          {
2348            refPicListModification->setRefPicSetIdxL1(i, 0 );
2349          }
2350        }
2351      }
2352    } 
2353    else
2354    {
2355      refPicListModification->setRefPicListModificationFlagL1(0);
2356    }
2357    if (rpcSlice->isInterB())
2358    {
2359      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
2360    }
2361
2362    rpcSlice->setCabacInitFlag( false ); // default
2363    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
2364    {
2365      READ_FLAG(uiCode, "cabac_init_flag");
2366      rpcSlice->setCabacInitFlag( uiCode ? true : false );
2367    }
2368
2369    if ( rpcSlice->getEnableTMVPFlag() )
2370    {
2371      if ( rpcSlice->getSliceType() == B_SLICE )
2372      {
2373        READ_FLAG( uiCode, "collocated_from_l0_flag" );
2374        rpcSlice->setColFromL0Flag(uiCode);
2375      }
2376      else
2377      {
2378        rpcSlice->setColFromL0Flag( 1 );
2379      }
2380
2381      if ( rpcSlice->getSliceType() != I_SLICE &&
2382          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
2383           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
2384      {
2385        READ_UVLC( uiCode, "collocated_ref_idx" );
2386        rpcSlice->setColRefIdx(uiCode);
2387      }
2388      else
2389      {
2390        rpcSlice->setColRefIdx(0);
2391      }
2392    }
2393    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
2394    {
2395      xParsePredWeightTable(rpcSlice);
2396      rpcSlice->initWpScaling();
2397    }
2398#if H_3D_IC
2399    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) && !rpcSlice->getIsDepth())
2400    {
2401      UInt uiCodeTmp = 0;
2402
2403      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
2404      rpcSlice->setApplyIC( uiCodeTmp );
2405
2406      if ( uiCodeTmp )
2407      {
2408        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
2409        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
2410      }
2411    }
2412#endif
2413    if (!rpcSlice->isIntra())
2414    {
2415      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
2416#if H_3D_IV_MERGE
2417      if(rpcSlice->getIsDepth())
2418      {
2419        Bool bMPIFlag = rpcSlice->getVPS()->getMPIFlag( rpcSlice->getLayerIdInVps() ) ;
2420        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2421        rpcSlice->setMaxNumMergeCand(( ( bMPIFlag || ivMvPredFlag ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2422      }
2423      else
2424      {
2425        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2426        rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2427      }
2428
2429#else
2430      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
2431#endif
2432    }
2433
2434    READ_SVLC( iCode, "slice_qp_delta" );
2435    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
2436
2437    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
2438    assert( rpcSlice->getSliceQp() <=  51 );
2439
2440    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
2441    {
2442      READ_SVLC( iCode, "slice_qp_delta_cb" );
2443      rpcSlice->setSliceQpDeltaCb( iCode );
2444      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
2445      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
2446      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
2447      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
2448
2449      READ_SVLC( iCode, "slice_qp_delta_cr" );
2450      rpcSlice->setSliceQpDeltaCr( iCode );
2451      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
2452      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
2453      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
2454      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
2455    }
2456
2457    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
2458    {
2459      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
2460      {
2461        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
2462      }
2463      else
2464      { 
2465        rpcSlice->setDeblockingFilterOverrideFlag(0);
2466      }
2467      if(rpcSlice->getDeblockingFilterOverrideFlag())
2468      {
2469        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
2470        if(!rpcSlice->getDeblockingFilterDisable())
2471        {
2472          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
2473          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
2474                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
2475          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
2476          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
2477                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
2478        }
2479      }
2480      else
2481      {
2482        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
2483        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
2484        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
2485      }
2486    }
2487    else
2488    { 
2489      rpcSlice->setDeblockingFilterDisable       ( false );
2490      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
2491      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
2492    }
2493
2494    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
2495    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
2496
2497    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
2498    {
2499      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
2500    }
2501    else
2502    {
2503      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
2504    }
2505    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
2506
2507  }
2508 
2509    UInt *entryPointOffset          = NULL;
2510    UInt numEntryPointOffsets, offsetLenMinus1;
2511  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2512  {
2513    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
2514    if (numEntryPointOffsets>0)
2515    {
2516      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2517    }
2518    entryPointOffset = new UInt[numEntryPointOffsets];
2519    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2520    {
2521      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2522      entryPointOffset[ idx ] = uiCode + 1;
2523    }
2524  }
2525  else
2526  {
2527    rpcSlice->setNumEntryPointOffsets ( 0 );
2528  }
2529
2530#if H_3D
2531  if( rpcSlice->getVPS()->hasCamParInSliceHeader( rpcSlice->getViewIndex() )  && !rpcSlice->getIsDepth() )
2532  {
2533    UInt uiViewIndex = rpcSlice->getViewIndex();
2534    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
2535    {
2536      READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
2537      READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
2538      READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
2539      READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
2540    }
2541    rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
2542  }
2543#endif
2544
2545  if(pps->getSliceHeaderExtensionPresentFlag())
2546  {
2547#if H_MV
2548    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
2549    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
2550
2551    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
2552    {
2553      READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
2554    }
2555    else
2556    {
2557      rpcSlice->setPocResetIdc( 0 );
2558    }
2559
2560    if( rpcSlice->getPocResetIdc() !=  0 )
2561    {
2562      READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
2563    }
2564    else
2565    {
2566      // TODO Copy poc_reset_period from earlier picture
2567      rpcSlice->setPocResetPeriodId( 0 );
2568    }
2569   
2570    if( rpcSlice->getPocResetIdc() ==  3 ) 
2571    {
2572      READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
2573      READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
2574    }         
2575
2576    // Derive the value of PocMsbValRequiredFlag
2577    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
2578                                          /* || TODO related to vps_poc_lsb_aligned_flag */
2579                                          );
2580
2581    if( !rpcSlice->getPocMsbValRequiredFlag() /* TODO &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
2582    {
2583      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
2584    }
2585    else
2586    {
2587      if( rpcSlice->getPocMsbValRequiredFlag() )
2588      {
2589        rpcSlice->setPocMsbValPresentFlag( true );
2590      }
2591      else
2592      {
2593        rpcSlice->setPocMsbValPresentFlag( false );
2594      }
2595    }
2596
2597   
2598    if( rpcSlice->getPocMsbValPresentFlag() )
2599    {
2600      READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
2601    }
2602
2603    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
2604    {
2605     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
2606    }
2607    assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
2608#else
2609    READ_UVLC( uiCode, "slice_header_extension_length" );
2610    for(Int i=0; i<uiCode; i++)
2611    {
2612      UInt ignore;
2613      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2614    }
2615  }
2616#endif
2617  }
2618
2619
2620  m_pcBitstream->readByteAlignment();
2621
2622  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2623  {
2624    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2625   
2626    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2627    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2628    {
2629      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2630      {
2631        endOfSliceHeaderLocation++;
2632      }
2633    }
2634
2635    Int  curEntryPointOffset     = 0;
2636    Int  prevEntryPointOffset    = 0;
2637    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2638    {
2639      curEntryPointOffset += entryPointOffset[ idx ];
2640
2641      Int emulationPreventionByteCount = 0;
2642      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2643      {
2644        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
2645             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2646        {
2647          emulationPreventionByteCount++;
2648        }
2649      }
2650
2651      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2652      prevEntryPointOffset = curEntryPointOffset;
2653    }
2654
2655    if ( pps->getTilesEnabledFlag() )
2656    {
2657      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2658
2659      UInt prevPos = 0;
2660      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2661      {
2662        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2663        prevPos += entryPointOffset[ idx ];
2664      }
2665    }
2666    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2667    {
2668    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2669      rpcSlice->allocSubstreamSizes(numSubstreams);
2670      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2671      for (Int idx=0; idx<numSubstreams-1; idx++)
2672      {
2673        if ( idx < numEntryPointOffsets )
2674        {
2675          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2676        }
2677        else
2678        {
2679          pSubstreamSizes[ idx ] = 0;
2680        }
2681      }
2682    }
2683
2684    if (entryPointOffset)
2685    {
2686      delete [] entryPointOffset;
2687    }
2688  }
2689
2690  return;
2691}
2692 
2693Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2694{
2695  UInt uiCode;
2696  if(profilePresentFlag)
2697  {
2698    parseProfileTier(rpcPTL->getGeneralPTL());
2699  }
2700  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2701
2702  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2703  {
2704#if !H_MV
2705    if(profilePresentFlag)
2706    {
2707#endif
2708      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2709#if H_MV
2710    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
2711#else
2712    }
2713#endif
2714    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2715  }
2716 
2717  if (maxNumSubLayersMinus1 > 0)
2718  {
2719    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2720    {
2721      READ_CODE(2, uiCode, "reserved_zero_2bits");
2722      assert(uiCode == 0);
2723    }
2724  }
2725 
2726  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2727  {
2728    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2729    {
2730      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2731    }
2732    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2733    {
2734      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2735    }
2736  }
2737}
2738
2739Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2740{
2741  UInt uiCode;
2742  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2743  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2744  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2745  for(Int j = 0; j < 32; j++)
2746  {
2747    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2748  }
2749  READ_FLAG(uiCode, "general_progressive_source_flag");
2750  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2751
2752  READ_FLAG(uiCode, "general_interlaced_source_flag");
2753  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2754 
2755  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2756  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2757 
2758  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2759  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2760 
2761  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2762  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2763  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2764}
2765
2766Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2767{
2768  ruiBit = false;
2769  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2770  if(iBitsLeft <= 8)
2771  {
2772    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2773    if (uiPeekValue == (1<<(iBitsLeft-1)))
2774    {
2775      ruiBit = true;
2776    }
2777  }
2778}
2779
2780Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2781{
2782  assert(0);
2783}
2784
2785Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2786{
2787  assert(0);
2788}
2789
2790Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2791{
2792  assert(0);
2793}
2794
2795Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2796{
2797  assert(0);
2798}
2799
2800Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2801{
2802  assert(0);
2803}
2804
2805Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2806{
2807  assert(0);
2808}
2809
2810/** Parse I_PCM information.
2811* \param pcCU pointer to CU
2812* \param uiAbsPartIdx CU index
2813* \param uiDepth CU depth
2814* \returns Void
2815*
2816* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2817*/
2818Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2819{
2820  assert(0);
2821}
2822
2823Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2824{ 
2825  assert(0);
2826}
2827
2828Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2829{
2830  assert(0);
2831}
2832
2833Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2834{
2835  assert(0);
2836}
2837
2838Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2839{
2840  assert(0);
2841}
2842
2843Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
2844{
2845  assert(0);
2846}
2847
2848Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2849{
2850  Int qp;
2851  Int  iDQp;
2852
2853  xReadSvlc( iDQp );
2854
2855  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
2856  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2857
2858  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
2859  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2860
2861  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2862}
2863
2864Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
2865{
2866  assert(0);
2867}
2868
2869Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
2870{
2871  assert(0);
2872}
2873
2874Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
2875{
2876  assert(0);
2877}
2878
2879Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
2880{
2881  assert(0);
2882}
2883
2884Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
2885{
2886  assert(0);
2887}
2888
2889Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
2890{
2891  assert(0);
2892}
2893
2894Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
2895{
2896  assert(0);
2897}
2898
2899#if H_3D_ARP
2900Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2901{
2902  assert(0);
2903}
2904#endif
2905#if H_3D_IC
2906Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2907{
2908  assert(0);
2909}
2910#endif
2911#if H_3D_INTER_SDC
2912Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2913{ 
2914  assert(0);
2915}
2916
2917Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2918{
2919  assert(0);
2920}
2921
2922#endif
2923#if H_3D_DBBP
2924  Void TDecCavlc::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2925  {
2926    assert(0);
2927  }
2928#endif
2929// ====================================================================================================================
2930// Protected member functions
2931// ====================================================================================================================
2932
2933/** parse explicit wp tables
2934* \param TComSlice* pcSlice
2935* \returns Void
2936*/
2937Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
2938{
2939  wpScalingParam  *wp;
2940  Bool            bChroma     = true; // color always present in HEVC ?
2941  SliceType       eSliceType  = pcSlice->getSliceType();
2942  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
2943  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
2944  UInt            uiTotalSignalledWeightFlags = 0;
2945 
2946  Int iDeltaDenom;
2947  // decode delta_luma_log2_weight_denom :
2948  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
2949  assert( uiLog2WeightDenomLuma <= 7 );
2950  if( bChroma ) 
2951  {
2952    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
2953    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
2954    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
2955    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
2956  }
2957
2958  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
2959  {
2960    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
2961    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2962    {
2963      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2964
2965      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
2966      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2967      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2968
2969      UInt  uiCode;
2970      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
2971      wp[0].bPresentFlag = ( uiCode == 1 );
2972      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
2973    }
2974    if ( bChroma ) 
2975    {
2976      UInt  uiCode;
2977      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2978      {
2979        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2980        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
2981        wp[1].bPresentFlag = ( uiCode == 1 );
2982        wp[2].bPresentFlag = ( uiCode == 1 );
2983        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
2984      }
2985    }
2986    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2987    {
2988      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2989      if ( wp[0].bPresentFlag ) 
2990      {
2991        Int iDeltaWeight;
2992        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
2993        assert( iDeltaWeight >= -128 );
2994        assert( iDeltaWeight <=  127 );
2995        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
2996        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
2997        assert( wp[0].iOffset >= -128 );
2998        assert( wp[0].iOffset <=  127 );
2999      }
3000      else 
3001      {
3002        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3003        wp[0].iOffset = 0;
3004      }
3005      if ( bChroma ) 
3006      {
3007        if ( wp[1].bPresentFlag ) 
3008        {
3009          for ( Int j=1 ; j<3 ; j++ ) 
3010          {
3011            Int iDeltaWeight;
3012            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3013            assert( iDeltaWeight >= -128 );
3014            assert( iDeltaWeight <=  127 );
3015            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3016
3017            Int iDeltaChroma;
3018            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3019            assert( iDeltaChroma >= -512 );
3020            assert( iDeltaChroma <=  511 );
3021            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3022            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3023          }
3024        }
3025        else 
3026        {
3027          for ( Int j=1 ; j<3 ; j++ ) 
3028          {
3029            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3030            wp[j].iOffset = 0;
3031          }
3032        }
3033      }
3034    }
3035
3036    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
3037    {
3038      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3039
3040      wp[0].bPresentFlag = false;
3041      wp[1].bPresentFlag = false;
3042      wp[2].bPresentFlag = false;
3043    }
3044  }
3045  assert(uiTotalSignalledWeightFlags<=24);
3046}
3047
3048/** decode quantization matrix
3049* \param scalingList quantization matrix information
3050*/
3051Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3052{
3053  UInt  code, sizeId, listId;
3054  Bool scalingListPredModeFlag;
3055  //for each size
3056  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3057  {
3058    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3059    {
3060      READ_FLAG( code, "scaling_list_pred_mode_flag");
3061      scalingListPredModeFlag = (code) ? true : false;
3062      if(!scalingListPredModeFlag) //Copy Mode
3063      {
3064        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3065        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3066        if( sizeId > SCALING_LIST_8x8 )
3067        {
3068          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3069        }
3070        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3071
3072      }
3073      else //DPCM Mode
3074      {
3075        xDecodeScalingList(scalingList, sizeId, listId);
3076      }
3077    }
3078  }
3079
3080  return;
3081}
3082/** decode DPCM
3083* \param scalingList  quantization matrix information
3084* \param sizeId size index
3085* \param listId list index
3086*/
3087Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3088{
3089  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3090  Int data;
3091  Int scalingListDcCoefMinus8 = 0;
3092  Int nextCoef = SCALING_LIST_START_VALUE;
3093  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3094  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3095
3096  if( sizeId > SCALING_LIST_8x8 )
3097  {
3098    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3099    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3100    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3101  }
3102
3103  for(i = 0; i < coefNum; i++)
3104  {
3105    READ_SVLC( data, "scaling_list_delta_coef");
3106    nextCoef = (nextCoef + data + 256 ) % 256;
3107    dst[scan[i]] = nextCoef;
3108  }
3109}
3110
3111Bool TDecCavlc::xMoreRbspData()
3112{ 
3113  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3114
3115  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3116  if (bitsLeft > 8)
3117  {
3118    return true;
3119  }
3120
3121  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3122  Int cnt = bitsLeft;
3123
3124  // remove trailing bits equal to zero
3125  while ((cnt>0) && ((lastByte & 1) == 0))
3126  {
3127    lastByte >>= 1;
3128    cnt--;
3129  }
3130  // remove bit equal to one
3131  cnt--;
3132
3133  // we should not have a negative number of bits
3134  assert (cnt>=0);
3135
3136  // we have more data, if cnt is not zero
3137  return (cnt>0);
3138}
3139
3140//! \}
3141
Note: See TracBrowser for help on using the repository browser.