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

Last change on this file since 1417 was 749, checked in by zte, 11 years ago

JCT3V-F0131, JCT3V-F0139

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