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

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