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

Last change on this file since 858 was 858, checked in by qualcomm, 11 years ago

JCTVC-P0306: Coding some fixed-length coded elements in VPS extn as ue(v) and other minor modifications (Macro: H_MV_HLS_7_VPS_P0306_22)

From: Adarsh K. Ramasubramonian <aramasub@…>

  • Property svn:eol-style set to native
File size: 120.0 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_HLS_7_VPS_P0306_22
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_HLS_7_VPS_P0306_22
1460    READ_UVLC( 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#if H_MV_HLS_7_VPS_P0306_22
1482        Int numBits = 1;
1483        while ((1 << numBits) < (pcVPS->getVpsNumRepFormatsMinus1() + 1))
1484        {
1485          numBits++;
1486        }
1487        READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1488#else
1489        READ_CODE( 8, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1490#endif
1491      }
1492    }
1493  }
1494
1495  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
1496#if H_MV_HLS7_GEN
1497  READ_FLAG( uiCode, "vps_poc_lsb_aligned_flag" ); pcVPS->setVpsPocLsbAlignedFlag( uiCode == 1 );
1498#endif
1499  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1500  {
1501    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) )  ==  0 )
1502    {     
1503      READ_FLAG( uiCode, "poc_lsb_not_present_flag" ); pcVPS->setPocLsbNotPresentFlag( i, uiCode == 1 );
1504    }
1505  }
1506
1507#if H_MV_HLS_7_RESERVED_FLAGS
1508  READ_FLAG( uiCode, "vps_reserved_zero_flag" ); 
1509#endif
1510  parseDpbSize( pcVPS ); 
1511
1512  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
1513
1514  READ_FLAG( uiCode, "default_direct_dependency_flag" ); pcVPS->setDefaultDirectDependencyFlag( uiCode == 1 );
1515  if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1516  { 
1517    READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2, uiCode, "default_direct_dependency_type" ); pcVPS->setDefaultDirectDependencyType( uiCode );
1518  }
1519
1520  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1521  {
1522    for( Int j = 0; j < i; j++ )
1523    {
1524      if (pcVPS->getDirectDependencyFlag( i, j) )
1525      {       
1526        if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1527        { 
1528          pcVPS->setDirectDependencyType( i, j , pcVPS->getDefaultDirectDependencyType( ) );
1529        }
1530        else
1531        {
1532          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1533        }
1534      }
1535    }
1536  } 
1537
1538#if H_MV_HLS_7_VPS_P0307_23
1539  READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode ); 
1540  for ( Int i = 1; i <= pcVPS->getVpsNonVuiExtensionLength(); i++ )
1541  {
1542    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" );
1543  }
1544  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
1545#endif
1546#if !H_MV_HLS_7_RESERVED_FLAGS
1547  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" ); 
1548#endif
1549  if( pcVPS->getVpsVuiPresentFlag() )
1550  {
1551    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
1552    parseVPSVUI( pcVPS ); 
1553  }     
1554#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
1555  {
1556    TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1557    assert( pcVPSVUI ); 
1558    pcVPSVUI->inferVpsVui( false ); 
1559  }
1560#endif
1561
1562  pcVPS->checkVPSExtensionSyntax(); 
1563}
1564
1565Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
1566{
1567  assert( pcRepFormat ); 
1568
1569  UInt uiCode; 
1570
1571  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
1572  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
1573  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" ); pcRepFormat->setChromaAndBitDepthVpsPresentFlag( uiCode == 1 );
1574
1575  pcRepFormat->checkChromaAndBitDepthVpsPresentFlag( i ); 
1576
1577  if ( pcRepFormat->getChromaAndBitDepthVpsPresentFlag() )
1578  { 
1579  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
1580  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
1581  {
1582    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
1583  }
1584  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
1585  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
1586  }
1587  else
1588  {
1589    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false ); 
1590  }
1591}
1592
1593
1594Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
1595{
1596  assert( pcVPS ); 
1597
1598  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1599
1600  assert( pcVPSVUI ); 
1601
1602  UInt uiCode; 
1603  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
1604  if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
1605  { 
1606    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
1607  }
1608#if H_MV_HLS_7_MISC_P0068_21
1609  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
1610  {
1611    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
1612  }
1613#endif
1614  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
1615  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
1616  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1617  {
1618#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1619    for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
1620#else
1621    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
1622#endif
1623    {
1624      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
1625      {
1626        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
1627        {
1628          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
1629        }
1630        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
1631        {
1632          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
1633        }
1634        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
1635        {
1636          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
1637          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
1638        }
1639        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
1640        {
1641          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
1642          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
1643        }
1644      }
1645    }
1646  }
1647
1648#if H_MV_HLS_7_VPS_P0076_15
1649  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1650  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1651  {
1652    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1653  }
1654  else
1655  {
1656    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
1657  }
1658
1659  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1660  {
1661    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1662    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1663    parseVideoSignalInfo( curVideoSignalInfo ); 
1664    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1665  }
1666
1667  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1668  {
1669    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1670    {
1671      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1672      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
1673    }
1674  }
1675  else
1676  {
1677    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1678    {
1679      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ); 
1680    }
1681  }
1682#endif
1683
1684  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
1685  if( !pcVPSVUI->getTilesNotInUseFlag() ) 
1686  {     
1687    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1688    {
1689      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
1690      if( pcVPSVUI->getTilesInUseFlag( i ) ) 
1691      {
1692        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
1693      }
1694    } 
1695
1696    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1697    {
1698      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
1699      { 
1700        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getRefLayerId(pcVPS->getLayerIdInNuh( i ) , j  )); 
1701        if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
1702        {
1703          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
1704        }
1705      } 
1706    }
1707  } 
1708 
1709  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
1710 
1711  if( !pcVPSVUI->getWppNotInUseFlag( ))
1712  {
1713    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1714    {
1715      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
1716    }
1717  }
1718
1719#if H_MV_HLS_7_RESERVED_FLAGS
1720  READ_CODE( 3, uiCode, "vps_vui_reserved_zero_3bits" ); 
1721#endif
1722
1723  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
1724
1725  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1726  {
1727    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1728    {
1729      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
1730      {
1731        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
1732        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1733        {
1734          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
1735          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1736          {
1737            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
1738          }
1739        }
1740      }
1741    }
1742  }
1743
1744#if !H_MV_HLS_7_VPS_P0076_15
1745  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1746  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1747  {
1748    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1749  }
1750  else
1751  {
1752    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
1753  }
1754
1755  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1756  {
1757    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1758    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1759    parseVideoSignalInfo( curVideoSignalInfo ); 
1760    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1761  }
1762 
1763  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1764  {
1765    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1766    {
1767      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1768      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
1769    }
1770  }
1771  else
1772  {
1773    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1774    {
1775      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ); 
1776    }
1777  }
1778#endif
1779  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
1780  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
1781  {
1782    parseVpsVuiBspHrdParameters( pcVPS ); 
1783}
1784#if H_MV_HLS_7_MISC_P0182_13
1785  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1786  {
1787    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 ) 
1788    {
1789      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
1790    }
1791  }
1792#endif
1793}
1794
1795Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
1796{
1797  assert( pcVPS ); 
1798
1799  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1800
1801  assert( pcVPSVUI ); 
1802
1803  TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters(); 
1804 
1805  assert ( vpsVuiBspHrdP );
1806
1807  UInt uiCode; 
1808  READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vpsVuiBspHrdP->setVpsNumBspHrdParametersMinus1( uiCode );
1809  for( Int i = 0; i <= vpsVuiBspHrdP->getVpsNumBspHrdParametersMinus1( ); i++ )
1810  { 
1811    if( i > 0 )
1812    {
1813      READ_FLAG( uiCode, "bsp_cprms_present_flag" ); vpsVuiBspHrdP->setBspCprmsPresentFlag( i, uiCode == 1 );
1814    }
1815    TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i ); 
1816    parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getBspCprmsPresentFlag( i ), pcVPS->getMaxSubLayersMinus1() );     
1817  } 
1818  for( Int h = 1; h <= pcVPS->getVpsNumLayerSetsMinus1(); h++ )
1819  { 
1820    READ_UVLC( uiCode, "num_bitstream_partitions" ); vpsVuiBspHrdP->setNumBitstreamPartitions( h, uiCode );
1821    for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ ) 
1822    {
1823      for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ ) 
1824      {
1825        if( pcVPS->getLayerIdIncludedFlag( h ,j ) )
1826        {
1827          READ_FLAG( uiCode, "layer_in_bsp_flag" ); vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, uiCode == 1 );
1828        }
1829        else
1830        {
1831          vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec
1832        }
1833      }
1834    }
1835    vpsVuiBspHrdP->checkLayerInBspFlag( pcVPS, h ); 
1836   
1837    if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
1838    { 
1839      READ_UVLC( uiCode, "num_bsp_sched_combinations" ); vpsVuiBspHrdP->setNumBspSchedCombinations( h, uiCode );
1840      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
1841      {
1842        for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
1843        { 
1844          READ_UVLC( uiCode, "bsp_comb_hrd_idx" ); vpsVuiBspHrdP->setBspCombHrdIdx( h, i, j, uiCode );
1845          READ_UVLC( uiCode, "bsp_comb_sched_idx" ); vpsVuiBspHrdP->setBspCombSchedIdx( h, i, j, uiCode );
1846        } 
1847      }
1848    } 
1849  } 
1850} 
1851
1852Void TDecCavlc::parseVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo ) 
1853{
1854  UInt uiCode; 
1855  READ_CODE( 3, uiCode, "video_vps_format" );             pcVideoSignalInfo->setVideoVpsFormat( uiCode );
1856  READ_FLAG( uiCode, "video_full_range_vps_flag" );       pcVideoSignalInfo->setVideoFullRangeVpsFlag( uiCode == 1 );
1857  READ_CODE( 8, uiCode, "colour_primaries_vps" );         pcVideoSignalInfo->setColourPrimariesVps( uiCode );
1858  READ_CODE( 8, uiCode, "transfer_characteristics_vps" ); pcVideoSignalInfo->setTransferCharacteristicsVps( uiCode );
1859  READ_CODE( 8, uiCode, "matrix_coeffs_vps" );            pcVideoSignalInfo->setMatrixCoeffsVps( uiCode );
1860}
1861
1862Void TDecCavlc::parseDpbSize( TComVPS* vps )
1863{
1864  UInt uiCode; 
1865  TComDpbSize* dpbSize = vps->getDpbSize(); 
1866  assert ( dpbSize != 0 ); 
1867
1868  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
1869  { 
1870    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
1871#if H_MV_HLS_7_HRD_P0156_7
1872    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
1873#else
1874    for( Int j = 0; j  <=  vps->getMaxTLayers() - 1 ; j++ )
1875#endif
1876    { 
1877      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
1878      {
1879        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
1880      }
1881      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
1882      { 
1883#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1884        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
1885#else
1886        for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
1887#endif
1888        {
1889          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
1890        }
1891        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
1892#if H_MV_HLS7_GEN
1893        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) ) 
1894        {
1895          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
1896          {
1897            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1" ); dpbSize->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode );
1898          }
1899        }
1900#endif
1901        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
1902      }
1903      else
1904      {
1905        if ( j > 0 )
1906        {
1907          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
1908          {
1909            dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
1910          }
1911          dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
1912          dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
1913        }
1914      }
1915    } 
1916  } 
1917}
1918#endif
1919
1920#if H_3D
1921Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
1922{
1923  UInt uiCode; 
1924  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1925  {
1926#if H_3D_ARP
1927    pcVPS->setUseAdvRP  ( i, 0 );
1928    pcVPS->setARPStepNum( i, 1 );
1929#endif 
1930#if H_3D_SPIVMP
1931    pcVPS->setSubPULog2Size(i, 0);
1932#endif
1933    if ( i != 0 )
1934    {
1935      if( !( pcVPS->getDepthId( i ) == 1 ) )
1936      {
1937#if H_3D_IV_MERGE
1938        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1939#if H_3D_SPIVMP
1940#if SEC_SPIVMP_MCP_SIZE_G0077
1941        READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1942#else
1943        READ_UVLC (uiCode, "log2_sub_PU_size_minus2");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1944#endif
1945#endif
1946#endif
1947#if H_3D_ARP
1948        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1949
1950#endif
1951#if H_3D_NBDV_REF
1952        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1953#endif
1954#if H_3D_VSP
1955        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1956#endif
1957#if H_3D_DBBP
1958          READ_FLAG( uiCode, "use_dbbp_flag[i]" ); pcVPS->setUseDBBP( i, uiCode == 1 ? true : false );
1959#endif
1960      }
1961      else
1962      {
1963#if H_3D_IV_MERGE
1964        if(i!=1)
1965        {
1966          READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1967        }
1968#endif
1969#if H_3D_SPIVMP
1970        if (i!=1)
1971        {
1972#if SEC_SPIVMP_MCP_SIZE_G0077
1973          READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1974#else
1975          READ_UVLC (uiCode, "log2_sub_PU_size_minus2[i]");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1976#endif
1977        }
1978#endif
1979#if H_3D_IV_MERGE
1980        READ_FLAG( uiCode, "mpi_flag[i]" );             pcVPS->setMPIFlag( i, uiCode == 1 ? true : false );
1981#endif
1982        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1983        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
1984#if H_3D_INTER_SDC
1985            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
1986#endif
1987      }
1988    }
1989  }
1990
1991  UInt uiCamParPrecision = 0; 
1992  Bool bCamParSlice      = false; 
1993  Bool bCamParPresentFlag = false;
1994
1995  READ_UVLC( uiCamParPrecision, "cp_precision" );
1996  for (UInt viewIndex=0; viewIndex<pcVPS->getNumViews(); viewIndex++)
1997  {
1998#if FIX_CAM_PARS_COLLECTOR
1999    pcVPS->setCamParPresent         ( viewIndex, false );
2000    pcVPS->setHasCamParInSliceHeader( viewIndex, false );
2001#endif
2002    READ_FLAG( uiCode, "cp_present_flag[i]" );                  bCamParPresentFlag = ( uiCode == 1);
2003    if ( bCamParPresentFlag )
2004    {
2005      READ_FLAG( uiCode, "cp_in_slice_segment_header_flag[i]" );          bCamParSlice = ( uiCode == 1);
2006      if ( !bCamParSlice )
2007      {
2008        for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
2009        {
2010          Int iCode; 
2011          READ_SVLC( iCode, "vps_cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
2012          READ_SVLC( iCode, "vps_cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
2013          READ_SVLC( iCode, "vps_cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
2014          READ_SVLC( iCode, "vps_cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
2015        }
2016      }
2017      pcVPS->initCamParaVPS( viewIndex, bCamParPresentFlag, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
2018    }
2019  }
2020#if QC_SPIVMP_MPI_G0119
2021  READ_UVLC (uiCode, "log2_sub_PU_MPI_size_minus3");              pcVPS->setSubPUMPILog2Size( uiCode + 3 ); 
2022#endif
2023  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
2024}
2025#endif
2026
2027Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
2028{
2029  UInt  uiCode;
2030  Int   iCode;
2031
2032#if ENC_DEC_TRACE
2033  xTraceSliceHeader(rpcSlice);
2034#endif
2035  TComPPS* pps = NULL;
2036  TComSPS* sps = NULL;
2037#if H_MV
2038  TComVPS* vps = NULL;
2039#endif
2040
2041  UInt firstSliceSegmentInPic;
2042  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
2043  if( rpcSlice->getRapPicFlag())
2044  { 
2045    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
2046  }
2047  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
2048  pps = parameterSetManager->getPrefetchedPPS(uiCode);
2049  //!KS: need to add error handling code here, if PPS is not available
2050  assert(pps!=0);
2051  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
2052  //!KS: need to add error handling code here, if SPS is not available
2053  assert(sps!=0);
2054#if H_MV
2055  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
2056  assert( vps != NULL );
2057 
2058  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
2059  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
2060  if ( sps->getVuiParametersPresentFlag() )
2061  {
2062    sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() ); 
2063  }
2064  rpcSlice->setVPS(vps);     
2065  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
2066  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
2067#if H_3D 
2068  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
2069#endif
2070#endif
2071  rpcSlice->setSPS(sps);
2072  rpcSlice->setPPS(pps);
2073  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
2074  {
2075    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
2076  }
2077  else
2078  {
2079    rpcSlice->setDependentSliceSegmentFlag(false);
2080  }
2081  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2082  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
2083  UInt sliceSegmentAddress = 0;
2084  Int bitsSliceSegmentAddress = 0;
2085  while(numCTUs>(1<<bitsSliceSegmentAddress))
2086  {
2087    bitsSliceSegmentAddress++;
2088  }
2089
2090  if(!firstSliceSegmentInPic)
2091  {
2092    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
2093  }
2094  //set uiCode to equal slice start address (or dependent slice start address)
2095  Int startCuAddress = maxParts*sliceSegmentAddress;
2096  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
2097  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
2098
2099  if (rpcSlice->getDependentSliceSegmentFlag())
2100  {
2101    rpcSlice->setNextSlice          ( false );
2102    rpcSlice->setNextSliceSegment ( true  );
2103  }
2104  else
2105  {
2106    rpcSlice->setNextSlice          ( true  );
2107    rpcSlice->setNextSliceSegment ( false );
2108
2109    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
2110    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
2111  }
2112 
2113  if(!rpcSlice->getDependentSliceSegmentFlag())
2114  {
2115#if H_MV   
2116    Int esb = 0; //Don't use i, otherwise will shadow something below
2117
2118    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2119    {
2120      esb++; 
2121      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
2122    }
2123
2124    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2125    {
2126      esb++; 
2127      READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
2128    }
2129    rpcSlice->checkCrossLayerBlaFlag( ); 
2130
2131#if !H_MV_HLS7_GEN
2132    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2133    {
2134      esb++; 
2135      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
2136    }
2137#endif
2138
2139    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
2140#else
2141    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2142#endif     
2143    {
2144      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2145    }
2146
2147    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
2148    if( pps->getOutputFlagPresentFlag() )
2149    {
2150      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
2151    }
2152    else
2153    {
2154      rpcSlice->setPicOutputFlag( true );
2155    }
2156    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
2157    assert (sps->getChromaFormatIdc() == 1 );
2158    // if( separate_colour_plane_flag  ==  1 )
2159    //   colour_plane_id                                      u(2)
2160
2161
2162#if H_MV
2163    UInt slicePicOrderCntLsb = 0;
2164    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
2165    if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
2166    {
2167      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
2168    }   
2169
2170    Bool picOrderCntMSBZeroFlag = false;     
2171
2172    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
2173    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ); 
2174    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
2175    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ); 
2176    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag(); 
2177
2178    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
2179
2180    Int picOrderCntMSB = 0; 
2181
2182    if ( !picOrderCntMSBZeroFlag )
2183    {
2184      Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
2185      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
2186      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
2187      Int prevPicOrderCntMsb = prevPicOrderCnt - prevPicOrderCntLsb;
2188           
2189      if( ( slicePicOrderCntLsb  <  prevPicOrderCntLsb ) && ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
2190      {
2191        picOrderCntMSB = prevPicOrderCntMsb + maxPicOrderCntLsb;
2192      }
2193      else if( (slicePicOrderCntLsb  >  prevPicOrderCntLsb )  && ( (slicePicOrderCntLsb - prevPicOrderCntLsb )  >  ( maxPicOrderCntLsb / 2 ) ) ) 
2194      {
2195        picOrderCntMSB = prevPicOrderCntMsb - maxPicOrderCntLsb;
2196      }
2197      else
2198      {
2199        picOrderCntMSB = prevPicOrderCntMsb;
2200      }   
2201    }
2202     
2203    rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
2204    if ( rpcSlice->getPocResetFlag() ) 
2205    {
2206      rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
2207      rpcSlice->setPOC              ( 0 );
2208    }     
2209#endif
2210
2211    if( rpcSlice->getIdrPicFlag() )
2212    {
2213#if !H_MV
2214      rpcSlice->setPOC(0);
2215#endif
2216      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2217      rps->setNumberOfNegativePictures(0);
2218      rps->setNumberOfPositivePictures(0);
2219      rps->setNumberOfLongtermPictures(0);
2220      rps->setNumberOfPictures(0);
2221      rpcSlice->setRPS(rps);
2222#if H_MV
2223      rpcSlice->setEnableTMVPFlag(false);
2224#endif
2225    }
2226    else
2227    {
2228#if !H_MV
2229      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
2230      Int iPOClsb = uiCode;
2231      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2232      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2233      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2234      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2235      Int iPOCmsb;
2236      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2237      {
2238        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2239      }
2240      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
2241      {
2242        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2243      }
2244      else
2245      {
2246        iPOCmsb = iPrevPOCmsb;
2247      }
2248      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2249        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2250        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2251      {
2252        // For BLA picture types, POCmsb is set to 0.
2253        iPOCmsb = 0;
2254      }
2255      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2256#endif
2257      TComReferencePictureSet* rps;
2258      rps = rpcSlice->getLocalRPS();
2259      rpcSlice->setRPS(rps);
2260      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2261      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2262      {
2263        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2264      }
2265      else // use reference to short-term reference picture set in PPS
2266      {
2267        Int numBits = 0;
2268        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2269        {
2270          numBits++;
2271        }
2272        if (numBits > 0)
2273        {
2274          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2275        }
2276        else
2277        {
2278          uiCode = 0;
2279        }
2280        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2281      }
2282      if(sps->getLongTermRefsPresent())
2283      {
2284        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2285        UInt numOfLtrp = 0;
2286        UInt numLtrpInSPS = 0;
2287        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2288        {
2289          READ_UVLC( uiCode, "num_long_term_sps");
2290          numLtrpInSPS = uiCode;
2291          numOfLtrp += numLtrpInSPS;
2292          rps->setNumberOfLongtermPictures(numOfLtrp);
2293        }
2294        Int bitsForLtrpInSPS = 0;
2295        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2296        {
2297          bitsForLtrpInSPS++;
2298        }
2299        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2300        numOfLtrp += uiCode;
2301        rps->setNumberOfLongtermPictures(numOfLtrp);
2302        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2303        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2304        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2305        {
2306          Int pocLsbLt;
2307          if (k < numLtrpInSPS)
2308          {
2309            uiCode = 0;
2310            if (bitsForLtrpInSPS > 0)
2311            {
2312              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2313            }
2314            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2315
2316            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2317            rps->setUsed(j,usedByCurrFromSPS);
2318          }
2319          else
2320          {
2321            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2322            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2323          }
2324          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2325          Bool mSBPresentFlag = uiCode ? true : false;
2326          if(mSBPresentFlag)                 
2327          {
2328            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2329            Bool deltaFlag = false;
2330            //            First LTRP                               || First LTRP from SH
2331            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2332            {
2333              deltaFlag = true;
2334            }
2335            if(deltaFlag)
2336            {
2337              deltaPocMSBCycleLT = uiCode;
2338            }
2339            else
2340            {
2341              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
2342            }
2343
2344            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2345                                        - iPOClsb + pocLsbLt;
2346            rps->setPOC     (j, pocLTCurr); 
2347            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2348            rps->setCheckLTMSBPresent(j,true); 
2349          }
2350          else
2351          {
2352            rps->setPOC     (j, pocLsbLt);
2353            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2354            rps->setCheckLTMSBPresent(j,false); 
2355           
2356            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2357            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2358            {
2359              deltaPocMSBCycleLT = 0;
2360            }
2361          }
2362          prevDeltaMSB = deltaPocMSBCycleLT;
2363        }
2364        offset += rps->getNumberOfLongtermPictures();
2365        rps->setNumberOfPictures(offset);       
2366      } 
2367      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2368        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2369        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2370      {
2371        // In the case of BLA picture types, rps data is read from slice header but ignored
2372        rps = rpcSlice->getLocalRPS();
2373        rps->setNumberOfNegativePictures(0);
2374        rps->setNumberOfPositivePictures(0);
2375        rps->setNumberOfLongtermPictures(0);
2376        rps->setNumberOfPictures(0);
2377        rpcSlice->setRPS(rps);
2378      }
2379      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2380      {
2381        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2382        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
2383      }
2384      else
2385      {
2386        rpcSlice->setEnableTMVPFlag(false);
2387      }
2388    }
2389#if H_MV
2390    Bool interLayerPredLayerIdcPresentFlag = false; 
2391    Int layerId       = rpcSlice->getLayerId(); 
2392    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
2393    {   
2394      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
2395      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
2396      {           
2397        if( !vps->getMaxOneActiveRefLayerFlag()) 
2398        {
2399          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
2400        }
2401        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
2402        {
2403          interLayerPredLayerIdcPresentFlag = true; 
2404          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
2405          {
2406            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
2407          }
2408        }
2409      } 
2410    }
2411    if ( !interLayerPredLayerIdcPresentFlag )
2412    {
2413      for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
2414      {
2415        rpcSlice->setInterLayerPredLayerIdc( i, rpcSlice->getRefLayerPicIdc( i ) );
2416      }
2417    }
2418#endif
2419    if(sps->getUseSAO())
2420    {
2421      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2422      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2423    }
2424
2425    if (rpcSlice->getIdrPicFlag())
2426    {
2427      rpcSlice->setEnableTMVPFlag(false);
2428    }
2429    if (!rpcSlice->isIntra())
2430    {
2431
2432      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2433      if (uiCode)
2434      {
2435        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2436        if (rpcSlice->isInterB())
2437        {
2438          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2439        }
2440        else
2441        {
2442          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2443        }
2444      }
2445      else
2446      {
2447        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2448        if (rpcSlice->isInterB())
2449        {
2450          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2451        }
2452        else
2453        {
2454          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2455        }
2456      }
2457    }
2458    // }
2459    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2460    if(!rpcSlice->isIntra())
2461    {
2462      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2463      {
2464        refPicListModification->setRefPicListModificationFlagL0( 0 );
2465      }
2466      else
2467      {
2468        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2469      }
2470
2471      if(refPicListModification->getRefPicListModificationFlagL0())
2472      { 
2473        uiCode = 0;
2474        Int i = 0;
2475        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2476        if ( numRpsCurrTempList0 > 1 )
2477        {
2478          Int length = 1;
2479          numRpsCurrTempList0 --;
2480          while ( numRpsCurrTempList0 >>= 1) 
2481          {
2482            length ++;
2483          }
2484          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2485          {
2486            READ_CODE( length, uiCode, "list_entry_l0" );
2487            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2488          }
2489        }
2490        else
2491        {
2492          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2493          {
2494            refPicListModification->setRefPicSetIdxL0(i, 0 );
2495          }
2496        }
2497      }
2498    }
2499    else
2500    {
2501      refPicListModification->setRefPicListModificationFlagL0(0);
2502    }
2503    if(rpcSlice->isInterB())
2504    {
2505      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2506      {
2507        refPicListModification->setRefPicListModificationFlagL1( 0 );
2508      }
2509      else
2510      {
2511        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2512      }
2513      if(refPicListModification->getRefPicListModificationFlagL1())
2514      {
2515        uiCode = 0;
2516        Int i = 0;
2517        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
2518        if ( numRpsCurrTempList1 > 1 )
2519        {
2520          Int length = 1;
2521          numRpsCurrTempList1 --;
2522          while ( numRpsCurrTempList1 >>= 1) 
2523          {
2524            length ++;
2525          }
2526          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2527          {
2528            READ_CODE( length, uiCode, "list_entry_l1" );
2529            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2530          }
2531        }
2532        else
2533        {
2534          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2535          {
2536            refPicListModification->setRefPicSetIdxL1(i, 0 );
2537          }
2538        }
2539      }
2540    } 
2541    else
2542    {
2543      refPicListModification->setRefPicListModificationFlagL1(0);
2544    }
2545    if (rpcSlice->isInterB())
2546    {
2547      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
2548    }
2549
2550    rpcSlice->setCabacInitFlag( false ); // default
2551    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
2552    {
2553      READ_FLAG(uiCode, "cabac_init_flag");
2554      rpcSlice->setCabacInitFlag( uiCode ? true : false );
2555    }
2556
2557    if ( rpcSlice->getEnableTMVPFlag() )
2558    {
2559      if ( rpcSlice->getSliceType() == B_SLICE )
2560      {
2561        READ_FLAG( uiCode, "collocated_from_l0_flag" );
2562        rpcSlice->setColFromL0Flag(uiCode);
2563      }
2564      else
2565      {
2566        rpcSlice->setColFromL0Flag( 1 );
2567      }
2568
2569      if ( rpcSlice->getSliceType() != I_SLICE &&
2570          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
2571           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
2572      {
2573        READ_UVLC( uiCode, "collocated_ref_idx" );
2574        rpcSlice->setColRefIdx(uiCode);
2575      }
2576      else
2577      {
2578        rpcSlice->setColRefIdx(0);
2579      }
2580    }
2581    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
2582    {
2583      xParsePredWeightTable(rpcSlice);
2584      rpcSlice->initWpScaling();
2585    }
2586#if H_3D_IC
2587    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) && !rpcSlice->getIsDepth())
2588    {
2589      UInt uiCodeTmp = 0;
2590
2591      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
2592      rpcSlice->setApplyIC( uiCodeTmp );
2593
2594      if ( uiCodeTmp )
2595      {
2596        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
2597        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
2598      }
2599    }
2600#endif
2601    if (!rpcSlice->isIntra())
2602    {
2603      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
2604#if H_3D_IV_MERGE
2605      if(rpcSlice->getIsDepth())
2606      {
2607        Bool bMPIFlag = rpcSlice->getVPS()->getMPIFlag( rpcSlice->getLayerIdInVps() ) ;
2608        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2609        rpcSlice->setMaxNumMergeCand(( ( bMPIFlag || ivMvPredFlag ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2610      }
2611      else
2612      {
2613        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2614        rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2615      }
2616
2617#else
2618      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
2619#endif
2620    }
2621
2622    READ_SVLC( iCode, "slice_qp_delta" );
2623    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
2624
2625    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
2626    assert( rpcSlice->getSliceQp() <=  51 );
2627
2628    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
2629    {
2630      READ_SVLC( iCode, "slice_qp_delta_cb" );
2631      rpcSlice->setSliceQpDeltaCb( iCode );
2632      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
2633      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
2634      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
2635      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
2636
2637      READ_SVLC( iCode, "slice_qp_delta_cr" );
2638      rpcSlice->setSliceQpDeltaCr( iCode );
2639      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
2640      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
2641      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
2642      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
2643    }
2644
2645    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
2646    {
2647      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
2648      {
2649        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
2650      }
2651      else
2652      { 
2653        rpcSlice->setDeblockingFilterOverrideFlag(0);
2654      }
2655      if(rpcSlice->getDeblockingFilterOverrideFlag())
2656      {
2657        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
2658        if(!rpcSlice->getDeblockingFilterDisable())
2659        {
2660          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
2661          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
2662                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
2663          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
2664          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
2665                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
2666        }
2667      }
2668      else
2669      {
2670        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
2671        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
2672        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
2673      }
2674    }
2675    else
2676    { 
2677      rpcSlice->setDeblockingFilterDisable       ( false );
2678      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
2679      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
2680    }
2681
2682    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
2683    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
2684
2685    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
2686    {
2687      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
2688    }
2689    else
2690    {
2691      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
2692    }
2693    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
2694
2695  }
2696 
2697    UInt *entryPointOffset          = NULL;
2698    UInt numEntryPointOffsets, offsetLenMinus1;
2699  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2700  {
2701    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
2702    if (numEntryPointOffsets>0)
2703    {
2704      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2705    }
2706    entryPointOffset = new UInt[numEntryPointOffsets];
2707    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2708    {
2709      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2710      entryPointOffset[ idx ] = uiCode + 1;
2711    }
2712  }
2713  else
2714  {
2715    rpcSlice->setNumEntryPointOffsets ( 0 );
2716  }
2717
2718#if H_3D
2719  if( rpcSlice->getVPS()->hasCamParInSliceHeader( rpcSlice->getViewIndex() )  && !rpcSlice->getIsDepth() )
2720  {
2721    UInt uiViewIndex = rpcSlice->getViewIndex();
2722    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
2723    {
2724      READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
2725      READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
2726      READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
2727      READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
2728    }
2729    rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
2730  }
2731#endif
2732
2733  if(pps->getSliceHeaderExtensionPresentFlag())
2734  {
2735#if !H_MV_HLS7_GEN   
2736    READ_UVLC(uiCode,"slice_header_extension_length");
2737    for(Int i=0; i<uiCode; i++)
2738    {
2739      UInt ignore;
2740      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2741    }
2742  }
2743#else
2744#if H_MV
2745    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
2746    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
2747
2748    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
2749    {
2750      READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
2751    }
2752
2753    if( rpcSlice->getPocResetIdc() !=  0 )
2754    {
2755      READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
2756    }
2757   
2758    if( rpcSlice->getPocResetIdc() ==  3 ) 
2759    {
2760      READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
2761      READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
2762    }         
2763
2764    if( !rpcSlice->getPocMsbValRequiredFlag() &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
2765    {
2766      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
2767    }
2768   
2769    if( rpcSlice->getPocMsbValPresentFlag() )
2770    {
2771      READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
2772    }
2773
2774    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 );
2775    {
2776     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
2777    }
2778    assert( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
2779#else
2780    READ_UVLC( uiCode, "slice_header_extension_length" );
2781    for(Int i=0; i<uiCode; i++)
2782    {
2783      UInt ignore;
2784      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2785    }
2786  }
2787#endif
2788#endif
2789
2790
2791  m_pcBitstream->readByteAlignment();
2792
2793  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2794  {
2795    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2796   
2797    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2798    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2799    {
2800      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2801      {
2802        endOfSliceHeaderLocation++;
2803      }
2804    }
2805
2806    Int  curEntryPointOffset     = 0;
2807    Int  prevEntryPointOffset    = 0;
2808    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2809    {
2810      curEntryPointOffset += entryPointOffset[ idx ];
2811
2812      Int emulationPreventionByteCount = 0;
2813      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2814      {
2815        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
2816             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2817        {
2818          emulationPreventionByteCount++;
2819        }
2820      }
2821
2822      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2823      prevEntryPointOffset = curEntryPointOffset;
2824    }
2825
2826    if ( pps->getTilesEnabledFlag() )
2827    {
2828      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2829
2830      UInt prevPos = 0;
2831      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2832      {
2833        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2834        prevPos += entryPointOffset[ idx ];
2835      }
2836    }
2837    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2838    {
2839    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2840      rpcSlice->allocSubstreamSizes(numSubstreams);
2841      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2842      for (Int idx=0; idx<numSubstreams-1; idx++)
2843      {
2844        if ( idx < numEntryPointOffsets )
2845        {
2846          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2847        }
2848        else
2849        {
2850          pSubstreamSizes[ idx ] = 0;
2851        }
2852      }
2853    }
2854
2855    if (entryPointOffset)
2856    {
2857      delete [] entryPointOffset;
2858    }
2859  }
2860
2861  return;
2862}
2863 
2864Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2865{
2866  UInt uiCode;
2867  if(profilePresentFlag)
2868  {
2869    parseProfileTier(rpcPTL->getGeneralPTL());
2870  }
2871  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2872
2873  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2874  {
2875#if !H_MV
2876    if(profilePresentFlag)
2877    {
2878#endif
2879      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2880#if H_MV
2881    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
2882#else
2883    }
2884#endif
2885    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2886  }
2887 
2888  if (maxNumSubLayersMinus1 > 0)
2889  {
2890    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2891    {
2892      READ_CODE(2, uiCode, "reserved_zero_2bits");
2893      assert(uiCode == 0);
2894    }
2895  }
2896 
2897  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2898  {
2899    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2900    {
2901      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2902    }
2903    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2904    {
2905      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2906    }
2907  }
2908}
2909
2910Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2911{
2912  UInt uiCode;
2913  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2914  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2915  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2916  for(Int j = 0; j < 32; j++)
2917  {
2918    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2919  }
2920  READ_FLAG(uiCode, "general_progressive_source_flag");
2921  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2922
2923  READ_FLAG(uiCode, "general_interlaced_source_flag");
2924  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2925 
2926  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2927  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2928 
2929  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2930  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2931 
2932  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2933  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2934  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2935}
2936
2937Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2938{
2939  ruiBit = false;
2940  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2941  if(iBitsLeft <= 8)
2942  {
2943    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2944    if (uiPeekValue == (1<<(iBitsLeft-1)))
2945    {
2946      ruiBit = true;
2947    }
2948  }
2949}
2950
2951Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2952{
2953  assert(0);
2954}
2955
2956Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2957{
2958  assert(0);
2959}
2960
2961Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2962{
2963  assert(0);
2964}
2965
2966Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2967{
2968  assert(0);
2969}
2970
2971Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2972{
2973  assert(0);
2974}
2975
2976Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2977{
2978  assert(0);
2979}
2980
2981/** Parse I_PCM information.
2982* \param pcCU pointer to CU
2983* \param uiAbsPartIdx CU index
2984* \param uiDepth CU depth
2985* \returns Void
2986*
2987* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2988*/
2989Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2990{
2991  assert(0);
2992}
2993
2994Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2995{ 
2996  assert(0);
2997}
2998
2999Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3000{
3001  assert(0);
3002}
3003
3004Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
3005{
3006  assert(0);
3007}
3008
3009Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
3010{
3011  assert(0);
3012}
3013
3014Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
3015{
3016  assert(0);
3017}
3018
3019Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3020{
3021  Int qp;
3022  Int  iDQp;
3023
3024  xReadSvlc( iDQp );
3025
3026  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
3027  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
3028
3029  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
3030  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
3031
3032  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
3033}
3034
3035Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
3036{
3037  assert(0);
3038}
3039
3040Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
3041{
3042  assert(0);
3043}
3044
3045Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
3046{
3047  assert(0);
3048}
3049
3050Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
3051{
3052  assert(0);
3053}
3054
3055Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
3056{
3057  assert(0);
3058}
3059
3060Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
3061{
3062  assert(0);
3063}
3064
3065Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
3066{
3067  assert(0);
3068}
3069
3070#if H_3D_ARP
3071Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3072{
3073  assert(0);
3074}
3075#endif
3076#if H_3D_IC
3077Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3078{
3079  assert(0);
3080}
3081#endif
3082#if H_3D_INTER_SDC
3083#if QC_SDC_UNIFY_G0130
3084Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3085{ 
3086  assert(0);
3087}
3088
3089Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3090{
3091  assert(0);
3092}
3093#else
3094Void TDecCavlc::parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3095{
3096  assert(0);
3097}
3098
3099Void TDecCavlc::parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
3100{
3101  assert(0);
3102}
3103#endif
3104#endif
3105#if H_3D_DBBP
3106  Void TDecCavlc::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3107  {
3108    assert(0);
3109  }
3110#endif
3111// ====================================================================================================================
3112// Protected member functions
3113// ====================================================================================================================
3114
3115/** parse explicit wp tables
3116* \param TComSlice* pcSlice
3117* \returns Void
3118*/
3119Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3120{
3121  wpScalingParam  *wp;
3122  Bool            bChroma     = true; // color always present in HEVC ?
3123  SliceType       eSliceType  = pcSlice->getSliceType();
3124  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3125  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3126  UInt            uiTotalSignalledWeightFlags = 0;
3127 
3128  Int iDeltaDenom;
3129  // decode delta_luma_log2_weight_denom :
3130  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3131  assert( uiLog2WeightDenomLuma <= 7 );
3132  if( bChroma ) 
3133  {
3134    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3135    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3136    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
3137    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3138  }
3139
3140  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
3141  {
3142    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3143    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3144    {
3145      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3146
3147      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3148      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3149      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3150
3151      UInt  uiCode;
3152      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3153      wp[0].bPresentFlag = ( uiCode == 1 );
3154      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
3155    }
3156    if ( bChroma ) 
3157    {
3158      UInt  uiCode;
3159      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3160      {
3161        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3162        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3163        wp[1].bPresentFlag = ( uiCode == 1 );
3164        wp[2].bPresentFlag = ( uiCode == 1 );
3165        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
3166      }
3167    }
3168    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3169    {
3170      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3171      if ( wp[0].bPresentFlag ) 
3172      {
3173        Int iDeltaWeight;
3174        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3175        assert( iDeltaWeight >= -128 );
3176        assert( iDeltaWeight <=  127 );
3177        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3178        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3179        assert( wp[0].iOffset >= -128 );
3180        assert( wp[0].iOffset <=  127 );
3181      }
3182      else 
3183      {
3184        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3185        wp[0].iOffset = 0;
3186      }
3187      if ( bChroma ) 
3188      {
3189        if ( wp[1].bPresentFlag ) 
3190        {
3191          for ( Int j=1 ; j<3 ; j++ ) 
3192          {
3193            Int iDeltaWeight;
3194            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3195            assert( iDeltaWeight >= -128 );
3196            assert( iDeltaWeight <=  127 );
3197            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3198
3199            Int iDeltaChroma;
3200            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3201            assert( iDeltaChroma >= -512 );
3202            assert( iDeltaChroma <=  511 );
3203            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3204            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3205          }
3206        }
3207        else 
3208        {
3209          for ( Int j=1 ; j<3 ; j++ ) 
3210          {
3211            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3212            wp[j].iOffset = 0;
3213          }
3214        }
3215      }
3216    }
3217
3218    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
3219    {
3220      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3221
3222      wp[0].bPresentFlag = false;
3223      wp[1].bPresentFlag = false;
3224      wp[2].bPresentFlag = false;
3225    }
3226  }
3227  assert(uiTotalSignalledWeightFlags<=24);
3228}
3229
3230/** decode quantization matrix
3231* \param scalingList quantization matrix information
3232*/
3233Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3234{
3235  UInt  code, sizeId, listId;
3236  Bool scalingListPredModeFlag;
3237  //for each size
3238  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3239  {
3240    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3241    {
3242      READ_FLAG( code, "scaling_list_pred_mode_flag");
3243      scalingListPredModeFlag = (code) ? true : false;
3244      if(!scalingListPredModeFlag) //Copy Mode
3245      {
3246        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3247        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3248        if( sizeId > SCALING_LIST_8x8 )
3249        {
3250          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3251        }
3252        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3253
3254      }
3255      else //DPCM Mode
3256      {
3257        xDecodeScalingList(scalingList, sizeId, listId);
3258      }
3259    }
3260  }
3261
3262  return;
3263}
3264/** decode DPCM
3265* \param scalingList  quantization matrix information
3266* \param sizeId size index
3267* \param listId list index
3268*/
3269Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3270{
3271  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3272  Int data;
3273  Int scalingListDcCoefMinus8 = 0;
3274  Int nextCoef = SCALING_LIST_START_VALUE;
3275  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3276  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3277
3278  if( sizeId > SCALING_LIST_8x8 )
3279  {
3280    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3281    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3282    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3283  }
3284
3285  for(i = 0; i < coefNum; i++)
3286  {
3287    READ_SVLC( data, "scaling_list_delta_coef");
3288    nextCoef = (nextCoef + data + 256 ) % 256;
3289    dst[scan[i]] = nextCoef;
3290  }
3291}
3292
3293Bool TDecCavlc::xMoreRbspData()
3294{ 
3295  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3296
3297  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3298  if (bitsLeft > 8)
3299  {
3300    return true;
3301  }
3302
3303  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3304  Int cnt = bitsLeft;
3305
3306  // remove trailing bits equal to zero
3307  while ((cnt>0) && ((lastByte & 1) == 0))
3308  {
3309    lastByte >>= 1;
3310    cnt--;
3311  }
3312  // remove bit equal to one
3313  cnt--;
3314
3315  // we should not have a negative number of bits
3316  assert (cnt>=0);
3317
3318  // we have more data, if cnt is not zero
3319  return (cnt>0);
3320}
3321
3322//! \}
3323
Note: See TracBrowser for help on using the repository browser.