source: 3DVCSoftware/branches/HTM-9.0r1-F0122/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 747

Last change on this file since 747 was 747, checked in by qualcomm, 10 years ago

MV-HEVC+D support based on JCT3V-F0122

  • Property svn:eol-style set to native
File size: 91.9 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#if H_MV
333  if ( pcPPS->getLayerId() > 0 )
334  {
335    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );   
336  }
337
338  if( pcPPS->getPpsInferScalingListFlag( ) ) 
339  {
340    READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
341  }
342  else
343  { 
344#endif
345  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
346  if(pcPPS->getScalingListPresentFlag ())
347  {
348    parseScalingList( pcPPS->getScalingList() );
349  }
350#if H_MV
351  }
352#endif
353
354  READ_FLAG( uiCode, "lists_modification_present_flag");
355  pcPPS->setListsModificationPresentFlag(uiCode);
356
357  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
358  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
359
360  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
361  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
362
363  READ_FLAG( uiCode, "pps_extension_flag");
364  if (uiCode)
365  {
366    while ( xMoreRbspData() )
367    {
368      READ_FLAG( uiCode, "pps_extension_data_flag");
369    }
370  }
371}
372
373Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
374{
375#if ENC_DEC_TRACE
376  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
377#endif
378  UInt  uiCode;
379
380  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
381  if (pcVUI->getAspectRatioInfoPresentFlag())
382  {
383    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
384    if (pcVUI->getAspectRatioIdc() == 255)
385    {
386      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
387      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
388    }
389  }
390
391  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
392  if (pcVUI->getOverscanInfoPresentFlag())
393  {
394    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
395  }
396
397  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
398  if (pcVUI->getVideoSignalTypePresentFlag())
399  {
400    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
401    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
402    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
403    if (pcVUI->getColourDescriptionPresentFlag())
404    {
405      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
406      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
407      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
408    }
409  }
410
411  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
412  if (pcVUI->getChromaLocInfoPresentFlag())
413  {
414    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
415    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
416  }
417
418  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
419
420  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
421
422  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
423
424  READ_FLAG(     uiCode, "default_display_window_flag");
425  if (uiCode != 0)
426  {
427    Window &defDisp = pcVUI->getDefaultDisplayWindow();
428#if H_MV
429    defDisp.setScaledFlag( false ); 
430    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
431    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
432    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
433    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
434#else
435    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
436    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
437    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
438    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
439#endif
440  }
441  TimingInfo *timingInfo = pcVUI->getTimingInfo();
442  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
443  if(timingInfo->getTimingInfoPresentFlag())
444  {
445    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
446    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
447    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
448    if(timingInfo->getPocProportionalToTimingFlag())
449    {
450      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
451    }
452  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
453  if( pcVUI->getHrdParametersPresentFlag() )
454  {
455    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
456  }
457  }
458  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
459  if (pcVUI->getBitstreamRestrictionFlag())
460  {
461    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
462    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
463    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
464    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
465    assert(uiCode < 4096);
466    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
467    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
468    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
469    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
470  }
471}
472
473Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
474{
475  UInt  uiCode;
476  if( commonInfPresentFlag )
477  {
478    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
479    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
480    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
481    {
482      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
483      if( hrd->getSubPicCpbParamsPresentFlag() )
484      {
485        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
486        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
487        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
488        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
489      }
490      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
491      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
492      if( hrd->getSubPicCpbParamsPresentFlag() )
493      {
494        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
495      }
496      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
497      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
498      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
499    }
500  }
501  Int i, j, nalOrVcl;
502  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
503  {
504    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
505    if( !hrd->getFixedPicRateFlag( i ) )
506    {
507      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
508    }
509    else
510    {
511      hrd->setFixedPicRateWithinCvsFlag( i, true );
512    }
513    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
514    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
515    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
516    {
517      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
518    }
519    else
520    {     
521      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
522    }
523    if (!hrd->getLowDelayHrdFlag( i ))
524    {
525      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
526    }
527    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
528    {
529      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
530          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
531      {
532        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
533        {
534          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
535          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
536          if( hrd->getSubPicCpbParamsPresentFlag() )
537          {
538            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
539            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
540          }
541          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
542        }
543      }
544    }
545  }
546}
547
548#if H_3D
549Void TDecCavlc::parseSPS(TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
550#else
551Void TDecCavlc::parseSPS(TComSPS* pcSPS)
552#endif
553{
554#if ENC_DEC_TRACE 
555  xTraceSPSHeader (pcSPS);
556#endif
557
558  UInt  uiCode;
559  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
560#if H_MV
561  if ( pcSPS->getLayerId() == 0 )
562  {
563#endif
564  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
565  assert(uiCode <= 6);
566 
567  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
568  if ( pcSPS->getMaxTLayers() == 1 )
569  {
570    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
571    assert( uiCode == 1 );
572  }
573 
574  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
575#if H_MV
576  }
577#endif
578  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
579  assert(uiCode <= 15);
580#if H_MV
581  if ( pcSPS->getLayerId() > 0 )
582  {
583    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
584  }
585 
586  if ( pcSPS->getUpdateRepFormatFlag() )
587  { 
588#endif
589  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
590  assert(uiCode <= 3);
591  // 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
592  assert (uiCode == 1);
593  if( uiCode == 3 )
594  {
595    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
596  }
597
598  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
599  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
600#if H_MV
601  }
602#endif
603  READ_FLAG(     uiCode, "conformance_window_flag");
604  if (uiCode != 0)
605  {
606    Window &conf = pcSPS->getConformanceWindow();
607#if H_MV
608    // Needs to be scaled later, when ChromaFormatIdc is known.
609    conf.setScaledFlag( false ); 
610    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
611    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
612    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
613    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );   
614#else
615    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
616    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
617    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
618    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
619#endif
620  }
621
622#if H_MV
623  if ( pcSPS->getUpdateRepFormatFlag() )
624  { 
625#endif
626  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
627  assert(uiCode <= 6);
628  pcSPS->setBitDepthY( uiCode + 8 );
629  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
630
631  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
632  assert(uiCode <= 6);
633  pcSPS->setBitDepthC( uiCode + 8 );
634  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
635#if H_MV
636  }
637#endif
638
639  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
640  assert(uiCode <= 12);
641
642  UInt subLayerOrderingInfoPresentFlag;
643  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
644 
645  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
646  {
647#if H_MV
648    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
649#else
650    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
651#endif
652    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
653#if H_MV
654    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
655#else
656    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
657#endif
658    pcSPS->setNumReorderPics(uiCode, i);
659#if H_MV
660    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
661#else
662    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
663#endif
664    pcSPS->setMaxLatencyIncrease( uiCode, i );
665
666    if (!subLayerOrderingInfoPresentFlag)
667    {
668      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
669      {
670        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
671        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
672        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
673      }
674      break;
675    }
676  }
677
678  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
679  Int log2MinCUSize = uiCode + 3;
680  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
681  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
682  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
683  Int maxCUDepthDelta = uiCode;
684  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
685  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
686  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
687
688  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
689  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
690
691  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
692  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
693
694  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
695  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
696
697  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
698  if(pcSPS->getScalingListFlag())
699  {
700#if H_MV
701    if ( pcSPS->getLayerId() > 0 )
702    {   
703      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
704    }
705
706    if ( pcSPS->getSpsInferScalingListFlag() )
707    {
708      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
709    }
710    else
711    {   
712#endif
713    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
714    if(pcSPS->getScalingListPresentFlag ())
715    {
716      parseScalingList( pcSPS->getScalingList() );
717    }
718#if H_MV
719    }
720#endif
721  }
722  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
723  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
724
725  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
726  if( pcSPS->getUsePCM() )
727  {
728    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
729    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
730    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
731    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
732    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
733  }
734
735  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
736  assert(uiCode <= 64);
737  pcSPS->createRPSList(uiCode);
738
739  TComRPSList* rpsList = pcSPS->getRPSList();
740  TComReferencePictureSet* rps;
741
742  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
743  {
744    rps = rpsList->getReferencePictureSet(i);
745    parseShortTermRefPicSet(pcSPS,rps,i);
746  }
747  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
748  if (pcSPS->getLongTermRefsPresent()) 
749  {
750    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
751    pcSPS->setNumLongTermRefPicSPS(uiCode);
752    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
753    {
754      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
755      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
756      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
757      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
758    }
759  }
760  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
761
762  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
763
764  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
765
766  if (pcSPS->getVuiParametersPresentFlag())
767  {
768    parseVUI(pcSPS->getVuiParameters(), pcSPS);
769  }
770
771  READ_FLAG( uiCode, "sps_extension_flag");
772  if (uiCode)
773  {
774#if H_MV
775    parseSPSExtension( pcSPS ); 
776    READ_FLAG( uiCode, "sps_extension2_flag");
777    if ( uiCode )
778    {
779#if H_3D
780      parseSPSExtension2( pcSPS, viewIndex, depthFlag ); 
781      READ_FLAG( uiCode, "sps_extension3_flag");
782      if ( uiCode )
783      {
784#endif
785#endif
786        while ( xMoreRbspData() )
787        {
788          READ_FLAG( uiCode, "sps_extension_data_flag");
789        }
790#if H_MV     
791#if H_3D
792      }
793#endif
794    }
795#endif
796  }
797}
798
799#if H_MV
800Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
801{
802  UInt uiCode; 
803  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
804  READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" ); 
805}
806
807#if H_3D
808Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
809{ 
810  UInt uiCode; 
811#if H_3D_QTLPC
812  //GT: This has to go to VPS
813  if( depthFlag )
814  {
815#if H_3DV
816    READ_FLAG( uiCode, "use_qtl_flag" );
817    pcSPS->setUseQTL( uiCode );
818    READ_FLAG( uiCode, "use_pc_flag" );
819    pcSPS->setUsePC( uiCode );
820#else
821    pcSPS->setUsePC( 0 );
822#endif
823  }
824#endif
825
826  UInt uiCamParPrecision = 0; 
827  Bool bCamParSlice      = false; 
828  if ( !depthFlag )
829  {     
830    READ_UVLC( uiCamParPrecision, "cp_precision" );
831    READ_FLAG( uiCode, "cp_in_slice_header_flag" );    bCamParSlice = ( uiCode == 1 );
832    if( !bCamParSlice )
833    {       
834      for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
835      {
836        Int iCode; 
837        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
838        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
839        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
840        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
841      }
842    }
843  }
844  pcSPS->initCamParaSPS( viewIndex, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
845}
846#endif
847#endif
848
849Void TDecCavlc::parseVPS(TComVPS* pcVPS)
850{
851  UInt  uiCode;
852 
853  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
854  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
855#if H_MV
856  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( uiCode  );
857#else
858  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
859#endif
860  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
861  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
862  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
863#if H_MV
864  READ_CODE( 16, uiCode,  "vps_extension_offset" );               
865#else
866  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
867#endif
868  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
869  UInt subLayerOrderingInfoPresentFlag;
870  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
871  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
872  {
873    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
874    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
875    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
876
877    if (!subLayerOrderingInfoPresentFlag)
878    {
879      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
880      {
881        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
882        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
883        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
884      }
885      break;
886    }
887  }
888
889  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
890#if H_MV
891  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
892  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
893
894  READ_UVLC(    uiCode, "vps_max_num_layer_sets_minus1" );               pcVPS->setVpsNumLayerSetsMinus1( uiCode );
895  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
896  {
897    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
898#else
899  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
900  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
901  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
902  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
903  {
904    // Operation point set
905    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
906#endif
907    {
908      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
909    }
910  }
911  TimingInfo *timingInfo = pcVPS->getTimingInfo();
912  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
913  if(timingInfo->getTimingInfoPresentFlag())
914  {
915    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
916    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
917    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
918    if(timingInfo->getPocProportionalToTimingFlag())
919    {
920      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
921    }
922    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
923
924    if( pcVPS->getNumHrdParameters() > 0 )
925    {
926      pcVPS->createHrdParamBuffer();
927    }
928    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
929    {
930      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
931      if( i > 0 )
932      {
933        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
934      }
935      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
936    }
937  }
938  READ_FLAG( uiCode,  "vps_extension_flag" );
939  if (uiCode)
940  {
941#if H_MV
942    m_pcBitstream->readOutTrailingBits();
943    parseVPSExtension( pcVPS );   
944    READ_FLAG( uiCode,  "vps_extension2_flag" );
945    if (uiCode)
946    {
947#if H_3D
948      m_pcBitstream->readOutTrailingBits();
949      parseVPSExtension2( pcVPS );   
950      READ_FLAG( uiCode,  "vps_extension3_flag" );
951      if (uiCode)
952      {     
953#endif
954#endif 
955        while ( xMoreRbspData() )
956        {
957          READ_FLAG( uiCode, "vps_extension_data_flag");
958        }
959#if H_MV
960#if H_3D
961      }
962#endif
963    }
964#endif
965  }
966  return; 
967}
968
969#if H_MV
970Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
971{
972  UInt uiCode; 
973  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
974  READ_CODE( 16, uiCode, "vps_vui_offset" );                      pcVPS->setVpsVuiOffset( uiCode );
975  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
976
977  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
978  {
979    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );     
980  }
981
982  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
983  {
984    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
985  }
986
987  if ( pcVPS->getSplittingFlag() )
988  {
989    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
990  }
991
992  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
993
994  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
995  {
996    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
997    {
998      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
999    }
1000    else
1001    {
1002      pcVPS->setLayerIdInNuh( i, i );; 
1003    }
1004
1005    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
1006
1007    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
1008    {
1009      if ( !pcVPS->getSplittingFlag() )
1010      {
1011        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
1012      }
1013      else
1014      {
1015        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
1016      }
1017    }
1018  }
1019
1020  // GT spec says: trac #39
1021  // if ( pcVPS->getNumViews() > 1 ) 
1022  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
1023  {
1024    READ_CODE( 4, uiCode, "view_id_len_minus1" ); pcVPS->setViewIdLenMinus1( uiCode );
1025  }
1026
1027  for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1028  {
1029    READ_CODE( pcVPS->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
1030  }
1031
1032  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1033  {
1034    for( Int j = 0; j < i; j++ )
1035    {
1036      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
1037    }
1038  }
1039
1040  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
1041
1042  if ( pcVPS->getMaxTidRefPresentFlag() )
1043  {   
1044    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
1045    {
1046      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
1047    }
1048  }
1049
1050  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
1051  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
1052  READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
1053
1054  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
1055  {
1056    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
1057    if( !pcVPS->getVpsProfilePresentFlag( i ) )
1058    {
1059      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
1060    }
1061    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
1062    if( !pcVPS->getVpsProfilePresentFlag( i ) )
1063    {
1064      TComPTL temp = *pcVPS->getPTL( i );
1065      *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
1066      pcVPS->getPTL( i )->copyLevelFrom( &temp );
1067    }
1068  }
1069
1070  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
1071
1072  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
1073
1074  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
1075  {
1076    READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
1077    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
1078  }
1079
1080  if( numOutputLayerSets > 1)
1081  {
1082    READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
1083  } 
1084
1085  for( Int i = 1; i < numOutputLayerSets; i++ )
1086  {
1087    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
1088    {       
1089      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
1090      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
1091      {
1092        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1093      }       
1094    }
1095    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
1096    {     
1097      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
1098    }
1099  }
1100
1101  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
1102  if ( pcVPS->getRepFormatIdxPresentFlag() )
1103  {
1104    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
1105  }
1106
1107  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
1108  { 
1109    assert( pcVPS->getRepFormat(i) == NULL ); 
1110    TComRepFormat* repFormat = new TComRepFormat(); 
1111    parseRepFormat( repFormat );
1112    pcVPS->setRepFormat(i, repFormat ); 
1113  }
1114
1115  if( pcVPS->getRepFormatIdxPresentFlag() ) 
1116  {
1117    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1118    {
1119      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
1120      {
1121        READ_CODE( 4, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1122      }
1123    }
1124  }
1125
1126  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
1127  READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPS->setCrossLayerIrapAlignedFlag( uiCode == 1 );
1128  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
1129
1130  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1131  {
1132    for( Int j = 0; j < i; j++ )
1133    {
1134      if (pcVPS->getDirectDependencyFlag( i, j) )
1135      {       
1136        READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1137      }
1138    }
1139  }
1140
1141  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" ); 
1142  READ_FLAG( uiCode, "vps_vui_present_flag" )       ; pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
1143
1144  if( pcVPS->getVpsVuiPresentFlag() )
1145  {
1146    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
1147    parseVPSVUI( pcVPS ); 
1148  }     
1149
1150  pcVPS->checkVPSExtensionSyntax(); 
1151  pcVPS->setRefLayers(); 
1152}
1153
1154Void TDecCavlc::parseRepFormat( TComRepFormat* pcRepFormat )
1155{
1156  assert( pcRepFormat ); 
1157
1158  UInt uiCode; 
1159  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
1160  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
1161  {
1162    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
1163  }
1164  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
1165  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
1166  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
1167  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
1168}
1169
1170
1171Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
1172{
1173  assert( pcVPS ); 
1174
1175  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1176
1177  assert( pcVPSVUI ); 
1178
1179  UInt uiCode; 
1180  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
1181  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
1182  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1183  {
1184    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
1185    {
1186      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
1187      {
1188        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
1189        {
1190          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
1191        }
1192        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
1193        {
1194          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
1195        }
1196        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
1197        {
1198          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
1199          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
1200        }
1201        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
1202        {
1203          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
1204          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
1205        }
1206      }
1207    }
1208  }
1209
1210  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1211  {
1212    for( Int  j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ ) 
1213    {
1214      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
1215    }
1216  }
1217
1218  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
1219
1220  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1221  {
1222    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1223    {
1224      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
1225      {
1226        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
1227        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1228        {
1229          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
1230          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1231          {
1232            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
1233          }
1234        }
1235      }
1236    }
1237  }
1238}
1239#endif
1240
1241#if H_3D
1242Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
1243{
1244  UInt uiCode; 
1245  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1246  {
1247#if H_3D_ARP
1248    pcVPS->setUseAdvRP  ( i, 0 );
1249    pcVPS->setARPStepNum( i, 1 );
1250#endif 
1251#if MTK_SPIVMP_F0110
1252    pcVPS->setSubPULog2Size(i, 0);
1253#endif
1254    if ( i != 0 )
1255    {
1256      if( !( pcVPS->getDepthId( i ) == 1 ) )
1257      {
1258#if H_3D_IV_MERGE
1259        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1260#if MTK_SPIVMP_F0110
1261        READ_UVLC (uiCode, "log2_sub_PU_size_minus2");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1262#endif
1263#endif
1264#if H_3D_ARP
1265        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1266
1267#endif
1268#if H_3D_NBDV_REF
1269        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1270#endif
1271#if H_3D_VSP
1272        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1273#endif
1274      }
1275      else
1276      {
1277#if QC_DEPTH_IV_MRG_F0125 && H_3D_IV_MERGE
1278        if(i!=1)
1279        {
1280          READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1281        }
1282#endif
1283#if MTK_SPIVMP_F0110
1284        if (i!=1)
1285        {
1286          READ_UVLC (uiCode, "log2_sub_PU_size_minus2");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1287        }
1288#endif
1289#if SEC_MPI_ENABLING_MERGE_F0150
1290        READ_FLAG( uiCode, "mpi_flag[i]" );             pcVPS->setMPIFlag( i, uiCode == 1 ? true : false );
1291#endif
1292        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1293        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
1294#if H_3D_DIM_DLT
1295        if( pcVPS->getVpsDepthModesFlag( i ) )
1296        {
1297          READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
1298        }
1299        if( pcVPS->getUseDLTFlag( i ) )
1300        {
1301          // decode mapping
1302          UInt uiNumDepthValues;
1303          // parse number of values in DLT
1304          READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
1305
1306          // parse actual DLT values
1307          Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
1308          for(Int d=0; d<uiNumDepthValues; d++)
1309          {
1310            READ_UVLC(uiCode, "dlt_depth_value[i][d]");
1311            aiIdx2DepthValue[d] = (Int)uiCode;
1312          }
1313
1314          pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
1315
1316          // clean memory
1317          free(aiIdx2DepthValue);
1318        }
1319#endif
1320#if H_3D_INTER_SDC
1321            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
1322#endif
1323      }
1324    }
1325  }
1326#if H_3DV
1327  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
1328#endif
1329}
1330#endif
1331
1332Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
1333{
1334  UInt  uiCode;
1335  Int   iCode;
1336
1337#if ENC_DEC_TRACE
1338  xTraceSliceHeader(rpcSlice);
1339#endif
1340  TComPPS* pps = NULL;
1341  TComSPS* sps = NULL;
1342#if H_MV
1343  TComVPS* vps = NULL;
1344#endif
1345
1346  UInt firstSliceSegmentInPic;
1347  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1348  if( rpcSlice->getRapPicFlag())
1349  { 
1350    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
1351  }
1352  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1353  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1354  //!KS: need to add error handling code here, if PPS is not available
1355  assert(pps!=0);
1356  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1357  //!KS: need to add error handling code here, if SPS is not available
1358  assert(sps!=0);
1359#if H_MV
1360  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
1361  assert( vps != NULL );
1362 
1363  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
1364  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
1365
1366  rpcSlice->setVPS(vps);     
1367  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
1368  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
1369#if H_3D 
1370  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
1371#endif
1372#endif
1373  rpcSlice->setSPS(sps);
1374  rpcSlice->setPPS(pps);
1375  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1376  {
1377    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1378  }
1379  else
1380  {
1381    rpcSlice->setDependentSliceSegmentFlag(false);
1382  }
1383  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1384  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
1385  UInt sliceSegmentAddress = 0;
1386  Int bitsSliceSegmentAddress = 0;
1387  while(numCTUs>(1<<bitsSliceSegmentAddress))
1388  {
1389    bitsSliceSegmentAddress++;
1390  }
1391
1392  if(!firstSliceSegmentInPic)
1393  {
1394    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
1395  }
1396  //set uiCode to equal slice start address (or dependent slice start address)
1397  Int startCuAddress = maxParts*sliceSegmentAddress;
1398  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
1399  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
1400
1401  if (rpcSlice->getDependentSliceSegmentFlag())
1402  {
1403    rpcSlice->setNextSlice          ( false );
1404    rpcSlice->setNextSliceSegment ( true  );
1405  }
1406  else
1407  {
1408    rpcSlice->setNextSlice          ( true  );
1409    rpcSlice->setNextSliceSegment ( false );
1410
1411    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
1412    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
1413  }
1414 
1415  if(!rpcSlice->getDependentSliceSegmentFlag())
1416  {
1417#if H_MV   
1418    Int esb = 0; //Don't use i, otherwise will shadow something below
1419    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
1420    {
1421      esb++; 
1422      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
1423    }
1424
1425    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
1426    {
1427      esb++; 
1428      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
1429    }
1430
1431    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
1432#else
1433    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1434#endif     
1435    {
1436      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1437    }
1438
1439    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
1440    if( pps->getOutputFlagPresentFlag() )
1441    {
1442      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
1443    }
1444    else
1445    {
1446      rpcSlice->setPicOutputFlag( true );
1447    }
1448    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
1449    assert (sps->getChromaFormatIdc() == 1 );
1450    // if( separate_colour_plane_flag  ==  1 )
1451    //   colour_plane_id                                      u(2)
1452
1453    if( rpcSlice->getIdrPicFlag() )
1454    {
1455      rpcSlice->setPOC(0);
1456      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
1457      rps->setNumberOfNegativePictures(0);
1458      rps->setNumberOfPositivePictures(0);
1459      rps->setNumberOfLongtermPictures(0);
1460      rps->setNumberOfPictures(0);
1461      rpcSlice->setRPS(rps);
1462#if H_MV
1463      rpcSlice->setEnableTMVPFlag(false);
1464#endif
1465    }
1466    else
1467    {
1468      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
1469      Int iPOClsb = uiCode;
1470      Int iPrevPOC = rpcSlice->getPrevTid0POC();
1471      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
1472      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
1473      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
1474      Int iPOCmsb;
1475      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
1476      {
1477        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
1478      }
1479      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
1480      {
1481        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
1482      }
1483      else
1484      {
1485        iPOCmsb = iPrevPOCmsb;
1486      }
1487      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1488        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1489        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1490      {
1491        // For BLA picture types, POCmsb is set to 0.
1492        iPOCmsb = 0;
1493      }
1494      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
1495#if H_MV
1496      if ( rpcSlice->getPocResetFlag() ) 
1497      {
1498        rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
1499        rpcSlice->setPOC              ( 0 );
1500
1501      }     
1502#endif
1503      TComReferencePictureSet* rps;
1504      rps = rpcSlice->getLocalRPS();
1505      rpcSlice->setRPS(rps);
1506      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
1507      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
1508      {
1509        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
1510      }
1511      else // use reference to short-term reference picture set in PPS
1512      {
1513        Int numBits = 0;
1514        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
1515        {
1516          numBits++;
1517        }
1518        if (numBits > 0)
1519        {
1520          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
1521        }
1522        else
1523        {
1524          uiCode = 0;
1525        }
1526        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
1527      }
1528      if(sps->getLongTermRefsPresent())
1529      {
1530        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
1531        UInt numOfLtrp = 0;
1532        UInt numLtrpInSPS = 0;
1533        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
1534        {
1535          READ_UVLC( uiCode, "num_long_term_sps");
1536          numLtrpInSPS = uiCode;
1537          numOfLtrp += numLtrpInSPS;
1538          rps->setNumberOfLongtermPictures(numOfLtrp);
1539        }
1540        Int bitsForLtrpInSPS = 0;
1541        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
1542        {
1543          bitsForLtrpInSPS++;
1544        }
1545        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
1546        numOfLtrp += uiCode;
1547        rps->setNumberOfLongtermPictures(numOfLtrp);
1548        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
1549        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
1550        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
1551        {
1552          Int pocLsbLt;
1553          if (k < numLtrpInSPS)
1554          {
1555            uiCode = 0;
1556            if (bitsForLtrpInSPS > 0)
1557            {
1558              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
1559            }
1560            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
1561
1562            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
1563            rps->setUsed(j,usedByCurrFromSPS);
1564          }
1565          else
1566          {
1567            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
1568            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
1569          }
1570          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
1571          Bool mSBPresentFlag = uiCode ? true : false;
1572          if(mSBPresentFlag)                 
1573          {
1574            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
1575            Bool deltaFlag = false;
1576            //            First LTRP                               || First LTRP from SH
1577            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
1578            {
1579              deltaFlag = true;
1580            }
1581            if(deltaFlag)
1582            {
1583              deltaPocMSBCycleLT = uiCode;
1584            }
1585            else
1586            {
1587              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
1588            }
1589
1590            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
1591                                        - iPOClsb + pocLsbLt;
1592            rps->setPOC     (j, pocLTCurr); 
1593            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
1594            rps->setCheckLTMSBPresent(j,true); 
1595          }
1596          else
1597          {
1598            rps->setPOC     (j, pocLsbLt);
1599            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
1600            rps->setCheckLTMSBPresent(j,false); 
1601           
1602            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
1603            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
1604            {
1605              deltaPocMSBCycleLT = 0;
1606            }
1607          }
1608          prevDeltaMSB = deltaPocMSBCycleLT;
1609        }
1610        offset += rps->getNumberOfLongtermPictures();
1611        rps->setNumberOfPictures(offset);       
1612      } 
1613      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1614        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1615        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1616      {
1617        // In the case of BLA picture types, rps data is read from slice header but ignored
1618        rps = rpcSlice->getLocalRPS();
1619        rps->setNumberOfNegativePictures(0);
1620        rps->setNumberOfPositivePictures(0);
1621        rps->setNumberOfLongtermPictures(0);
1622        rps->setNumberOfPictures(0);
1623        rpcSlice->setRPS(rps);
1624      }
1625      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
1626      {
1627        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
1628        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
1629      }
1630      else
1631      {
1632        rpcSlice->setEnableTMVPFlag(false);
1633      }
1634    }
1635#if H_MV
1636    Int layerId       = rpcSlice->getLayerId(); 
1637    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )    {   
1638      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
1639      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
1640      {           
1641        if( !vps->getMaxOneActiveRefLayerFlag()) 
1642        {
1643          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
1644        }
1645        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
1646        {
1647          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
1648          {
1649            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
1650          }
1651        }
1652      } 
1653    }
1654#endif
1655    if(sps->getUseSAO())
1656    {
1657      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
1658      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
1659    }
1660
1661    if (rpcSlice->getIdrPicFlag())
1662    {
1663      rpcSlice->setEnableTMVPFlag(false);
1664    }
1665    if (!rpcSlice->isIntra())
1666    {
1667
1668      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
1669      if (uiCode)
1670      {
1671        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
1672        if (rpcSlice->isInterB())
1673        {
1674          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
1675        }
1676        else
1677        {
1678          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
1679        }
1680      }
1681      else
1682      {
1683        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
1684        if (rpcSlice->isInterB())
1685        {
1686          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
1687        }
1688        else
1689        {
1690          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
1691        }
1692      }
1693    }
1694    // }
1695    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
1696    if(!rpcSlice->isIntra())
1697    {
1698      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1699      {
1700        refPicListModification->setRefPicListModificationFlagL0( 0 );
1701      }
1702      else
1703      {
1704        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
1705      }
1706
1707      if(refPicListModification->getRefPicListModificationFlagL0())
1708      { 
1709        uiCode = 0;
1710        Int i = 0;
1711        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
1712        if ( numRpsCurrTempList0 > 1 )
1713        {
1714          Int length = 1;
1715          numRpsCurrTempList0 --;
1716          while ( numRpsCurrTempList0 >>= 1) 
1717          {
1718            length ++;
1719          }
1720          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1721          {
1722            READ_CODE( length, uiCode, "list_entry_l0" );
1723            refPicListModification->setRefPicSetIdxL0(i, uiCode );
1724          }
1725        }
1726        else
1727        {
1728          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1729          {
1730            refPicListModification->setRefPicSetIdxL0(i, 0 );
1731          }
1732        }
1733      }
1734    }
1735    else
1736    {
1737      refPicListModification->setRefPicListModificationFlagL0(0);
1738    }
1739    if(rpcSlice->isInterB())
1740    {
1741      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1742      {
1743        refPicListModification->setRefPicListModificationFlagL1( 0 );
1744      }
1745      else
1746      {
1747        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
1748      }
1749      if(refPicListModification->getRefPicListModificationFlagL1())
1750      {
1751        uiCode = 0;
1752        Int i = 0;
1753        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
1754        if ( numRpsCurrTempList1 > 1 )
1755        {
1756          Int length = 1;
1757          numRpsCurrTempList1 --;
1758          while ( numRpsCurrTempList1 >>= 1) 
1759          {
1760            length ++;
1761          }
1762          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1763          {
1764            READ_CODE( length, uiCode, "list_entry_l1" );
1765            refPicListModification->setRefPicSetIdxL1(i, uiCode );
1766          }
1767        }
1768        else
1769        {
1770          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1771          {
1772            refPicListModification->setRefPicSetIdxL1(i, 0 );
1773          }
1774        }
1775      }
1776    } 
1777    else
1778    {
1779      refPicListModification->setRefPicListModificationFlagL1(0);
1780    }
1781    if (rpcSlice->isInterB())
1782    {
1783      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
1784    }
1785
1786    rpcSlice->setCabacInitFlag( false ); // default
1787    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
1788    {
1789      READ_FLAG(uiCode, "cabac_init_flag");
1790      rpcSlice->setCabacInitFlag( uiCode ? true : false );
1791    }
1792
1793    if ( rpcSlice->getEnableTMVPFlag() )
1794    {
1795      if ( rpcSlice->getSliceType() == B_SLICE )
1796      {
1797        READ_FLAG( uiCode, "collocated_from_l0_flag" );
1798        rpcSlice->setColFromL0Flag(uiCode);
1799      }
1800      else
1801      {
1802        rpcSlice->setColFromL0Flag( 1 );
1803      }
1804
1805      if ( rpcSlice->getSliceType() != I_SLICE &&
1806          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
1807           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
1808      {
1809        READ_UVLC( uiCode, "collocated_ref_idx" );
1810        rpcSlice->setColRefIdx(uiCode);
1811      }
1812      else
1813      {
1814        rpcSlice->setColRefIdx(0);
1815      }
1816    }
1817    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
1818    {
1819      xParsePredWeightTable(rpcSlice);
1820      rpcSlice->initWpScaling();
1821    }
1822#if H_3D_IC
1823#if SEC_ONLY_TEXTURE_IC_F0151
1824    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) && !rpcSlice->getIsDepth())
1825#else
1826    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) )
1827#endif
1828    {
1829      UInt uiCodeTmp = 0;
1830
1831      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
1832      rpcSlice->setApplyIC( uiCodeTmp );
1833
1834      if ( uiCodeTmp )
1835      {
1836        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
1837        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
1838      }
1839    }
1840#endif
1841    if (!rpcSlice->isIntra())
1842    {
1843      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
1844#if H_3D_IV_MERGE
1845#if SEC_MPI_ENABLING_MERGE_F0150
1846      if(rpcSlice->getIsDepth())
1847      {
1848        Bool bMPIFlag = rpcSlice->getVPS()->getMPIFlag( rpcSlice->getLayerIdInVps() ) ;
1849        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
1850        rpcSlice->setMaxNumMergeCand(( ( bMPIFlag || ivMvPredFlag ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
1851      }
1852      else
1853      {
1854        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
1855        rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
1856      }
1857#else
1858      Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
1859      rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
1860#endif
1861#else
1862      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
1863#endif
1864    }
1865
1866    READ_SVLC( iCode, "slice_qp_delta" );
1867    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
1868
1869    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
1870    assert( rpcSlice->getSliceQp() <=  51 );
1871
1872    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
1873    {
1874      READ_SVLC( iCode, "slice_qp_delta_cb" );
1875      rpcSlice->setSliceQpDeltaCb( iCode );
1876      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
1877      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
1878      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
1879      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
1880
1881      READ_SVLC( iCode, "slice_qp_delta_cr" );
1882      rpcSlice->setSliceQpDeltaCr( iCode );
1883      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
1884      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
1885      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
1886      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
1887    }
1888
1889    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
1890    {
1891      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
1892      {
1893        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
1894      }
1895      else
1896      { 
1897        rpcSlice->setDeblockingFilterOverrideFlag(0);
1898      }
1899      if(rpcSlice->getDeblockingFilterOverrideFlag())
1900      {
1901        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
1902        if(!rpcSlice->getDeblockingFilterDisable())
1903        {
1904          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
1905          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
1906                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
1907          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
1908          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
1909                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
1910        }
1911      }
1912      else
1913      {
1914        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
1915        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
1916        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
1917      }
1918    }
1919    else
1920    { 
1921      rpcSlice->setDeblockingFilterDisable       ( false );
1922      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
1923      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
1924    }
1925
1926    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
1927    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
1928
1929    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
1930    {
1931      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
1932    }
1933    else
1934    {
1935      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
1936    }
1937    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
1938
1939  }
1940 
1941    UInt *entryPointOffset          = NULL;
1942    UInt numEntryPointOffsets, offsetLenMinus1;
1943  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1944  {
1945    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
1946    if (numEntryPointOffsets>0)
1947    {
1948      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
1949    }
1950    entryPointOffset = new UInt[numEntryPointOffsets];
1951    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
1952    {
1953      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
1954      entryPointOffset[ idx ] = uiCode + 1;
1955    }
1956  }
1957  else
1958  {
1959    rpcSlice->setNumEntryPointOffsets ( 0 );
1960  }
1961
1962  if(pps->getSliceHeaderExtensionPresentFlag())
1963  {
1964    READ_UVLC(uiCode,"slice_header_extension_length");
1965#if H_3D
1966    if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
1967    {
1968      UInt uiViewIndex = rpcSlice->getViewIndex();
1969      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
1970      {
1971        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
1972        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
1973        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
1974        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
1975      }
1976      rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
1977    }
1978
1979    READ_FLAG(uiCode,"slice_segment_header_extension2_flag"); 
1980    if ( uiCode )
1981    {   
1982      READ_UVLC(uiCode,"slice_header_extension2_length");
1983      for(Int i=0; i<uiCode; i++)
1984      {
1985        UInt ignore;
1986        READ_CODE(8,ignore,"slice_header_extension2_data_byte");
1987      }
1988    }
1989  }
1990#else
1991    for(Int i=0; i<uiCode; i++)
1992    {
1993      UInt ignore;
1994      READ_CODE(8,ignore,"slice_header_extension_data_byte");
1995    }
1996  }
1997#endif
1998  m_pcBitstream->readByteAlignment();
1999
2000  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2001  {
2002    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2003   
2004    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2005    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2006    {
2007      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2008      {
2009        endOfSliceHeaderLocation++;
2010      }
2011    }
2012
2013    Int  curEntryPointOffset     = 0;
2014    Int  prevEntryPointOffset    = 0;
2015    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2016    {
2017      curEntryPointOffset += entryPointOffset[ idx ];
2018
2019      Int emulationPreventionByteCount = 0;
2020      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2021      {
2022        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
2023             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2024        {
2025          emulationPreventionByteCount++;
2026        }
2027      }
2028
2029      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2030      prevEntryPointOffset = curEntryPointOffset;
2031    }
2032
2033    if ( pps->getTilesEnabledFlag() )
2034    {
2035      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2036
2037      UInt prevPos = 0;
2038      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2039      {
2040        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2041        prevPos += entryPointOffset[ idx ];
2042      }
2043    }
2044    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2045    {
2046    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2047      rpcSlice->allocSubstreamSizes(numSubstreams);
2048      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2049      for (Int idx=0; idx<numSubstreams-1; idx++)
2050      {
2051        if ( idx < numEntryPointOffsets )
2052        {
2053          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2054        }
2055        else
2056        {
2057          pSubstreamSizes[ idx ] = 0;
2058        }
2059      }
2060    }
2061
2062    if (entryPointOffset)
2063    {
2064      delete [] entryPointOffset;
2065    }
2066  }
2067
2068  return;
2069}
2070 
2071Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2072{
2073  UInt uiCode;
2074  if(profilePresentFlag)
2075  {
2076    parseProfileTier(rpcPTL->getGeneralPTL());
2077  }
2078  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2079
2080  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2081  {
2082#if !H_MV
2083    if(profilePresentFlag)
2084    {
2085#endif
2086      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2087#if H_MV
2088    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
2089#else
2090    }
2091#endif
2092    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2093  }
2094 
2095  if (maxNumSubLayersMinus1 > 0)
2096  {
2097    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2098    {
2099      READ_CODE(2, uiCode, "reserved_zero_2bits");
2100      assert(uiCode == 0);
2101    }
2102  }
2103 
2104  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2105  {
2106    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2107    {
2108      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2109    }
2110    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2111    {
2112      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2113    }
2114  }
2115}
2116
2117Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2118{
2119  UInt uiCode;
2120  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2121  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2122  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2123  for(Int j = 0; j < 32; j++)
2124  {
2125    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2126  }
2127  READ_FLAG(uiCode, "general_progressive_source_flag");
2128  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2129
2130  READ_FLAG(uiCode, "general_interlaced_source_flag");
2131  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2132 
2133  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2134  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2135 
2136  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2137  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2138 
2139  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2140  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2141  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2142}
2143
2144Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2145{
2146  ruiBit = false;
2147  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2148  if(iBitsLeft <= 8)
2149  {
2150    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2151    if (uiPeekValue == (1<<(iBitsLeft-1)))
2152    {
2153      ruiBit = true;
2154    }
2155  }
2156}
2157
2158Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2159{
2160  assert(0);
2161}
2162
2163Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2164{
2165  assert(0);
2166}
2167
2168Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2169{
2170  assert(0);
2171}
2172
2173Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2174{
2175  assert(0);
2176}
2177
2178Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2179{
2180  assert(0);
2181}
2182
2183Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2184{
2185  assert(0);
2186}
2187
2188/** Parse I_PCM information.
2189* \param pcCU pointer to CU
2190* \param uiAbsPartIdx CU index
2191* \param uiDepth CU depth
2192* \returns Void
2193*
2194* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2195*/
2196Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2197{
2198  assert(0);
2199}
2200
2201Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2202{ 
2203  assert(0);
2204}
2205
2206Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2207{
2208  assert(0);
2209}
2210
2211Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2212{
2213  assert(0);
2214}
2215
2216Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2217{
2218  assert(0);
2219}
2220
2221Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
2222{
2223  assert(0);
2224}
2225
2226Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2227{
2228  Int qp;
2229  Int  iDQp;
2230
2231  xReadSvlc( iDQp );
2232
2233  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
2234  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2235
2236  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
2237  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2238
2239  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2240}
2241
2242Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
2243{
2244  assert(0);
2245}
2246
2247Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
2248{
2249  assert(0);
2250}
2251
2252Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
2253{
2254  assert(0);
2255}
2256
2257Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
2258{
2259  assert(0);
2260}
2261
2262Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
2263{
2264  assert(0);
2265}
2266
2267Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
2268{
2269  assert(0);
2270}
2271
2272Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
2273{
2274  assert(0);
2275}
2276
2277#if H_3D_ARP
2278Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2279{
2280  assert(0);
2281}
2282#endif
2283#if H_3D_IC
2284Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2285{
2286  assert(0);
2287}
2288#endif
2289#if H_3D_INTER_SDC
2290Void TDecCavlc::parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2291{
2292  assert(0);
2293}
2294
2295Void TDecCavlc::parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
2296{
2297  assert(0);
2298}
2299#endif
2300// ====================================================================================================================
2301// Protected member functions
2302// ====================================================================================================================
2303
2304/** parse explicit wp tables
2305* \param TComSlice* pcSlice
2306* \returns Void
2307*/
2308Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
2309{
2310  wpScalingParam  *wp;
2311  Bool            bChroma     = true; // color always present in HEVC ?
2312  SliceType       eSliceType  = pcSlice->getSliceType();
2313  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
2314  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
2315  UInt            uiTotalSignalledWeightFlags = 0;
2316 
2317  Int iDeltaDenom;
2318  // decode delta_luma_log2_weight_denom :
2319  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
2320  assert( uiLog2WeightDenomLuma <= 7 );
2321  if( bChroma ) 
2322  {
2323    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
2324    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
2325    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
2326    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
2327  }
2328
2329  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
2330  {
2331    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
2332    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2333    {
2334      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2335
2336      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
2337      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2338      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2339
2340      UInt  uiCode;
2341      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
2342      wp[0].bPresentFlag = ( uiCode == 1 );
2343      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
2344    }
2345    if ( bChroma ) 
2346    {
2347      UInt  uiCode;
2348      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2349      {
2350        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2351        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
2352        wp[1].bPresentFlag = ( uiCode == 1 );
2353        wp[2].bPresentFlag = ( uiCode == 1 );
2354        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
2355      }
2356    }
2357    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
2358    {
2359      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2360      if ( wp[0].bPresentFlag ) 
2361      {
2362        Int iDeltaWeight;
2363        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
2364        assert( iDeltaWeight >= -128 );
2365        assert( iDeltaWeight <=  127 );
2366        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
2367        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
2368        assert( wp[0].iOffset >= -128 );
2369        assert( wp[0].iOffset <=  127 );
2370      }
2371      else 
2372      {
2373        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
2374        wp[0].iOffset = 0;
2375      }
2376      if ( bChroma ) 
2377      {
2378        if ( wp[1].bPresentFlag ) 
2379        {
2380          for ( Int j=1 ; j<3 ; j++ ) 
2381          {
2382            Int iDeltaWeight;
2383            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
2384            assert( iDeltaWeight >= -128 );
2385            assert( iDeltaWeight <=  127 );
2386            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
2387
2388            Int iDeltaChroma;
2389            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
2390            assert( iDeltaChroma >= -512 );
2391            assert( iDeltaChroma <=  511 );
2392            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
2393            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
2394          }
2395        }
2396        else 
2397        {
2398          for ( Int j=1 ; j<3 ; j++ ) 
2399          {
2400            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
2401            wp[j].iOffset = 0;
2402          }
2403        }
2404      }
2405    }
2406
2407    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
2408    {
2409      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2410
2411      wp[0].bPresentFlag = false;
2412      wp[1].bPresentFlag = false;
2413      wp[2].bPresentFlag = false;
2414    }
2415  }
2416  assert(uiTotalSignalledWeightFlags<=24);
2417}
2418
2419/** decode quantization matrix
2420* \param scalingList quantization matrix information
2421*/
2422Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
2423{
2424  UInt  code, sizeId, listId;
2425  Bool scalingListPredModeFlag;
2426  //for each size
2427  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2428  {
2429    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
2430    {
2431      READ_FLAG( code, "scaling_list_pred_mode_flag");
2432      scalingListPredModeFlag = (code) ? true : false;
2433      if(!scalingListPredModeFlag) //Copy Mode
2434      {
2435        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
2436        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
2437        if( sizeId > SCALING_LIST_8x8 )
2438        {
2439          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
2440        }
2441        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
2442
2443      }
2444      else //DPCM Mode
2445      {
2446        xDecodeScalingList(scalingList, sizeId, listId);
2447      }
2448    }
2449  }
2450
2451  return;
2452}
2453/** decode DPCM
2454* \param scalingList  quantization matrix information
2455* \param sizeId size index
2456* \param listId list index
2457*/
2458Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
2459{
2460  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
2461  Int data;
2462  Int scalingListDcCoefMinus8 = 0;
2463  Int nextCoef = SCALING_LIST_START_VALUE;
2464  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
2465  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
2466
2467  if( sizeId > SCALING_LIST_8x8 )
2468  {
2469    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
2470    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
2471    nextCoef = scalingList->getScalingListDC(sizeId,listId);
2472  }
2473
2474  for(i = 0; i < coefNum; i++)
2475  {
2476    READ_SVLC( data, "scaling_list_delta_coef");
2477    nextCoef = (nextCoef + data + 256 ) % 256;
2478    dst[scan[i]] = nextCoef;
2479  }
2480}
2481
2482Bool TDecCavlc::xMoreRbspData()
2483{ 
2484  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
2485
2486  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
2487  if (bitsLeft > 8)
2488  {
2489    return true;
2490  }
2491
2492  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
2493  Int cnt = bitsLeft;
2494
2495  // remove trailing bits equal to zero
2496  while ((cnt>0) && ((lastByte & 1) == 0))
2497  {
2498    lastByte >>= 1;
2499    cnt--;
2500  }
2501  // remove bit equal to one
2502  cnt--;
2503
2504  // we should not have a negative number of bits
2505  assert (cnt>=0);
2506
2507  // we have more data, if cnt is not zero
2508  return (cnt>0);
2509}
2510
2511//! \}
2512
Note: See TracBrowser for help on using the repository browser.