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

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

Update to HM 11.0.

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