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

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

Integrated following changes:

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