source: SHVCSoftware/branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 459

Last change on this file since 459 was 458, checked in by qualcomm, 12 years ago

Fix to align all_ref_layer_active_flag according to JCT-VC N1008v3. Related to ticket [JCTVCSHM software] #5.

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