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

Last change on this file since 495 was 495, checked in by tech, 12 years ago

Fixed several bugs and mismatches.

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