source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 857

Last change on this file since 857 was 857, checked in by qualcomm, 10 years ago

H_MV_HLS_7_VPS_P0307_23

Implementation for adoption of (VPS/P0307/VPS VUI extension)

  • Move vps_vui_present_flag to the end of syntax table
  • Remove vps_vui_offset
  • Add vps_non_vui_extension_length and vps_non_vui_extension_data_byte

submitted by Hendry (fhendry@…

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