source: 3DVCSoftware/branches/HTM-10.2-dev3-Qualcomm/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 915

Last change on this file since 915 was 915, checked in by qualcomm, 10 years ago

Integration of H0137

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