source: 3DVCSoftware/branches/HTM-11.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 967

Last change on this file since 967 was 967, checked in by tech, 11 years ago

Cleanup part 1.

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