source: 3DVCSoftware/branches/HTM-13.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1169

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

Disabled chroma for depth.

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