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

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

Merged HTM-DEV-0.3-dev1 Rev. 520.

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