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

Last change on this file since 748 was 748, checked in by zte, 10 years ago

JCT3V-F0131, JCT3V-F0139

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