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

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

Further fixes.

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