source: SHVCSoftware/branches/SHM-5.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 567

Last change on this file since 567 was 566, checked in by seregin, 11 years ago

remove VERT_MV_CONSTRAINT macro

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