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

Last change on this file since 412 was 411, checked in by qualcomm, 12 years ago

JCTVC-N0244: Signaling of poc_reset_flag in the slice header (MACRO: POC_RESET_FLAG)

Signal poc_reset_flag in slice header, which will reset POC value of the current picture and decrement the POC of pictures in the DPB.

From: Adarsh K. Ramasubramonian <aramasub@…>

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