source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1066

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

Merged 12.0-dev1@1065.

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