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

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

Fixed misaligned #endif for MV configuration.

  • 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  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
880  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
881  {
882    // Operation point set
883    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
884#endif
885    {
886      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
887    }
888  }
889#if L0043_TIMING_INFO
890  TimingInfo *timingInfo = pcVPS->getTimingInfo();
891  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
892  if(timingInfo->getTimingInfoPresentFlag())
893  {
894    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
895    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
896    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
897    if(timingInfo->getPocProportionalToTimingFlag())
898    {
899      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
900    }
901#endif
902    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
903
904    if( pcVPS->getNumHrdParameters() > 0 )
905    {
906      pcVPS->createHrdParamBuffer();
907    }
908    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
909    {
910      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
911      if( i > 0 )
912      {
913        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
914      }
915      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
916    }
917#if L0043_TIMING_INFO
918  }
919#endif
920  READ_FLAG( uiCode,  "vps_extension_flag" );
921  if (uiCode)
922  {
923#if H_MV
924    m_pcBitstream->readOutTrailingBits();
925
926    READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
927    READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
928
929    for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
930    {
931      READ_FLAG( uiCode,  "scalability_mask[i]" );                  pcVPS->setScalabilityMask( sIdx, uiCode == 1 ? true : false );     
932    }
933
934    for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
935    {
936        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
937    }
938
939    if ( pcVPS->getSplittingFlag() )
940      {
941      pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
942      }
943
944    READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
945
946    for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
947    {
948      if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
949      {
950        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
951      }
952      else
953      {
954        pcVPS->setLayerIdInNuh( i, i );; 
955    }
956
957      pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
958   
959      for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
960    {
961        if ( !pcVPS->getSplittingFlag() )
962      {
963          READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
964        }
965        else
966        {
967          pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
968        }
969      }
970    }
971
972
973    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
974    {
975      for( Int j = 0; j < i; j++ )
976      {
977        READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
978      }
979    }
980
981    for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
982    {
983      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
984    }
985
986    READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
987    READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
988
989    for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
990    {
991      READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
992      if( !pcVPS->getVpsProfilePresentFlag( i ) )
993      {
994        READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
995      }
996      parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
997      if( !pcVPS->getVpsProfilePresentFlag( i ) )
998      {
999        TComPTL temp = *pcVPS->getPTL( i );
1000        *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
1001        pcVPS->getPTL( i )->copyLevelFrom( &temp );
1002      }
1003    }
1004
1005    Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
1006
1007    READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
1008
1009    if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
1010    {
1011      READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
1012      numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
1013    }
1014
1015    if( numOutputLayerSets > 1)
1016    {
1017      READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
1018    } 
1019
1020    for( Int i = 1; i < numOutputLayerSets; i++ )
1021    {
1022      if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
1023      {       
1024        READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
1025        for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
1026        {
1027          READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1028        }       
1029      }
1030      if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
1031      {     
1032        READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
1033      }
1034    }
1035
1036    READ_FLAG( uiCode , "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag( uiCode == 1 ); 
1037    READ_UVLC( uiCode,  "direct_dep_type_len_minus2"); pcVPS->setDirectDepTypeLenMinus2 ( uiCode ); 
1038
1039    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
1040    {
1041      for( Int j = 0; j < i; j++ )
1042      {
1043        if (pcVPS->getDirectDependencyFlag( i, j) )
1044        {       
1045          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1046        }
1047      }
1048    }
1049
1050    READ_FLAG ( uiCode,                    "vps_shvc_reserved_zero_flag" ); 
1051
1052#if H_3D   
1053    READ_FLAG( uiCode,  "vps_extension2_flag" );
1054    if (uiCode)
1055    {
1056      m_pcBitstream->readOutTrailingBits();
1057
1058      for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
1059      {
1060
1061#if H_3D_ARP
1062        pcVPS->setUseAdvRP  ( i, 0 );
1063        pcVPS->setARPStepNum( i, 1 );
1064#endif 
1065        if ( i != 0 )
1066        {
1067          if( !( pcVPS->getDepthId( i ) == 1 ) )
1068          {
1069#if H_3D_IV_MERGE
1070                READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1071#endif
1072#if H_3D_ARP
1073                READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );  pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1074
1075#endif
1076#if H_3D_NBDV_REF
1077                READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1078#endif
1079#if H_3D_VSP
1080                READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1081#endif
1082          }
1083          else
1084          {
1085
1086            READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1087            //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
1088#if H_3D_DIM_DLT
1089            if( pcVPS->getVpsDepthModesFlag( i ) )
1090            {
1091              READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
1092            }
1093            if( pcVPS->getUseDLTFlag( i ) )
1094            {
1095              // decode mapping
1096              UInt uiNumDepthValues;
1097              // parse number of values in DLT
1098              READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
1099
1100              // parse actual DLT values
1101              Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
1102              for(Int d=0; d<uiNumDepthValues; d++)
1103              {
1104                READ_UVLC(uiCode, "dlt_depth_value[i][d]");
1105                aiIdx2DepthValue[d] = (Int)uiCode;
1106              }
1107
1108              pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
1109
1110              // clean memory
1111              free(aiIdx2DepthValue);
1112            }
1113#endif
1114          }
1115        }
1116      }
1117      READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
1118    }
1119#endif
1120    pcVPS->checkVPSExtensionSyntax(); 
1121
1122    pcVPS->setRefLayers(); 
1123
1124#else
1125    while ( xMoreRbspData() )
1126    {
1127      READ_FLAG( uiCode, "vps_extension_data_flag");
1128    }
1129#endif   
1130  }
1131
1132#if H_3D
1133  pcVPS->initViewIndex(); 
1134#endif
1135  return;
1136}
1137
1138Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
1139{
1140  UInt  uiCode;
1141  Int   iCode;
1142
1143#if ENC_DEC_TRACE
1144  xTraceSliceHeader(rpcSlice);
1145#endif
1146  TComPPS* pps = NULL;
1147  TComSPS* sps = NULL;
1148#if H_MV
1149  TComVPS* vps = NULL;
1150#endif
1151
1152  UInt firstSliceSegmentInPic;
1153  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1154  if( rpcSlice->getRapPicFlag())
1155  { 
1156    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
1157  }
1158  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1159  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1160  //!KS: need to add error handling code here, if PPS is not available
1161  assert(pps!=0);
1162  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1163  //!KS: need to add error handling code here, if SPS is not available
1164  assert(sps!=0);
1165#if H_MV
1166  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
1167  assert(vps!=0);
1168  rpcSlice->setVPS(vps);     
1169  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerIdInVps() )      );
1170#if H_3D 
1171  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerIdInVps() )      ); 
1172  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerIdInVps() ) == 1 );
1173#endif
1174#endif
1175  rpcSlice->setSPS(sps);
1176  rpcSlice->setPPS(pps);
1177  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1178  {
1179    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1180  }
1181  else
1182  {
1183    rpcSlice->setDependentSliceSegmentFlag(false);
1184  }
1185  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1186  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
1187  UInt sliceSegmentAddress = 0;
1188  Int bitsSliceSegmentAddress = 0;
1189  while(numCTUs>(1<<bitsSliceSegmentAddress))
1190  {
1191    bitsSliceSegmentAddress++;
1192  }
1193
1194  if(!firstSliceSegmentInPic)
1195  {
1196    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
1197  }
1198  //set uiCode to equal slice start address (or dependent slice start address)
1199  Int startCuAddress = maxParts*sliceSegmentAddress;
1200  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
1201  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
1202
1203  if (rpcSlice->getDependentSliceSegmentFlag())
1204  {
1205    rpcSlice->setNextSlice          ( false );
1206    rpcSlice->setNextSliceSegment ( true  );
1207  }
1208  else
1209  {
1210    rpcSlice->setNextSlice          ( true  );
1211    rpcSlice->setNextSliceSegment ( false );
1212
1213    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
1214    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
1215  }
1216 
1217  if(!rpcSlice->getDependentSliceSegmentFlag())
1218  {
1219#if H_MV   
1220    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
1221    {
1222      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
1223    }
1224
1225    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)   
1226#else
1227    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1228#endif     
1229    {
1230      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1231    }
1232
1233    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
1234    if( pps->getOutputFlagPresentFlag() )
1235    {
1236      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
1237    }
1238    else
1239    {
1240      rpcSlice->setPicOutputFlag( true );
1241    }
1242    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
1243    assert (sps->getChromaFormatIdc() == 1 );
1244    // if( separate_colour_plane_flag  ==  1 )
1245    //   colour_plane_id                                      u(2)
1246
1247    if( rpcSlice->getIdrPicFlag() )
1248    {
1249      rpcSlice->setPOC(0);
1250      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
1251      rps->setNumberOfNegativePictures(0);
1252      rps->setNumberOfPositivePictures(0);
1253      rps->setNumberOfLongtermPictures(0);
1254      rps->setNumberOfPictures(0);
1255      rpcSlice->setRPS(rps);
1256#if H_MV
1257      rpcSlice->setEnableTMVPFlag(false);
1258#endif
1259    }
1260    else
1261    {
1262      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
1263      Int iPOClsb = uiCode;
1264      Int iPrevPOC = rpcSlice->getPrevPOC();
1265      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
1266      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
1267      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
1268      Int iPOCmsb;
1269      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
1270      {
1271        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
1272      }
1273      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
1274      {
1275        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
1276      }
1277      else
1278      {
1279        iPOCmsb = iPrevPOCmsb;
1280      }
1281      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1282        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1283        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1284      {
1285        // For BLA picture types, POCmsb is set to 0.
1286        iPOCmsb = 0;
1287      }
1288      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
1289
1290      TComReferencePictureSet* rps;
1291      rps = rpcSlice->getLocalRPS();
1292      rpcSlice->setRPS(rps);
1293      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
1294      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
1295      {
1296        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
1297      }
1298      else // use reference to short-term reference picture set in PPS
1299      {
1300        Int numBits = 0;
1301        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
1302        {
1303          numBits++;
1304        }
1305        if (numBits > 0)
1306        {
1307          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
1308        }
1309        else
1310        {
1311          uiCode = 0;
1312        }
1313        memcpy(rps,sps->getRPSList()->getReferencePictureSet(uiCode),sizeof(TComReferencePictureSet));
1314      }
1315      if(sps->getLongTermRefsPresent())
1316      {
1317        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
1318        UInt numOfLtrp = 0;
1319        UInt numLtrpInSPS = 0;
1320        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
1321        {
1322          READ_UVLC( uiCode, "num_long_term_sps");
1323          numLtrpInSPS = uiCode;
1324          numOfLtrp += numLtrpInSPS;
1325          rps->setNumberOfLongtermPictures(numOfLtrp);
1326        }
1327        Int bitsForLtrpInSPS = 0;
1328        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
1329        {
1330          bitsForLtrpInSPS++;
1331        }
1332        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
1333        numOfLtrp += uiCode;
1334        rps->setNumberOfLongtermPictures(numOfLtrp);
1335        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
1336        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
1337        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
1338        {
1339          Int pocLsbLt;
1340          if (k < numLtrpInSPS)
1341          {
1342            uiCode = 0;
1343            if (bitsForLtrpInSPS > 0)
1344            {
1345              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
1346            }
1347            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
1348
1349            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
1350            rps->setUsed(j,usedByCurrFromSPS);
1351          }
1352          else
1353          {
1354            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
1355            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
1356          }
1357          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
1358          Bool mSBPresentFlag = uiCode ? true : false;
1359          if(mSBPresentFlag)                 
1360          {
1361            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
1362            Bool deltaFlag = false;
1363            //            First LTRP                               || First LTRP from SH
1364            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
1365            {
1366              deltaFlag = true;
1367            }
1368            if(deltaFlag)
1369            {
1370              deltaPocMSBCycleLT = uiCode;
1371            }
1372            else
1373            {
1374              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
1375            }
1376
1377            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
1378                                        - iPOClsb + pocLsbLt;
1379            rps->setPOC     (j, pocLTCurr); 
1380            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
1381            rps->setCheckLTMSBPresent(j,true); 
1382          }
1383          else
1384          {
1385            rps->setPOC     (j, pocLsbLt);
1386            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
1387            rps->setCheckLTMSBPresent(j,false); 
1388          }
1389          prevDeltaMSB = deltaPocMSBCycleLT;
1390        }
1391        offset += rps->getNumberOfLongtermPictures();
1392        rps->setNumberOfPictures(offset);       
1393      } 
1394      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1395        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1396        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1397      {
1398        // In the case of BLA picture types, rps data is read from slice header but ignored
1399        rps = rpcSlice->getLocalRPS();
1400        rps->setNumberOfNegativePictures(0);
1401        rps->setNumberOfPositivePictures(0);
1402        rps->setNumberOfLongtermPictures(0);
1403        rps->setNumberOfPictures(0);
1404        rpcSlice->setRPS(rps);
1405      }
1406      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
1407      {
1408        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
1409        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
1410      }
1411      else
1412      {
1413        rpcSlice->setEnableTMVPFlag(false);
1414      }
1415    }
1416#if H_MV
1417    Int layerIdInVps       = rpcSlice->getLayerIdInVps(); 
1418    if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
1419    {   
1420      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
1421      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
1422      {           
1423        if( !vps->getMaxOneActiveRefLayerFlag()) 
1424        {
1425          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
1426        }
1427        for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
1428        {
1429          READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( i, uiCode );
1430        }
1431      } 
1432    }
1433
1434    rpcSlice->setActiveMotionPredRefLayers( );
1435
1436    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  rpcSlice->getNumActiveRefLayerPics() > 0 )
1437    {
1438      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
1439    }
1440
1441#endif
1442    if(sps->getUseSAO())
1443    {
1444      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
1445      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
1446    }
1447
1448    if (rpcSlice->getIdrPicFlag())
1449    {
1450      rpcSlice->setEnableTMVPFlag(false);
1451    }
1452    if (!rpcSlice->isIntra())
1453    {
1454
1455      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
1456      if (uiCode)
1457      {
1458        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
1459        if (rpcSlice->isInterB())
1460        {
1461          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
1462        }
1463        else
1464        {
1465          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
1466        }
1467      }
1468      else
1469      {
1470        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
1471        if (rpcSlice->isInterB())
1472        {
1473          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
1474        }
1475        else
1476        {
1477          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
1478        }
1479      }
1480    }
1481    // }
1482    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
1483    if(!rpcSlice->isIntra())
1484    {
1485      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1486      {
1487        refPicListModification->setRefPicListModificationFlagL0( 0 );
1488      }
1489      else
1490      {
1491        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
1492      }
1493
1494      if(refPicListModification->getRefPicListModificationFlagL0())
1495      { 
1496        uiCode = 0;
1497        Int i = 0;
1498        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
1499        if ( numRpsCurrTempList0 > 1 )
1500        {
1501          Int length = 1;
1502          numRpsCurrTempList0 --;
1503          while ( numRpsCurrTempList0 >>= 1) 
1504          {
1505            length ++;
1506          }
1507          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1508          {
1509            READ_CODE( length, uiCode, "list_entry_l0" );
1510            refPicListModification->setRefPicSetIdxL0(i, uiCode );
1511          }
1512        }
1513        else
1514        {
1515          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1516          {
1517            refPicListModification->setRefPicSetIdxL0(i, 0 );
1518          }
1519        }
1520      }
1521    }
1522    else
1523    {
1524      refPicListModification->setRefPicListModificationFlagL0(0);
1525    }
1526    if(rpcSlice->isInterB())
1527    {
1528      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1529      {
1530        refPicListModification->setRefPicListModificationFlagL1( 0 );
1531      }
1532      else
1533      {
1534        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
1535      }
1536      if(refPicListModification->getRefPicListModificationFlagL1())
1537      {
1538        uiCode = 0;
1539        Int i = 0;
1540        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
1541        if ( numRpsCurrTempList1 > 1 )
1542        {
1543          Int length = 1;
1544          numRpsCurrTempList1 --;
1545          while ( numRpsCurrTempList1 >>= 1) 
1546          {
1547            length ++;
1548          }
1549          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1550          {
1551            READ_CODE( length, uiCode, "list_entry_l1" );
1552            refPicListModification->setRefPicSetIdxL1(i, uiCode );
1553          }
1554        }
1555        else
1556        {
1557          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1558          {
1559            refPicListModification->setRefPicSetIdxL1(i, 0 );
1560          }
1561        }
1562      }
1563    } 
1564    else
1565    {
1566      refPicListModification->setRefPicListModificationFlagL1(0);
1567    }
1568    if (rpcSlice->isInterB())
1569    {
1570      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
1571    }
1572
1573    rpcSlice->setCabacInitFlag( false ); // default
1574    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
1575    {
1576      READ_FLAG(uiCode, "cabac_init_flag");
1577      rpcSlice->setCabacInitFlag( uiCode ? true : false );
1578    }
1579
1580    if ( rpcSlice->getEnableTMVPFlag() )
1581    {
1582#if H_MV
1583      if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
1584      {
1585        READ_FLAG( uiCode, "alt_collocated_indication_flag" ); rpcSlice->setAltCollocatedIndicationFlag( uiCode == 1 );
1586      }
1587
1588      if( rpcSlice->getAltCollocatedIndicationFlag() && rpcSlice->getNumActiveMotionPredRefLayers() > 1 ) 
1589      {         
1590        READ_UVLC( uiCode, "collocated_ref_layer_idx" ); rpcSlice->setCollocatedRefLayerIdx( uiCode );
1591      }     
1592      else 
1593      {
1594#endif
1595      if ( rpcSlice->getSliceType() == B_SLICE )
1596      {
1597        READ_FLAG( uiCode, "collocated_from_l0_flag" );
1598        rpcSlice->setColFromL0Flag(uiCode);
1599      }
1600      else
1601      {
1602        rpcSlice->setColFromL0Flag( 1 );
1603      }
1604
1605      if ( rpcSlice->getSliceType() != I_SLICE &&
1606          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
1607           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
1608      {
1609        READ_UVLC( uiCode, "collocated_ref_idx" );
1610        rpcSlice->setColRefIdx(uiCode);
1611      }
1612      else
1613      {
1614        rpcSlice->setColRefIdx(0);
1615      }
1616#if H_MV
1617      }
1618#endif
1619    }
1620    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
1621    {
1622      xParsePredWeightTable(rpcSlice);
1623      rpcSlice->initWpScaling();
1624    }
1625#if H_3D_IC
1626    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) )
1627    {
1628      UInt uiCodeTmp = 0;
1629
1630      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
1631      rpcSlice->setApplyIC( uiCodeTmp );
1632
1633      if ( uiCodeTmp )
1634      {
1635        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
1636        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
1637      }
1638    }
1639#endif
1640    if (!rpcSlice->isIntra())
1641    {
1642      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
1643#if H_3D_IV_MERGE
1644      Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
1645      rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
1646#else
1647      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
1648#endif
1649    }
1650
1651    READ_SVLC( iCode, "slice_qp_delta" );
1652    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
1653
1654    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
1655    assert( rpcSlice->getSliceQp() <=  51 );
1656
1657    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
1658    {
1659      READ_SVLC( iCode, "slice_qp_delta_cb" );
1660      rpcSlice->setSliceQpDeltaCb( iCode );
1661      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
1662      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
1663      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
1664      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
1665
1666      READ_SVLC( iCode, "slice_qp_delta_cr" );
1667      rpcSlice->setSliceQpDeltaCr( iCode );
1668      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
1669      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
1670      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
1671      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
1672    }
1673
1674    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
1675    {
1676      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
1677      {
1678        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
1679      }
1680      else
1681      { 
1682        rpcSlice->setDeblockingFilterOverrideFlag(0);
1683      }
1684      if(rpcSlice->getDeblockingFilterOverrideFlag())
1685      {
1686        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
1687        if(!rpcSlice->getDeblockingFilterDisable())
1688        {
1689          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
1690          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
1691                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
1692          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
1693          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
1694                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
1695        }
1696      }
1697      else
1698      {
1699        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
1700        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
1701        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
1702      }
1703    }
1704    else
1705    { 
1706      rpcSlice->setDeblockingFilterDisable       ( false );
1707      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
1708      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
1709    }
1710
1711    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
1712    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
1713
1714    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
1715    {
1716      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
1717    }
1718    else
1719    {
1720      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
1721    }
1722    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
1723
1724  }
1725 
1726    UInt *entryPointOffset          = NULL;
1727    UInt numEntryPointOffsets, offsetLenMinus1;
1728  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1729  {
1730    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
1731    if (numEntryPointOffsets>0)
1732    {
1733      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
1734    }
1735    entryPointOffset = new UInt[numEntryPointOffsets];
1736    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
1737    {
1738#if L0116_ENTRY_POINT
1739      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
1740      entryPointOffset[ idx ] = uiCode + 1;
1741#else
1742      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
1743      entryPointOffset[ idx ] = uiCode;
1744#endif
1745    }
1746  }
1747  else
1748  {
1749    rpcSlice->setNumEntryPointOffsets ( 0 );
1750  }
1751
1752  if(pps->getSliceHeaderExtensionPresentFlag())
1753  {
1754    READ_UVLC(uiCode,"slice_header_extension_length");
1755#if H_3D
1756    if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
1757    {
1758      UInt uiViewIndex = rpcSlice->getViewIndex();
1759      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
1760      {
1761        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
1762        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
1763        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
1764        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
1765      }
1766      rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
1767    }
1768
1769    READ_FLAG(uiCode,"slice_segment_header_extension2_flag"); 
1770    if ( uiCode )
1771    {   
1772      READ_UVLC(uiCode,"slice_header_extension2_length");
1773      for(Int i=0; i<uiCode; i++)
1774      {
1775        UInt ignore;
1776        READ_CODE(8,ignore,"slice_header_extension2_data_byte");
1777      }
1778    }
1779  }
1780#else
1781    for(Int i=0; i<uiCode; i++)
1782    {
1783      UInt ignore;
1784      READ_CODE(8,ignore,"slice_header_extension_data_byte");
1785    }
1786  }
1787#endif
1788  m_pcBitstream->readByteAlignment();
1789
1790  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1791  {
1792    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
1793    Int  curEntryPointOffset     = 0;
1794    Int  prevEntryPointOffset    = 0;
1795    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
1796    {
1797      curEntryPointOffset += entryPointOffset[ idx ];
1798
1799      Int emulationPreventionByteCount = 0;
1800      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
1801      {
1802        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
1803             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
1804        {
1805          emulationPreventionByteCount++;
1806        }
1807      }
1808
1809      entryPointOffset[ idx ] -= emulationPreventionByteCount;
1810      prevEntryPointOffset = curEntryPointOffset;
1811    }
1812
1813    if ( pps->getTilesEnabledFlag() )
1814    {
1815      rpcSlice->setTileLocationCount( numEntryPointOffsets );
1816
1817      UInt prevPos = 0;
1818      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
1819      {
1820        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
1821        prevPos += entryPointOffset[ idx ];
1822      }
1823    }
1824    else if ( pps->getEntropyCodingSyncEnabledFlag() )
1825    {
1826    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
1827      rpcSlice->allocSubstreamSizes(numSubstreams);
1828      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
1829      for (Int idx=0; idx<numSubstreams-1; idx++)
1830      {
1831        if ( idx < numEntryPointOffsets )
1832        {
1833          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
1834        }
1835        else
1836        {
1837          pSubstreamSizes[ idx ] = 0;
1838        }
1839      }
1840    }
1841
1842    if (entryPointOffset)
1843    {
1844      delete [] entryPointOffset;
1845    }
1846  }
1847
1848  return;
1849}
1850 
1851Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
1852{
1853  UInt uiCode;
1854  if(profilePresentFlag)
1855  {
1856    parseProfileTier(rpcPTL->getGeneralPTL());
1857  }
1858  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
1859
1860#if L0363_BYTE_ALIGN
1861  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
1862  {
1863#if !H_MV
1864    if(profilePresentFlag)
1865    {
1866#endif
1867      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
1868#if H_MV
1869    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
1870#else
1871    }
1872#endif
1873    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
1874  }
1875 
1876  if (maxNumSubLayersMinus1 > 0)
1877  {
1878    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
1879    {
1880      READ_CODE(2, uiCode, "reserved_zero_2bits");
1881      assert(uiCode == 0);
1882    }
1883  }
1884#endif
1885 
1886  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
1887  {
1888#if !L0363_BYTE_ALIGN
1889    if(profilePresentFlag)
1890    {
1891      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
1892    }
1893    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
1894#endif
1895    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
1896    {
1897      parseProfileTier(rpcPTL->getSubLayerPTL(i));
1898    }
1899    if(rpcPTL->getSubLayerLevelPresentFlag(i))
1900    {
1901      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
1902    }
1903  }
1904}
1905
1906Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
1907{
1908  UInt uiCode;
1909  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
1910  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
1911  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
1912  for(Int j = 0; j < 32; j++)
1913  {
1914    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
1915  }
1916#if L0046_CONSTRAINT_FLAGS
1917  READ_FLAG(uiCode, "general_progressive_source_flag");
1918  ptl->setProgressiveSourceFlag(uiCode ? true : false);
1919
1920  READ_FLAG(uiCode, "general_interlaced_source_flag");
1921  ptl->setInterlacedSourceFlag(uiCode ? true : false);
1922 
1923  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
1924  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
1925 
1926  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
1927  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
1928 
1929  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
1930  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
1931  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
1932#elif L0363_MORE_BITS
1933  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[0..15]");
1934  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[16..31]");
1935  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[32..47]");
1936#else
1937  READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]");  assert( uiCode == 0 );
1938#endif
1939}
1940#if SIGNAL_BITRATE_PICRATE_IN_VPS
1941Void TDecCavlc::parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
1942{
1943  UInt uiCode;
1944  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
1945  {
1946    READ_FLAG( uiCode, "bit_rate_info_present_flag[i]" ); info->setBitRateInfoPresentFlag(i, uiCode ? true : false);
1947    READ_FLAG( uiCode, "pic_rate_info_present_flag[i]" ); info->setPicRateInfoPresentFlag(i, uiCode ? true : false);
1948    if(info->getBitRateInfoPresentFlag(i))
1949    {
1950      READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); info->setAvgBitRate(i, uiCode);
1951      READ_CODE( 16, uiCode, "max_bit_rate[i]" ); info->setMaxBitRate(i, uiCode);
1952    }
1953    if(info->getPicRateInfoPresentFlag(i))
1954    {
1955      READ_CODE(  2, uiCode,  "constant_pic_rate_idc[i]" ); info->setConstantPicRateIdc(i, uiCode);
1956      READ_CODE( 16, uiCode,  "avg_pic_rate[i]"          ); info->setAvgPicRate(i, uiCode);
1957    }
1958  }
1959}
1960#endif 
1961Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
1962{
1963  ruiBit = false;
1964  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
1965  if(iBitsLeft <= 8)
1966  {
1967    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
1968    if (uiPeekValue == (1<<(iBitsLeft-1)))
1969    {
1970      ruiBit = true;
1971    }
1972  }
1973}
1974
1975Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1976{
1977  assert(0);
1978}
1979
1980Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1981{
1982  assert(0);
1983}
1984
1985Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
1986{
1987  assert(0);
1988}
1989
1990Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1991{
1992  assert(0);
1993}
1994
1995Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1996{
1997  assert(0);
1998}
1999
2000Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2001{
2002  assert(0);
2003}
2004
2005/** Parse I_PCM information.
2006* \param pcCU pointer to CU
2007* \param uiAbsPartIdx CU index
2008* \param uiDepth CU depth
2009* \returns Void
2010*
2011* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2012*/
2013Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2014{
2015  assert(0);
2016}
2017
2018Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2019{ 
2020  assert(0);
2021}
2022
2023Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2024{
2025  assert(0);
2026}
2027
2028Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2029{
2030  assert(0);
2031}
2032
2033Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2034{
2035  assert(0);
2036}
2037
2038Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
2039{
2040  assert(0);
2041}
2042
2043Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2044{
2045  Int qp;
2046  Int  iDQp;
2047
2048  xReadSvlc( iDQp );
2049
2050  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
2051  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2052
2053  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
2054  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2055
2056  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2057}
2058
2059Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
2060{
2061  assert(0);
2062}
2063
2064Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
2065{
2066  assert(0);
2067}
2068
2069Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
2070{
2071  assert(0);
2072}
2073
2074Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
2075{
2076  assert(0);
2077}
2078
2079Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
2080{
2081  assert(0);
2082}
2083
2084Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
2085{
2086  assert(0);
2087}
2088
2089Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
2090{
2091  assert(0);
2092}
2093
2094#if H_3D_ARP
2095Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2096{
2097  assert(0);
2098}
2099#endif
2100#if H_3D_IC
2101Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2102{
2103  assert(0);
2104}
2105#endif
2106// ====================================================================================================================
2107// Protected member functions
2108// ====================================================================================================================
2109
2110/** parse explicit wp tables
2111* \param TComSlice* pcSlice
2112* \returns Void
2113*/
2114Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
2115{
2116  wpScalingParam  *wp;
2117  Bool            bChroma     = true; // color always present in HEVC ?
2118  SliceType       eSliceType  = pcSlice->getSliceType();
2119  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
2120  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
2121  UInt            uiTotalSignalledWeightFlags = 0;
2122 
2123  Int iDeltaDenom;
2124  // decode delta_luma_log2_weight_denom :
2125  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
2126  assert( uiLog2WeightDenomLuma <= 7 );
2127  if( bChroma ) 
2128  {
2129    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
2130    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
2131    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
2132    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
2133  }
2134
2135  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
2136  {
2137    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
2138    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2139    {
2140      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2141
2142      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
2143      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2144      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2145
2146      UInt  uiCode;
2147      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
2148      wp[0].bPresentFlag = ( uiCode == 1 );
2149      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
2150    }
2151    if ( bChroma ) 
2152    {
2153      UInt  uiCode;
2154      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2155      {
2156        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2157        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
2158        wp[1].bPresentFlag = ( uiCode == 1 );
2159        wp[2].bPresentFlag = ( uiCode == 1 );
2160        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
2161      }
2162    }
2163    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2164    {
2165      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2166      if ( wp[0].bPresentFlag ) 
2167      {
2168        Int iDeltaWeight;
2169        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
2170        assert( iDeltaWeight >= -128 );
2171        assert( iDeltaWeight <=  127 );
2172        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
2173        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
2174        assert( wp[0].iOffset >= -128 );
2175        assert( wp[0].iOffset <=  127 );
2176      }
2177      else 
2178      {
2179        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
2180        wp[0].iOffset = 0;
2181      }
2182      if ( bChroma ) 
2183      {
2184        if ( wp[1].bPresentFlag ) 
2185        {
2186          for ( Int j=1 ; j<3 ; j++ ) 
2187          {
2188            Int iDeltaWeight;
2189            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
2190            assert( iDeltaWeight >= -128 );
2191            assert( iDeltaWeight <=  127 );
2192            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
2193
2194            Int iDeltaChroma;
2195            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
2196            assert( iDeltaChroma >= -512 );
2197            assert( iDeltaChroma <=  511 );
2198            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
2199            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
2200          }
2201        }
2202        else 
2203        {
2204          for ( Int j=1 ; j<3 ; j++ ) 
2205          {
2206            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
2207            wp[j].iOffset = 0;
2208          }
2209        }
2210      }
2211    }
2212
2213    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
2214    {
2215      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2216
2217      wp[0].bPresentFlag = false;
2218      wp[1].bPresentFlag = false;
2219      wp[2].bPresentFlag = false;
2220    }
2221  }
2222  assert(uiTotalSignalledWeightFlags<=24);
2223}
2224
2225/** decode quantization matrix
2226* \param scalingList quantization matrix information
2227*/
2228Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
2229{
2230  UInt  code, sizeId, listId;
2231  Bool scalingListPredModeFlag;
2232  //for each size
2233  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2234  {
2235    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
2236    {
2237      READ_FLAG( code, "scaling_list_pred_mode_flag");
2238      scalingListPredModeFlag = (code) ? true : false;
2239      if(!scalingListPredModeFlag) //Copy Mode
2240      {
2241        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
2242        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
2243        if( sizeId > SCALING_LIST_8x8 )
2244        {
2245          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
2246        }
2247        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
2248
2249      }
2250      else //DPCM Mode
2251      {
2252        xDecodeScalingList(scalingList, sizeId, listId);
2253      }
2254    }
2255  }
2256
2257  return;
2258}
2259/** decode DPCM
2260* \param scalingList  quantization matrix information
2261* \param sizeId size index
2262* \param listId list index
2263*/
2264Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
2265{
2266  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
2267  Int data;
2268  Int scalingListDcCoefMinus8 = 0;
2269  Int nextCoef = SCALING_LIST_START_VALUE;
2270  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
2271  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
2272
2273  if( sizeId > SCALING_LIST_8x8 )
2274  {
2275    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
2276    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
2277    nextCoef = scalingList->getScalingListDC(sizeId,listId);
2278  }
2279
2280  for(i = 0; i < coefNum; i++)
2281  {
2282    READ_SVLC( data, "scaling_list_delta_coef");
2283    nextCoef = (nextCoef + data + 256 ) % 256;
2284    dst[scan[i]] = nextCoef;
2285  }
2286}
2287
2288Bool TDecCavlc::xMoreRbspData()
2289{ 
2290  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
2291
2292  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
2293  if (bitsLeft > 8)
2294  {
2295    return true;
2296  }
2297
2298  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
2299  Int cnt = bitsLeft;
2300
2301  // remove trailing bits equal to zero
2302  while ((cnt>0) && ((lastByte & 1) == 0))
2303  {
2304    lastByte >>= 1;
2305    cnt--;
2306  }
2307  // remove bit equal to one
2308  cnt--;
2309
2310  // we should not have a negative number of bits
2311  assert (cnt>=0);
2312
2313  // we have more data, if cnt is not zero
2314  return (cnt>0);
2315}
2316
2317//! \}
2318
Note: See TracBrowser for help on using the repository browser.