source: 3DVCSoftware/branches/HTM-9.2-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 768

Last change on this file since 768 was 768, checked in by tech, 11 years ago

Further fixes.

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