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

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

Signal view ID-related syntax elements in VPS (Macro: VIEW_ID_RELATED_SIGNALING)

Introduce signaling of view_id_len_minus1 and view_id_val.

From: Adarsh K. Ramasubramonian <aramasub@…>

  • Property svn:eol-style set to native
File size: 90.8 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license.
5*
6* Copyright (c) 2010-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 !VPS_MOVE_DIR_DEPENDENCY_FLAG
1208#if VPS_EXTN_DIRECT_REF_LAYERS
1209  // For layer 0
1210  vps->setNumDirectRefLayers(0, 0);
1211  // For other layers
1212  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1213  {
1214    UInt numDirectRefLayers = 0;
1215    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1216    {
1217      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
1218      if(uiCode)
1219      {
1220        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
1221        numDirectRefLayers++;
1222      }
1223    }
1224    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
1225  }
1226#endif
1227#endif
1228#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
1229  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
1230  for(i = 1; i < vps->getMaxLayers(); i++)
1231  {
1232    for(j = 0; j < i; j++)
1233    {
1234      if (vps->getDirectDependencyFlag(i, j))
1235      {
1236        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); vps->setDirectDependencyType(i, j, uiCode);
1237      }
1238    }
1239  }
1240#endif
1241#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1242  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
1243#endif
1244
1245  READ_FLAG( uiCode,  "vps_vui_present_flag" );
1246  if (uiCode)
1247  {
1248#if VPS_VUI
1249    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1250    {
1251      READ_FLAG( uiCode, "vps_vui_alignment_bit_equal_to_one"); assert(uiCode == 1);
1252    }
1253    parseVPSVUI(vps);
1254#endif
1255  }
1256}
1257#endif
1258#if REPN_FORMAT_IN_VPS
1259Void  TDecCavlc::parseRepFormat      ( RepFormat *repFormat )
1260{
1261  UInt uiCode;
1262  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
1263 
1264  if( repFormat->getChromaFormatVpsIdc() == 3 )
1265  {
1266    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
1267  }
1268
1269  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
1270  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
1271 
1272  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
1273  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
1274
1275}
1276#endif
1277#if VPS_VUI
1278Void TDecCavlc::parseVPSVUI(TComVPS *vps)
1279{
1280  UInt i,j;
1281  UInt uiCode;
1282#if VPS_VUI_BITRATE_PICRATE
1283  READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
1284  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
1285
1286  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
1287  {
1288    for( i = 0; i < vps->getNumLayerSets(); i++ )
1289    {
1290      for( j = 0; j < vps->getMaxTLayers(); j++ )
1291      {
1292        if( parseFlag && vps->getBitRatePresentVpsFlag() )
1293        {
1294          READ_FLAG( uiCode,        "bit_rate_present_vps_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
1295        }
1296        else
1297        {
1298          vps->setBitRatePresentFlag( i, j, false );
1299        }
1300        if( parseFlag && vps->getPicRatePresentVpsFlag() )
1301        {
1302          READ_FLAG( uiCode,        "pic_rate_present_vps_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
1303        }
1304        else
1305        {
1306          vps->setPicRatePresentFlag( i, j, false );
1307        }
1308        if( parseFlag && vps->getBitRatePresentFlag(i, j) )
1309        {
1310          READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
1311          READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
1312        }
1313        else
1314        {
1315          vps->setAvgBitRate( i, j, 0 );
1316          vps->setMaxBitRate( i, j, 0 );
1317        }
1318        if( parseFlag && vps->getPicRatePresentFlag(i, j) )
1319        {
1320          READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
1321          READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
1322        }
1323        else
1324        {
1325          vps->setConstPicRateIdc( i, j, 0 );
1326          vps->setAvgPicRate     ( i, j, 0 );
1327        }
1328      }
1329    }
1330  }
1331#endif
1332#if TILE_BOUNDARY_ALIGNED_FLAG
1333  for(i = 1; i < vps->getMaxLayers(); i++)
1334  {
1335    for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
1336    {
1337      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));     
1338    }
1339  } 
1340#endif
1341#if N0160_VUI_EXT_ILP_REF
1342    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 ); 
1343  if( vps->getNumIlpRestrictedRefLayers())
1344  {
1345    for(i = 1; i < vps->getMaxLayers(); i++)
1346    {
1347      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
1348      {
1349        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode ); 
1350        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) 
1351        { 
1352          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 ); 
1353          if(vps->getCtuBasedOffsetEnabledFlag(i,j)) 
1354          {
1355            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode ); 
1356          }
1357        } 
1358      } 
1359    }
1360  }
1361#endif
1362}
1363#endif
1364Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
1365{
1366  UInt  uiCode;
1367  Int   iCode;
1368
1369#if ENC_DEC_TRACE
1370  xTraceSliceHeader(rpcSlice);
1371#endif
1372  TComPPS* pps = NULL;
1373  TComSPS* sps = NULL;
1374
1375  UInt firstSliceSegmentInPic;
1376  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1377  if( rpcSlice->getRapPicFlag())
1378  {
1379    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
1380  }
1381  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1382  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1383  //!KS: need to add error handling code here, if PPS is not available
1384  assert(pps!=0);
1385  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1386  //!KS: need to add error handling code here, if SPS is not available
1387  assert(sps!=0);
1388  rpcSlice->setSPS(sps);
1389  rpcSlice->setPPS(pps);
1390  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1391  {
1392    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1393  }
1394  else
1395  {
1396    rpcSlice->setDependentSliceSegmentFlag(false);
1397  }
1398#if REPN_FORMAT_IN_VPS
1399  Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1400#else
1401  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1402#endif
1403  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
1404  UInt sliceSegmentAddress = 0;
1405  Int bitsSliceSegmentAddress = 0;
1406  while(numCTUs>(1<<bitsSliceSegmentAddress))
1407  {
1408    bitsSliceSegmentAddress++;
1409  }
1410
1411  if(!firstSliceSegmentInPic)
1412  {
1413    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
1414  }
1415  //set uiCode to equal slice start address (or dependent slice start address)
1416  Int startCuAddress = maxParts*sliceSegmentAddress;
1417  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
1418  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
1419
1420  if (rpcSlice->getDependentSliceSegmentFlag())
1421  {
1422    rpcSlice->setNextSlice          ( false );
1423    rpcSlice->setNextSliceSegment ( true  );
1424  }
1425  else
1426  {
1427    rpcSlice->setNextSlice          ( true  );
1428    rpcSlice->setNextSliceSegment ( false );
1429
1430    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
1431    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
1432  }
1433
1434  if(!rpcSlice->getDependentSliceSegmentFlag())
1435  {
1436
1437#if SH_DISCARDABLE_FLAG
1438    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
1439    {
1440      READ_FLAG(uiCode, "discardable_flag"); // ignored
1441    }
1442    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1443    {
1444      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1445    }
1446#else
1447    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1448    {
1449      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1450    }
1451#endif
1452
1453    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
1454    if( pps->getOutputFlagPresentFlag() )
1455    {
1456      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
1457    }
1458    else
1459    {
1460      rpcSlice->setPicOutputFlag( true );
1461    }
1462    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
1463    assert (sps->getChromaFormatIdc() == 1 );
1464    // if( separate_colour_plane_flag  ==  1 )
1465    //   colour_plane_id                                      u(2)
1466
1467    if( rpcSlice->getIdrPicFlag() )
1468    {
1469      rpcSlice->setPOC(0);
1470      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
1471      rps->setNumberOfNegativePictures(0);
1472      rps->setNumberOfPositivePictures(0);
1473      rps->setNumberOfLongtermPictures(0);
1474      rps->setNumberOfPictures(0);
1475      rpcSlice->setRPS(rps);
1476    }
1477    else
1478    {
1479      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
1480      Int iPOClsb = uiCode;
1481      Int iPrevPOC = rpcSlice->getPrevPOC();
1482      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
1483      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
1484      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
1485      Int iPOCmsb;
1486      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
1487      {
1488        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
1489      }
1490      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
1491      {
1492        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
1493      }
1494      else
1495      {
1496        iPOCmsb = iPrevPOCmsb;
1497      }
1498      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1499        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1500        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1501      {
1502        // For BLA picture types, POCmsb is set to 0.
1503        iPOCmsb = 0;
1504      }
1505      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
1506
1507      TComReferencePictureSet* rps;
1508      rps = rpcSlice->getLocalRPS();
1509      rpcSlice->setRPS(rps);
1510      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
1511      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
1512      {
1513        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
1514      }
1515      else // use reference to short-term reference picture set in PPS
1516      {
1517        Int numBits = 0;
1518        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
1519        {
1520          numBits++;
1521        }
1522        if (numBits > 0)
1523        {
1524          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
1525        }
1526        else
1527        {
1528          uiCode = 0;
1529        }
1530        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
1531      }
1532      if(sps->getLongTermRefsPresent())
1533      {
1534        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
1535        UInt numOfLtrp = 0;
1536        UInt numLtrpInSPS = 0;
1537        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
1538        {
1539          READ_UVLC( uiCode, "num_long_term_sps");
1540          numLtrpInSPS = uiCode;
1541          numOfLtrp += numLtrpInSPS;
1542          rps->setNumberOfLongtermPictures(numOfLtrp);
1543        }
1544        Int bitsForLtrpInSPS = 0;
1545        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
1546        {
1547          bitsForLtrpInSPS++;
1548        }
1549        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
1550        numOfLtrp += uiCode;
1551        rps->setNumberOfLongtermPictures(numOfLtrp);
1552        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
1553        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
1554        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
1555        {
1556          Int pocLsbLt;
1557          if (k < numLtrpInSPS)
1558          {
1559            uiCode = 0;
1560            if (bitsForLtrpInSPS > 0)
1561            {
1562              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
1563            }
1564            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
1565
1566            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
1567            rps->setUsed(j,usedByCurrFromSPS);
1568          }
1569          else
1570          {
1571            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
1572            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
1573          }
1574          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
1575          Bool mSBPresentFlag = uiCode ? true : false;
1576          if(mSBPresentFlag)
1577          {
1578            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
1579            Bool deltaFlag = false;
1580            //            First LTRP                               || First LTRP from SH
1581            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
1582            {
1583              deltaFlag = true;
1584            }
1585            if(deltaFlag)
1586            {
1587              deltaPocMSBCycleLT = uiCode;
1588            }
1589            else
1590            {
1591              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
1592            }
1593
1594            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
1595                                        - iPOClsb + pocLsbLt;
1596            rps->setPOC     (j, pocLTCurr);
1597            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
1598            rps->setCheckLTMSBPresent(j,true);
1599          }
1600          else
1601          {
1602            rps->setPOC     (j, pocLsbLt);
1603            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
1604            rps->setCheckLTMSBPresent(j,false);
1605          }
1606          prevDeltaMSB = deltaPocMSBCycleLT;
1607        }
1608        offset += rps->getNumberOfLongtermPictures();
1609        rps->setNumberOfPictures(offset);
1610      }
1611      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1612        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1613        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1614      {
1615        // In the case of BLA picture types, rps data is read from slice header but ignored
1616        rps = rpcSlice->getLocalRPS();
1617        rps->setNumberOfNegativePictures(0);
1618        rps->setNumberOfPositivePictures(0);
1619        rps->setNumberOfLongtermPictures(0);
1620        rps->setNumberOfPictures(0);
1621        rpcSlice->setRPS(rps);
1622      }
1623      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
1624      {
1625        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
1626        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
1627      }
1628      else
1629      {
1630        rpcSlice->setEnableTMVPFlag(false);
1631      }
1632    }
1633
1634#if SVC_EXTENSION
1635#if JCTVC_M0458_INTERLAYER_RPS_SIG
1636    rpcSlice->setActiveNumILRRefIdx(0);
1637#if ILP_SSH_SIG
1638    if((sps->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
1639#else
1640    if((sps->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
1641#endif
1642    {
1643      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
1644      rpcSlice->setInterLayerPredEnabledFlag(uiCode);
1645      if( rpcSlice->getInterLayerPredEnabledFlag())
1646      {
1647        if(rpcSlice->getNumILRRefIdx() > 1)
1648        {
1649          Int numBits = 1;
1650          while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
1651          {
1652            numBits++;
1653          }
1654          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
1655          {
1656            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
1657            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
1658          }
1659          else
1660          {
1661            rpcSlice->setActiveNumILRRefIdx(1);
1662          }
1663#if ILP_NUM_REF_CHK
1664          if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
1665          {
1666            for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
1667            {
1668              rpcSlice->setInterLayerPredLayerIdc(i,i);
1669            }
1670          }
1671          else
1672          {
1673#endif
1674          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
1675          {
1676            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
1677            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
1678          }
1679#if ILP_NUM_REF_CHK
1680          }
1681#endif
1682        }
1683        else
1684        {
1685          rpcSlice->setActiveNumILRRefIdx(1);
1686          rpcSlice->setInterLayerPredLayerIdc(0,0);
1687        }
1688      }
1689    }
1690#if ILP_SSH_SIG
1691    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
1692    {
1693      rpcSlice->setInterLayerPredEnabledFlag(true);
1694      rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
1695      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
1696      {
1697        rpcSlice->setInterLayerPredLayerIdc(i,i);
1698      }
1699    }
1700#endif
1701#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
1702    rpcSlice->setInterLayerSamplePredOnlyFlag( false );
1703    if( rpcSlice->getNumSamplePredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() > 0 )
1704    {
1705      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" );
1706      rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode > 0 );
1707    }
1708#endif
1709#else
1710    if( rpcSlice->getLayerId() > 0 )
1711    {
1712      rpcSlice->setNumILRRefIdx( rpcSlice->getVPS()->getNumDirectRefLayers( rpcSlice->getLayerId() ) );
1713    }
1714#endif
1715#endif
1716
1717    if(sps->getUseSAO())
1718    {
1719      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
1720      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
1721    }
1722
1723    if (rpcSlice->getIdrPicFlag())
1724    {
1725      rpcSlice->setEnableTMVPFlag(false);
1726    }
1727    if (!rpcSlice->isIntra())
1728    {
1729
1730      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
1731      if (uiCode)
1732      {
1733        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
1734        if (rpcSlice->isInterB())
1735        {
1736          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
1737        }
1738        else
1739        {
1740          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
1741        }
1742      }
1743      else
1744      {
1745        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
1746        if (rpcSlice->isInterB())
1747        {
1748          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
1749        }
1750        else
1751        {
1752          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
1753        }
1754      }
1755    }
1756    // }
1757    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
1758    if(!rpcSlice->isIntra())
1759    {
1760      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1761      {
1762        refPicListModification->setRefPicListModificationFlagL0( 0 );
1763      }
1764      else
1765      {
1766        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
1767      }
1768
1769      if(refPicListModification->getRefPicListModificationFlagL0())
1770      {
1771        uiCode = 0;
1772        Int i = 0;
1773        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
1774        if ( numRpsCurrTempList0 > 1 )
1775        {
1776          Int length = 1;
1777          numRpsCurrTempList0 --;
1778          while ( numRpsCurrTempList0 >>= 1)
1779          {
1780            length ++;
1781          }
1782          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1783          {
1784            READ_CODE( length, uiCode, "list_entry_l0" );
1785            refPicListModification->setRefPicSetIdxL0(i, uiCode );
1786          }
1787        }
1788        else
1789        {
1790          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1791          {
1792            refPicListModification->setRefPicSetIdxL0(i, 0 );
1793          }
1794        }
1795      }
1796    }
1797    else
1798    {
1799      refPicListModification->setRefPicListModificationFlagL0(0);
1800    }
1801    if(rpcSlice->isInterB())
1802    {
1803      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1804      {
1805        refPicListModification->setRefPicListModificationFlagL1( 0 );
1806      }
1807      else
1808      {
1809        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
1810      }
1811      if(refPicListModification->getRefPicListModificationFlagL1())
1812      {
1813        uiCode = 0;
1814        Int i = 0;
1815        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
1816        if ( numRpsCurrTempList1 > 1 )
1817        {
1818          Int length = 1;
1819          numRpsCurrTempList1 --;
1820          while ( numRpsCurrTempList1 >>= 1)
1821          {
1822            length ++;
1823          }
1824          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1825          {
1826            READ_CODE( length, uiCode, "list_entry_l1" );
1827            refPicListModification->setRefPicSetIdxL1(i, uiCode );
1828          }
1829        }
1830        else
1831        {
1832          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1833          {
1834            refPicListModification->setRefPicSetIdxL1(i, 0 );
1835          }
1836        }
1837      }
1838    }
1839    else
1840    {
1841      refPicListModification->setRefPicListModificationFlagL1(0);
1842    }
1843    if (rpcSlice->isInterB())
1844    {
1845      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
1846    }
1847
1848    rpcSlice->setCabacInitFlag( false ); // default
1849    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
1850    {
1851      READ_FLAG(uiCode, "cabac_init_flag");
1852      rpcSlice->setCabacInitFlag( uiCode ? true : false );
1853    }
1854
1855    if ( rpcSlice->getEnableTMVPFlag() )
1856    {
1857#if M0457_COL_PICTURE_SIGNALING
1858#if REMOVE_COL_PICTURE_SIGNALING
1859      rpcSlice->setMFMEnabledFlag( rpcSlice->getNumMotionPredRefLayers() > 0 ? true : false );
1860#else
1861      rpcSlice->setMFMEnabledFlag( false );
1862      rpcSlice->setColRefLayerIdx( 0 );
1863      rpcSlice->setAltColIndicationFlag( false );
1864      if ( sps->getLayerId() > 0 && rpcSlice->getActiveNumILRRefIdx() > 0 && rpcSlice->getNumMotionPredRefLayers() > 0 )
1865      {
1866        READ_FLAG( uiCode, "alt_collocated_indication_flag" );
1867        rpcSlice->setAltColIndicationFlag( uiCode == 1 ? true : false );
1868        rpcSlice->setMFMEnabledFlag( uiCode == 1 ? true : false );
1869        if ( rpcSlice->getNumMotionPredRefLayers() > 1 )
1870        {
1871          READ_UVLC( uiCode, "collocated_ref_layer_idx" );
1872          rpcSlice->setColRefLayerIdx( uiCode );
1873        }
1874      }
1875      else
1876      {
1877#endif //REMOVE_COL_PICTURE_SIGNALING
1878#endif
1879      if ( rpcSlice->getSliceType() == B_SLICE )
1880      {
1881        READ_FLAG( uiCode, "collocated_from_l0_flag" );
1882        rpcSlice->setColFromL0Flag(uiCode);
1883      }
1884      else
1885      {
1886        rpcSlice->setColFromL0Flag( 1 );
1887      }
1888
1889      if ( rpcSlice->getSliceType() != I_SLICE &&
1890          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
1891           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
1892      {
1893        READ_UVLC( uiCode, "collocated_ref_idx" );
1894        rpcSlice->setColRefIdx(uiCode);
1895      }
1896      else
1897      {
1898        rpcSlice->setColRefIdx(0);
1899      }
1900#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1901      }
1902#endif
1903    }
1904    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
1905    {
1906      xParsePredWeightTable(rpcSlice);
1907      rpcSlice->initWpScaling();
1908    }
1909    if (!rpcSlice->isIntra())
1910    {
1911      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
1912      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
1913    }
1914
1915    READ_SVLC( iCode, "slice_qp_delta" );
1916    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
1917
1918#if REPN_FORMAT_IN_VPS
1919    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
1920#else
1921    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
1922#endif
1923    assert( rpcSlice->getSliceQp() <=  51 );
1924
1925    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
1926    {
1927      READ_SVLC( iCode, "slice_qp_delta_cb" );
1928      rpcSlice->setSliceQpDeltaCb( iCode );
1929      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
1930      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
1931      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
1932      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
1933
1934      READ_SVLC( iCode, "slice_qp_delta_cr" );
1935      rpcSlice->setSliceQpDeltaCr( iCode );
1936      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
1937      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
1938      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
1939      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
1940    }
1941
1942    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
1943    {
1944      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
1945      {
1946        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
1947      }
1948      else
1949      {
1950        rpcSlice->setDeblockingFilterOverrideFlag(0);
1951      }
1952      if(rpcSlice->getDeblockingFilterOverrideFlag())
1953      {
1954        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
1955        if(!rpcSlice->getDeblockingFilterDisable())
1956        {
1957          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
1958          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
1959                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
1960          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
1961          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
1962                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
1963        }
1964      }
1965      else
1966      {
1967        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
1968        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
1969        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
1970      }
1971    }
1972    else
1973    {
1974      rpcSlice->setDeblockingFilterDisable       ( false );
1975      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
1976      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
1977    }
1978
1979    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
1980    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
1981
1982    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
1983    {
1984      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
1985    }
1986    else
1987    {
1988      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
1989    }
1990    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
1991
1992  }
1993
1994    UInt *entryPointOffset          = NULL;
1995    UInt numEntryPointOffsets, offsetLenMinus1;
1996  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1997  {
1998    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
1999    if (numEntryPointOffsets>0)
2000    {
2001      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2002    }
2003    entryPointOffset = new UInt[numEntryPointOffsets];
2004    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2005    {
2006      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2007      entryPointOffset[ idx ] = uiCode + 1;
2008    }
2009  }
2010  else
2011  {
2012    rpcSlice->setNumEntryPointOffsets ( 0 );
2013  }
2014
2015  if(pps->getSliceHeaderExtensionPresentFlag())
2016  {
2017    READ_UVLC(uiCode,"slice_header_extension_length");
2018    for(Int i=0; i<uiCode; i++)
2019    {
2020      UInt ignore;
2021      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2022    }
2023  }
2024  m_pcBitstream->readByteAlignment();
2025
2026  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2027  {
2028    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2029   
2030    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2031    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2032    {
2033      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2034      {
2035        endOfSliceHeaderLocation++;
2036      }
2037    }
2038
2039    Int  curEntryPointOffset     = 0;
2040    Int  prevEntryPointOffset    = 0;
2041    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2042    {
2043      curEntryPointOffset += entryPointOffset[ idx ];
2044
2045      Int emulationPreventionByteCount = 0;
2046      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2047      {
2048        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
2049             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2050        {
2051          emulationPreventionByteCount++;
2052        }
2053      }
2054
2055      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2056      prevEntryPointOffset = curEntryPointOffset;
2057    }
2058
2059    if ( pps->getTilesEnabledFlag() )
2060    {
2061      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2062
2063      UInt prevPos = 0;
2064      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2065      {
2066        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2067        prevPos += entryPointOffset[ idx ];
2068      }
2069    }
2070    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2071    {
2072    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2073      rpcSlice->allocSubstreamSizes(numSubstreams);
2074      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2075      for (Int idx=0; idx<numSubstreams-1; idx++)
2076      {
2077        if ( idx < numEntryPointOffsets )
2078        {
2079          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2080        }
2081        else
2082        {
2083          pSubstreamSizes[ idx ] = 0;
2084        }
2085      }
2086    }
2087
2088    if (entryPointOffset)
2089    {
2090      delete [] entryPointOffset;
2091    }
2092  }
2093
2094  return;
2095}
2096
2097Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2098{
2099  UInt uiCode;
2100  if(profilePresentFlag)
2101  {
2102    parseProfileTier(rpcPTL->getGeneralPTL());
2103  }
2104  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2105
2106  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2107  {
2108    if(profilePresentFlag)
2109    {
2110      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2111    }
2112    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2113  }
2114
2115  if (maxNumSubLayersMinus1 > 0)
2116  {
2117    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2118    {
2119      READ_CODE(2, uiCode, "reserved_zero_2bits");
2120      assert(uiCode == 0);
2121    }
2122  }
2123
2124  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2125  {
2126    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2127    {
2128      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2129    }
2130    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2131    {
2132      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2133    }
2134  }
2135}
2136
2137Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2138{
2139  UInt uiCode;
2140  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2141  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2142  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2143  for(Int j = 0; j < 32; j++)
2144  {
2145    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2146  }
2147  READ_FLAG(uiCode, "general_progressive_source_flag");
2148  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2149
2150  READ_FLAG(uiCode, "general_interlaced_source_flag");
2151  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2152
2153  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2154  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2155
2156  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2157  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2158
2159  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2160  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2161  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2162}
2163
2164Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2165{
2166  ruiBit = false;
2167  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2168  if(iBitsLeft <= 8)
2169  {
2170    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2171    if (uiPeekValue == (1<<(iBitsLeft-1)))
2172    {
2173      ruiBit = true;
2174    }
2175  }
2176}
2177
2178Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2179{
2180  assert(0);
2181}
2182
2183Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2184{
2185  assert(0);
2186}
2187
2188Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2189{
2190  assert(0);
2191}
2192
2193Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2194{
2195  assert(0);
2196}
2197
2198Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2199{
2200  assert(0);
2201}
2202
2203Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2204{
2205  assert(0);
2206}
2207
2208/** Parse I_PCM information.
2209* \param pcCU pointer to CU
2210* \param uiAbsPartIdx CU index
2211* \param uiDepth CU depth
2212* \returns Void
2213*
2214* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
2215*/
2216Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2217{
2218  assert(0);
2219}
2220
2221Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2222{
2223  assert(0);
2224}
2225
2226Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2227{
2228  assert(0);
2229}
2230
2231Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2232{
2233  assert(0);
2234}
2235
2236Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2237{
2238  assert(0);
2239}
2240
2241Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
2242{
2243  assert(0);
2244}
2245
2246Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2247{
2248  Int qp;
2249  Int  iDQp;
2250
2251  xReadSvlc( iDQp );
2252
2253#if REPN_FORMAT_IN_VPS
2254  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
2255#else
2256  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
2257#endif
2258  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2259
2260  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
2261  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2262
2263  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2264}
2265
2266Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
2267{
2268  assert(0);
2269}
2270
2271Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
2272{
2273  assert(0);
2274}
2275
2276Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
2277{
2278  assert(0);
2279}
2280
2281Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
2282{
2283  assert(0);
2284}
2285
2286Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
2287{
2288  assert(0);
2289}
2290
2291Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
2292{
2293  assert(0);
2294}
2295
2296Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
2297{
2298  assert(0);
2299}
2300
2301// ====================================================================================================================
2302// Protected member functions
2303// ====================================================================================================================
2304
2305/** parse explicit wp tables
2306* \param TComSlice* pcSlice
2307* \returns Void
2308*/
2309Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
2310{
2311  wpScalingParam  *wp;
2312  Bool            bChroma     = true; // color always present in HEVC ?
2313  SliceType       eSliceType  = pcSlice->getSliceType();
2314  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
2315  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
2316  UInt            uiTotalSignalledWeightFlags = 0;
2317
2318  Int iDeltaDenom;
2319  // decode delta_luma_log2_weight_denom :
2320  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
2321  assert( uiLog2WeightDenomLuma <= 7 );
2322  if( bChroma )
2323  {
2324    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
2325    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
2326    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
2327    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
2328  }
2329
2330  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
2331  {
2332    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
2333    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2334    {
2335      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2336
2337      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
2338      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2339      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2340
2341      UInt  uiCode;
2342      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
2343      wp[0].bPresentFlag = ( uiCode == 1 );
2344      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
2345    }
2346    if ( bChroma )
2347    {
2348      UInt  uiCode;
2349      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2350      {
2351        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2352        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
2353        wp[1].bPresentFlag = ( uiCode == 1 );
2354        wp[2].bPresentFlag = ( uiCode == 1 );
2355        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
2356      }
2357    }
2358    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2359    {
2360      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2361      if ( wp[0].bPresentFlag )
2362      {
2363        Int iDeltaWeight;
2364        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
2365        assert( iDeltaWeight >= -128 );
2366        assert( iDeltaWeight <=  127 );
2367        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
2368        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
2369        assert( wp[0].iOffset >= -128 );
2370        assert( wp[0].iOffset <=  127 );
2371      }
2372      else
2373      {
2374        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
2375        wp[0].iOffset = 0;
2376      }
2377      if ( bChroma )
2378      {
2379        if ( wp[1].bPresentFlag )
2380        {
2381          for ( Int j=1 ; j<3 ; j++ )
2382          {
2383            Int iDeltaWeight;
2384            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
2385            assert( iDeltaWeight >= -128 );
2386            assert( iDeltaWeight <=  127 );
2387            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
2388
2389            Int iDeltaChroma;
2390            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
2391            assert( iDeltaChroma >= -512 );
2392            assert( iDeltaChroma <=  511 );
2393            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
2394            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
2395          }
2396        }
2397        else
2398        {
2399          for ( Int j=1 ; j<3 ; j++ )
2400          {
2401            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
2402            wp[j].iOffset = 0;
2403          }
2404        }
2405      }
2406    }
2407
2408    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
2409    {
2410      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2411
2412      wp[0].bPresentFlag = false;
2413      wp[1].bPresentFlag = false;
2414      wp[2].bPresentFlag = false;
2415    }
2416  }
2417  assert(uiTotalSignalledWeightFlags<=24);
2418}
2419
2420/** decode quantization matrix
2421* \param scalingList quantization matrix information
2422*/
2423Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
2424{
2425  UInt  code, sizeId, listId;
2426  Bool scalingListPredModeFlag;
2427  //for each size
2428  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2429  {
2430    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
2431    {
2432      READ_FLAG( code, "scaling_list_pred_mode_flag");
2433      scalingListPredModeFlag = (code) ? true : false;
2434      if(!scalingListPredModeFlag) //Copy Mode
2435      {
2436        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
2437        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
2438        if( sizeId > SCALING_LIST_8x8 )
2439        {
2440          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
2441        }
2442        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
2443
2444      }
2445      else //DPCM Mode
2446      {
2447        xDecodeScalingList(scalingList, sizeId, listId);
2448      }
2449    }
2450  }
2451
2452  return;
2453}
2454/** decode DPCM
2455* \param scalingList  quantization matrix information
2456* \param sizeId size index
2457* \param listId list index
2458*/
2459Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
2460{
2461  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
2462  Int data;
2463  Int scalingListDcCoefMinus8 = 0;
2464  Int nextCoef = SCALING_LIST_START_VALUE;
2465  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
2466  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
2467
2468  if( sizeId > SCALING_LIST_8x8 )
2469  {
2470    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
2471    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
2472    nextCoef = scalingList->getScalingListDC(sizeId,listId);
2473  }
2474
2475  for(i = 0; i < coefNum; i++)
2476  {
2477    READ_SVLC( data, "scaling_list_delta_coef");
2478    nextCoef = (nextCoef + data + 256 ) % 256;
2479    dst[scan[i]] = nextCoef;
2480  }
2481}
2482
2483Bool TDecCavlc::xMoreRbspData()
2484{
2485  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
2486
2487  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
2488  if (bitsLeft > 8)
2489  {
2490    return true;
2491  }
2492
2493  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
2494  Int cnt = bitsLeft;
2495
2496  // remove trailing bits equal to zero
2497  while ((cnt>0) && ((lastByte & 1) == 0))
2498  {
2499    lastByte >>= 1;
2500    cnt--;
2501  }
2502  // remove bit equal to one
2503  cnt--;
2504
2505  // we should not have a negative number of bits
2506  assert (cnt>=0);
2507
2508  // we have more data, if cnt is not zero
2509  return (cnt>0);
2510}
2511//! \}
2512
Note: See TracBrowser for help on using the repository browser.