source: 3DVCSoftware/branches/HTM-12.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1075

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

Removed MV-HEVC related macros part 1.

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