source: SHVCSoftware/branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 421

Last change on this file since 421 was 414, checked in by sony, 12 years ago

IL_SL_SIGNALLING_N0371

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