source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 758

Last change on this file since 758 was 758, checked in by tech, 10 years ago

Merged HTM-9.1-dev0-MediaTek@757. (3D-HEVC HLS)

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