source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 292

Last change on this file since 292 was 291, checked in by nokia, 12 years ago

JCTVC-M0457: Co-located picture signaling

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