source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 854

Last change on this file since 854 was 854, checked in by tech, 10 years ago

Integrated following MV-HEVC HLS 7 items:

H_MV_HLS7_GEN Stub for further integrations (not tested)
H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
Output layer sets, various

(VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
(VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
(VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).

H_MV_HLS_7_HRD_P0156_7 (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
H_MV_HLS_7_VPS_P0048_14
(VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
H_MV_HLS_7_VPS_P0076_15 (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
H_MV_HLS_7_SPS_P0155_16_32
(SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
H_MV_HLS_7_GEN_P0166_PPS_EXTENSION (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
H_MV_HLS_7_FIX_SET_DPB_SIZE
Fix derivation dpb size parameters
H_MV_HLS_7_RESERVED_FLAGS Added flags

(SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
(VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
(VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.

H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO Discard VPS with nuh_layer_Id > 0
H_MV_HLS_7_MISC_P0130_EOS
(MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
H_MV_HLS_7_MISC_P0182_13 (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
H_MV_HLS_7_MISC_P0068_21
(MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG Fix inference of cross_layer_irap_aligned_flag
H_MV_HLS_7_MISC_P0079_18
(MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.

  • Property svn:eol-style set to native
File size: 119.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license. 
5*
6* Copyright (c) 2010-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
42//! \ingroup TLibDecoder
43//! \{
44
45#if ENC_DEC_TRACE
46
47Void  xTraceSPSHeader (TComSPS *pSPS)
48{
49#if H_MV_ENC_DEC_TRAC
50  if ( g_disableHLSTrace )
51  {
52    return; 
53  }
54  // To avoid mismatches
55  fprintf( g_hTrace, "=========== Sequence Parameter Set ===========\n" );
56#else
57  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
58#endif
59}
60
61Void  xTracePPSHeader (TComPPS *pPPS)
62{
63#if H_MV_ENC_DEC_TRAC
64  if ( g_disableHLSTrace )
65  {
66    return; 
67  }
68  fprintf( g_hTrace, "=========== Picture Parameter Set ===========\n" );
69#else
70  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
71#endif
72}
73
74Void  xTraceSliceHeader (TComSlice *pSlice)
75{
76#if H_MV_ENC_DEC_TRAC
77  if ( g_disableHLSTrace )
78  {
79    return; 
80  }
81#endif
82  fprintf( g_hTrace, "=========== Slice ===========\n");
83}
84
85#endif
86
87// ====================================================================================================================
88// Constructor / destructor / create / destroy
89// ====================================================================================================================
90
91TDecCavlc::TDecCavlc()
92{
93#if H_3D
94  m_aaiTempScale            = new Int* [ MAX_NUM_LAYERS ];
95  m_aaiTempOffset           = new Int* [ MAX_NUM_LAYERS ];
96  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
97  {
98    m_aaiTempScale            [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
99    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
100  }
101#endif
102}
103
104TDecCavlc::~TDecCavlc()
105{
106#if H_3D
107  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
108  {
109    delete [] m_aaiTempScale            [ uiVId ];
110    delete [] m_aaiTempOffset           [ uiVId ];
111  }
112  delete [] m_aaiTempScale;
113  delete [] m_aaiTempOffset;
114#endif
115}
116
117// ====================================================================================================================
118// Public member functions
119// ====================================================================================================================
120
121void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
122{
123  UInt code;
124  UInt interRPSPred;
125  if (idx > 0)
126  {
127    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
128  }
129  else
130  {
131    interRPSPred = false;
132    rps->setInterRPSPrediction(false);
133  }
134
135  if (interRPSPred) 
136  {
137    UInt bit;
138    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
139    {
140      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
141    }
142    else
143    {
144      code = 0;
145    }
146    assert(code <= idx-1); // delta_idx_minus1 shall not be larger than idx-1, otherwise we will predict from a negative row position that does not exist. When idx equals 0 there is no legal value and interRPSPred must be zero. See J0185-r2
147    Int rIdx =  idx - 1 - code;
148    assert (rIdx <= idx-1 && rIdx >= 0); // Made assert tighter; if rIdx = idx then prediction is done from itself. rIdx must belong to range 0, idx-1, inclusive, see J0185-r2
149    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
150    Int k = 0, k0 = 0, k1 = 0;
151    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
152    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
153    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
154    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
155    {
156      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
157      Int refIdc = bit;
158      if (refIdc == 0) 
159      {
160        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
161        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
162      }
163      if (refIdc == 1 || refIdc == 2)
164      {
165        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
166        rps->setDeltaPOC(k, deltaPOC);
167        rps->setUsed(k, (refIdc == 1));
168
169        if (deltaPOC < 0)
170        {
171          k0++;
172        }
173        else 
174        {
175          k1++;
176        }
177        k++;
178      } 
179      rps->setRefIdc(j,refIdc); 
180    }
181    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
182    rps->setNumberOfPictures(k);
183    rps->setNumberOfNegativePictures(k0);
184    rps->setNumberOfPositivePictures(k1);
185    rps->sortDeltaPOC();
186  }
187  else
188  {
189    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
190    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
191    Int prev = 0;
192    Int poc;
193    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
194    {
195      READ_UVLC(code, "delta_poc_s0_minus1");
196      poc = prev-code-1;
197      prev = poc;
198      rps->setDeltaPOC(j,poc);
199      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
200    }
201    prev = 0;
202    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
203    {
204      READ_UVLC(code, "delta_poc_s1_minus1");
205      poc = prev+code+1;
206      prev = poc;
207      rps->setDeltaPOC(j,poc);
208      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
209    }
210    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
211  }
212#if PRINT_RPS_INFO
213  rps->printDeltaPOC();
214#endif
215}
216
217#if H_3D
218Void TDecCavlc::parsePPS(TComPPS* pcPPS, TComVPS* pcVPS )
219#else
220Void TDecCavlc::parsePPS(TComPPS* pcPPS)
221#endif
222{
223#if ENC_DEC_TRACE 
224  xTracePPSHeader (pcPPS);
225#endif
226  UInt  uiCode;
227
228  Int   iCode;
229
230  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
231  assert(uiCode <= 63);
232  pcPPS->setPPSId (uiCode);
233 
234  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
235  assert(uiCode <= 15);
236  pcPPS->setSPSId (uiCode);
237 
238  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
239  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
240
241  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
242  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
243
244  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
245
246  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
247  assert(uiCode <= 14);
248  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
249 
250  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
251  assert(uiCode <= 14);
252  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
253 
254  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
255  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
256  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
257  pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
258
259  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
260  if( pcPPS->getUseDQP() )
261  {
262    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
263    pcPPS->setMaxCuDQPDepth( uiCode );
264  }
265  else
266  {
267    pcPPS->setMaxCuDQPDepth( 0 );
268  }
269  READ_SVLC( iCode, "pps_cb_qp_offset");
270  pcPPS->setChromaCbQpOffset(iCode);
271  assert( pcPPS->getChromaCbQpOffset() >= -12 );
272  assert( pcPPS->getChromaCbQpOffset() <=  12 );
273
274  READ_SVLC( iCode, "pps_cr_qp_offset");
275  pcPPS->setChromaCrQpOffset(iCode);
276  assert( pcPPS->getChromaCrQpOffset() >= -12 );
277  assert( pcPPS->getChromaCrQpOffset() <=  12 );
278
279  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
280  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
281
282  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
283  pcPPS->setUseWP( uiCode==1 );
284  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
285  pcPPS->setWPBiPred( uiCode==1 );
286
287  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
288  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
289  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
290  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
291 
292  if( pcPPS->getTilesEnabledFlag() )
293  {
294    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode ); 
295    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode ); 
296    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
297
298    if( !pcPPS->getUniformSpacingFlag())
299    {
300      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
301      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
302      { 
303        READ_UVLC( uiCode, "column_width_minus1" ); 
304        columnWidth[i] = uiCode+1;
305      }
306      pcPPS->setColumnWidth(columnWidth);
307      free(columnWidth);
308
309      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
310      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
311      {
312        READ_UVLC( uiCode, "row_height_minus1" );
313        rowHeight[i] = uiCode + 1;
314      }
315      pcPPS->setRowHeight(rowHeight);
316      free(rowHeight); 
317    }
318
319    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
320    {
321      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
322    }
323  }
324  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
325  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
326  if(pcPPS->getDeblockingFilterControlPresentFlag())
327  {
328    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
329    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
330    if(!pcPPS->getPicDisableDeblockingFilterFlag())
331    {
332      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
333      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
334    }
335  }
336#if H_MV
337  if ( pcPPS->getLayerId() > 0 )
338  {
339    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );   
340  }
341
342  if( pcPPS->getPpsInferScalingListFlag( ) ) 
343  {
344    READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
345  }
346  else
347  { 
348#endif
349  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
350  if(pcPPS->getScalingListPresentFlag ())
351  {
352    parseScalingList( pcPPS->getScalingList() );
353  }
354#if H_MV
355  }
356#endif
357
358  READ_FLAG( uiCode, "lists_modification_present_flag");
359  pcPPS->setListsModificationPresentFlag(uiCode);
360
361  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
362  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
363
364  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
365  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
366
367  READ_FLAG( uiCode, "pps_extension_flag");
368#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
369  if (uiCode)
370  {
371#if H_MV
372    for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
373    {
374      READ_FLAG( uiCode, "pps_extension_type_flag" ); pcPPS->setPpsExtensionTypeFlag( i, uiCode == 1 );
375#if H_3D
376      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_3D || i == PPS_EX_T_ESC ); 
377#else
378      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_ESC ); 
379#endif
380    }
381   
382
383    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_MV ) )
384    {
385#if H_MV_HLS7_GEN
386      READ_FLAG( uiCode, "poc_reset_info_present_flag" ); pcPPS->setPocResetInfoPresentFlag( uiCode == 1 );
387#endif
388    }
389
390#if H_3D
391    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_3D ) ) // This probably needs to be aligned with Rext and SHVC
392    {
393      parsePPSExtension( pcPPS, pcVPS );
394    }
395#endif
396
397    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_ESC ) )
398    {
399#endif
400      while ( xMoreRbspData() )
401      {
402        READ_FLAG( uiCode, "pps_extension_data_flag");
403      }
404#if H_MV
405    }
406#endif
407  }
408#else
409  if (uiCode)
410  {
411#if H_3D
412    parsePPSExtension( pcPPS, pcVPS );
413    READ_FLAG( uiCode, "pps_extension2_flag");
414    if ( uiCode )
415    {
416#endif
417      while ( xMoreRbspData() )
418      {
419        READ_FLAG( uiCode, "pps_extension_data_flag");
420      }
421#if H_3D
422    }
423#endif
424  }
425#endif
426}
427
428#if H_3D
429Void TDecCavlc::parsePPSExtension( TComPPS* pcPPS, TComVPS* pcVPS )
430{
431  //Ed.(GT): pcVPS should not be used here. Needs to be fixed.
432  UInt uiCode = 0; 
433  TComDLT* pcDLT = new TComDLT;
434
435  READ_FLAG(uiCode, "dlt_present_flag");
436  pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
437
438  if ( pcDLT->getDltPresentFlag() )
439  {
440    READ_CODE(6, uiCode, "pps_depth_layers_minus1");
441    pcDLT->setNumDepthViews( uiCode );
442
443    READ_CODE(4, uiCode, "pps_bit_depth_for_depth_views_minus8");
444    pcDLT->setDepthViewBitDepth( (uiCode+8) );
445
446    for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
447    {
448      if ( i != 0 )
449      {
450        if( pcVPS->getDepthId( i ) == 1 ) 
451        {
452          READ_FLAG(uiCode, "dlt_flag[i]");
453          pcDLT->setUseDLTFlag(i, (uiCode == 1) ? true : false);
454
455          if ( pcDLT->getUseDLTFlag( i ) )
456          {
457            Bool bDltBitMapRepFlag    = false;
458            UInt uiMaxDiff            = 0xffffffff;
459            UInt uiMinDiff            = 0;
460            UInt uiCodeLength         = 0;
461
462            READ_FLAG(uiCode, "inter_view_dlt_pred_enable_flag[ i ]"); 
463            pcDLT->setInterViewDltPredEnableFlag( i, (uiCode == 1) ? true : false );
464
465            if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
466            {
467              READ_FLAG(uiCode, "dlt_bit_map_rep_flag[ layerId ]");
468              bDltBitMapRepFlag = (uiCode == 1) ? true : false; 
469            }
470            else
471            {
472              bDltBitMapRepFlag = false;
473            }
474           
475            UInt uiNumDepthValues = 0;
476            Int  aiIdx2DepthValue[256];
477
478            // Bit map
479            if ( bDltBitMapRepFlag )
480            {
481              for (UInt d=0; d<256; d++)
482              {
483                READ_FLAG(uiCode, "dlt_bit_map_flag[ layerId ][ j ]");
484                if (uiCode == 1)
485                {
486                  aiIdx2DepthValue[uiNumDepthValues] = d;
487                  uiNumDepthValues++;
488                }
489              }
490            }
491            // Diff Coding
492            else
493            {
494              READ_CODE(8, uiNumDepthValues, "num_depth_values_in_dlt[i]");   // num_entry
495
496#if !H_3D_DELTA_DLT
497              if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )       // Single-view DLT Diff Coding
498#endif
499              {
500                // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
501
502                if (uiNumDepthValues > 1)
503                {
504                  READ_CODE(8, uiCode, "max_diff[ layerId ]"); 
505                  uiMaxDiff = uiCode;
506                }
507                else
508                {
509                  uiMaxDiff = 0;           // when there is only one value in DLT
510                }
511
512                if (uiNumDepthValues > 2)
513                {
514                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff + 1));
515                  READ_CODE(uiCodeLength, uiCode, "min_diff_minus1[ layerId ]");
516                  uiMinDiff = uiCode + 1;
517                }
518                else
519                {
520                  uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
521                }
522
523                READ_CODE(8, uiCode, "dlt_depth_value0[layerId]");   // entry0
524                aiIdx2DepthValue[0] = uiCode;
525
526                if (uiMaxDiff == uiMinDiff)
527                {
528                  for (UInt d=1; d<uiNumDepthValues; d++)
529                  {
530                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
531                  }
532                }
533                else
534                {
535                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
536                  for (UInt d=1; d<uiNumDepthValues; d++)
537                  {
538                    READ_CODE(uiCodeLength, uiCode, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");
539                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
540                  }
541                }
542
543              }
544            }
545           
546#if H_3D_DELTA_DLT
547            if( pcDLT->getInterViewDltPredEnableFlag( i ) )
548            {
549              // interpret decoded values as delta DLT
550              AOF( pcVPS->getDepthId( 1 ) == 1 );
551              AOF( i > 1 );
552              // assumes ref layer id to be 1
553              Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
554              UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
555              pcDLT->setDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
556            }
557            else
558            {
559              // store final DLT
560              pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
561            }
562#else
563            // store final DLT
564            pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
565#endif
566          }
567        }
568      }
569    }
570  }
571
572  pcPPS->setDLT( pcDLT );
573}
574#endif
575
576Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
577{
578#if ENC_DEC_TRACE
579  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
580#endif
581  UInt  uiCode;
582
583  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
584  if (pcVUI->getAspectRatioInfoPresentFlag())
585  {
586    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
587    if (pcVUI->getAspectRatioIdc() == 255)
588    {
589      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
590      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
591    }
592  }
593
594  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
595  if (pcVUI->getOverscanInfoPresentFlag())
596  {
597    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
598  }
599
600  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
601#if H_MV
602  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() ); 
603#endif
604  if (pcVUI->getVideoSignalTypePresentFlag())
605  {
606    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
607    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
608    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
609    if (pcVUI->getColourDescriptionPresentFlag())
610    {
611      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
612      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
613      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
614    }
615  }
616
617  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
618  if (pcVUI->getChromaLocInfoPresentFlag())
619  {
620    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
621    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
622  }
623
624  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
625
626  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
627
628  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
629
630  READ_FLAG(     uiCode, "default_display_window_flag");
631  if (uiCode != 0)
632  {
633    Window &defDisp = pcVUI->getDefaultDisplayWindow();
634#if H_MV
635    defDisp.setScaledFlag( false ); 
636    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
637    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
638    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
639    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
640#else
641    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
642    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
643    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
644    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
645#endif
646  }
647  TimingInfo *timingInfo = pcVUI->getTimingInfo();
648  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
649  if(timingInfo->getTimingInfoPresentFlag())
650  {
651    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
652    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
653    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
654    if(timingInfo->getPocProportionalToTimingFlag())
655    {
656      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
657    }
658  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
659  if( pcVUI->getHrdParametersPresentFlag() )
660  {
661    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
662  }
663  }
664  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
665  if (pcVUI->getBitstreamRestrictionFlag())
666  {
667    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
668    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
669    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
670    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
671    assert(uiCode < 4096);
672    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
673    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
674    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
675    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
676  }
677}
678
679Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
680{
681  UInt  uiCode;
682  if( commonInfPresentFlag )
683  {
684    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
685    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
686    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
687    {
688      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
689      if( hrd->getSubPicCpbParamsPresentFlag() )
690      {
691        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
692        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
693        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
694        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
695      }
696      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
697      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
698      if( hrd->getSubPicCpbParamsPresentFlag() )
699      {
700        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
701      }
702      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
703      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
704      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
705    }
706  }
707  Int i, j, nalOrVcl;
708  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
709  {
710    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
711    if( !hrd->getFixedPicRateFlag( i ) )
712    {
713      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
714    }
715    else
716    {
717      hrd->setFixedPicRateWithinCvsFlag( i, true );
718    }
719    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
720    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
721    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
722    {
723      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
724    }
725    else
726    {     
727      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
728    }
729    if (!hrd->getLowDelayHrdFlag( i ))
730    {
731      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
732    }
733    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
734    {
735      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
736          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
737      {
738        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
739        {
740          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
741          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
742          if( hrd->getSubPicCpbParamsPresentFlag() )
743          {
744            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
745            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
746          }
747          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
748        }
749      }
750    }
751  }
752}
753
754#if H_3D
755Void TDecCavlc::parseSPS(TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
756#else
757Void TDecCavlc::parseSPS(TComSPS* pcSPS)
758#endif
759{
760#if ENC_DEC_TRACE 
761  xTraceSPSHeader (pcSPS);
762#endif
763
764  UInt  uiCode;
765  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
766#if H_MV
767  if ( pcSPS->getLayerId() == 0 )
768  {
769#endif
770  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
771  assert(uiCode <= 6);
772 
773  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
774  if ( pcSPS->getMaxTLayers() == 1 )
775  {
776    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
777    assert( uiCode == 1 );
778  }
779 
780  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
781#if H_MV
782  }
783#endif
784  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
785  assert(uiCode <= 15);
786#if H_MV
787  if ( pcSPS->getLayerId() > 0 )
788  {
789    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
790    if ( pcSPS->getUpdateRepFormatFlag() )
791    { 
792      READ_CODE( 8, uiCode, "sps_rep_format_idx" );                pcSPS->setSpsRepFormatIdx( uiCode );
793    }
794  }
795  else
796  {
797#endif
798  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
799  assert(uiCode <= 3);
800  // 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
801  assert (uiCode == 1);
802  if( uiCode == 3 )
803  {
804    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
805  }
806
807  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
808  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
809#if H_MV
810  }
811#endif
812  READ_FLAG(     uiCode, "conformance_window_flag");
813  if (uiCode != 0)
814  {
815    Window &conf = pcSPS->getConformanceWindow();
816#if H_MV
817    // Needs to be scaled later, when ChromaFormatIdc is known.
818    conf.setScaledFlag( false ); 
819    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
820    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
821    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
822    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );   
823#else
824    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
825    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
826    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
827    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
828#endif
829  }
830
831#if H_MV
832  if ( pcSPS->getLayerId() == 0 )
833  { 
834#endif
835  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
836  assert(uiCode <= 6);
837  pcSPS->setBitDepthY( uiCode + 8 );
838  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
839
840  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
841  assert(uiCode <= 6);
842  pcSPS->setBitDepthC( uiCode + 8 );
843  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
844#if H_MV
845  }
846#endif
847
848  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
849  assert(uiCode <= 12);
850
851#if H_MV_HLS_7_SPS_P0155_16_32
852  if ( pcSPS->getLayerId() == 0 ) 
853  { 
854#endif
855  UInt subLayerOrderingInfoPresentFlag;
856  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
857 
858  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
859  {
860#if H_MV
861    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
862#else
863    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
864#endif
865    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
866#if H_MV
867    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
868#else
869    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
870#endif
871    pcSPS->setNumReorderPics(uiCode, i);
872#if H_MV
873    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
874#else
875    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
876#endif
877    pcSPS->setMaxLatencyIncrease( uiCode, i );
878
879    if (!subLayerOrderingInfoPresentFlag)
880    {
881      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
882      {
883        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
884        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
885        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
886      }
887      break;
888    }
889  }
890#if H_MV_HLS_7_SPS_P0155_16_32
891  }
892#endif
893
894  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
895  Int log2MinCUSize = uiCode + 3;
896  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
897  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
898  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
899 
900  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
901  {
902    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
903  }
904 
905  Int maxCUDepthDelta = uiCode;
906  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
907  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
908  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
909
910  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
911  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
912
913  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
914  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
915
916  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
917  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
918
919  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
920  if(pcSPS->getScalingListFlag())
921  {
922#if H_MV
923    if ( pcSPS->getLayerId() > 0 )
924    {   
925      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
926    }
927
928    if ( pcSPS->getSpsInferScalingListFlag() )
929    {
930      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
931    }
932    else
933    {   
934#endif
935    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
936    if(pcSPS->getScalingListPresentFlag ())
937    {
938      parseScalingList( pcSPS->getScalingList() );
939    }
940#if H_MV
941    }
942#endif
943  }
944  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
945  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
946
947  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
948  if( pcSPS->getUsePCM() )
949  {
950    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
951    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
952    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
953    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
954    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
955  }
956
957  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
958  assert(uiCode <= 64);
959  pcSPS->createRPSList(uiCode);
960
961  TComRPSList* rpsList = pcSPS->getRPSList();
962  TComReferencePictureSet* rps;
963
964  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
965  {
966    rps = rpsList->getReferencePictureSet(i);
967    parseShortTermRefPicSet(pcSPS,rps,i);
968  }
969  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
970  if (pcSPS->getLongTermRefsPresent()) 
971  {
972    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
973    pcSPS->setNumLongTermRefPicSPS(uiCode);
974    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
975    {
976      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
977      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
978      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
979      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
980    }
981  }
982  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
983
984  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
985
986  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
987
988  if (pcSPS->getVuiParametersPresentFlag())
989  {
990    parseVUI(pcSPS->getVuiParameters(), pcSPS);
991  }
992
993  READ_FLAG( uiCode, "sps_extension_flag");
994#if H_MV
995  pcSPS->setSpsExtensionFlag( uiCode ); 
996  if (pcSPS->getSpsExtensionFlag( ) )
997#else
998  if (uiCode)
999#endif
1000  {
1001#if H_MV
1002    for (Int i = 0; i < PS_EX_T_MAX_NUM; i++)
1003    {
1004      READ_FLAG( uiCode, "sps_extension_type_flag" ); pcSPS->setSpsExtensionTypeFlag( i, uiCode );
1005#if H_3D
1006      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV || i == PS_EX_T_3D || i == PS_EX_T_ESC ); 
1007#else
1008      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV || i == PS_EX_T_ESC ); 
1009#endif
1010    } 
1011
1012    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_MV ))
1013    {
1014      parseSPSExtension( pcSPS ); 
1015    }
1016
1017#if H_3D
1018    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_3D ))
1019    {
1020      parseSPSExtension2( pcSPS, viewIndex, depthFlag  ); 
1021    }
1022#endif
1023
1024    if ( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_ESC ))
1025    {   
1026#endif
1027        while ( xMoreRbspData() )
1028        {
1029          READ_FLAG( uiCode, "sps_extension_data_flag");
1030        }
1031#if H_MV
1032    }
1033#endif
1034  }
1035}
1036
1037#if H_MV
1038Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
1039{
1040  UInt uiCode; 
1041  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
1042 
1043  READ_UVLC( uiCode, "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets( uiCode );
1044
1045  for( Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets( ); i++)
1046  {   
1047    READ_CODE( 6, uiCode, "scaled_ref_layer_id" ); pcSPS->setScaledRefLayerId( i, uiCode ); 
1048
1049    Int j = pcSPS->getScaledRefLayerId( i ); 
1050    Int iCode; 
1051    READ_SVLC( iCode, "scaled_ref_layer_left_offset" ); pcSPS->setScaledRefLayerLeftOffset( j, iCode );
1052    READ_SVLC( iCode, "scaled_ref_layer_top_offset" ); pcSPS->setScaledRefLayerTopOffset( j, iCode );
1053    READ_SVLC( iCode, "scaled_ref_layer_right_offset" ); pcSPS->setScaledRefLayerRightOffset( j, iCode );
1054    READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" ); pcSPS->setScaledRefLayerBottomOffset( j, iCode );
1055#if H_MV_HLS_7_RESERVED_FLAGS
1056    READ_FLAG( uiCode, "sps_multilayer_ext_reserved_zero_flag[ i ]" );
1057#endif
1058  }
1059}
1060
1061#if H_3D
1062Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
1063{ 
1064  UInt uiCode; 
1065#if H_3D_QTLPC
1066  //GT: This has to go to VPS
1067  if( depthFlag )
1068  {
1069    READ_FLAG( uiCode, "use_qtl_flag" );
1070    pcSPS->setUseQTL( uiCode );
1071    READ_FLAG( uiCode, "use_pc_flag" );
1072    pcSPS->setUsePC( uiCode );
1073  }
1074#endif
1075}
1076#endif
1077#endif
1078
1079Void TDecCavlc::parseVPS(TComVPS* pcVPS)
1080{
1081  UInt  uiCode;
1082 
1083  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
1084  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
1085#if H_MV
1086  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
1087#else
1088  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
1089#endif
1090  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
1091  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
1092  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
1093
1094
1095#if H_MV && !H_MV_HLS7_GEN
1096  READ_CODE( 16, uiCode,  "vps_extension_offset" );               
1097#else
1098  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
1099#endif
1100  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
1101  UInt subLayerOrderingInfoPresentFlag;
1102  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
1103  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
1104  {
1105    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
1106    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
1107    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
1108
1109    if (!subLayerOrderingInfoPresentFlag)
1110    {
1111      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
1112      {
1113        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
1114        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
1115        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
1116      }
1117      break;
1118    }
1119  }
1120
1121  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
1122#if H_MV
1123  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
1124  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
1125
1126  READ_UVLC(    uiCode, "vps_max_num_layer_sets_minus1" );               pcVPS->setVpsNumLayerSetsMinus1( uiCode );
1127  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
1128  {
1129    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
1130#else
1131  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
1132  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
1133  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
1134  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
1135  {
1136    // Operation point set
1137    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
1138#endif
1139    {
1140      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
1141    }
1142  }
1143#if H_MV
1144  pcVPS->deriveLayerSetLayerIdList(); 
1145#endif
1146  TimingInfo *timingInfo = pcVPS->getTimingInfo();
1147  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
1148  if(timingInfo->getTimingInfoPresentFlag())
1149  {
1150    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
1151    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
1152    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
1153    if(timingInfo->getPocProportionalToTimingFlag())
1154    {
1155      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
1156    }
1157    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1158
1159    if( pcVPS->getNumHrdParameters() > 0 )
1160    {
1161      pcVPS->createHrdParamBuffer();
1162    }
1163    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1164    {
1165      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1166      if( i > 0 )
1167      {
1168        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1169      }
1170      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1171    }
1172  }
1173  READ_FLAG( uiCode,  "vps_extension_flag" );
1174  if (uiCode)
1175  {
1176#if H_MV
1177    m_pcBitstream->readOutTrailingBits();
1178    parseVPSExtension( pcVPS );   
1179    READ_FLAG( uiCode,  "vps_extension2_flag" );
1180    if (uiCode)
1181    {
1182#if H_3D
1183      m_pcBitstream->readOutTrailingBits();
1184      pcVPS->createCamPars(pcVPS->getNumViews());
1185      parseVPSExtension2( pcVPS );   
1186      READ_FLAG( uiCode,  "vps_extension3_flag" );
1187      if (uiCode)
1188      {     
1189#endif
1190#endif 
1191        while ( xMoreRbspData() )
1192        {
1193          READ_FLAG( uiCode, "vps_extension_data_flag");
1194        }
1195#if H_MV
1196#if H_3D
1197      }
1198#endif
1199    }
1200#endif
1201  }
1202  return; 
1203}
1204
1205#if H_MV
1206Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
1207{
1208  UInt uiCode; 
1209  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
1210#if !H_MV_HLS7_GEN
1211  READ_FLAG( uiCode, "vps_vui_present_flag" );                    pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
1212  if ( pcVPS->getVpsVuiPresentFlag() )
1213  { 
1214  READ_CODE( 16, uiCode, "vps_vui_offset" );                      pcVPS->setVpsVuiOffset( uiCode );
1215  }
1216#endif
1217
1218  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
1219
1220  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
1221  {
1222    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );     
1223  }
1224
1225  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
1226  {
1227    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
1228  }
1229
1230  if ( pcVPS->getSplittingFlag() )
1231  {
1232    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
1233  }
1234
1235  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
1236
1237  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1238  {
1239    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
1240    {
1241      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
1242    }
1243    else
1244    {
1245      pcVPS->setLayerIdInNuh( i, i );; 
1246    }
1247
1248    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
1249
1250    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
1251    {
1252      if ( !pcVPS->getSplittingFlag() )
1253      {
1254        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
1255      }
1256      else
1257      {
1258        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
1259      }
1260    }
1261  }
1262
1263  READ_CODE( 4, uiCode, "view_id_len" ); pcVPS->setViewIdLen( uiCode );
1264
1265  if ( pcVPS->getViewIdLen( ) > 0 )
1266  {   
1267    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1268    {
1269      READ_CODE( pcVPS->getViewIdLen( ), uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
1270    }
1271  }
1272  else
1273  {
1274    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1275    {
1276      pcVPS->setViewIdVal( i, 0 ); 
1277    }
1278  }
1279
1280
1281  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1282  {
1283    for( Int j = 0; j < i; j++ )
1284    {
1285      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
1286    }
1287  }
1288  pcVPS->setRefLayers(); 
1289  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag" ); pcVPS->setVpsSubLayersMaxMinus1PresentFlag( uiCode == 1 );
1290  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
1291  {
1292    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1293    {
1294      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1" ); pcVPS->setSubLayersVpsMaxMinus1( i, uiCode );   
1295      pcVPS->checkSubLayersVpsMaxMinus1( i ); 
1296
1297    }
1298  } 
1299  else
1300  {
1301    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1302    {
1303      pcVPS->setSubLayersVpsMaxMinus1( i, pcVPS->getMaxTLayers( ) - 1);   
1304    }
1305  }
1306  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
1307
1308  if ( pcVPS->getMaxTidRefPresentFlag() )
1309  {   
1310    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
1311    {
1312      for( Int j = i + 1; j <= pcVPS->getMaxLayersMinus1(); j++ )
1313      {
1314        if ( pcVPS->getDirectDependencyFlag(j,i) )
1315        {
1316          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1" ); pcVPS->setMaxTidIlRefPicsPlus1( i, j, uiCode );
1317        }
1318      }
1319    }
1320  }
1321
1322  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
1323#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1324  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
1325#endif
1326
1327#if !H_MV_HLS7_GEN
1328  READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
1329#else
1330  READ_UVLC( uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode ); 
1331#endif
1332  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
1333  {
1334    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
1335#if !H_MV_HLS_7_VPS_P0048_14
1336    if( !pcVPS->getVpsProfilePresentFlag( i ) )
1337    {
1338      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
1339      pcVPS->checkProfileRefMinus1( i );     
1340    }
1341#endif
1342    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
1343    if( !pcVPS->getVpsProfilePresentFlag( i ) )
1344    {
1345      TComPTL temp = *pcVPS->getPTL( i );
1346#if H_MV_HLS_7_VPS_P0048_14
1347      *pcVPS->getPTL( i ) = *pcVPS->getPTL( i - 1 );
1348#else
1349      *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
1350#endif
1351      pcVPS->getPTL( i )->copyLevelFrom( &temp );
1352    }
1353  }
1354
1355#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1356  READ_UVLC( uiCode, "num_add_output_layer_sets"      ); pcVPS->setNumAddOutputLayerSets( uiCode );
1357  pcVPS->initTargetLayerIdLists( ); 
1358  if( pcVPS->getNumOutputLayerSets() > 1)
1359  {
1360    READ_CODE( 2, uiCode, "default_target_output_layer_idc" ); pcVPS->setDefaultTargetOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );   
1361  } 
1362
1363#else
1364  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
1365
1366  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
1367
1368  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
1369  {
1370    READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
1371    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
1372  }
1373
1374  if( numOutputLayerSets > 1)
1375  {
1376    READ_CODE( 2, uiCode, "default_one_target_output_layer_idc" ); pcVPS->setDefaultOneTargetOutputLayerIdc( uiCode );
1377    pcVPS->checkDefaultOneTargetOutputLayerIdc(); 
1378  } 
1379#endif
1380
1381  pcVPS->setOutputLayerFlag(0, 0, pcVPS->inferOutputLayerFlag( 0, 0 )); 
1382  pcVPS->setOutputLayerSetIdxMinus1(0, -1); 
1383
1384#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1385  pcVPS->deriveTargetLayerIdList( 0 ); 
1386  for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
1387  {
1388    if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )   
1389#else
1390  for( Int i = 1; i < numOutputLayerSets; i++ )
1391  {
1392    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
1393#endif
1394    {       
1395      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
1396#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1397    }
1398
1399    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
1400    {       
1401      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
1402      {
1403        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1404      }
1405    }
1406    else
1407    { 
1408      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
1409      {             
1410        pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j )); 
1411      }
1412    }
1413    pcVPS->deriveTargetLayerIdList( i ); 
1414#else
1415      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
1416      {
1417        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1418      }       
1419    }
1420    else
1421    { // These inference rules would also be helpful in spec text
1422      pcVPS->setOutputLayerSetIdxMinus1(i, i - 1 ); 
1423      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
1424      {             
1425        pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j )); 
1426      }
1427    }
1428#endif
1429    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
1430    {     
1431      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
1432    }
1433
1434#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1435    if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
1436    {
1437      READ_FLAG( uiCode, "alt_output_layer_flag[ i ]" ); pcVPS->setAltOutputLayerFlag( i, uiCode == 1 );
1438    }
1439  }
1440#else
1441  }
1442  if( pcVPS->getMaxLayersMinus1() > 0 )
1443  {
1444    READ_FLAG( uiCode, "alt_output_layer_flag" ); pcVPS->setAltOutputLayerFlag( uiCode == 1 );
1445  }
1446#endif
1447
1448#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1449  pcVPS->deriveTargetLayerIdLists(); 
1450#endif
1451
1452  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
1453  if ( pcVPS->getRepFormatIdxPresentFlag() )
1454  {
1455#if H_MV_HLS7_GEN
1456    READ_UVLC( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
1457#else
1458    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
1459#endif
1460  }
1461
1462  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
1463  { 
1464    assert( pcVPS->getRepFormat(i) == NULL ); 
1465    TComRepFormat* curRepFormat = new TComRepFormat(); 
1466    TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL; 
1467    parseRepFormat( i, curRepFormat ,  prevRepFormat); 
1468    pcVPS->setRepFormat(i, curRepFormat ); 
1469  }
1470
1471  if( pcVPS->getRepFormatIdxPresentFlag() ) 
1472  {
1473    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1474    {
1475      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
1476      {
1477        READ_CODE( 8, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1478      }
1479    }
1480  }
1481
1482  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
1483#if H_MV_HLS7_GEN
1484  READ_FLAG( uiCode, "vps_poc_lsb_aligned_flag" ); pcVPS->setVpsPocLsbAlignedFlag( uiCode == 1 );
1485#endif
1486  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1487  {
1488    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) )  ==  0 )
1489    {     
1490      READ_FLAG( uiCode, "poc_lsb_not_present_flag" ); pcVPS->setPocLsbNotPresentFlag( i, uiCode == 1 );
1491    }
1492  }
1493
1494#if H_MV_HLS_7_RESERVED_FLAGS
1495  READ_FLAG( uiCode, "vps_reserved_zero_flag" ); 
1496#endif
1497  parseDpbSize( pcVPS ); 
1498
1499  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
1500
1501  READ_FLAG( uiCode, "default_direct_dependency_flag" ); pcVPS->setDefaultDirectDependencyFlag( uiCode == 1 );
1502  if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1503  { 
1504    READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2, uiCode, "default_direct_dependency_type" ); pcVPS->setDefaultDirectDependencyType( uiCode );
1505  }
1506
1507  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1508  {
1509    for( Int j = 0; j < i; j++ )
1510    {
1511      if (pcVPS->getDirectDependencyFlag( i, j) )
1512      {       
1513        if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1514        { 
1515          pcVPS->setDirectDependencyType( i, j , pcVPS->getDefaultDirectDependencyType( ) );
1516        }
1517        else
1518        {
1519          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1520        }
1521      }
1522    }
1523  } 
1524
1525#if H_MV_HLS7_GEN
1526  READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode ); 
1527  for ( Int i = 1; i < pcVPS->getVpsNonVuiExtensionLength(); i++ )
1528  {
1529    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" );
1530  }
1531  READ_FLAG( uiCode, "vps_vui_present_flag" );                    pcVPS->setVpsVuiPresentFlag( uiCode == 1 );  if ( pcVPS->getVpsVuiPresentFlag() )
1532#endif
1533#if !H_MV_HLS_7_RESERVED_FLAGS
1534  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" ); 
1535#endif
1536  if( pcVPS->getVpsVuiPresentFlag() )
1537  {
1538    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
1539    parseVPSVUI( pcVPS ); 
1540  }     
1541#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
1542  {
1543    TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1544    assert( pcVPSVUI ); 
1545    pcVPSVUI->inferVpsVui( false ); 
1546  }
1547#endif
1548
1549  pcVPS->checkVPSExtensionSyntax(); 
1550}
1551
1552Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
1553{
1554  assert( pcRepFormat ); 
1555
1556  UInt uiCode; 
1557
1558  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
1559  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
1560  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" ); pcRepFormat->setChromaAndBitDepthVpsPresentFlag( uiCode == 1 );
1561
1562  pcRepFormat->checkChromaAndBitDepthVpsPresentFlag( i ); 
1563
1564  if ( pcRepFormat->getChromaAndBitDepthVpsPresentFlag() )
1565  { 
1566  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
1567  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
1568  {
1569    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
1570  }
1571  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
1572  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
1573  }
1574  else
1575  {
1576    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false ); 
1577  }
1578}
1579
1580
1581Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
1582{
1583  assert( pcVPS ); 
1584
1585  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1586
1587  assert( pcVPSVUI ); 
1588
1589  UInt uiCode; 
1590  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
1591  if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
1592  { 
1593    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
1594  }
1595#if H_MV_HLS_7_MISC_P0068_21
1596  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
1597  {
1598    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
1599  }
1600#endif
1601  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
1602  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
1603  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1604  {
1605#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1606    for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
1607#else
1608    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
1609#endif
1610    {
1611      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
1612      {
1613        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
1614        {
1615          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
1616        }
1617        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
1618        {
1619          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
1620        }
1621        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
1622        {
1623          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
1624          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
1625        }
1626        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
1627        {
1628          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
1629          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
1630        }
1631      }
1632    }
1633  }
1634
1635#if H_MV_HLS_7_VPS_P0076_15
1636  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1637  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1638  {
1639    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1640  }
1641  else
1642  {
1643    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
1644  }
1645
1646  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1647  {
1648    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1649    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1650    parseVideoSignalInfo( curVideoSignalInfo ); 
1651    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1652  }
1653
1654  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1655  {
1656    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1657    {
1658      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1659      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
1660    }
1661  }
1662  else
1663  {
1664    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1665    {
1666      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ); 
1667    }
1668  }
1669#endif
1670
1671  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
1672  if( !pcVPSVUI->getTilesNotInUseFlag() ) 
1673  {     
1674    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1675    {
1676      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
1677      if( pcVPSVUI->getTilesInUseFlag( i ) ) 
1678      {
1679        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
1680      }
1681    } 
1682
1683    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1684    {
1685      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
1686      { 
1687        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getRefLayerId(pcVPS->getLayerIdInNuh( i ) , j  )); 
1688        if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
1689        {
1690          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
1691        }
1692      } 
1693    }
1694  } 
1695 
1696  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
1697 
1698  if( !pcVPSVUI->getWppNotInUseFlag( ))
1699  {
1700    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1701    {
1702      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
1703    }
1704  }
1705
1706#if H_MV_HLS_7_RESERVED_FLAGS
1707  READ_CODE( 3, uiCode, "vps_vui_reserved_zero_3bits" ); 
1708#endif
1709
1710  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
1711
1712  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1713  {
1714    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1715    {
1716      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
1717      {
1718        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
1719        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1720        {
1721          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
1722          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1723          {
1724            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
1725          }
1726        }
1727      }
1728    }
1729  }
1730
1731#if !H_MV_HLS_7_VPS_P0076_15
1732  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1733  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1734  {
1735    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1736  }
1737  else
1738  {
1739    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
1740  }
1741
1742  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1743  {
1744    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1745    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1746    parseVideoSignalInfo( curVideoSignalInfo ); 
1747    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1748  }
1749 
1750  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1751  {
1752    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1753    {
1754      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1755      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
1756    }
1757  }
1758  else
1759  {
1760    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1761    {
1762      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ); 
1763    }
1764  }
1765#endif
1766  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
1767  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
1768  {
1769    parseVpsVuiBspHrdParameters( pcVPS ); 
1770}
1771#if H_MV_HLS_7_MISC_P0182_13
1772  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1773  {
1774    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 ) 
1775    {
1776      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
1777    }
1778  }
1779#endif
1780}
1781
1782Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
1783{
1784  assert( pcVPS ); 
1785
1786  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1787
1788  assert( pcVPSVUI ); 
1789
1790  TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters(); 
1791 
1792  assert ( vpsVuiBspHrdP );
1793
1794  UInt uiCode; 
1795  READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vpsVuiBspHrdP->setVpsNumBspHrdParametersMinus1( uiCode );
1796  for( Int i = 0; i <= vpsVuiBspHrdP->getVpsNumBspHrdParametersMinus1( ); i++ )
1797  { 
1798    if( i > 0 )
1799    {
1800      READ_FLAG( uiCode, "bsp_cprms_present_flag" ); vpsVuiBspHrdP->setBspCprmsPresentFlag( i, uiCode == 1 );
1801    }
1802    TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i ); 
1803    parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getBspCprmsPresentFlag( i ), pcVPS->getMaxSubLayersMinus1() );     
1804  } 
1805  for( Int h = 1; h <= pcVPS->getVpsNumLayerSetsMinus1(); h++ )
1806  { 
1807    READ_UVLC( uiCode, "num_bitstream_partitions" ); vpsVuiBspHrdP->setNumBitstreamPartitions( h, uiCode );
1808    for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ ) 
1809    {
1810      for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ ) 
1811      {
1812        if( pcVPS->getLayerIdIncludedFlag( h ,j ) )
1813        {
1814          READ_FLAG( uiCode, "layer_in_bsp_flag" ); vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, uiCode == 1 );
1815        }
1816        else
1817        {
1818          vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec
1819        }
1820      }
1821    }
1822    vpsVuiBspHrdP->checkLayerInBspFlag( pcVPS, h ); 
1823   
1824    if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
1825    { 
1826      READ_UVLC( uiCode, "num_bsp_sched_combinations" ); vpsVuiBspHrdP->setNumBspSchedCombinations( h, uiCode );
1827      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
1828      {
1829        for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
1830        { 
1831          READ_UVLC( uiCode, "bsp_comb_hrd_idx" ); vpsVuiBspHrdP->setBspCombHrdIdx( h, i, j, uiCode );
1832          READ_UVLC( uiCode, "bsp_comb_sched_idx" ); vpsVuiBspHrdP->setBspCombSchedIdx( h, i, j, uiCode );
1833        } 
1834      }
1835    } 
1836  } 
1837} 
1838
1839Void TDecCavlc::parseVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo ) 
1840{
1841  UInt uiCode; 
1842  READ_CODE( 3, uiCode, "video_vps_format" );             pcVideoSignalInfo->setVideoVpsFormat( uiCode );
1843  READ_FLAG( uiCode, "video_full_range_vps_flag" );       pcVideoSignalInfo->setVideoFullRangeVpsFlag( uiCode == 1 );
1844  READ_CODE( 8, uiCode, "colour_primaries_vps" );         pcVideoSignalInfo->setColourPrimariesVps( uiCode );
1845  READ_CODE( 8, uiCode, "transfer_characteristics_vps" ); pcVideoSignalInfo->setTransferCharacteristicsVps( uiCode );
1846  READ_CODE( 8, uiCode, "matrix_coeffs_vps" );            pcVideoSignalInfo->setMatrixCoeffsVps( uiCode );
1847}
1848
1849Void TDecCavlc::parseDpbSize( TComVPS* vps )
1850{
1851  UInt uiCode; 
1852  TComDpbSize* dpbSize = vps->getDpbSize(); 
1853  assert ( dpbSize != 0 ); 
1854
1855  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
1856  { 
1857    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
1858#if H_MV_HLS_7_HRD_P0156_7
1859    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
1860#else
1861    for( Int j = 0; j  <=  vps->getMaxTLayers() - 1 ; j++ )
1862#endif
1863    { 
1864      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
1865      {
1866        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
1867      }
1868      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
1869      { 
1870#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1871        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
1872#else
1873        for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
1874#endif
1875        {
1876          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
1877        }
1878        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
1879#if H_MV_HLS7_GEN
1880        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) ) 
1881        {
1882          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
1883          {
1884            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1" ); dpbSize->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode );
1885          }
1886        }
1887#endif
1888        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
1889      }
1890      else
1891      {
1892        if ( j > 0 )
1893        {
1894          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
1895          {
1896            dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
1897          }
1898          dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
1899          dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
1900        }
1901      }
1902    } 
1903  } 
1904}
1905#endif
1906
1907#if H_3D
1908Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
1909{
1910  UInt uiCode; 
1911  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1912  {
1913#if H_3D_ARP
1914    pcVPS->setUseAdvRP  ( i, 0 );
1915    pcVPS->setARPStepNum( i, 1 );
1916#endif 
1917#if H_3D_SPIVMP
1918    pcVPS->setSubPULog2Size(i, 0);
1919#endif
1920    if ( i != 0 )
1921    {
1922      if( !( pcVPS->getDepthId( i ) == 1 ) )
1923      {
1924#if H_3D_IV_MERGE
1925        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1926#if H_3D_SPIVMP
1927#if SEC_SPIVMP_MCP_SIZE_G0077
1928        READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1929#else
1930        READ_UVLC (uiCode, "log2_sub_PU_size_minus2");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1931#endif
1932#endif
1933#endif
1934#if H_3D_ARP
1935        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1936
1937#endif
1938#if H_3D_NBDV_REF
1939        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1940#endif
1941#if H_3D_VSP
1942        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1943#endif
1944#if H_3D_DBBP
1945          READ_FLAG( uiCode, "use_dbbp_flag[i]" ); pcVPS->setUseDBBP( i, uiCode == 1 ? true : false );
1946#endif
1947      }
1948      else
1949      {
1950#if H_3D_IV_MERGE
1951        if(i!=1)
1952        {
1953          READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1954        }
1955#endif
1956#if H_3D_SPIVMP
1957        if (i!=1)
1958        {
1959#if SEC_SPIVMP_MCP_SIZE_G0077
1960          READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1961#else
1962          READ_UVLC (uiCode, "log2_sub_PU_size_minus2[i]");     pcVPS->setSubPULog2Size(i, uiCode+2); 
1963#endif
1964        }
1965#endif
1966#if H_3D_IV_MERGE
1967        READ_FLAG( uiCode, "mpi_flag[i]" );             pcVPS->setMPIFlag( i, uiCode == 1 ? true : false );
1968#endif
1969        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1970        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
1971#if H_3D_INTER_SDC
1972            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
1973#endif
1974      }
1975    }
1976  }
1977
1978  UInt uiCamParPrecision = 0; 
1979  Bool bCamParSlice      = false; 
1980  Bool bCamParPresentFlag = false;
1981
1982  READ_UVLC( uiCamParPrecision, "cp_precision" );
1983  for (UInt viewIndex=0; viewIndex<pcVPS->getNumViews(); viewIndex++)
1984  {
1985#if FIX_CAM_PARS_COLLECTOR
1986    pcVPS->setCamParPresent         ( viewIndex, false );
1987    pcVPS->setHasCamParInSliceHeader( viewIndex, false );
1988#endif
1989    READ_FLAG( uiCode, "cp_present_flag[i]" );                  bCamParPresentFlag = ( uiCode == 1);
1990    if ( bCamParPresentFlag )
1991    {
1992      READ_FLAG( uiCode, "cp_in_slice_segment_header_flag[i]" );          bCamParSlice = ( uiCode == 1);
1993      if ( !bCamParSlice )
1994      {
1995        for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
1996        {
1997          Int iCode; 
1998          READ_SVLC( iCode, "vps_cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
1999          READ_SVLC( iCode, "vps_cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
2000          READ_SVLC( iCode, "vps_cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
2001          READ_SVLC( iCode, "vps_cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
2002        }
2003      }
2004      pcVPS->initCamParaVPS( viewIndex, bCamParPresentFlag, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
2005    }
2006  }
2007#if QC_SPIVMP_MPI_G0119
2008  READ_UVLC (uiCode, "log2_sub_PU_MPI_size_minus3");              pcVPS->setSubPUMPILog2Size( uiCode + 3 ); 
2009#endif
2010  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
2011}
2012#endif
2013
2014Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
2015{
2016  UInt  uiCode;
2017  Int   iCode;
2018
2019#if ENC_DEC_TRACE
2020  xTraceSliceHeader(rpcSlice);
2021#endif
2022  TComPPS* pps = NULL;
2023  TComSPS* sps = NULL;
2024#if H_MV
2025  TComVPS* vps = NULL;
2026#endif
2027
2028  UInt firstSliceSegmentInPic;
2029  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
2030  if( rpcSlice->getRapPicFlag())
2031  { 
2032    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
2033  }
2034  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
2035  pps = parameterSetManager->getPrefetchedPPS(uiCode);
2036  //!KS: need to add error handling code here, if PPS is not available
2037  assert(pps!=0);
2038  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
2039  //!KS: need to add error handling code here, if SPS is not available
2040  assert(sps!=0);
2041#if H_MV
2042  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
2043  assert( vps != NULL );
2044 
2045  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
2046  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
2047  if ( sps->getVuiParametersPresentFlag() )
2048  {
2049    sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() ); 
2050  }
2051  rpcSlice->setVPS(vps);     
2052  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
2053  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
2054#if H_3D 
2055  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
2056#endif
2057#endif
2058  rpcSlice->setSPS(sps);
2059  rpcSlice->setPPS(pps);
2060  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
2061  {
2062    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
2063  }
2064  else
2065  {
2066    rpcSlice->setDependentSliceSegmentFlag(false);
2067  }
2068  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2069  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
2070  UInt sliceSegmentAddress = 0;
2071  Int bitsSliceSegmentAddress = 0;
2072  while(numCTUs>(1<<bitsSliceSegmentAddress))
2073  {
2074    bitsSliceSegmentAddress++;
2075  }
2076
2077  if(!firstSliceSegmentInPic)
2078  {
2079    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
2080  }
2081  //set uiCode to equal slice start address (or dependent slice start address)
2082  Int startCuAddress = maxParts*sliceSegmentAddress;
2083  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
2084  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
2085
2086  if (rpcSlice->getDependentSliceSegmentFlag())
2087  {
2088    rpcSlice->setNextSlice          ( false );
2089    rpcSlice->setNextSliceSegment ( true  );
2090  }
2091  else
2092  {
2093    rpcSlice->setNextSlice          ( true  );
2094    rpcSlice->setNextSliceSegment ( false );
2095
2096    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
2097    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
2098  }
2099 
2100  if(!rpcSlice->getDependentSliceSegmentFlag())
2101  {
2102#if H_MV   
2103    Int esb = 0; //Don't use i, otherwise will shadow something below
2104
2105    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2106    {
2107      esb++; 
2108      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
2109    }
2110
2111    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2112    {
2113      esb++; 
2114      READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
2115    }
2116    rpcSlice->checkCrossLayerBlaFlag( ); 
2117
2118#if !H_MV_HLS7_GEN
2119    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2120    {
2121      esb++; 
2122      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
2123    }
2124#endif
2125
2126    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
2127#else
2128    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2129#endif     
2130    {
2131      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2132    }
2133
2134    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
2135    if( pps->getOutputFlagPresentFlag() )
2136    {
2137      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
2138    }
2139    else
2140    {
2141      rpcSlice->setPicOutputFlag( true );
2142    }
2143    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
2144    assert (sps->getChromaFormatIdc() == 1 );
2145    // if( separate_colour_plane_flag  ==  1 )
2146    //   colour_plane_id                                      u(2)
2147
2148
2149#if H_MV
2150    UInt slicePicOrderCntLsb = 0;
2151    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
2152    if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
2153    {
2154      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
2155    }   
2156
2157    Bool picOrderCntMSBZeroFlag = false;     
2158
2159    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
2160    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ); 
2161    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
2162    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ); 
2163    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag(); 
2164
2165    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
2166
2167    Int picOrderCntMSB = 0; 
2168
2169    if ( !picOrderCntMSBZeroFlag )
2170    {
2171      Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
2172      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
2173      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
2174      Int prevPicOrderCntMsb = prevPicOrderCnt - prevPicOrderCntLsb;
2175           
2176      if( ( slicePicOrderCntLsb  <  prevPicOrderCntLsb ) && ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
2177      {
2178        picOrderCntMSB = prevPicOrderCntMsb + maxPicOrderCntLsb;
2179      }
2180      else if( (slicePicOrderCntLsb  >  prevPicOrderCntLsb )  && ( (slicePicOrderCntLsb - prevPicOrderCntLsb )  >  ( maxPicOrderCntLsb / 2 ) ) ) 
2181      {
2182        picOrderCntMSB = prevPicOrderCntMsb - maxPicOrderCntLsb;
2183      }
2184      else
2185      {
2186        picOrderCntMSB = prevPicOrderCntMsb;
2187      }   
2188    }
2189     
2190    rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
2191    if ( rpcSlice->getPocResetFlag() ) 
2192    {
2193      rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
2194      rpcSlice->setPOC              ( 0 );
2195    }     
2196#endif
2197
2198    if( rpcSlice->getIdrPicFlag() )
2199    {
2200#if !H_MV
2201      rpcSlice->setPOC(0);
2202#endif
2203      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2204      rps->setNumberOfNegativePictures(0);
2205      rps->setNumberOfPositivePictures(0);
2206      rps->setNumberOfLongtermPictures(0);
2207      rps->setNumberOfPictures(0);
2208      rpcSlice->setRPS(rps);
2209#if H_MV
2210      rpcSlice->setEnableTMVPFlag(false);
2211#endif
2212    }
2213    else
2214    {
2215#if !H_MV
2216      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
2217      Int iPOClsb = uiCode;
2218      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2219      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2220      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2221      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2222      Int iPOCmsb;
2223      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2224      {
2225        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2226      }
2227      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
2228      {
2229        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2230      }
2231      else
2232      {
2233        iPOCmsb = iPrevPOCmsb;
2234      }
2235      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2236        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2237        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2238      {
2239        // For BLA picture types, POCmsb is set to 0.
2240        iPOCmsb = 0;
2241      }
2242      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2243#endif
2244      TComReferencePictureSet* rps;
2245      rps = rpcSlice->getLocalRPS();
2246      rpcSlice->setRPS(rps);
2247      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2248      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2249      {
2250        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2251      }
2252      else // use reference to short-term reference picture set in PPS
2253      {
2254        Int numBits = 0;
2255        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2256        {
2257          numBits++;
2258        }
2259        if (numBits > 0)
2260        {
2261          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2262        }
2263        else
2264        {
2265          uiCode = 0;
2266        }
2267        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2268      }
2269      if(sps->getLongTermRefsPresent())
2270      {
2271        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2272        UInt numOfLtrp = 0;
2273        UInt numLtrpInSPS = 0;
2274        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2275        {
2276          READ_UVLC( uiCode, "num_long_term_sps");
2277          numLtrpInSPS = uiCode;
2278          numOfLtrp += numLtrpInSPS;
2279          rps->setNumberOfLongtermPictures(numOfLtrp);
2280        }
2281        Int bitsForLtrpInSPS = 0;
2282        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2283        {
2284          bitsForLtrpInSPS++;
2285        }
2286        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2287        numOfLtrp += uiCode;
2288        rps->setNumberOfLongtermPictures(numOfLtrp);
2289        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2290        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2291        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2292        {
2293          Int pocLsbLt;
2294          if (k < numLtrpInSPS)
2295          {
2296            uiCode = 0;
2297            if (bitsForLtrpInSPS > 0)
2298            {
2299              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2300            }
2301            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2302
2303            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2304            rps->setUsed(j,usedByCurrFromSPS);
2305          }
2306          else
2307          {
2308            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2309            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2310          }
2311          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2312          Bool mSBPresentFlag = uiCode ? true : false;
2313          if(mSBPresentFlag)                 
2314          {
2315            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2316            Bool deltaFlag = false;
2317            //            First LTRP                               || First LTRP from SH
2318            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2319            {
2320              deltaFlag = true;
2321            }
2322            if(deltaFlag)
2323            {
2324              deltaPocMSBCycleLT = uiCode;
2325            }
2326            else
2327            {
2328              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
2329            }
2330
2331            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2332                                        - iPOClsb + pocLsbLt;
2333            rps->setPOC     (j, pocLTCurr); 
2334            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2335            rps->setCheckLTMSBPresent(j,true); 
2336          }
2337          else
2338          {
2339            rps->setPOC     (j, pocLsbLt);
2340            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2341            rps->setCheckLTMSBPresent(j,false); 
2342           
2343            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2344            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2345            {
2346              deltaPocMSBCycleLT = 0;
2347            }
2348          }
2349          prevDeltaMSB = deltaPocMSBCycleLT;
2350        }
2351        offset += rps->getNumberOfLongtermPictures();
2352        rps->setNumberOfPictures(offset);       
2353      } 
2354      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2355        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2356        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2357      {
2358        // In the case of BLA picture types, rps data is read from slice header but ignored
2359        rps = rpcSlice->getLocalRPS();
2360        rps->setNumberOfNegativePictures(0);
2361        rps->setNumberOfPositivePictures(0);
2362        rps->setNumberOfLongtermPictures(0);
2363        rps->setNumberOfPictures(0);
2364        rpcSlice->setRPS(rps);
2365      }
2366      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2367      {
2368        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2369        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
2370      }
2371      else
2372      {
2373        rpcSlice->setEnableTMVPFlag(false);
2374      }
2375    }
2376#if H_MV
2377    Bool interLayerPredLayerIdcPresentFlag = false; 
2378    Int layerId       = rpcSlice->getLayerId(); 
2379    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
2380    {   
2381      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
2382      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
2383      {           
2384        if( !vps->getMaxOneActiveRefLayerFlag()) 
2385        {
2386          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
2387        }
2388        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
2389        {
2390          interLayerPredLayerIdcPresentFlag = true; 
2391          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
2392          {
2393            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
2394          }
2395        }
2396      } 
2397    }
2398    if ( !interLayerPredLayerIdcPresentFlag )
2399    {
2400      for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
2401      {
2402        rpcSlice->setInterLayerPredLayerIdc( i, rpcSlice->getRefLayerPicIdc( i ) );
2403      }
2404    }
2405#endif
2406    if(sps->getUseSAO())
2407    {
2408      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2409      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2410    }
2411
2412    if (rpcSlice->getIdrPicFlag())
2413    {
2414      rpcSlice->setEnableTMVPFlag(false);
2415    }
2416    if (!rpcSlice->isIntra())
2417    {
2418
2419      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2420      if (uiCode)
2421      {
2422        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2423        if (rpcSlice->isInterB())
2424        {
2425          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2426        }
2427        else
2428        {
2429          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2430        }
2431      }
2432      else
2433      {
2434        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2435        if (rpcSlice->isInterB())
2436        {
2437          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2438        }
2439        else
2440        {
2441          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2442        }
2443      }
2444    }
2445    // }
2446    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2447    if(!rpcSlice->isIntra())
2448    {
2449      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2450      {
2451        refPicListModification->setRefPicListModificationFlagL0( 0 );
2452      }
2453      else
2454      {
2455        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2456      }
2457
2458      if(refPicListModification->getRefPicListModificationFlagL0())
2459      { 
2460        uiCode = 0;
2461        Int i = 0;
2462        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2463        if ( numRpsCurrTempList0 > 1 )
2464        {
2465          Int length = 1;
2466          numRpsCurrTempList0 --;
2467          while ( numRpsCurrTempList0 >>= 1) 
2468          {
2469            length ++;
2470          }
2471          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2472          {
2473            READ_CODE( length, uiCode, "list_entry_l0" );
2474            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2475          }
2476        }
2477        else
2478        {
2479          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2480          {
2481            refPicListModification->setRefPicSetIdxL0(i, 0 );
2482          }
2483        }
2484      }
2485    }
2486    else
2487    {
2488      refPicListModification->setRefPicListModificationFlagL0(0);
2489    }
2490    if(rpcSlice->isInterB())
2491    {
2492      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2493      {
2494        refPicListModification->setRefPicListModificationFlagL1( 0 );
2495      }
2496      else
2497      {
2498        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2499      }
2500      if(refPicListModification->getRefPicListModificationFlagL1())
2501      {
2502        uiCode = 0;
2503        Int i = 0;
2504        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
2505        if ( numRpsCurrTempList1 > 1 )
2506        {
2507          Int length = 1;
2508          numRpsCurrTempList1 --;
2509          while ( numRpsCurrTempList1 >>= 1) 
2510          {
2511            length ++;
2512          }
2513          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2514          {
2515            READ_CODE( length, uiCode, "list_entry_l1" );
2516            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2517          }
2518        }
2519        else
2520        {
2521          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2522          {
2523            refPicListModification->setRefPicSetIdxL1(i, 0 );
2524          }
2525        }
2526      }
2527    } 
2528    else
2529    {
2530      refPicListModification->setRefPicListModificationFlagL1(0);
2531    }
2532    if (rpcSlice->isInterB())
2533    {
2534      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
2535    }
2536
2537    rpcSlice->setCabacInitFlag( false ); // default
2538    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
2539    {
2540      READ_FLAG(uiCode, "cabac_init_flag");
2541      rpcSlice->setCabacInitFlag( uiCode ? true : false );
2542    }
2543
2544    if ( rpcSlice->getEnableTMVPFlag() )
2545    {
2546      if ( rpcSlice->getSliceType() == B_SLICE )
2547      {
2548        READ_FLAG( uiCode, "collocated_from_l0_flag" );
2549        rpcSlice->setColFromL0Flag(uiCode);
2550      }
2551      else
2552      {
2553        rpcSlice->setColFromL0Flag( 1 );
2554      }
2555
2556      if ( rpcSlice->getSliceType() != I_SLICE &&
2557          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
2558           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
2559      {
2560        READ_UVLC( uiCode, "collocated_ref_idx" );
2561        rpcSlice->setColRefIdx(uiCode);
2562      }
2563      else
2564      {
2565        rpcSlice->setColRefIdx(0);
2566      }
2567    }
2568    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
2569    {
2570      xParsePredWeightTable(rpcSlice);
2571      rpcSlice->initWpScaling();
2572    }
2573#if H_3D_IC
2574    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) && !rpcSlice->getIsDepth())
2575    {
2576      UInt uiCodeTmp = 0;
2577
2578      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
2579      rpcSlice->setApplyIC( uiCodeTmp );
2580
2581      if ( uiCodeTmp )
2582      {
2583        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
2584        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
2585      }
2586    }
2587#endif
2588    if (!rpcSlice->isIntra())
2589    {
2590      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
2591#if H_3D_IV_MERGE
2592      if(rpcSlice->getIsDepth())
2593      {
2594        Bool bMPIFlag = rpcSlice->getVPS()->getMPIFlag( rpcSlice->getLayerIdInVps() ) ;
2595        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2596        rpcSlice->setMaxNumMergeCand(( ( bMPIFlag || ivMvPredFlag ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2597      }
2598      else
2599      {
2600        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2601        rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2602      }
2603
2604#else
2605      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
2606#endif
2607    }
2608
2609    READ_SVLC( iCode, "slice_qp_delta" );
2610    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
2611
2612    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
2613    assert( rpcSlice->getSliceQp() <=  51 );
2614
2615    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
2616    {
2617      READ_SVLC( iCode, "slice_qp_delta_cb" );
2618      rpcSlice->setSliceQpDeltaCb( iCode );
2619      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
2620      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
2621      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
2622      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
2623
2624      READ_SVLC( iCode, "slice_qp_delta_cr" );
2625      rpcSlice->setSliceQpDeltaCr( iCode );
2626      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
2627      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
2628      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
2629      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
2630    }
2631
2632    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
2633    {
2634      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
2635      {
2636        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
2637      }
2638      else
2639      { 
2640        rpcSlice->setDeblockingFilterOverrideFlag(0);
2641      }
2642      if(rpcSlice->getDeblockingFilterOverrideFlag())
2643      {
2644        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
2645        if(!rpcSlice->getDeblockingFilterDisable())
2646        {
2647          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
2648          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
2649                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
2650          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
2651          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
2652                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
2653        }
2654      }
2655      else
2656      {
2657        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
2658        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
2659        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
2660      }
2661    }
2662    else
2663    { 
2664      rpcSlice->setDeblockingFilterDisable       ( false );
2665      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
2666      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
2667    }
2668
2669    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
2670    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
2671
2672    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
2673    {
2674      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
2675    }
2676    else
2677    {
2678      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
2679    }
2680    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
2681
2682  }
2683 
2684    UInt *entryPointOffset          = NULL;
2685    UInt numEntryPointOffsets, offsetLenMinus1;
2686  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2687  {
2688    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
2689    if (numEntryPointOffsets>0)
2690    {
2691      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2692    }
2693    entryPointOffset = new UInt[numEntryPointOffsets];
2694    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2695    {
2696      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2697      entryPointOffset[ idx ] = uiCode + 1;
2698    }
2699  }
2700  else
2701  {
2702    rpcSlice->setNumEntryPointOffsets ( 0 );
2703  }
2704
2705#if H_3D
2706  if( rpcSlice->getVPS()->hasCamParInSliceHeader( rpcSlice->getViewIndex() )  && !rpcSlice->getIsDepth() )
2707  {
2708    UInt uiViewIndex = rpcSlice->getViewIndex();
2709    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
2710    {
2711      READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
2712      READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
2713      READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
2714      READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
2715    }
2716    rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
2717  }
2718#endif
2719
2720  if(pps->getSliceHeaderExtensionPresentFlag())
2721  {
2722#if !H_MV_HLS7_GEN   
2723    READ_UVLC(uiCode,"slice_header_extension_length");
2724    for(Int i=0; i<uiCode; i++)
2725    {
2726      UInt ignore;
2727      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2728    }
2729  }
2730#else
2731#if H_MV
2732    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
2733    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
2734
2735    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
2736    {
2737      READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
2738    }
2739
2740    if( rpcSlice->getPocResetIdc() !=  0 )
2741    {
2742      READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
2743    }
2744   
2745    if( rpcSlice->getPocResetIdc() ==  3 ) 
2746    {
2747      READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
2748      READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
2749    }         
2750
2751    if( !rpcSlice->getPocMsbValRequiredFlag() &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
2752    {
2753      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
2754    }
2755   
2756    if( rpcSlice->getPocMsbValPresentFlag() )
2757    {
2758      READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
2759    }
2760
2761    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 );
2762    {
2763     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
2764    }
2765    assert( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
2766#else
2767    READ_UVLC( uiCode, "slice_header_extension_length" );
2768    for(Int i=0; i<uiCode; i++)
2769    {
2770      UInt ignore;
2771      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2772    }
2773  }
2774#endif
2775#endif
2776
2777
2778  m_pcBitstream->readByteAlignment();
2779
2780  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2781  {
2782    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2783   
2784    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2785    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2786    {
2787      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2788      {
2789        endOfSliceHeaderLocation++;
2790      }
2791    }
2792
2793    Int  curEntryPointOffset     = 0;
2794    Int  prevEntryPointOffset    = 0;
2795    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2796    {
2797      curEntryPointOffset += entryPointOffset[ idx ];
2798
2799      Int emulationPreventionByteCount = 0;
2800      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2801      {
2802        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
2803             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2804        {
2805          emulationPreventionByteCount++;
2806        }
2807      }
2808
2809      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2810      prevEntryPointOffset = curEntryPointOffset;
2811    }
2812
2813    if ( pps->getTilesEnabledFlag() )
2814    {
2815      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2816
2817      UInt prevPos = 0;
2818      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2819      {
2820        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2821        prevPos += entryPointOffset[ idx ];
2822      }
2823    }
2824    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2825    {
2826    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2827      rpcSlice->allocSubstreamSizes(numSubstreams);
2828      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2829      for (Int idx=0; idx<numSubstreams-1; idx++)
2830      {
2831        if ( idx < numEntryPointOffsets )
2832        {
2833          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2834        }
2835        else
2836        {
2837          pSubstreamSizes[ idx ] = 0;
2838        }
2839      }
2840    }
2841
2842    if (entryPointOffset)
2843    {
2844      delete [] entryPointOffset;
2845    }
2846  }
2847
2848  return;
2849}
2850 
2851Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2852{
2853  UInt uiCode;
2854  if(profilePresentFlag)
2855  {
2856    parseProfileTier(rpcPTL->getGeneralPTL());
2857  }
2858  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2859
2860  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2861  {
2862#if !H_MV
2863    if(profilePresentFlag)
2864    {
2865#endif
2866      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2867#if H_MV
2868    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
2869#else
2870    }
2871#endif
2872    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2873  }
2874 
2875  if (maxNumSubLayersMinus1 > 0)
2876  {
2877    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2878    {
2879      READ_CODE(2, uiCode, "reserved_zero_2bits");
2880      assert(uiCode == 0);
2881    }
2882  }
2883 
2884  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2885  {
2886    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2887    {
2888      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2889    }
2890    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2891    {
2892      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2893    }
2894  }
2895}
2896
2897Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2898{
2899  UInt uiCode;
2900  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2901  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2902  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2903  for(Int j = 0; j < 32; j++)
2904  {
2905    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2906  }
2907  READ_FLAG(uiCode, "general_progressive_source_flag");
2908  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2909
2910  READ_FLAG(uiCode, "general_interlaced_source_flag");
2911  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2912 
2913  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2914  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2915 
2916  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2917  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2918 
2919  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2920  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2921  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2922}
2923
2924Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2925{
2926  ruiBit = false;
2927  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2928  if(iBitsLeft <= 8)
2929  {
2930    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2931    if (uiPeekValue == (1<<(iBitsLeft-1)))
2932    {
2933      ruiBit = true;
2934    }
2935  }
2936}
2937
2938Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2939{
2940  assert(0);
2941}
2942
2943Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2944{
2945  assert(0);
2946}
2947
2948Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2949{
2950  assert(0);
2951}
2952
2953Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2954{
2955  assert(0);
2956}
2957
2958Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2959{
2960  assert(0);
2961}
2962
2963Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2964{
2965  assert(0);
2966}
2967
2968/** Parse I_PCM information.
2969* \param pcCU pointer to CU
2970* \param uiAbsPartIdx CU index
2971* \param uiDepth CU depth
2972* \returns Void
2973*
2974* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2975*/
2976Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2977{
2978  assert(0);
2979}
2980
2981Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2982{ 
2983  assert(0);
2984}
2985
2986Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2987{
2988  assert(0);
2989}
2990
2991Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2992{
2993  assert(0);
2994}
2995
2996Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2997{
2998  assert(0);
2999}
3000
3001Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
3002{
3003  assert(0);
3004}
3005
3006Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3007{
3008  Int qp;
3009  Int  iDQp;
3010
3011  xReadSvlc( iDQp );
3012
3013  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
3014  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
3015
3016  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
3017  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
3018
3019  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
3020}
3021
3022Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
3023{
3024  assert(0);
3025}
3026
3027Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
3028{
3029  assert(0);
3030}
3031
3032Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
3033{
3034  assert(0);
3035}
3036
3037Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
3038{
3039  assert(0);
3040}
3041
3042Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
3043{
3044  assert(0);
3045}
3046
3047Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
3048{
3049  assert(0);
3050}
3051
3052Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
3053{
3054  assert(0);
3055}
3056
3057#if H_3D_ARP
3058Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3059{
3060  assert(0);
3061}
3062#endif
3063#if H_3D_IC
3064Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3065{
3066  assert(0);
3067}
3068#endif
3069#if H_3D_INTER_SDC
3070#if QC_SDC_UNIFY_G0130
3071Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3072{ 
3073  assert(0);
3074}
3075
3076Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3077{
3078  assert(0);
3079}
3080#else
3081Void TDecCavlc::parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3082{
3083  assert(0);
3084}
3085
3086Void TDecCavlc::parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
3087{
3088  assert(0);
3089}
3090#endif
3091#endif
3092#if H_3D_DBBP
3093  Void TDecCavlc::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3094  {
3095    assert(0);
3096  }
3097#endif
3098// ====================================================================================================================
3099// Protected member functions
3100// ====================================================================================================================
3101
3102/** parse explicit wp tables
3103* \param TComSlice* pcSlice
3104* \returns Void
3105*/
3106Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3107{
3108  wpScalingParam  *wp;
3109  Bool            bChroma     = true; // color always present in HEVC ?
3110  SliceType       eSliceType  = pcSlice->getSliceType();
3111  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3112  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3113  UInt            uiTotalSignalledWeightFlags = 0;
3114 
3115  Int iDeltaDenom;
3116  // decode delta_luma_log2_weight_denom :
3117  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3118  assert( uiLog2WeightDenomLuma <= 7 );
3119  if( bChroma ) 
3120  {
3121    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3122    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3123    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
3124    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3125  }
3126
3127  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
3128  {
3129    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3130    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3131    {
3132      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3133
3134      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3135      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3136      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3137
3138      UInt  uiCode;
3139      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3140      wp[0].bPresentFlag = ( uiCode == 1 );
3141      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
3142    }
3143    if ( bChroma ) 
3144    {
3145      UInt  uiCode;
3146      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3147      {
3148        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3149        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3150        wp[1].bPresentFlag = ( uiCode == 1 );
3151        wp[2].bPresentFlag = ( uiCode == 1 );
3152        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
3153      }
3154    }
3155    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3156    {
3157      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3158      if ( wp[0].bPresentFlag ) 
3159      {
3160        Int iDeltaWeight;
3161        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3162        assert( iDeltaWeight >= -128 );
3163        assert( iDeltaWeight <=  127 );
3164        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3165        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3166        assert( wp[0].iOffset >= -128 );
3167        assert( wp[0].iOffset <=  127 );
3168      }
3169      else 
3170      {
3171        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3172        wp[0].iOffset = 0;
3173      }
3174      if ( bChroma ) 
3175      {
3176        if ( wp[1].bPresentFlag ) 
3177        {
3178          for ( Int j=1 ; j<3 ; j++ ) 
3179          {
3180            Int iDeltaWeight;
3181            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3182            assert( iDeltaWeight >= -128 );
3183            assert( iDeltaWeight <=  127 );
3184            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3185
3186            Int iDeltaChroma;
3187            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3188            assert( iDeltaChroma >= -512 );
3189            assert( iDeltaChroma <=  511 );
3190            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3191            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3192          }
3193        }
3194        else 
3195        {
3196          for ( Int j=1 ; j<3 ; j++ ) 
3197          {
3198            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3199            wp[j].iOffset = 0;
3200          }
3201        }
3202      }
3203    }
3204
3205    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
3206    {
3207      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3208
3209      wp[0].bPresentFlag = false;
3210      wp[1].bPresentFlag = false;
3211      wp[2].bPresentFlag = false;
3212    }
3213  }
3214  assert(uiTotalSignalledWeightFlags<=24);
3215}
3216
3217/** decode quantization matrix
3218* \param scalingList quantization matrix information
3219*/
3220Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3221{
3222  UInt  code, sizeId, listId;
3223  Bool scalingListPredModeFlag;
3224  //for each size
3225  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3226  {
3227    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3228    {
3229      READ_FLAG( code, "scaling_list_pred_mode_flag");
3230      scalingListPredModeFlag = (code) ? true : false;
3231      if(!scalingListPredModeFlag) //Copy Mode
3232      {
3233        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3234        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3235        if( sizeId > SCALING_LIST_8x8 )
3236        {
3237          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3238        }
3239        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3240
3241      }
3242      else //DPCM Mode
3243      {
3244        xDecodeScalingList(scalingList, sizeId, listId);
3245      }
3246    }
3247  }
3248
3249  return;
3250}
3251/** decode DPCM
3252* \param scalingList  quantization matrix information
3253* \param sizeId size index
3254* \param listId list index
3255*/
3256Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3257{
3258  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3259  Int data;
3260  Int scalingListDcCoefMinus8 = 0;
3261  Int nextCoef = SCALING_LIST_START_VALUE;
3262  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3263  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3264
3265  if( sizeId > SCALING_LIST_8x8 )
3266  {
3267    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3268    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3269    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3270  }
3271
3272  for(i = 0; i < coefNum; i++)
3273  {
3274    READ_SVLC( data, "scaling_list_delta_coef");
3275    nextCoef = (nextCoef + data + 256 ) % 256;
3276    dst[scan[i]] = nextCoef;
3277  }
3278}
3279
3280Bool TDecCavlc::xMoreRbspData()
3281{ 
3282  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3283
3284  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3285  if (bitsLeft > 8)
3286  {
3287    return true;
3288  }
3289
3290  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3291  Int cnt = bitsLeft;
3292
3293  // remove trailing bits equal to zero
3294  while ((cnt>0) && ((lastByte & 1) == 0))
3295  {
3296    lastByte >>= 1;
3297    cnt--;
3298  }
3299  // remove bit equal to one
3300  cnt--;
3301
3302  // we should not have a negative number of bits
3303  assert (cnt>=0);
3304
3305  // we have more data, if cnt is not zero
3306  return (cnt>0);
3307}
3308
3309//! \}
3310
Note: See TracBrowser for help on using the repository browser.