source: 3DVCSoftware/branches/HTM-10.2-dev0-Fix/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 942

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

Merged 10.2-dev2-MediaTek@930.

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