source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 772

Last change on this file since 772 was 772, checked in by seregin, 12 years ago

fix assignment of all_layers_idr_aligned_flag, ticket #29

  • Property svn:eol-style set to native
File size: 133.9 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license.
5*
6* Copyright (c) 2010-2014, 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#if Q0048_CGS_3D_ASYMLUT
42#include "../TLibCommon/TCom3DAsymLUT.h"
43#endif
44
45//! \ingroup TLibDecoder
46//! \{
47
48#if ENC_DEC_TRACE
49
50Void  xTraceSPSHeader (TComSPS *pSPS)
51{
52  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
53}
54
55Void  xTracePPSHeader (TComPPS *pPPS)
56{
57  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
58}
59
60Void  xTraceSliceHeader (TComSlice *pSlice)
61{
62  fprintf( g_hTrace, "=========== Slice ===========\n");
63}
64
65#endif
66
67// ====================================================================================================================
68// Constructor / destructor / create / destroy
69// ====================================================================================================================
70
71TDecCavlc::TDecCavlc()
72{
73}
74
75TDecCavlc::~TDecCavlc()
76{
77
78}
79
80// ====================================================================================================================
81// Public member functions
82// ====================================================================================================================
83
84void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
85{
86  UInt code;
87  UInt interRPSPred;
88  if (idx > 0)
89  {
90    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
91  }
92  else
93  {
94    interRPSPred = false;
95    rps->setInterRPSPrediction(false);
96  }
97
98  if (interRPSPred)
99  {
100    UInt bit;
101    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
102    {
103      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
104    }
105    else
106    {
107      code = 0;
108    }
109    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
110    Int rIdx =  idx - 1 - code;
111    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
112    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
113    Int k = 0, k0 = 0, k1 = 0;
114    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
115    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
116    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
117    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
118    {
119      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
120      Int refIdc = bit;
121      if (refIdc == 0)
122      {
123        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
124        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
125      }
126      if (refIdc == 1 || refIdc == 2)
127      {
128        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
129        rps->setDeltaPOC(k, deltaPOC);
130        rps->setUsed(k, (refIdc == 1));
131
132        if (deltaPOC < 0)
133        {
134          k0++;
135        }
136        else
137        {
138          k1++;
139        }
140        k++;
141      }
142      rps->setRefIdc(j,refIdc);
143    }
144    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
145    rps->setNumberOfPictures(k);
146    rps->setNumberOfNegativePictures(k0);
147    rps->setNumberOfPositivePictures(k1);
148    rps->sortDeltaPOC();
149  }
150  else
151  {
152    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
153    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
154    Int prev = 0;
155    Int poc;
156    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
157    {
158      READ_UVLC(code, "delta_poc_s0_minus1");
159      poc = prev-code-1;
160      prev = poc;
161      rps->setDeltaPOC(j,poc);
162      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
163    }
164    prev = 0;
165    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
166    {
167      READ_UVLC(code, "delta_poc_s1_minus1");
168      poc = prev+code+1;
169      prev = poc;
170      rps->setDeltaPOC(j,poc);
171      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
172    }
173    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
174  }
175#if PRINT_RPS_INFO
176  rps->printDeltaPOC();
177#endif
178}
179
180Void TDecCavlc::parsePPS(TComPPS* pcPPS
181#if Q0048_CGS_3D_ASYMLUT
182  , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
183#endif
184  )
185{
186#if ENC_DEC_TRACE
187  xTracePPSHeader (pcPPS);
188#endif
189  UInt  uiCode;
190
191  Int   iCode;
192
193  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
194  assert(uiCode <= 63);
195  pcPPS->setPPSId (uiCode);
196
197  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
198  assert(uiCode <= 15);
199  pcPPS->setSPSId (uiCode);
200
201  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
202  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
203
204  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
205  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
206
207  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
208
209  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
210  assert(uiCode <= 14);
211  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
212
213  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
214  assert(uiCode <= 14);
215  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
216
217  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
218  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
219  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
220  pcPPS->setUseTransformSkip ( uiCode ? true : false );
221
222  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
223  if( pcPPS->getUseDQP() )
224  {
225    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
226    pcPPS->setMaxCuDQPDepth( uiCode );
227  }
228  else
229  {
230    pcPPS->setMaxCuDQPDepth( 0 );
231  }
232  READ_SVLC( iCode, "pps_cb_qp_offset");
233  pcPPS->setChromaCbQpOffset(iCode);
234  assert( pcPPS->getChromaCbQpOffset() >= -12 );
235  assert( pcPPS->getChromaCbQpOffset() <=  12 );
236
237  READ_SVLC( iCode, "pps_cr_qp_offset");
238  pcPPS->setChromaCrQpOffset(iCode);
239  assert( pcPPS->getChromaCrQpOffset() >= -12 );
240  assert( pcPPS->getChromaCrQpOffset() <=  12 );
241
242  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
243  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
244
245  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
246  pcPPS->setUseWP( uiCode==1 );
247  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
248  pcPPS->setWPBiPred( uiCode==1 );
249
250  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
251  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
252  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
253  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
254
255  if( pcPPS->getTilesEnabledFlag() )
256  {
257    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );
258    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );
259    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
260
261    if( !pcPPS->getUniformSpacingFlag())
262    {
263      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
264      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
265      {
266        READ_UVLC( uiCode, "column_width_minus1" );
267        columnWidth[i] = uiCode+1;
268      }
269      pcPPS->setColumnWidth(columnWidth);
270      free(columnWidth);
271
272      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
273      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
274      {
275        READ_UVLC( uiCode, "row_height_minus1" );
276        rowHeight[i] = uiCode + 1;
277      }
278      pcPPS->setRowHeight(rowHeight);
279      free(rowHeight);
280    }
281
282    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
283    {
284      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
285    }
286  }
287  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
288  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
289  if(pcPPS->getDeblockingFilterControlPresentFlag())
290  {
291    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
292    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
293    if(!pcPPS->getPicDisableDeblockingFilterFlag())
294    {
295      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
296      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
297    }
298  }
299
300#if SCALINGLIST_INFERRING
301  if( pcPPS->getLayerId() > 0 )
302  {
303    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
304    pcPPS->setInferScalingListFlag( uiCode );
305  }
306
307  if( pcPPS->getInferScalingListFlag() )
308  {
309    READ_UVLC( uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setScalingListRefLayerId( uiCode );
310
311    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
312    assert( pcPPS->getScalingListRefLayerId() <= 62 );
313
314    pcPPS->setScalingListPresentFlag( false );
315  }
316  else
317  {
318#endif
319
320  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
321
322  if(pcPPS->getScalingListPresentFlag ())
323  {
324    parseScalingList( pcPPS->getScalingList() );
325  }
326
327#if SCALINGLIST_INFERRING
328  }
329#endif
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  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
338  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
339
340  READ_FLAG( uiCode, "pps_extension_flag");
341#if POC_RESET_INFO_INFERENCE
342  pcPPS->setExtensionFlag( uiCode ? true : false );
343
344  if( pcPPS->getExtensionFlag() )
345#else
346  if (uiCode)
347#endif 
348  {
349#if P0166_MODIFIED_PPS_EXTENSION
350    UInt ppsExtensionTypeFlag[8];
351    for (UInt i = 0; i < 8; i++)
352    {
353      READ_FLAG( ppsExtensionTypeFlag[i], "pps_extension_type_flag" );
354    }
355#if !POC_RESET_IDC
356    if (ppsExtensionTypeFlag[1])
357    {
358#else
359    if( ppsExtensionTypeFlag[0] )
360    {
361      READ_FLAG( uiCode, "poc_reset_info_present_flag" );
362      pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
363#if Q0048_CGS_3D_ASYMLUT
364      READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
365      pcPPS->setCGSFlag( uiCode );
366      if( pcPPS->getCGSFlag() )
367      {
368        xParse3DAsymLUT( pc3DAsymLUT );
369        pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
370        pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
371      }
372#endif
373#endif
374    }
375#if POC_RESET_INFO_INFERENCE
376    else  // Extension type 0 absent
377    {
378      pcPPS->setPocResetInfoPresentFlag( false );
379    }
380#endif
381    if (ppsExtensionTypeFlag[7])
382    {
383#endif
384
385    while ( xMoreRbspData() )
386    {
387      READ_FLAG( uiCode, "pps_extension_data_flag");
388    }
389#if P0166_MODIFIED_PPS_EXTENSION
390    }
391#endif
392  }
393#if POC_RESET_INFO_INFERENCE
394  if( !pcPPS->getExtensionFlag() )
395  {
396    pcPPS->setPocResetInfoPresentFlag( false );
397  }
398#endif
399}
400
401Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
402{
403#if ENC_DEC_TRACE
404  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
405#endif
406  UInt  uiCode;
407
408  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
409  if (pcVUI->getAspectRatioInfoPresentFlag())
410  {
411    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
412    if (pcVUI->getAspectRatioIdc() == 255)
413    {
414      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
415      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
416    }
417  }
418
419  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
420  if (pcVUI->getOverscanInfoPresentFlag())
421  {
422    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
423  }
424
425  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
426  if (pcVUI->getVideoSignalTypePresentFlag())
427  {
428    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
429    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
430    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
431    if (pcVUI->getColourDescriptionPresentFlag())
432    {
433      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
434      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
435      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
436    }
437  }
438
439  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
440  if (pcVUI->getChromaLocInfoPresentFlag())
441  {
442    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
443    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
444  }
445
446  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
447
448  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
449
450  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
451
452  READ_FLAG(     uiCode, "default_display_window_flag");
453  if (uiCode != 0)
454  {
455    Window &defDisp = pcVUI->getDefaultDisplayWindow();
456    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
457    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
458    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
459    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
460  }
461  TimingInfo *timingInfo = pcVUI->getTimingInfo();
462  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
463#if SVC_EXTENSION
464  if( pcSPS->getLayerId() > 0 )
465  {
466    assert( timingInfo->getTimingInfoPresentFlag() == false );
467  }
468#endif
469  if(timingInfo->getTimingInfoPresentFlag())
470  {
471    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
472    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
473    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
474    if(timingInfo->getPocProportionalToTimingFlag())
475    {
476      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
477    }
478  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
479  if( pcVUI->getHrdParametersPresentFlag() )
480  {
481    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
482  }
483  }
484  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
485  if (pcVUI->getBitstreamRestrictionFlag())
486  {
487    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
488    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
489    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
490    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
491    assert(uiCode < 4096);
492    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
493    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
494    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
495    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
496  }
497}
498
499Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
500{
501  UInt  uiCode;
502  if( commonInfPresentFlag )
503  {
504    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
505    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
506    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
507    {
508      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
509      if( hrd->getSubPicCpbParamsPresentFlag() )
510      {
511        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
512        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
513        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
514        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
515      }
516      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
517      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
518      if( hrd->getSubPicCpbParamsPresentFlag() )
519      {
520        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
521      }
522      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
523      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
524      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
525    }
526  }
527  Int i, j, nalOrVcl;
528  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
529  {
530    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
531    if( !hrd->getFixedPicRateFlag( i ) )
532    {
533      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
534    }
535    else
536    {
537      hrd->setFixedPicRateWithinCvsFlag( i, true );
538    }
539    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
540    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
541    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
542    {
543      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
544    }
545    else
546    {
547      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
548    }
549    if (!hrd->getLowDelayHrdFlag( i ))
550    {
551      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
552    }
553    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
554    {
555      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
556          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
557      {
558        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
559        {
560          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
561          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
562          if( hrd->getSubPicCpbParamsPresentFlag() )
563          {
564            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
565            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
566          }
567          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
568        }
569      }
570    }
571  }
572}
573
574#if SVC_EXTENSION && !SPS_DPB_PARAMS
575Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
576#else
577Void TDecCavlc::parseSPS(TComSPS* pcSPS)
578#endif
579{
580#if ENC_DEC_TRACE
581  xTraceSPSHeader (pcSPS);
582#endif
583
584  UInt  uiCode;
585  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
586#if SVC_EXTENSION
587  if(pcSPS->getLayerId() == 0)
588  {
589#endif
590    READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
591    assert(uiCode <= 6);
592
593    READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
594#if SVC_EXTENSION
595  }
596#if !SPS_DPB_PARAMS
597  else
598  {
599    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
600    pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
601  }
602#endif
603#endif
604
605#if !Q0177_SPS_TEMP_NESTING_FIX   //This part is not needed anymore as it is already covered by implementation in TDecTop::xActivateParameterSets()
606  if ( pcSPS->getMaxTLayers() == 1 )
607  {
608    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
609#if SVC_EXTENSION
610#if !SPS_DPB_PARAMS
611    assert( pcSPS->getTemporalIdNestingFlag() == true );
612#endif
613#else
614    assert( uiCode == 1 );
615#endif
616  }
617#endif
618
619#ifdef SPS_PTL_FIX
620  if ( pcSPS->getLayerId() == 0)
621  {
622    parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
623  }
624#else
625  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
626#endif
627
628  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
629  assert(uiCode <= 15);
630
631#if REPN_FORMAT_IN_VPS
632  if( pcSPS->getLayerId() > 0 )
633  {
634    READ_FLAG( uiCode, "update_rep_format_flag" );
635    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
636  }
637  else
638  {
639#if REP_FORMAT_FIX
640    pcSPS->setUpdateRepFormatFlag( false );
641#else
642    pcSPS->setUpdateRepFormatFlag( true );
643#endif
644  }
645#if O0096_REP_FORMAT_INDEX
646  if( pcSPS->getLayerId() == 0 )
647#else
648  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
649#endif
650  {
651#endif
652#if AUXILIARY_PICTURES
653    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
654#else
655    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
656#endif
657    assert(uiCode <= 3);
658    // 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
659    assert (uiCode == 1);
660    if( uiCode == 3 )
661    {
662      READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
663    }
664
665    READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
666    READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
667#if REPN_FORMAT_IN_VPS
668  }
669#if O0096_REP_FORMAT_INDEX
670  else if ( pcSPS->getUpdateRepFormatFlag() )
671  {
672    READ_CODE(8, uiCode, "update_rep_format_index");
673    pcSPS->setUpdateRepFormatIndex(uiCode);
674  }
675#endif
676#endif
677  READ_FLAG(     uiCode, "conformance_window_flag");
678  if (uiCode != 0)
679  {
680    Window &conf = pcSPS->getConformanceWindow();
681#if REPN_FORMAT_IN_VPS
682    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
683    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
684    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
685    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
686#else
687    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
688    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
689    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
690    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
691#endif
692  }
693#if REPN_FORMAT_IN_VPS
694#if O0096_REP_FORMAT_INDEX
695  if( pcSPS->getLayerId() == 0 )
696#else
697  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
698#endif
699  {
700#endif
701    READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
702    assert(uiCode <= 6);
703    pcSPS->setBitDepthY( uiCode + 8 );
704    pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
705
706    READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
707    assert(uiCode <= 6);
708    pcSPS->setBitDepthC( uiCode + 8 );
709    pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
710#if REPN_FORMAT_IN_VPS
711  }
712#endif
713  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
714  assert(uiCode <= 12);
715
716#if SPS_DPB_PARAMS
717  if( pcSPS->getLayerId() == 0 ) 
718  {
719#endif
720    UInt subLayerOrderingInfoPresentFlag;
721    READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
722
723    for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
724    {
725      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
726      pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
727      READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
728      pcSPS->setNumReorderPics(uiCode, i);
729      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
730      pcSPS->setMaxLatencyIncrease( uiCode, i );
731
732      if (!subLayerOrderingInfoPresentFlag)
733      {
734        for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
735        {
736          pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
737          pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
738          pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
739        }
740        break;
741      }
742    }
743#if SPS_DPB_PARAMS
744  }
745#endif
746  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
747  Int log2MinCUSize = uiCode + 3;
748  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
749  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
750  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
751 
752  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
753  {
754    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
755  }
756 
757  Int maxCUDepthDelta = uiCode;
758  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
759  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
760  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
761
762  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
763  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
764
765  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
766  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
767
768  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
769  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
770  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
771
772  if(pcSPS->getScalingListFlag())
773  {
774#if SCALINGLIST_INFERRING
775    if( pcSPS->getLayerId() > 0 )
776    {
777      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
778    }
779
780    if( pcSPS->getInferScalingListFlag() )
781    {
782      READ_UVLC( uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setScalingListRefLayerId( uiCode );
783
784      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
785      assert( pcSPS->getScalingListRefLayerId() <= 62 );
786
787      pcSPS->setScalingListPresentFlag( false );
788    }
789    else
790    {
791#endif
792    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
793    if(pcSPS->getScalingListPresentFlag ())
794    {
795      parseScalingList( pcSPS->getScalingList() );
796    }
797#if SCALINGLIST_INFERRING
798    }
799#endif
800  }
801  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
802  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
803
804  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
805  if( pcSPS->getUsePCM() )
806  {
807    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
808    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
809    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
810    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
811    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
812  }
813
814  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
815  assert(uiCode <= 64);
816  pcSPS->createRPSList(uiCode);
817
818  TComRPSList* rpsList = pcSPS->getRPSList();
819  TComReferencePictureSet* rps;
820
821  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
822  {
823    rps = rpsList->getReferencePictureSet(i);
824    parseShortTermRefPicSet(pcSPS,rps,i);
825  }
826  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
827  if (pcSPS->getLongTermRefsPresent())
828  {
829    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
830    pcSPS->setNumLongTermRefPicSPS(uiCode);
831    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
832    {
833      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
834      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
835      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
836      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
837    }
838  }
839  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
840  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
841
842  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
843
844  if (pcSPS->getVuiParametersPresentFlag())
845  {
846    parseVUI(pcSPS->getVuiParameters(), pcSPS);
847  }
848
849  READ_FLAG( uiCode, "sps_extension_flag");
850  if (uiCode)
851  {
852#if SPS_EXTENSION
853
854#if O0142_CONDITIONAL_SPS_EXTENSION
855    UInt spsExtensionTypeFlag[8];
856    for (UInt i = 0; i < 8; i++)
857    {
858      READ_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
859    }
860    if (spsExtensionTypeFlag[1])
861    {
862      parseSPSExtension( pcSPS );
863    }
864    if (spsExtensionTypeFlag[7])
865    {
866#else
867    parseSPSExtension( pcSPS );
868    READ_FLAG( uiCode, "sps_extension2_flag");
869    if(uiCode)
870    {
871#endif
872
873#endif
874      while ( xMoreRbspData() )
875      {
876        READ_FLAG( uiCode, "sps_extension_data_flag");
877      }
878#if SPS_EXTENSION
879    }
880#endif
881  }
882}
883
884#if SPS_EXTENSION
885Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
886{
887  UInt uiCode;
888  // more syntax elements to be parsed here
889
890  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
891  // Vertical MV component restriction is not used in SHVC CTC
892  assert( uiCode == 0 );
893
894  if( pcSPS->getLayerId() > 0 )
895  {
896    Int iCode;
897    READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
898    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
899    {
900      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
901#if O0098_SCALED_REF_LAYER_ID
902      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
903#endif
904      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
905      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
906      READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
907      READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
908#if P0312_VERT_PHASE_ADJ
909      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);   
910#endif
911    }
912  }
913}
914#endif
915
916Void TDecCavlc::parseVPS(TComVPS* pcVPS)
917{
918  UInt  uiCode;
919
920  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
921  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
922#if VPS_RENAME
923#if O0137_MAX_LAYERID
924  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
925#else
926  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
927#endif
928#else
929  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
930#endif
931  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode+1 <= MAX_TLAYER);
932  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
933  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
934#if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
935#if VPS_EXTN_OFFSET
936  READ_CODE( 16, uiCode,  "vps_extension_offset" );               pcVPS->setExtensionOffset( uiCode );
937#else
938  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
939#endif
940#else
941  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
942#endif
943  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
944  UInt subLayerOrderingInfoPresentFlag;
945  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
946  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
947  {
948    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
949    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
950    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
951
952    if (!subLayerOrderingInfoPresentFlag)
953    {
954      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
955      {
956        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
957        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
958        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
959      }
960      break;
961    }
962  }
963
964#if VPS_RENAME
965  assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
966  assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
967  READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
968  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
969  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
970  {
971    // Operation point set
972    for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ )
973#else
974  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
975  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
976  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
977  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
978  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
979  {
980    // Operation point set
981    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
982#endif
983    {
984      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
985    }
986  }
987#if DERIVE_LAYER_ID_LIST_VARIABLES
988  pcVPS->deriveLayerIdListVariables();
989#endif
990  TimingInfo *timingInfo = pcVPS->getTimingInfo();
991  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
992  if(timingInfo->getTimingInfoPresentFlag())
993  {
994    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
995    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
996    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
997    if(timingInfo->getPocProportionalToTimingFlag())
998    {
999      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
1000    }
1001    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1002
1003    if( pcVPS->getNumHrdParameters() > 0 )
1004    {
1005      pcVPS->createHrdParamBuffer();
1006    }
1007    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1008    {
1009      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1010      if( i > 0 )
1011      {
1012        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1013      }
1014      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1015    }
1016  }
1017
1018#if VPS_EXTNS
1019  READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
1020
1021  // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
1022  if( pcVPS->getMaxLayers() > 1 )
1023  {
1024    assert( pcVPS->getVpsExtensionFlag() == true );
1025  }
1026
1027  if( pcVPS->getVpsExtensionFlag()  )
1028  {
1029    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1030    {
1031      READ_FLAG( uiCode, "vps_extension_alignment_bit_equal_to_one"); assert(uiCode == 1);
1032    }
1033    parseVPSExtension(pcVPS);
1034    READ_FLAG( uiCode, "vps_entension2_flag" );
1035    if(uiCode)
1036    {
1037      while ( xMoreRbspData() )
1038      {
1039        READ_FLAG( uiCode, "vps_extension_data_flag");
1040      }
1041    }
1042  }
1043  else
1044  {
1045    // set default parameters when syntax elements are not present
1046    defaultVPSExtension(pcVPS);   
1047  }
1048#else
1049  READ_FLAG( uiCode,  "vps_extension_flag" );
1050  if (uiCode)
1051  {
1052    while ( xMoreRbspData() )
1053    {
1054      READ_FLAG( uiCode, "vps_extension_data_flag");
1055    }
1056  }
1057#endif
1058
1059  return;
1060}
1061
1062#if SVC_EXTENSION
1063#if VPS_EXTNS
1064Void TDecCavlc::parseVPSExtension(TComVPS *vps)
1065{
1066  UInt uiCode;
1067  // ... More syntax elements to be parsed here
1068#if P0300_ALT_OUTPUT_LAYER_FLAG
1069  Int NumOutputLayersInOutputLayerSet[MAX_VPS_LAYER_SETS_PLUS1];
1070  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
1071#endif
1072#if VPS_EXTN_MASK_AND_DIM_INFO
1073  UInt numScalabilityTypes = 0, i = 0, j = 0;
1074
1075  READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
1076
1077#if !P0307_REMOVE_VPS_VUI_OFFSET
1078#if O0109_MOVE_VPS_VUI_FLAG
1079  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
1080  if ( uiCode )
1081  {
1082#endif
1083#if VPS_VUI_OFFSET
1084  READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
1085#endif
1086#if O0109_MOVE_VPS_VUI_FLAG
1087  }
1088#endif
1089#endif
1090  READ_FLAG( uiCode, "splitting_flag" ); vps->setSplittingFlag(uiCode ? true : false);
1091
1092  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1093  {
1094    READ_FLAG( uiCode, "scalability_mask[i]" ); vps->setScalabilityMask(i, uiCode ? true : false);
1095    numScalabilityTypes += uiCode;
1096  }
1097  vps->setNumScalabilityTypes(numScalabilityTypes);
1098
1099  for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
1100  {
1101    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
1102  }
1103
1104  if(vps->getSplittingFlag())
1105  {
1106    UInt numBits = 0;
1107    for(j = 0; j < numScalabilityTypes - 1; j++)
1108    {
1109      numBits += vps->getDimensionIdLen(j);
1110    }
1111    assert( numBits < 6 );
1112    vps->setDimensionIdLen(numScalabilityTypes-1, 6 - numBits);
1113    numBits = 6;
1114  }
1115
1116  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
1117  vps->setLayerIdInNuh(0, 0);
1118  vps->setLayerIdInVps(0, 0);
1119  for(i = 1; i < vps->getMaxLayers(); i++)
1120  {
1121    if( vps->getNuhLayerIdPresentFlag() )
1122    {
1123      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" ); vps->setLayerIdInNuh(i, uiCode);
1124      assert( uiCode > vps->getLayerIdInNuh(i-1) );
1125    }
1126    else
1127    {
1128      vps->setLayerIdInNuh(i, i);
1129    }
1130    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1131
1132    if( !vps->getSplittingFlag() )
1133    {
1134    for(j = 0; j < numScalabilityTypes; j++)
1135    {
1136      READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
1137#if !AUXILIARY_PICTURES
1138      assert( uiCode <= vps->getMaxLayerId() );
1139#endif
1140    }
1141  }
1142  }
1143#endif
1144#if VIEW_ID_RELATED_SIGNALING
1145  // if ( pcVPS->getNumViews() > 1 )
1146  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
1147  {
1148#if O0109_VIEW_ID_LEN
1149    READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
1150#else
1151    READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
1152#endif
1153  }
1154
1155#if O0109_VIEW_ID_LEN
1156  if ( vps->getViewIdLen() > 0 )
1157  {
1158    for(  i = 0; i < vps->getNumViews(); i++ )
1159    {
1160      READ_CODE( vps->getViewIdLen( ), uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
1161    }
1162  }
1163#else
1164  for(  i = 0; i < vps->getNumViews(); i++ )
1165  {
1166    READ_CODE( vps->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
1167  }
1168#endif
1169#endif // view id related signaling
1170#if VPS_EXTN_DIRECT_REF_LAYERS
1171  // For layer 0
1172  vps->setNumDirectRefLayers(0, 0);
1173  // For other layers
1174  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1175  {
1176    UInt numDirectRefLayers = 0;
1177    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1178    {
1179      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
1180      if(uiCode)
1181      {
1182        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
1183        numDirectRefLayers++;
1184      }
1185    }
1186    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
1187  }
1188#endif
1189#if VPS_TSLAYERS
1190  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
1191
1192  if (vps->getMaxTSLayersPresentFlag())
1193  {
1194    for(i = 0; i < vps->getMaxLayers(); i++)
1195    {
1196      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
1197    }
1198  }
1199  else
1200  {
1201    for( i = 0; i < vps->getMaxLayers(); i++)
1202    {
1203      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
1204    }
1205  }
1206#endif
1207  READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
1208  if (vps->getMaxTidRefPresentFlag())
1209  {
1210    for(i = 0; i < vps->getMaxLayers() - 1; i++)
1211    {
1212#if O0225_MAX_TID_FOR_REF_LAYERS
1213       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
1214       {
1215         if(vps->getDirectDependencyFlag(j, i))
1216         {
1217           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
1218           assert( uiCode <= vps->getMaxTLayers());
1219         }
1220       }
1221#else
1222      READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
1223      assert( uiCode <= vps->getMaxTLayers());
1224#endif
1225    }
1226  }
1227  else
1228  {
1229    for(i = 0; i < vps->getMaxLayers() - 1; i++)
1230    {
1231#if O0225_MAX_TID_FOR_REF_LAYERS
1232       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
1233       {
1234          vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1235       }
1236#else
1237      vps->setMaxTidIlRefPicsPlus1(i, 7);
1238#endif
1239    }
1240  }
1241#if ILP_SSH_SIG
1242    READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
1243#endif
1244#if VPS_EXTN_PROFILE_INFO
1245  // Profile-tier-level signalling
1246#if !VPS_EXTN_UEV_CODING
1247  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1" );     assert( uiCode == (vps->getNumLayerSets() - 1) );
1248  READ_CODE(  6, uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
1249#else
1250  READ_UVLC(  uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
1251#endif
1252  vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
1253  for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
1254  {
1255    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
1256    if( !vps->getProfilePresentFlag(idx) )
1257    {
1258#if P0048_REMOVE_PROFILE_REF
1259      // Copy profile information from previous one
1260      vps->getPTLForExtn(idx)->copyProfileInfo( (idx==1) ? vps->getPTL() : vps->getPTLForExtn( idx - 1 ) );
1261#else
1262      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
1263#if O0109_PROF_REF_MINUS1
1264      assert( vps->getProfileLayerSetRef(idx) <= idx );
1265#else
1266      assert( vps->getProfileLayerSetRef(idx) < idx );
1267#endif
1268      // Copy profile information as indicated
1269      vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
1270#endif
1271    }
1272    parsePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
1273  }
1274#endif
1275
1276#if !VPS_EXTN_UEV_CODING
1277  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
1278  Int numOutputLayerSets = 0;
1279  if(! vps->getMoreOutputLayerSetsThanDefaultFlag() )
1280  {
1281    numOutputLayerSets = vps->getNumLayerSets();
1282  }
1283  else
1284  {
1285    READ_CODE( 10, uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
1286    numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
1287  }
1288#else
1289
1290#if Q0165_NUM_ADD_OUTPUT_LAYER_SETS
1291  if( vps->getNumLayerSets() > 1 )
1292  {
1293    READ_UVLC( uiCode, "num_add_output_layer_sets" );            vps->setNumAddOutputLayerSets( uiCode );
1294    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
1295  }
1296  else
1297  {
1298    vps->setNumAddOutputLayerSets( 0 );
1299  }
1300#else
1301  READ_UVLC( uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
1302#endif
1303
1304  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
1305  assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
1306
1307  Int numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
1308#endif
1309
1310#if P0295_DEFAULT_OUT_LAYER_IDC
1311#if !Q0165_NUM_ADD_OUTPUT_LAYER_SETS
1312  if( numOutputLayerSets > 1 )
1313  {
1314    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
1315  }
1316#endif
1317  vps->setNumOutputLayerSets( numOutputLayerSets );
1318
1319  for(i = 1; i < numOutputLayerSets; i++)
1320  {
1321    if( i > (vps->getNumLayerSets() - 1) )
1322    {
1323      Int numBits = 1;
1324      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
1325      {
1326        numBits++;
1327      }
1328      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
1329    }
1330    else
1331    {
1332      vps->setOutputLayerSetIdx( i, i );
1333    }
1334    if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
1335    {
1336      Int lsIdx = vps->getOutputLayerSetIdx(i);
1337#if NUM_OL_FLAGS
1338      for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1339#else
1340      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
1341#endif
1342      {
1343        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
1344      }
1345    }
1346    else
1347    {
1348      // i <= (vps->getNumLayerSets() - 1)
1349      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
1350      Int lsIdx = i;
1351      if( vps->getDefaultTargetOutputLayerIdc() == 1 )
1352      {
1353        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1354        {
1355          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1) == 0) );
1356        }
1357      }
1358      else if ( vps->getDefaultTargetOutputLayerIdc() == 0 )
1359      {
1360        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1361        {
1362          vps->setOutputLayerFlag(i, j, 1);
1363        }
1364      }
1365    }
1366    Int numBits = 1;
1367    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
1368    {
1369      numBits++;
1370    }
1371    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
1372#if P0300_ALT_OUTPUT_LAYER_FLAG
1373    NumOutputLayersInOutputLayerSet[i] = 0;
1374    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
1375    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
1376    {
1377      NumOutputLayersInOutputLayerSet[i] += vps->getOutputLayerFlag(i, j);
1378      if (vps->getOutputLayerFlag(i, j))
1379      {
1380        OlsHighestOutputLayerId[i] = vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j);
1381      }
1382    }
1383    if (NumOutputLayersInOutputLayerSet[i] == 1 && vps->getNumDirectRefLayers(OlsHighestOutputLayerId[i]) > 0)
1384    {
1385      READ_FLAG(uiCode, "alt_output_layer_flag[i]");
1386      vps->setAltOuputLayerFlag(i, uiCode ? true : false);
1387    }
1388#if Q0165_OUTPUT_LAYER_SET
1389    assert( NumOutputLayersInOutputLayerSet[i]>0 );
1390#endif
1391
1392#endif
1393  }
1394#else
1395  if( numOutputLayerSets > 1 )
1396  {
1397#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
1398    READ_CODE( 2, uiCode, "default_one_target_output_layer_idc" );   vps->setDefaultOneTargetOutputLayerIdc( uiCode );
1399#else
1400    READ_FLAG( uiCode, "default_one_target_output_layer_flag" );   vps->setDefaultOneTargetOutputLayerFlag( uiCode ? true : false );
1401#endif
1402  }
1403  vps->setNumOutputLayerSets( numOutputLayerSets );
1404
1405  for(i = 1; i < numOutputLayerSets; i++)
1406  {
1407    if( i > (vps->getNumLayerSets() - 1) )
1408    {
1409      Int numBits = 1;
1410      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
1411      {
1412        numBits++;
1413      }
1414      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
1415      Int lsIdx = vps->getOutputLayerSetIdx(i);
1416#if NUM_OL_FLAGS
1417      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) ; j++)
1418#else
1419      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
1420#endif
1421      {
1422        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
1423      }
1424    }
1425    else
1426    {
1427#if VPS_DPB_SIZE_TABLE
1428      vps->setOutputLayerSetIdx( i, i );
1429#endif
1430      // i <= (vps->getNumLayerSets() - 1)
1431      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
1432      Int lsIdx = i;
1433#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
1434      if( vps->getDefaultOneTargetOutputLayerIdc() == 1 )
1435      {
1436        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1437        {
1438#if O0135_DEFAULT_ONE_OUT_SEMANTIC
1439          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
1440#else
1441          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
1442#endif
1443        }
1444      }
1445      else if ( vps->getDefaultOneTargetOutputLayerIdc() == 0 )
1446      {
1447        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1448        {
1449          vps->setOutputLayerFlag(i, j, 1);
1450        }
1451      }
1452      else
1453      {
1454        // Other values of default_one_target_output_layer_idc than 0 and 1 are reserved for future use.
1455      }
1456#else
1457      if( vps->getDefaultOneTargetOutputLayerFlag() )
1458      {
1459        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1460        {
1461          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
1462        }
1463      }
1464      else
1465      {
1466        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1467        {
1468          vps->setOutputLayerFlag(i, j, 1);
1469        }
1470      }
1471#endif
1472    }
1473    Int numBits = 1;
1474    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
1475    {
1476      numBits++;
1477    }
1478    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
1479  }
1480#endif
1481
1482#if !P0300_ALT_OUTPUT_LAYER_FLAG
1483#if O0153_ALT_OUTPUT_LAYER_FLAG
1484  if( vps->getMaxLayers() > 1 )
1485  {
1486    READ_FLAG( uiCode, "alt_output_layer_flag");
1487    vps->setAltOuputLayerFlag( uiCode ? true : false );
1488  }
1489#endif
1490#endif
1491
1492#if REPN_FORMAT_IN_VPS
1493#if Q0195_REP_FORMAT_CLEANUP
1494  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
1495  vps->setVpsNumRepFormats( uiCode + 1 );
1496
1497  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
1498  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
1499
1500  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
1501  {
1502    // Read rep_format_structures
1503    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
1504  }
1505
1506  // Default assignment for layer 0
1507  vps->setVpsRepFormatIdx( 0, 0 );
1508
1509  if( vps->getVpsNumRepFormats() > 1 )
1510  {
1511    READ_FLAG( uiCode, "rep_format_idx_present_flag");
1512    vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
1513  }
1514  else
1515  {
1516    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
1517    vps->setRepFormatIdxPresentFlag( false );
1518  }
1519
1520  if( vps->getRepFormatIdxPresentFlag() )
1521  {
1522    for(i = 1; i < vps->getMaxLayers(); i++)
1523    {
1524      Int numBits = 1;
1525      while ((1 << numBits) < (vps->getVpsNumRepFormats()))
1526      {
1527        numBits++;
1528      }
1529      READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
1530      vps->setVpsRepFormatIdx( i, uiCode );
1531    }
1532  }
1533  else
1534  {
1535    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min (i, vps_num_rep_formats_minus1)
1536    for(i = 1; i < vps->getMaxLayers(); i++)
1537    {
1538      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats()-1 ) );
1539    }
1540  }
1541#else
1542  READ_FLAG( uiCode, "rep_format_idx_present_flag");
1543  vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
1544
1545  if( vps->getRepFormatIdxPresentFlag() )
1546  {
1547#if O0096_REP_FORMAT_INDEX
1548#if !VPS_EXTN_UEV_CODING
1549    READ_CODE( 8, uiCode, "vps_num_rep_formats_minus1" );
1550#else
1551    READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
1552#endif
1553#else
1554    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
1555#endif
1556    vps->setVpsNumRepFormats( uiCode + 1 );
1557  }
1558  else
1559  {
1560    // default assignment
1561    assert (vps->getMaxLayers() <= 16);       // If max_layers_is more than 15, num_rep_formats has to be signaled
1562    vps->setVpsNumRepFormats( vps->getMaxLayers() );
1563  }
1564
1565  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
1566  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
1567
1568  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
1569  {
1570    // Read rep_format_structures
1571    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
1572  }
1573
1574  // Default assignment for layer 0
1575  vps->setVpsRepFormatIdx( 0, 0 );
1576  if( vps->getRepFormatIdxPresentFlag() )
1577  {
1578    for(i = 1; i < vps->getMaxLayers(); i++)
1579    {
1580      if( vps->getVpsNumRepFormats() > 1 )
1581      {
1582#if O0096_REP_FORMAT_INDEX
1583#if !VPS_EXTN_UEV_CODING
1584        READ_CODE( 8, uiCode, "vps_rep_format_idx[i]" );
1585#else
1586        Int numBits = 1;
1587        while ((1 << numBits) < (vps->getVpsNumRepFormats()))
1588        {
1589          numBits++;
1590        }
1591        READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
1592#endif
1593#else
1594        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
1595#endif
1596        vps->setVpsRepFormatIdx( i, uiCode );
1597      }
1598      else
1599      {
1600        // default assignment - only one rep_format() structure
1601        vps->setVpsRepFormatIdx( i, 0 );
1602      }
1603    }
1604  }
1605  else
1606  {
1607    // default assignment - each layer assigned each rep_format() structure in the order signaled
1608    for(i = 1; i < vps->getMaxLayers(); i++)
1609    {
1610      vps->setVpsRepFormatIdx( i, i );
1611    }
1612  }
1613#endif
1614#endif
1615#if RESOLUTION_BASED_DPB
1616  vps->assignSubDpbIndices();
1617#endif
1618  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
1619  vps->setMaxOneActiveRefLayerFlag(uiCode);
1620#if O0062_POC_LSB_NOT_PRESENT_FLAG
1621  for(i = 1; i< vps->getMaxLayers(); i++)
1622  {
1623    if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
1624    {
1625      READ_FLAG(uiCode, "poc_lsb_not_present_flag[i]");
1626      vps->setPocLsbNotPresentFlag(i, uiCode);
1627    }
1628  }
1629#endif
1630#if O0215_PHASE_ALIGNMENT
1631  READ_FLAG( uiCode, "cross_layer_phase_alignment_flag"); vps->setPhaseAlignFlag( uiCode == 1 ? true : false );
1632#endif
1633
1634#if !IRAP_ALIGN_FLAG_IN_VPS_VUI
1635  READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
1636  vps->setCrossLayerIrapAlignFlag(uiCode);
1637#endif
1638
1639#if VPS_DPB_SIZE_TABLE
1640  parseVpsDpbSizeTable(vps);
1641#endif
1642
1643#if VPS_EXTN_DIRECT_REF_LAYERS
1644  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
1645#if O0096_DEFAULT_DEPENDENCY_TYPE
1646  READ_FLAG(uiCode, "default_direct_dependency_type_flag"); 
1647  vps->setDefaultDirectDependecyTypeFlag(uiCode == 1? true : false);
1648  if (vps->getDefaultDirectDependencyTypeFlag())
1649  {
1650    READ_CODE( vps->getDirectDepTypeLen(), uiCode, "default_direct_dependency_type" ); 
1651    vps->setDefaultDirectDependecyType(uiCode);
1652  }
1653#endif
1654  for(i = 1; i < vps->getMaxLayers(); i++)
1655  {
1656    for(j = 0; j < i; j++)
1657    {
1658      if (vps->getDirectDependencyFlag(i, j))
1659      {
1660#if O0096_DEFAULT_DEPENDENCY_TYPE
1661        if (vps->getDefaultDirectDependencyTypeFlag())
1662        {
1663          vps->setDirectDependencyType(i, j, vps->getDefaultDirectDependencyType());
1664        }
1665        else
1666        {
1667          READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
1668          vps->setDirectDependencyType(i, j, uiCode);
1669        }
1670#else
1671        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
1672        vps->setDirectDependencyType(i, j, uiCode);
1673#endif
1674      }
1675    }
1676  }
1677#endif
1678#if O0092_0094_DEPENDENCY_CONSTRAINT
1679  vps->setNumRefLayers();
1680
1681  if(vps->getMaxLayers() > MAX_REF_LAYERS)
1682  {
1683    for(i = 1;i < vps->getMaxLayers(); i++)
1684    {
1685      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
1686    }
1687  }
1688#endif
1689
1690#if P0307_VPS_NON_VUI_EXTENSION
1691  READ_UVLC( uiCode,           "vps_non_vui_extension_length"); vps->setVpsNonVuiExtLength((Int)uiCode);
1692
1693  // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive.
1694  assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 );
1695
1696#if P0307_VPS_NON_VUI_EXT_UPDATE
1697  Int nonVuiExtByte = uiCode;
1698  for (i = 1; i <= nonVuiExtByte; i++)
1699  {
1700    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" ); //just parse and discard for now.
1701  }
1702#else
1703  if ( vps->getVpsNonVuiExtLength() > 0 )
1704  {
1705    printf("\n\nUp to the current spec, the value of vps_non_vui_extension_length is supposed to be 0\n");
1706  }
1707#endif
1708#endif
1709
1710#if !O0109_O0199_FLAGS_TO_VUI
1711#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1712  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
1713#endif
1714#if HIGHER_LAYER_IRAP_SKIP_FLAG
1715  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
1716#endif
1717#endif
1718
1719#if P0307_REMOVE_VPS_VUI_OFFSET
1720  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
1721#endif
1722
1723#if O0109_MOVE_VPS_VUI_FLAG
1724  if ( vps->getVpsVuiPresentFlag() )
1725#else
1726  READ_FLAG( uiCode,  "vps_vui_present_flag" );
1727  if (uiCode)
1728#endif
1729  {
1730#if VPS_VUI
1731    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1732    {
1733      READ_FLAG( uiCode, "vps_vui_alignment_bit_equal_to_one"); assert(uiCode == 1);
1734    }
1735    parseVPSVUI(vps);
1736#endif
1737  }
1738  else
1739  {
1740    // set default values for VPS VUI
1741    defaultVPSVUI( vps );
1742  }
1743}
1744
1745Void TDecCavlc::defaultVPSExtension( TComVPS* vps )
1746{
1747  // set default parameters when they are not present
1748  Int i, j;
1749
1750  // When layer_id_in_nuh[ i ] is not present, the value is inferred to be equal to i.
1751  for(i = 0; i < vps->getMaxLayers(); i++)
1752  {
1753    vps->setLayerIdInNuh(i, i);
1754    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1755  }
1756
1757  // When not present, sub_layers_vps_max_minus1[ i ] is inferred to be equal to vps_max_sub_layers_minus1.
1758  for( i = 0; i < vps->getMaxLayers(); i++)
1759  {
1760    vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
1761  }
1762
1763  // When not present, max_tid_il_ref_pics_plus1[ i ][ j ] is inferred to be equal to 7.
1764  for( i = 0; i < vps->getMaxLayers() - 1; i++ )
1765  {
1766#if O0225_MAX_TID_FOR_REF_LAYERS
1767    for( j = i + 1; j < vps->getMaxLayers(); j++ )
1768    {
1769      vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1770    }
1771#else
1772    vps->setMaxTidIlRefPicsPlus1(i, 7);
1773#endif
1774  }
1775 
1776  // When not present, the value of num_add_output_layer_sets is inferred to be equal to 0.
1777  // NumOutputLayerSets = num_add_output_layer_sets + vps_num_layer_sets_minus1 + 1
1778  vps->setNumOutputLayerSets( vps->getNumLayerSets() );
1779
1780  // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following:
1781  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : output_layer_set_idx_minus1[ i ] + 1
1782  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
1783  {
1784    vps->setOutputLayerSetIdx( i, i );
1785    Int lsIdx = vps->getOutputLayerSetIdx(i);
1786
1787    for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
1788    {
1789    vps->setOutputLayerFlag(i, j, 1);
1790    }
1791  }
1792
1793  // The value of sub_layer_dpb_info_present_flag[ i ][ 0 ] for any possible value of i is inferred to be equal to 1
1794  // When not present, the value of sub_layer_dpb_info_present_flag[ i ][ j ] for j greater than 0 and any possible value of i, is inferred to be equal to be equal to 0.
1795  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
1796  {
1797    vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
1798  }
1799 
1800  // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
1801  vps->setVpsNumRepFormats( vps->getMaxLayers() );
1802
1803  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
1804  vps->setRepFormatIdxPresentFlag( false );
1805
1806  if( !vps->getRepFormatIdxPresentFlag() )
1807  {
1808    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min(i, vps_num_rep_formats_minus1).
1809    for(i = 1; i < vps->getMaxLayers(); i++)
1810    {
1811      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats() - 1 ) );
1812    }
1813  }
1814
1815  // vps_poc_lsb_aligned_flag
1816  // When not present, vps_poc_lsb_aligned_flag is inferred to be equal to 0.
1817 
1818#if O0062_POC_LSB_NOT_PRESENT_FLAG
1819  // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
1820  for(i = 1; i< vps->getMaxLayers(); i++)
1821  {
1822    vps->setPocLsbNotPresentFlag(i, 0);
1823  }
1824#endif
1825
1826  // set default values for VPS VUI
1827  defaultVPSVUI( vps );
1828}
1829
1830Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
1831{
1832  // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
1833  vps->setCrossLayerIrapAlignFlag( false );
1834
1835#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1836  // When single_layer_for_non_irap_flag is not present, it is inferred to be equal to 0.
1837  vps->setSingleLayerForNonIrapFlag( false );
1838#endif
1839
1840#if HIGHER_LAYER_IRAP_SKIP_FLAG
1841  // When higher_layer_irap_skip_flag is not present it is inferred to be equal to 0
1842  vps->setHigherLayerIrapSkipFlag( false );
1843#endif
1844}
1845#endif
1846
1847#if REPN_FORMAT_IN_VPS
1848Void  TDecCavlc::parseRepFormat( RepFormat *repFormat, RepFormat *repFormatPrev )
1849{
1850  UInt uiCode;
1851#if REPN_FORMAT_CONTROL_FLAG 
1852  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );        repFormat->setPicWidthVpsInLumaSamples ( uiCode );
1853  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" );       repFormat->setPicHeightVpsInLumaSamples( uiCode );
1854  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" );    repFormat->setChromaAndBitDepthVpsPresentFlag( uiCode ? true : false ); 
1855
1856  if( !repFormatPrev )
1857  {
1858    // The value of chroma_and_bit_depth_vps_present_flag of the first rep_format( ) syntax structure in the VPS shall be equal to 1
1859    assert( repFormat->getChromaAndBitDepthVpsPresentFlag() );
1860  }
1861
1862  if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
1863  {
1864    READ_CODE( 2, uiCode, "chroma_format_vps_idc" );
1865#if AUXILIARY_PICTURES
1866    repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
1867#else
1868    repFormat->setChromaFormatVpsIdc( uiCode );
1869#endif
1870
1871    if( repFormat->getChromaFormatVpsIdc() == 3 )
1872    {
1873      READ_FLAG( uiCode, "separate_colour_plane_vps_flag" );       repFormat->setSeparateColourPlaneVpsFlag( uiCode ? true : false );
1874    }
1875
1876    READ_CODE( 4, uiCode, "bit_depth_vps_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
1877    READ_CODE( 4, uiCode, "bit_depth_vps_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
1878  }
1879  else if( repFormatPrev )
1880  {
1881    // chroma_and_bit_depth_vps_present_flag equal to 0 specifies that the syntax elements, chroma_format_vps_idc, separate_colour_plane_vps_flag, bit_depth_vps_luma_minus8, and
1882    // bit_depth_vps_chroma_minus8 are not present and inferred from the previous rep_format( ) syntax structure in the VPS.
1883
1884    repFormat->setChromaFormatVpsIdc        ( repFormatPrev->getChromaFormatVpsIdc() );
1885    repFormat->setSeparateColourPlaneVpsFlag( repFormatPrev->getSeparateColourPlaneVpsFlag() );
1886    repFormat->setBitDepthVpsLuma           ( repFormatPrev->getBitDepthVpsLuma() );
1887    repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
1888  }
1889#else
1890#if AUXILIARY_PICTURES
1891  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
1892#else
1893  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
1894#endif
1895 
1896  if( repFormat->getChromaFormatVpsIdc() == 3 )
1897  {
1898    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
1899  }
1900
1901  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
1902  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
1903
1904  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
1905  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
1906#endif
1907}
1908#endif
1909#if VPS_DPB_SIZE_TABLE
1910Void TDecCavlc::parseVpsDpbSizeTable( TComVPS *vps )
1911{
1912  UInt uiCode;
1913#if DPB_PARAMS_MAXTLAYERS
1914#if BITRATE_PICRATE_SIGNALLING
1915    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
1916    for(Int i = 0; i < vps->getNumLayerSets(); i++)
1917#else
1918    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
1919    for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
1920#endif
1921    {
1922        UInt maxSLMinus1 = 0;
1923#if CHANGE_NUMSUBDPB_IDX
1924        Int optLsIdx = vps->getOutputLayerSetIdx( i );
1925#else
1926        Int optLsIdx = i;
1927#endif
1928#if BITRATE_PICRATE_SIGNALLING
1929        optLsIdx = i;
1930#endif
1931        for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
1932            Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
1933            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
1934        }
1935        MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
1936#if BITRATE_PICRATE_SIGNALLING
1937        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
1938#endif
1939    }
1940#endif
1941   
1942#if !RESOLUTION_BASED_DPB
1943  vps->deriveNumberOfSubDpbs();
1944#endif
1945  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
1946  {
1947#if CHANGE_NUMSUBDPB_IDX
1948    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
1949#endif
1950    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
1951#if DPB_PARAMS_MAXTLAYERS
1952#if BITRATE_PICRATE_SIGNALLING
1953    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
1954#else
1955    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
1956#endif
1957#else
1958    for(Int j = 0; j <= vps->getMaxTLayers(); j++)
1959#endif
1960    {
1961      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
1962      {
1963        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag[i]");  vps->setSubLayerDpbInfoPresentFlag( i, j, uiCode ? true : false);
1964      }
1965      else
1966      {
1967        if( j == 0 )  // Always signal for the first sub-layer
1968        {
1969          vps->setSubLayerDpbInfoPresentFlag( i, j, true );
1970        }
1971        else // if (j != 0) && !vps->getSubLayerFlagInfoPresentFlag(i)
1972        {
1973          vps->setSubLayerDpbInfoPresentFlag( i, j, false );
1974        }
1975      }
1976      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is present
1977      {
1978#if CHANGE_NUMSUBDPB_IDX
1979        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
1980#else
1981        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
1982#endif
1983        {
1984          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
1985        }
1986        READ_UVLC( uiCode, "max_vps_num_reorder_pics[i][j]" );              vps->setMaxVpsNumReorderPics( i, j, uiCode);
1987#if RESOLUTION_BASED_DPB
1988        if( vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) != vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ) ) 
1989        {
1990          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
1991          {
1992            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1[i][k][j]" ); vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode);
1993          }
1994        }
1995        else  // vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) == vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet )
1996        {         
1997          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
1998          {
1999            vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j));
2000          }
2001        }
2002#endif
2003        READ_UVLC( uiCode, "max_vps_latency_increase_plus1[i][j]" );        vps->setMaxVpsLatencyIncreasePlus1( i, j, uiCode);
2004      }
2005    }
2006    for(Int j = vps->getMaxTLayers(); j < MAX_TLAYER; j++)
2007    {
2008      vps->setSubLayerDpbInfoPresentFlag( i, j, false );
2009    }
2010  }
2011
2012  // Infer values when not signalled
2013  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
2014  {
2015    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
2016    for(Int j = 0; j < MAX_TLAYER; j++)
2017    {
2018      if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
2019      {
2020#if RESOLUTION_BASED_DPB
2021        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
2022#else
2023        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2024#endif
2025        {
2026          vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
2027        }
2028        vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
2029#if RESOLUTION_BASED_DPB
2030        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2031        {
2032          vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
2033        }
2034#endif
2035        vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
2036      }
2037    }
2038  }
2039}
2040#endif
2041#if VPS_VUI
2042Void TDecCavlc::parseVPSVUI(TComVPS *vps)
2043{
2044  UInt i,j;
2045  UInt uiCode;
2046#if O0223_PICTURE_TYPES_ALIGN_FLAG
2047  READ_FLAG(uiCode, "cross_layer_pic_type_aligned_flag" );
2048  vps->setCrossLayerPictureTypeAlignFlag(uiCode);
2049  if (!uiCode) 
2050  {
2051#endif
2052#if IRAP_ALIGN_FLAG_IN_VPS_VUI
2053    READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
2054    vps->setCrossLayerIrapAlignFlag(uiCode);
2055#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
2056    if( uiCode )
2057    {
2058      READ_FLAG( uiCode, "all_layers_idr_aligned_flag" );
2059      vps->setCrossLayerAlignedIdrOnlyFlag(uiCode);
2060    }
2061#endif
2062#endif
2063#if O0223_PICTURE_TYPES_ALIGN_FLAG
2064  }
2065  else
2066  {
2067    vps->setCrossLayerIrapAlignFlag(true);
2068  }
2069#endif
2070
2071  READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
2072  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
2073
2074  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
2075
2076  for( i = 0; i < vps->getNumLayerSets(); i++ )
2077  {
2078#if BITRATE_PICRATE_SIGNALLING
2079    for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
2080#else
2081    for( j = 0; j < vps->getMaxTLayers(); j++ )
2082#endif
2083    {
2084      if( parseFlag && vps->getBitRatePresentVpsFlag() )
2085      {
2086        READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
2087      }
2088      else
2089      {
2090        vps->setBitRatePresentFlag( i, j, false );
2091      }
2092      if( parseFlag && vps->getPicRatePresentVpsFlag() )
2093      {
2094        READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
2095      }
2096      else
2097      {
2098        vps->setPicRatePresentFlag( i, j, false );
2099      }
2100      if( parseFlag && vps->getBitRatePresentFlag(i, j) )
2101      {
2102        READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
2103        READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
2104      }
2105      else
2106      {
2107        vps->setAvgBitRate( i, j, 0 );
2108        vps->setMaxBitRate( i, j, 0 );
2109      }
2110      if( parseFlag && vps->getPicRatePresentFlag(i, j) )
2111      {
2112        READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
2113        READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
2114      }
2115      else
2116      {
2117        vps->setConstPicRateIdc( i, j, 0 );
2118        vps->setAvgPicRate     ( i, j, 0 );
2119      }
2120    }
2121  }
2122#if VPS_VUI_VIDEO_SIGNAL_MOVE
2123  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
2124  if (vps->getVideoSigPresentVpsFlag())
2125  {
2126    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
2127  }
2128  else
2129  {
2130    vps->setNumVideoSignalInfo(vps->getMaxLayers());
2131  }
2132
2133  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
2134  {
2135    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
2136    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
2137    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
2138    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
2139    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
2140  }
2141  if(!vps->getVideoSigPresentVpsFlag())
2142  {
2143    for (i=0; i < vps->getMaxLayers(); i++)
2144    {
2145      vps->setVideoSignalInfoIdx(i,i);
2146    }
2147  }
2148  else {
2149    vps->setVideoSignalInfoIdx(0,0);
2150    if (vps->getNumVideoSignalInfo() > 1 )
2151    {
2152      for (i=1; i < vps->getMaxLayers(); i++)
2153        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
2154    }
2155    else {
2156      for (i=1; i < vps->getMaxLayers(); i++)
2157      {
2158        vps->setVideoSignalInfoIdx(i,0);
2159      }
2160    }
2161  }
2162#endif
2163#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2164  UInt layerIdx;
2165  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vps->setTilesNotInUseFlag(uiCode == 1);
2166  if (!uiCode)
2167  {
2168    for(i = 0; i < vps->getMaxLayers(); i++)
2169    {
2170      READ_FLAG( uiCode, "tiles_in_use_flag[ i ]" ); vps->setTilesInUseFlag(i, (uiCode == 1));
2171      if (uiCode)
2172      {
2173        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[ i ]" ); vps->setLoopFilterNotAcrossTilesFlag(i, (uiCode == 1));
2174      }
2175      else
2176      {
2177        vps->setLoopFilterNotAcrossTilesFlag(i, false);
2178      }
2179    }
2180#endif
2181#if TILE_BOUNDARY_ALIGNED_FLAG
2182    for(i = 1; i < vps->getMaxLayers(); i++)
2183    {
2184      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
2185      {
2186#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2187        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
2188        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
2189          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
2190        }
2191#else
2192        READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
2193#endif
2194      }
2195    }
2196#endif
2197#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2198  }
2199#endif
2200#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2201  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vps->setWppNotInUseFlag(uiCode == 1);
2202  if (!uiCode)
2203  {
2204    for(i = 0; i < vps->getMaxLayers(); i++)
2205    {
2206      READ_FLAG( uiCode, "wpp_in_use_flag[ i ]" ); vps->setWppInUseFlag(i, (uiCode == 1));
2207    }
2208  }
2209#endif
2210
2211#if O0109_O0199_FLAGS_TO_VUI
2212#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2213  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
2214#endif
2215#if HIGHER_LAYER_IRAP_SKIP_FLAG
2216  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
2217
2218  // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0
2219  if( !vps->getSingleLayerForNonIrapFlag() )
2220  {
2221    assert( !vps->getHigherLayerIrapSkipFlag() );
2222  }
2223#endif
2224#endif
2225#if P0312_VERT_PHASE_ADJ
2226  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
2227#endif
2228#if N0160_VUI_EXT_ILP_REF
2229  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vps->setIlpRestrictedRefLayersFlag( uiCode == 1 );
2230  if( vps->getIlpRestrictedRefLayersFlag())
2231  {
2232    for(i = 1; i < vps->getMaxLayers(); i++)
2233    {
2234      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
2235      {
2236        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
2237        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
2238        {
2239          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 );
2240          if(vps->getCtuBasedOffsetEnabledFlag(i,j))
2241          {
2242            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode );
2243          }
2244        }
2245      }
2246    }
2247  }
2248#endif
2249#if VPS_VUI_VIDEO_SIGNAL
2250#if VPS_VUI_VIDEO_SIGNAL_MOVE
2251#else
2252    READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
2253    if (vps->getVideoSigPresentVpsFlag())
2254    {
2255        READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
2256    }
2257    else
2258    {
2259        vps->setNumVideoSignalInfo(vps->getMaxLayers());
2260    }
2261   
2262   
2263    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
2264    {
2265        READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
2266        READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
2267        READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
2268        READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
2269        READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
2270    }
2271    if(!vps->getVideoSigPresentVpsFlag())
2272    {
2273        for (i=0; i < vps->getMaxLayers(); i++)
2274        {
2275            vps->setVideoSignalInfoIdx(i,i);
2276        }
2277    }
2278    else {
2279        vps->setVideoSignalInfoIdx(0,0);
2280        if (vps->getNumVideoSignalInfo() > 1 )
2281        {
2282            for (i=1; i < vps->getMaxLayers(); i++)
2283                READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
2284        }
2285        else {
2286          for (i=1; i < vps->getMaxLayers(); i++)
2287          {
2288            vps->setVideoSignalInfoIdx(i,0);
2289          }
2290        }
2291    }
2292#endif
2293#endif
2294
2295#if O0164_MULTI_LAYER_HRD
2296    READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
2297    if (vps->getVpsVuiBspHrdPresentFlag())
2298    {
2299      READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
2300      vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
2301      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
2302      {
2303        if( i > 0 )
2304        {
2305          READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
2306        }
2307        parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
2308      }
2309      for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
2310      {
2311        READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
2312        for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
2313        {
2314          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
2315          {
2316            if( vps->getLayerIdIncludedFlag(h, j) )
2317            {
2318              READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
2319            }
2320          }
2321        }
2322        if (vps->getNumBitstreamPartitions(h))
2323        {
2324#if Q0182_MULTI_LAYER_HRD_UPDATE
2325          READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
2326#else
2327          READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
2328#endif
2329          for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
2330          {
2331            for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
2332            {
2333              READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
2334              READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
2335            }
2336          }
2337        }
2338      }
2339    }
2340#endif
2341
2342#if P0182_VPS_VUI_PS_FLAG
2343    for(i = 1; i < vps->getMaxLayers(); i++)
2344    {
2345      if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
2346      {
2347        READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
2348        vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
2349      }
2350      else
2351      {
2352        vps->setBaseLayerPSCompatibilityFlag( i, 0 );
2353      }
2354    }
2355#endif
2356}
2357#endif
2358#endif //SVC_EXTENSION
2359
2360Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
2361{
2362  UInt  uiCode;
2363  Int   iCode;
2364
2365#if ENC_DEC_TRACE
2366  xTraceSliceHeader(rpcSlice);
2367#endif
2368  TComPPS* pps = NULL;
2369  TComSPS* sps = NULL;
2370
2371  UInt firstSliceSegmentInPic;
2372  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
2373  if( rpcSlice->getRapPicFlag())
2374  {
2375    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
2376#if SETTING_NO_OUT_PIC_PRIOR
2377    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
2378#else
2379    rpcSlice->setNoOutputPicPrior( false );
2380#endif
2381  }
2382  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
2383  pps = parameterSetManager->getPrefetchedPPS(uiCode);
2384  //!KS: need to add error handling code here, if PPS is not available
2385  assert(pps!=0);
2386  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
2387  //!KS: need to add error handling code here, if SPS is not available
2388  assert(sps!=0);
2389  rpcSlice->setSPS(sps);
2390  rpcSlice->setPPS(pps);
2391  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
2392  {
2393    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
2394  }
2395  else
2396  {
2397    rpcSlice->setDependentSliceSegmentFlag(false);
2398  }
2399#if REPN_FORMAT_IN_VPS
2400  Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2401#else
2402  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2403#endif
2404  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
2405  UInt sliceSegmentAddress = 0;
2406  Int bitsSliceSegmentAddress = 0;
2407  while(numCTUs>(1<<bitsSliceSegmentAddress))
2408  {
2409    bitsSliceSegmentAddress++;
2410  }
2411
2412  if(!firstSliceSegmentInPic)
2413  {
2414    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
2415  }
2416  //set uiCode to equal slice start address (or dependent slice start address)
2417  Int startCuAddress = maxParts*sliceSegmentAddress;
2418  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
2419  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
2420
2421  if (rpcSlice->getDependentSliceSegmentFlag())
2422  {
2423    rpcSlice->setNextSlice          ( false );
2424    rpcSlice->setNextSliceSegment ( true  );
2425  }
2426  else
2427  {
2428    rpcSlice->setNextSlice          ( true  );
2429    rpcSlice->setNextSliceSegment ( false );
2430
2431    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
2432    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
2433  }
2434
2435#if Q0142_POC_LSB_NOT_PRESENT
2436#if SHM_FIX7
2437    Int iPOClsb = 0;
2438#endif
2439#endif
2440
2441  if(!rpcSlice->getDependentSliceSegmentFlag())
2442  {
2443#if SVC_EXTENSION
2444#if POC_RESET_FLAG
2445    Int iBits = 0;
2446    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2447    {
2448      READ_FLAG(uiCode, "poc_reset_flag");      rpcSlice->setPocResetFlag( uiCode ? true : false );
2449      iBits++;
2450    }
2451    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2452    {
2453#if DISCARDABLE_PIC_RPS
2454      READ_FLAG(uiCode, "discardable_flag"); rpcSlice->setDiscardableFlag( uiCode ? true : false );
2455#else
2456      READ_FLAG(uiCode, "discardable_flag"); // ignored
2457#endif
2458      iBits++;
2459    }
2460#if O0149_CROSS_LAYER_BLA_FLAG
2461    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2462    {
2463      READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
2464      iBits++;
2465    }
2466#endif
2467    for (; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
2468    {
2469      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2470    }
2471#else
2472    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
2473    {
2474      READ_FLAG(uiCode, "discardable_flag"); // ignored
2475    }
2476    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2477    {
2478      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2479    }
2480#endif
2481#else //SVC_EXTENSION
2482    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2483    {
2484      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2485    }
2486#endif //SVC_EXTENSION
2487
2488    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
2489    if( pps->getOutputFlagPresentFlag() )
2490    {
2491      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
2492    }
2493    else
2494    {
2495      rpcSlice->setPicOutputFlag( true );
2496    }
2497    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
2498    assert (sps->getChromaFormatIdc() == 1 );
2499    // if( separate_colour_plane_flag  ==  1 )
2500    //   colour_plane_id                                      u(2)
2501
2502    if( rpcSlice->getIdrPicFlag() )
2503    {
2504      rpcSlice->setPOC(0);
2505      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2506      rps->setNumberOfNegativePictures(0);
2507      rps->setNumberOfPositivePictures(0);
2508      rps->setNumberOfLongtermPictures(0);
2509      rps->setNumberOfPictures(0);
2510      rpcSlice->setRPS(rps);
2511    }
2512#if N0065_LAYER_POC_ALIGNMENT
2513#if !Q0142_POC_LSB_NOT_PRESENT
2514#if SHM_FIX7
2515    Int iPOClsb = 0;
2516#endif
2517#endif
2518#if O0062_POC_LSB_NOT_PRESENT_FLAG
2519    if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
2520#else
2521    if( rpcSlice->getLayerId() > 0 || !rpcSlice->getIdrPicFlag() )
2522#endif
2523#else
2524    else
2525#endif
2526    {
2527      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
2528#if SHM_FIX7
2529      iPOClsb = uiCode;
2530#else
2531      Int iPOClsb = uiCode;
2532#endif
2533      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2534      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2535      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2536      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2537      Int iPOCmsb;
2538      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2539      {
2540        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2541      }
2542      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
2543      {
2544        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2545      }
2546      else
2547      {
2548        iPOCmsb = iPrevPOCmsb;
2549      }
2550      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2551        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2552        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2553      {
2554        // For BLA picture types, POCmsb is set to 0.
2555        iPOCmsb = 0;
2556      }
2557      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2558
2559#if N0065_LAYER_POC_ALIGNMENT
2560#if SHM_FIX7
2561      }
2562#endif
2563      if( !rpcSlice->getIdrPicFlag() )
2564      {
2565#endif
2566      TComReferencePictureSet* rps;
2567      rps = rpcSlice->getLocalRPS();
2568      rpcSlice->setRPS(rps);
2569      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2570      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2571      {
2572        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2573      }
2574      else // use reference to short-term reference picture set in PPS
2575      {
2576        Int numBits = 0;
2577        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2578        {
2579          numBits++;
2580        }
2581        if (numBits > 0)
2582        {
2583          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2584        }
2585        else
2586        {
2587          uiCode = 0;       
2588        }
2589        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2590      }
2591      if(sps->getLongTermRefsPresent())
2592      {
2593        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2594        UInt numOfLtrp = 0;
2595        UInt numLtrpInSPS = 0;
2596        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2597        {
2598          READ_UVLC( uiCode, "num_long_term_sps");
2599          numLtrpInSPS = uiCode;
2600          numOfLtrp += numLtrpInSPS;
2601          rps->setNumberOfLongtermPictures(numOfLtrp);
2602        }
2603        Int bitsForLtrpInSPS = 0;
2604        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2605        {
2606          bitsForLtrpInSPS++;
2607        }
2608        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2609        numOfLtrp += uiCode;
2610        rps->setNumberOfLongtermPictures(numOfLtrp);
2611        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2612        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2613        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2614        {
2615          Int pocLsbLt;
2616          if (k < numLtrpInSPS)
2617          {
2618            uiCode = 0;
2619            if (bitsForLtrpInSPS > 0)
2620            {
2621              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2622            }
2623            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2624
2625            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2626            rps->setUsed(j,usedByCurrFromSPS);
2627          }
2628          else
2629          {
2630            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2631            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2632          }
2633          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2634          Bool mSBPresentFlag = uiCode ? true : false;
2635          if(mSBPresentFlag)
2636          {
2637            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2638            Bool deltaFlag = false;
2639            //            First LTRP                               || First LTRP from SH
2640            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2641            {
2642              deltaFlag = true;
2643            }
2644            if(deltaFlag)
2645            {
2646              deltaPocMSBCycleLT = uiCode;
2647            }
2648            else
2649            {
2650              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
2651            }
2652
2653            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2654                                        - iPOClsb + pocLsbLt;
2655            rps->setPOC     (j, pocLTCurr);
2656            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2657            rps->setCheckLTMSBPresent(j,true);
2658          }
2659          else
2660          {
2661            rps->setPOC     (j, pocLsbLt);
2662            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2663            rps->setCheckLTMSBPresent(j,false);
2664
2665            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2666            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2667            {
2668              deltaPocMSBCycleLT = 0;
2669            }
2670          }
2671          prevDeltaMSB = deltaPocMSBCycleLT;
2672        }
2673        offset += rps->getNumberOfLongtermPictures();
2674        rps->setNumberOfPictures(offset);
2675      }
2676      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2677        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2678        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2679      {
2680        // In the case of BLA picture types, rps data is read from slice header but ignored
2681        rps = rpcSlice->getLocalRPS();
2682        rps->setNumberOfNegativePictures(0);
2683        rps->setNumberOfPositivePictures(0);
2684        rps->setNumberOfLongtermPictures(0);
2685        rps->setNumberOfPictures(0);
2686        rpcSlice->setRPS(rps);
2687      }
2688      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2689      {
2690        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2691        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
2692      }
2693      else
2694      {
2695        rpcSlice->setEnableTMVPFlag(false);
2696      }
2697#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
2698    }
2699#endif
2700    }
2701
2702#if SVC_EXTENSION
2703    rpcSlice->setActiveNumILRRefIdx(0);
2704#if ILP_SSH_SIG
2705#if ILP_SSH_SIG_FIX
2706    if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
2707#else
2708    if((rpcSlice->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
2709#endif
2710#else
2711    if((rpcSlice->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
2712#endif
2713    {
2714      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
2715      rpcSlice->setInterLayerPredEnabledFlag(uiCode);
2716      if( rpcSlice->getInterLayerPredEnabledFlag())
2717      {
2718        if(rpcSlice->getNumILRRefIdx() > 1)
2719        {
2720          Int numBits = 1;
2721          while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
2722          {
2723            numBits++;
2724          }
2725          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
2726          {
2727            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
2728            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
2729          }
2730          else
2731          {
2732#if P0079_DERIVE_NUMACTIVE_REF_PICS
2733            for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
2734            {
2735#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2736              if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2737                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2738#else
2739              if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
2740                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2741#endif
2742              {         
2743                rpcSlice->setActiveNumILRRefIdx(1);
2744                break;
2745              }
2746            }
2747#else
2748            rpcSlice->setActiveNumILRRefIdx(1);
2749#endif
2750          }
2751#if ILP_NUM_REF_CHK
2752          if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
2753          {
2754            for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2755            {
2756              rpcSlice->setInterLayerPredLayerIdc(i,i);
2757            }
2758          }
2759          else
2760          {
2761#endif
2762          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2763          {
2764            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
2765            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
2766          }
2767#if ILP_NUM_REF_CHK
2768          }
2769#endif
2770        }
2771        else
2772        {
2773#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2774#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2775          if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2776            (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
2777#else
2778          if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
2779             (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
2780#endif
2781        {
2782#endif
2783          rpcSlice->setActiveNumILRRefIdx(1);
2784          rpcSlice->setInterLayerPredLayerIdc(0,0);
2785#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2786        }
2787#endif
2788        }
2789      }
2790    }
2791#if ILP_SSH_SIG
2792#if ILP_SSH_SIG_FIX
2793    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
2794#else
2795    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
2796#endif
2797    {
2798      rpcSlice->setInterLayerPredEnabledFlag(true);
2799
2800#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2801      Int   numRefLayerPics = 0;
2802      Int   i = 0;
2803      Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
2804      for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
2805      {
2806#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2807        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2808          (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2809#else
2810        if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
2811           (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2812#endif
2813        {         
2814          refLayerPicIdc[ numRefLayerPics++ ] = i;
2815        }
2816      }
2817      rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
2818      for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2819      {
2820        rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
2821      }     
2822#else
2823      rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
2824      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2825      {
2826        rpcSlice->setInterLayerPredLayerIdc(i,i);
2827      }
2828#endif
2829    }
2830#endif
2831#endif
2832#if P0312_VERT_PHASE_ADJ
2833    for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
2834    {
2835      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
2836      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
2837      {
2838        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
2839      }
2840    }
2841#endif
2842
2843    if(sps->getUseSAO())
2844    {
2845      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2846#if AUXILIARY_PICTURES
2847      ChromaFormat format;
2848#if REPN_FORMAT_IN_VPS
2849#if O0096_REP_FORMAT_INDEX
2850      if( sps->getLayerId() == 0 )
2851      {
2852        format = sps->getChromaFormatIdc();
2853      }
2854      else
2855      {
2856        format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
2857#if Q0195_REP_FORMAT_CLEANUP
2858         assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
2859#endif
2860      }
2861#else
2862      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
2863      {
2864        format = sps->getChromaFormatIdc();
2865      }
2866      else
2867      {
2868        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
2869      }
2870#endif
2871#else
2872      format = sps->getChromaFormatIdc();
2873#endif
2874      if (format != CHROMA_400)
2875      {
2876#endif
2877      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2878#if AUXILIARY_PICTURES
2879      }
2880      else
2881      {
2882        rpcSlice->setSaoEnabledFlagChroma(false);
2883      }
2884#endif
2885    }
2886
2887    if (rpcSlice->getIdrPicFlag())
2888    {
2889      rpcSlice->setEnableTMVPFlag(false);
2890    }
2891    if (!rpcSlice->isIntra())
2892    {
2893
2894      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2895      if (uiCode)
2896      {
2897        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2898        if (rpcSlice->isInterB())
2899        {
2900          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2901        }
2902        else
2903        {
2904          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2905        }
2906      }
2907      else
2908      {
2909        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2910        if (rpcSlice->isInterB())
2911        {
2912          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2913        }
2914        else
2915        {
2916          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2917        }
2918      }
2919    }
2920    // }
2921    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2922    if(!rpcSlice->isIntra())
2923    {
2924      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2925      {
2926        refPicListModification->setRefPicListModificationFlagL0( 0 );
2927      }
2928      else
2929      {
2930        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2931      }
2932
2933      if(refPicListModification->getRefPicListModificationFlagL0())
2934      {
2935        uiCode = 0;
2936        Int i = 0;
2937        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2938        if ( numRpsCurrTempList0 > 1 )
2939        {
2940          Int length = 1;
2941          numRpsCurrTempList0 --;
2942          while ( numRpsCurrTempList0 >>= 1)
2943          {
2944            length ++;
2945          }
2946          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2947          {
2948            READ_CODE( length, uiCode, "list_entry_l0" );
2949            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2950          }
2951        }
2952        else
2953        {
2954          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2955          {
2956            refPicListModification->setRefPicSetIdxL0(i, 0 );
2957          }
2958        }
2959      }
2960    }
2961    else
2962    {
2963      refPicListModification->setRefPicListModificationFlagL0(0);
2964    }
2965    if(rpcSlice->isInterB())
2966    {
2967      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2968      {
2969        refPicListModification->setRefPicListModificationFlagL1( 0 );
2970      }
2971      else
2972      {
2973        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2974      }
2975      if(refPicListModification->getRefPicListModificationFlagL1())
2976      {
2977        uiCode = 0;
2978        Int i = 0;
2979        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
2980        if ( numRpsCurrTempList1 > 1 )
2981        {
2982          Int length = 1;
2983          numRpsCurrTempList1 --;
2984          while ( numRpsCurrTempList1 >>= 1)
2985          {
2986            length ++;
2987          }
2988          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2989          {
2990            READ_CODE( length, uiCode, "list_entry_l1" );
2991            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2992          }
2993        }
2994        else
2995        {
2996          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2997          {
2998            refPicListModification->setRefPicSetIdxL1(i, 0 );
2999          }
3000        }
3001      }
3002    }
3003    else
3004    {
3005      refPicListModification->setRefPicListModificationFlagL1(0);
3006    }
3007    if (rpcSlice->isInterB())
3008    {
3009      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
3010    }
3011
3012    rpcSlice->setCabacInitFlag( false ); // default
3013    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
3014    {
3015      READ_FLAG(uiCode, "cabac_init_flag");
3016      rpcSlice->setCabacInitFlag( uiCode ? true : false );
3017    }
3018
3019    if ( rpcSlice->getEnableTMVPFlag() )
3020    {
3021#if SVC_EXTENSION && REF_IDX_MFM
3022      // set motion mapping flag
3023      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
3024#endif
3025      if ( rpcSlice->getSliceType() == B_SLICE )
3026      {
3027        READ_FLAG( uiCode, "collocated_from_l0_flag" );
3028        rpcSlice->setColFromL0Flag(uiCode);
3029      }
3030      else
3031      {
3032        rpcSlice->setColFromL0Flag( 1 );
3033      }
3034
3035      if ( rpcSlice->getSliceType() != I_SLICE &&
3036          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
3037           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
3038      {
3039        READ_UVLC( uiCode, "collocated_ref_idx" );
3040        rpcSlice->setColRefIdx(uiCode);
3041      }
3042      else
3043      {
3044        rpcSlice->setColRefIdx(0);
3045      }
3046    }
3047    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
3048    {
3049      xParsePredWeightTable(rpcSlice);
3050      rpcSlice->initWpScaling();
3051    }
3052    if (!rpcSlice->isIntra())
3053    {
3054      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
3055      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
3056    }
3057
3058    READ_SVLC( iCode, "slice_qp_delta" );
3059    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
3060
3061#if REPN_FORMAT_IN_VPS
3062#if O0194_DIFFERENT_BITDEPTH_EL_BL
3063    g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
3064    g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
3065#endif
3066    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
3067#else
3068    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
3069#endif
3070    assert( rpcSlice->getSliceQp() <=  51 );
3071
3072    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
3073    {
3074      READ_SVLC( iCode, "slice_qp_delta_cb" );
3075      rpcSlice->setSliceQpDeltaCb( iCode );
3076      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
3077      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
3078      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
3079      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
3080
3081      READ_SVLC( iCode, "slice_qp_delta_cr" );
3082      rpcSlice->setSliceQpDeltaCr( iCode );
3083      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
3084      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
3085      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
3086      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
3087    }
3088
3089    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
3090    {
3091      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
3092      {
3093        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
3094      }
3095      else
3096      {
3097        rpcSlice->setDeblockingFilterOverrideFlag(0);
3098      }
3099      if(rpcSlice->getDeblockingFilterOverrideFlag())
3100      {
3101        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
3102        if(!rpcSlice->getDeblockingFilterDisable())
3103        {
3104          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
3105          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
3106                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
3107          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
3108          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
3109                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
3110        }
3111      }
3112      else
3113      {
3114        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
3115        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
3116        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
3117      }
3118    }
3119    else
3120    {
3121      rpcSlice->setDeblockingFilterDisable       ( false );
3122      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
3123      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
3124    }
3125
3126    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
3127    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
3128
3129    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
3130    {
3131      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
3132    }
3133    else
3134    {
3135      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
3136    }
3137    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
3138
3139  }
3140
3141    UInt *entryPointOffset          = NULL;
3142    UInt numEntryPointOffsets, offsetLenMinus1;
3143  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
3144  {
3145    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
3146    if (numEntryPointOffsets>0)
3147    {
3148      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
3149    }
3150    entryPointOffset = new UInt[numEntryPointOffsets];
3151    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
3152    {
3153      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
3154      entryPointOffset[ idx ] = uiCode + 1;
3155    }
3156  }
3157  else
3158  {
3159    rpcSlice->setNumEntryPointOffsets ( 0 );
3160  }
3161
3162#if POC_RESET_IDC_SIGNALLING
3163  Int sliceHeaderExtensionLength = 0;
3164  if(pps->getSliceHeaderExtensionPresentFlag())
3165  {
3166    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
3167  }
3168  else
3169  {
3170    sliceHeaderExtensionLength = 0;
3171  }
3172  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
3173  if( sliceHeaderExtensionLength > 0 )
3174  {
3175    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
3176    {
3177      READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
3178    }
3179    else
3180    {
3181      rpcSlice->setPocResetIdc( 0 );
3182    }
3183#if Q0142_POC_LSB_NOT_PRESENT
3184    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
3185    {
3186      assert( rpcSlice->getPocResetIdc() != 2 );
3187    }
3188#endif
3189    if( rpcSlice->getPocResetIdc() > 0 )
3190    {
3191      READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
3192    }
3193    else
3194    {
3195     
3196      rpcSlice->setPocResetPeriodId( 0 );
3197    }
3198
3199    if (rpcSlice->getPocResetIdc() == 3)
3200    {
3201      READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
3202      READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
3203#if Q0142_POC_LSB_NOT_PRESENT
3204      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
3205      {
3206        assert( rpcSlice->getPocLsbVal() == 0 );
3207      }
3208#endif
3209    }
3210
3211    // Derive the value of PocMsbValRequiredFlag
3212    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
3213                                          /* || related to vps_poc_lsb_aligned_flag */
3214                                          );
3215
3216    if( !rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */ )
3217    {
3218      READ_FLAG( uiCode,    "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag( uiCode ? true : false );
3219    }
3220    else
3221    {
3222#if POC_MSB_VAL_PRESENT_FLAG_SEM
3223      if( sliceHeaderExtensionLength == 0 )
3224      {
3225        rpcSlice->setPocMsbValPresentFlag( false );
3226      }
3227      else if( rpcSlice->getPocMsbValRequiredFlag() )
3228#else
3229      if( rpcSlice->getPocMsbValRequiredFlag() )
3230#endif
3231      {
3232        rpcSlice->setPocMsbValPresentFlag( true );
3233      }
3234      else
3235      {
3236        rpcSlice->setPocMsbValPresentFlag( false );
3237      }
3238    }
3239
3240    Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
3241    if( rpcSlice->getPocMsbValPresentFlag() )
3242    {
3243      READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
3244      // Update POC of the slice based on this MSB val
3245      Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
3246      rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
3247    }
3248    else
3249    {
3250      rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
3251    }
3252
3253    // Read remaining bits in the slice header extension.
3254    UInt endBits = m_pcBitstream->getNumBitsRead();
3255    Int counter = (endBits - startBits) % 8;
3256    if( counter )
3257    {
3258      counter = 8 - counter;
3259    }
3260
3261    while( counter )
3262    {
3263#if Q0146_SSH_EXT_DATA_BIT
3264      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
3265#else
3266      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
3267#endif
3268      counter--;
3269    }
3270  }
3271#else
3272  if(pps->getSliceHeaderExtensionPresentFlag())
3273  {
3274    READ_UVLC(uiCode,"slice_header_extension_length");
3275    for(Int i=0; i<uiCode; i++)
3276    {
3277      UInt ignore;
3278      READ_CODE(8,ignore,"slice_header_extension_data_byte");
3279    }
3280  }
3281#endif
3282  m_pcBitstream->readByteAlignment();
3283
3284  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
3285  {
3286    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
3287
3288    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
3289    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
3290    {
3291      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
3292      {
3293        endOfSliceHeaderLocation++;
3294      }
3295    }
3296
3297    Int  curEntryPointOffset     = 0;
3298    Int  prevEntryPointOffset    = 0;
3299    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
3300    {
3301      curEntryPointOffset += entryPointOffset[ idx ];
3302
3303      Int emulationPreventionByteCount = 0;
3304      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
3305      {
3306        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
3307             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
3308        {
3309          emulationPreventionByteCount++;
3310        }
3311      }
3312
3313      entryPointOffset[ idx ] -= emulationPreventionByteCount;
3314      prevEntryPointOffset = curEntryPointOffset;
3315    }
3316
3317    if ( pps->getTilesEnabledFlag() )
3318    {
3319      rpcSlice->setTileLocationCount( numEntryPointOffsets );
3320
3321      UInt prevPos = 0;
3322      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
3323      {
3324        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
3325        prevPos += entryPointOffset[ idx ];
3326      }
3327    }
3328    else if ( pps->getEntropyCodingSyncEnabledFlag() )
3329    {
3330    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
3331      rpcSlice->allocSubstreamSizes(numSubstreams);
3332      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
3333      for (Int idx=0; idx<numSubstreams-1; idx++)
3334      {
3335        if ( idx < numEntryPointOffsets )
3336        {
3337          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
3338        }
3339        else
3340        {
3341          pSubstreamSizes[ idx ] = 0;
3342        }
3343      }
3344    }
3345
3346    if (entryPointOffset)
3347    {
3348      delete [] entryPointOffset;
3349    }
3350  }
3351
3352  return;
3353}
3354
3355Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
3356{
3357  UInt uiCode;
3358  if(profilePresentFlag)
3359  {
3360    parseProfileTier(rpcPTL->getGeneralPTL());
3361  }
3362  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
3363
3364  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
3365  {
3366    if(profilePresentFlag)
3367    {
3368      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
3369    }
3370    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
3371  }
3372
3373  if (maxNumSubLayersMinus1 > 0)
3374  {
3375    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
3376    {
3377      READ_CODE(2, uiCode, "reserved_zero_2bits");
3378      assert(uiCode == 0);
3379    }
3380  }
3381
3382  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
3383  {
3384    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
3385    {
3386      parseProfileTier(rpcPTL->getSubLayerPTL(i));
3387    }
3388    if(rpcPTL->getSubLayerLevelPresentFlag(i))
3389    {
3390      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
3391    }
3392  }
3393}
3394
3395Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
3396{
3397  UInt uiCode;
3398  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
3399  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
3400  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
3401  for(Int j = 0; j < 32; j++)
3402  {
3403    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
3404  }
3405  READ_FLAG(uiCode, "general_progressive_source_flag");
3406  ptl->setProgressiveSourceFlag(uiCode ? true : false);
3407
3408  READ_FLAG(uiCode, "general_interlaced_source_flag");
3409  ptl->setInterlacedSourceFlag(uiCode ? true : false);
3410
3411  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
3412  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
3413
3414  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
3415  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
3416
3417  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
3418  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
3419  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
3420}
3421
3422Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
3423{
3424  ruiBit = false;
3425  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
3426  if(iBitsLeft <= 8)
3427  {
3428    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
3429    if (uiPeekValue == (1<<(iBitsLeft-1)))
3430    {
3431      ruiBit = true;
3432    }
3433  }
3434}
3435
3436Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3437{
3438  assert(0);
3439}
3440
3441Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3442{
3443  assert(0);
3444}
3445
3446Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
3447{
3448  assert(0);
3449}
3450
3451Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3452{
3453  assert(0);
3454}
3455
3456Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3457{
3458  assert(0);
3459}
3460
3461Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3462{
3463  assert(0);
3464}
3465
3466/** Parse I_PCM information.
3467* \param pcCU pointer to CU
3468* \param uiAbsPartIdx CU index
3469* \param uiDepth CU depth
3470* \returns Void
3471*
3472* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
3473*/
3474Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3475{
3476  assert(0);
3477}
3478
3479Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3480{
3481  assert(0);
3482}
3483
3484Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3485{
3486  assert(0);
3487}
3488
3489Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
3490{
3491  assert(0);
3492}
3493
3494Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
3495{
3496  assert(0);
3497}
3498
3499Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
3500{
3501  assert(0);
3502}
3503
3504Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3505{
3506  Int qp;
3507  Int  iDQp;
3508
3509  xReadSvlc( iDQp );
3510
3511#if REPN_FORMAT_IN_VPS
3512  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
3513#else
3514  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
3515#endif
3516  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
3517
3518  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
3519  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
3520
3521  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
3522}
3523
3524Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
3525{
3526  assert(0);
3527}
3528
3529Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
3530{
3531  assert(0);
3532}
3533
3534Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
3535{
3536  assert(0);
3537}
3538
3539Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
3540{
3541  assert(0);
3542}
3543
3544Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
3545{
3546  assert(0);
3547}
3548
3549Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
3550{
3551  assert(0);
3552}
3553
3554Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
3555{
3556  assert(0);
3557}
3558
3559// ====================================================================================================================
3560// Protected member functions
3561// ====================================================================================================================
3562
3563/** parse explicit wp tables
3564* \param TComSlice* pcSlice
3565* \returns Void
3566*/
3567Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3568{
3569  wpScalingParam  *wp;
3570  Bool            bChroma     = true; // color always present in HEVC ?
3571  SliceType       eSliceType  = pcSlice->getSliceType();
3572  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3573#if SVC_EXTENSION
3574  UInt            uiLog2WeightDenomLuma = 0, uiLog2WeightDenomChroma = 0;
3575#else
3576  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3577#endif
3578  UInt            uiTotalSignalledWeightFlags = 0;
3579
3580  Int iDeltaDenom;
3581#if AUXILIARY_PICTURES
3582  if (pcSlice->getChromaFormatIdc() == CHROMA_400)
3583  {
3584    bChroma = false;
3585  }
3586#endif
3587  // decode delta_luma_log2_weight_denom :
3588  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3589  assert( uiLog2WeightDenomLuma <= 7 );
3590  if( bChroma )
3591  {
3592    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3593    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3594    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
3595    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3596  }
3597
3598  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
3599  {
3600    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3601    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3602    {
3603      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3604
3605      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3606#if AUXILIARY_PICTURES
3607      if (!bChroma)
3608      {
3609        wp[1].uiLog2WeightDenom = 0;
3610        wp[2].uiLog2WeightDenom = 0;
3611      }
3612      else
3613      {
3614#endif
3615      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3616      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3617#if AUXILIARY_PICTURES
3618      }
3619#endif
3620
3621      UInt  uiCode;
3622      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3623      wp[0].bPresentFlag = ( uiCode == 1 );
3624      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
3625    }
3626    if ( bChroma )
3627    {
3628      UInt  uiCode;
3629      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3630      {
3631        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3632        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3633        wp[1].bPresentFlag = ( uiCode == 1 );
3634        wp[2].bPresentFlag = ( uiCode == 1 );
3635        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
3636      }
3637    }
3638    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3639    {
3640      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3641      if ( wp[0].bPresentFlag )
3642      {
3643        Int iDeltaWeight;
3644        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3645        assert( iDeltaWeight >= -128 );
3646        assert( iDeltaWeight <=  127 );
3647        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3648        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3649        assert( wp[0].iOffset >= -128 );
3650        assert( wp[0].iOffset <=  127 );
3651      }
3652      else
3653      {
3654        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3655        wp[0].iOffset = 0;
3656      }
3657      if ( bChroma )
3658      {
3659        if ( wp[1].bPresentFlag )
3660        {
3661          for ( Int j=1 ; j<3 ; j++ )
3662          {
3663            Int iDeltaWeight;
3664            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3665            assert( iDeltaWeight >= -128 );
3666            assert( iDeltaWeight <=  127 );
3667            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3668
3669            Int iDeltaChroma;
3670            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3671            assert( iDeltaChroma >= -512 );
3672            assert( iDeltaChroma <=  511 );
3673            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3674            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3675          }
3676        }
3677        else
3678        {
3679          for ( Int j=1 ; j<3 ; j++ )
3680          {
3681            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3682            wp[j].iOffset = 0;
3683          }
3684        }
3685      }
3686    }
3687
3688    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
3689    {
3690      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3691
3692      wp[0].bPresentFlag = false;
3693      wp[1].bPresentFlag = false;
3694      wp[2].bPresentFlag = false;
3695    }
3696  }
3697  assert(uiTotalSignalledWeightFlags<=24);
3698}
3699
3700/** decode quantization matrix
3701* \param scalingList quantization matrix information
3702*/
3703Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3704{
3705  UInt  code, sizeId, listId;
3706  Bool scalingListPredModeFlag;
3707  //for each size
3708  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3709  {
3710    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3711    {
3712      READ_FLAG( code, "scaling_list_pred_mode_flag");
3713      scalingListPredModeFlag = (code) ? true : false;
3714      if(!scalingListPredModeFlag) //Copy Mode
3715      {
3716        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3717        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3718        if( sizeId > SCALING_LIST_8x8 )
3719        {
3720          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3721        }
3722        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3723
3724      }
3725      else //DPCM Mode
3726      {
3727        xDecodeScalingList(scalingList, sizeId, listId);
3728      }
3729    }
3730  }
3731
3732  return;
3733}
3734/** decode DPCM
3735* \param scalingList  quantization matrix information
3736* \param sizeId size index
3737* \param listId list index
3738*/
3739Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3740{
3741  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3742  Int data;
3743  Int scalingListDcCoefMinus8 = 0;
3744  Int nextCoef = SCALING_LIST_START_VALUE;
3745  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3746  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3747
3748  if( sizeId > SCALING_LIST_8x8 )
3749  {
3750    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3751    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3752    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3753  }
3754
3755  for(i = 0; i < coefNum; i++)
3756  {
3757    READ_SVLC( data, "scaling_list_delta_coef");
3758    nextCoef = (nextCoef + data + 256 ) % 256;
3759    dst[scan[i]] = nextCoef;
3760  }
3761}
3762
3763Bool TDecCavlc::xMoreRbspData()
3764{
3765  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3766
3767  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3768  if (bitsLeft > 8)
3769  {
3770    return true;
3771  }
3772
3773  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3774  Int cnt = bitsLeft;
3775
3776  // remove trailing bits equal to zero
3777  while ((cnt>0) && ((lastByte & 1) == 0))
3778  {
3779    lastByte >>= 1;
3780    cnt--;
3781  }
3782  // remove bit equal to one
3783  cnt--;
3784
3785  // we should not have a negative number of bits
3786  assert (cnt>=0);
3787
3788  // we have more data, if cnt is not zero
3789  return (cnt>0);
3790}
3791
3792#if Q0048_CGS_3D_ASYMLUT
3793Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
3794{
3795  UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
3796  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
3797  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
3798  READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
3799  Int iInputBitDepthCDelta;
3800  READ_SVLC(iInputBitDepthCDelta, "cm_input_bit_depth_chroma delta");
3801  READ_CODE( 3 , uiOutputBitDepthM8 , "cm_output_bit_depth_minus8" ); 
3802  Int iOutputBitDepthCDelta;
3803  READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
3804  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
3805  pc3DAsymLUT->destroy();
3806  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, uiOutputBitDepthM8 + 8 , uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,uiCurPartNumLog2 );
3807  pc3DAsymLUT->setResQuantBit( uiResQaunBit );
3808
3809  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
3810}
3811
3812Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
3813{
3814  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
3815  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
3816    READ_FLAG( uiOctantSplit , "split_octant_flag" );
3817  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
3818  if( uiOctantSplit )
3819  {
3820    Int nHalfLength = nLength >> 1;
3821    for( Int l = 0 ; l < 2 ; l++ )
3822    {
3823      for( Int m = 0 ; m < 2 ; m++ )
3824      {
3825        for( Int n = 0 ; n < 2 ; n++ )
3826        {
3827          xParse3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
3828        }
3829      }
3830    }
3831  }
3832  else
3833  {
3834    for( Int l = 0 ; l < nYPartNum ; l++ )
3835    {
3836      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
3837      {
3838        UInt uiCodeVertex = 0;
3839        Int deltaY = 0 , deltaU = 0 , deltaV = 0;
3840        READ_FLAG( uiCodeVertex , "coded_vertex_flag" );
3841        if( uiCodeVertex )
3842        {
3843          READ_SVLC( deltaY , "resY" );
3844          READ_SVLC( deltaU , "resU" );
3845          READ_SVLC( deltaV , "resV" );
3846        }
3847        pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
3848      }
3849    }
3850  }
3851}
3852#endif
3853//! \}
3854
Note: See TracBrowser for help on using the repository browser.