source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 534

Last change on this file since 534 was 534, checked in by tech, 11 years ago

MergeMerged tags/HTM-DEV-1.0.

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