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

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

H_MV_HLS_7_VPS_P0125_24

Implemention for P0125 (VPS/P0125/VPS extension offset ) #24 Decision: Keep it as a reserved FFFF value

submitted by Hendry (fhendry@…)

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