source: 3DVCSoftware/branches/HTM-9.1-dev0-RWTH/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 753

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