Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibDecoder


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

Location:
trunk/source/Lib/TLibDecoder
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/AnnexBread.cpp

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4242#include <vector>
    4343#include "AnnexBread.h"
     44#if RExt__DECODER_DEBUG_BIT_STATISTICS
     45#include "TLibCommon/TComCodingStatistics.h"
     46#endif
    4447
    4548using namespace std;
     
    5659 * be correct at this point.
    5760 */
    58 static void
     61static Void
    5962_byteStreamNALUnit(
    6063  InputByteStream& bs,
     
    7073   * 0x00000001.
    7174   */
     75#if RExt__DECODER_DEBUG_BIT_STATISTICS
     76  TComCodingStatistics::SStat &statBits=TComCodingStatistics::GetStatisticEP(STATS__NAL_UNIT_PACKING);
     77#endif
    7278  while ((bs.eofBeforeNBytes(24/8) || bs.peekBytes(24/8) != 0x000001)
    7379  &&     (bs.eofBeforeNBytes(32/8) || bs.peekBytes(32/8) != 0x00000001))
    7480  {
    7581    uint8_t leading_zero_8bits = bs.readByte();
     82#if RExt__DECODER_DEBUG_BIT_STATISTICS
     83    statBits.bits+=8; statBits.count++;
     84#endif
    7685    assert(leading_zero_8bits == 0);
    7786    stats.m_numLeadingZero8BitsBytes++;
     
    8998  {
    9099    uint8_t zero_byte = bs.readByte();
     100#if RExt__DECODER_DEBUG_BIT_STATISTICS
     101    statBits.bits+=8; statBits.count++;
     102#endif
    91103    assert(zero_byte == 0);
    92104    stats.m_numZeroByteBytes++;
     
    100112  /* NB, (1) guarantees that the next three bytes are 0x00 00 01 */
    101113  uint32_t start_code_prefix_one_3bytes = bs.readBytes(24/8);
     114#if RExt__DECODER_DEBUG_BIT_STATISTICS
     115  statBits.bits+=24; statBits.count+=3;
     116#endif
    102117  assert(start_code_prefix_one_3bytes == 0x000001);
    103118  stats.m_numStartCodePrefixBytes += 3;
     
    117132   */
    118133  /* NB, (unsigned)x > 2 implies n!=0 && n!=1 */
    119   while (bs.eofBeforeNBytes(24/8) || bs.peekBytes(24/8) > 2)
     134#if RExt__DECODER_DEBUG_BIT_STATISTICS
     135  TComCodingStatistics::SStat &bodyStats=TComCodingStatistics::GetStatisticEP(STATS__NAL_UNIT_TOTAL_BODY);
     136#endif
     137  while (bs.eofBeforeNBytes(24/8) || bs.peekBytes(24/8) > 2)
    120138  {
     139#if RExt__DECODER_DEBUG_BIT_STATISTICS
     140    uint8_t thebyte=bs.readByte();bodyStats.bits+=8;bodyStats.count++;
     141    nalUnit.push_back(thebyte);
     142#else
    121143    nalUnit.push_back(bs.readByte());
     144#endif
    122145  }
    123  
     146
    124147  /* 5. When the current position in the byte stream is:
    125148   *  - not at the end of the byte stream (as determined by unspecified means)
     
    141164  {
    142165    uint8_t trailing_zero_8bits = bs.readByte();
     166#if RExt__DECODER_DEBUG_BIT_STATISTICS
     167    statBits.bits+=8; statBits.count++;
     168#endif
    143169    assert(trailing_zero_8bits == 0);
    144170    stats.m_numTrailingZero8BitsBytes++;
  • trunk/source/Lib/TLibDecoder/AnnexBread.h

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3939#pragma once
    4040
     41#ifndef __ANNEXBREAD__
     42#define __ANNEXBREAD__
     43
    4144#include <stdint.h>
    4245#include <istream>
    4346#include <vector>
    4447
    45 #include "../TLibCommon/TypeDef.h"
     48#include "TLibCommon/CommonDef.h"
    4649
    4750//! \ingroup TLibDecoder
     
    7275   * modified externally to this class
    7376   */
    74   void reset()
     77  Void reset()
    7578  {
    7679    m_NumFutureBytes = 0;
     
    8689    assert(n <= 4);
    8790    if (m_NumFutureBytes >= n)
     91    {
    8892      return false;
     93    }
    8994
    9095    n -= m_NumFutureBytes;
     
    150155    uint32_t val = 0;
    151156    for (UInt i = 0; i < n; i++)
     157    {
    152158      val = (val << 8) | readByte();
     159    }
    153160    return val;
    154161  }
     162
     163#if RExt__DECODER_DEBUG_BIT_STATISTICS
     164  UInt GetNumBufferedBytes() const { return m_NumFutureBytes; }
     165#endif
    155166
    156167private:
     
    185196
    186197//! \}
     198
     199#endif
  • trunk/source/Lib/TLibDecoder/NALread.cpp

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3434/**
    3535 \file     NALread.cpp
    36  \brief    reading funtionality for NAL units
     36 \brief    reading functionality for NAL units
    3737 */
    3838
     
    4545#include "TLibCommon/NAL.h"
    4646#include "TLibCommon/TComBitStream.h"
     47#if RExt__DECODER_DEBUG_BIT_STATISTICS
     48#include "TLibCommon/TComCodingStatistics.h"
     49#endif
     50#if ENC_DEC_TRACE && DEC_NUH_TRACE
     51#include "TLibCommon/TComRom.h"
     52#endif
    4753
    4854using namespace std;
     
    5056//! \ingroup TLibDecoder
    5157//! \{
    52 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
     58static Void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
    5359{
    5460  UInt zeroCount = 0;
     
    6672      it_read++;
    6773      zeroCount = 0;
     74#if RExt__DECODER_DEBUG_BIT_STATISTICS
     75      TComCodingStatistics::IncrementStatisticEP(STATS__EMULATION_PREVENTION_3_BYTES, 8, 0);
     76#endif
    6877      if (it_read == nalUnitBuf.end())
    6978      {
     
    7685  }
    7786  assert(zeroCount == 0);
    78  
     87
    7988  if (isVclNalUnit)
    8089  {
    8190    // Remove cabac_zero_word from payload if present
    8291    Int n = 0;
    83    
     92
    8493    while (it_write[-1] == 0x00)
    8594    {
     
    8796      n++;
    8897    }
    89    
     98
    9099    if (n > 0)
    91100    {
    92       printf("\nDetected %d instances of cabac_zero_word", n/2);     
     101      printf("\nDetected %d instances of cabac_zero_word\n", n/2);
    93102    }
    94103  }
     
    97106}
    98107
     108#if ENC_DEC_TRACE && DEC_NUH_TRACE
     109void xTraceNalUnitHeader(InputNALUnit& nalu)
     110{
     111  fprintf( g_hTrace, "*********** NAL UNIT (%s) ***********\n", nalUnitTypeToString(nalu.m_nalUnitType) );
     112
     113  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     114  fprintf( g_hTrace, "%-50s u(%d)  : %u\n", "forbidden_zero_bit", 1, 0 );
     115
     116  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     117  fprintf( g_hTrace, "%-50s u(%d)  : %u\n", "nal_unit_type", 6, nalu.m_nalUnitType );
     118
     119  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     120  fprintf( g_hTrace, "%-50s u(%d)  : %u\n", "nuh_layer_id", 6, nalu.m_nuhLayerId );
     121
     122  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     123  fprintf( g_hTrace, "%-50s u(%d)  : %u\n", "nuh_temporal_id_plus1", 3, nalu.m_temporalId + 1 );
     124
     125  fflush ( g_hTrace );
     126}
     127#endif
     128
    99129Void readNalUnitHeader(InputNALUnit& nalu)
    100130{
    101   TComInputBitstream& bs = *nalu.m_Bitstream;
     131  TComInputBitstream& bs = nalu.getBitstream();
    102132
    103133  Bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
    104134  assert(forbidden_zero_bit == 0);
    105135  nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
    106 #if H_MV
    107   nalu.m_layerId = bs.read(6);                 // layerId
     136#if NH_MV
     137  nalu.m_nuhLayerId = bs.read(6);                 // layerId
    108138#else
    109   nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
    110   assert(nalu.m_reservedZero6Bits == 0);
     139  nalu.m_nuhLayerId = bs.read(6);                 // nuh_layer_id
    111140#endif
    112141  nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
    113 
    114   if ( nalu.m_temporalId )
     142#if RExt__DECODER_DEBUG_BIT_STATISTICS
     143  TComCodingStatistics::IncrementStatisticEP(STATS__NAL_UNIT_HEADER_BITS, 1+6+6+3, 0);
     144#endif
     145
     146#if ENC_DEC_TRACE && DEC_NUH_TRACE
     147  xTraceNalUnitHeader(nalu);
     148#endif
     149
     150  // only check these rules for base layer
     151  if (nalu.m_nuhLayerId == 0)
    115152  {
    116     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
    117          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
    118          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
    119          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
    120          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
    121          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
    122          && nalu.m_nalUnitType != NAL_UNIT_VPS
    123          && nalu.m_nalUnitType != NAL_UNIT_SPS
    124          && nalu.m_nalUnitType != NAL_UNIT_EOS
    125          && nalu.m_nalUnitType != NAL_UNIT_EOB );
    126   }
    127   else
    128   {
    129 #if H_MV
    130 
     153    if ( nalu.m_temporalId )
     154    {
     155      assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
     156           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
     157           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
     158           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
     159           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
     160           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
     161           && nalu.m_nalUnitType != NAL_UNIT_VPS
     162           && nalu.m_nalUnitType != NAL_UNIT_SPS
     163           && nalu.m_nalUnitType != NAL_UNIT_EOS
     164           && nalu.m_nalUnitType != NAL_UNIT_EOB );
     165    }
     166    else
     167    {
     168#if NH_MV
    131169    // If nal_unit_type is in the range of BLA_W_LP to RSV_IRAP_VCL23, inclusive, i.e. the coded
    132170    // slice segment belongs to an IRAP picture, TemporalId shall be equal to 0.
     
    139177         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N    );
    140178
    141     assert( nalu.m_layerId > 0
     179    assert( nalu.m_nuhLayerId > 0
    142180      || ( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
    143181        && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N ) );
    144182#else
    145     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
    146          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    147          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
    148          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
    149 #endif
     183      assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
     184           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
     185           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
     186           && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
     187#endif
     188    }
    150189  }
    151190}
     
    154193 * a bitstream
    155194 */
    156 void read(InputNALUnit& nalu, vector<uint8_t>& nalUnitBuf)
    157 {
    158   /* perform anti-emulation prevention */
    159   TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
    160   convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0);
    161  
    162   nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
    163   nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
    164   delete pcBitstream;
     195Void read(InputNALUnit& nalu)
     196{
     197  TComInputBitstream &bitstream = nalu.getBitstream();
     198  vector<uint8_t>& nalUnitBuf=bitstream.getFifo();
     199  // perform anti-emulation prevention
     200  convertPayloadToRBSP(nalUnitBuf, &bitstream, (nalUnitBuf[0] & 64) == 0);
     201  bitstream.resetToStart();
    165202  readNalUnitHeader(nalu);
    166203}
  • trunk/source/Lib/TLibDecoder/NALread.h

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3434/**
    3535 \file     NALread.h
    36  \brief    reading funtionality for NAL units
     36 \brief    reading functionality for NAL units
    3737 */
    3838
    3939#pragma once
    4040
    41 #include "../TLibCommon/TypeDef.h"
    42 #include "../TLibCommon/TComBitStream.h"
    43 #include "../TLibCommon/NAL.h"
    44 
     41#ifndef __NALREAD__
     42#define __NALREAD__
     43#include "TLibCommon/CommonDef.h"
     44#include "TLibCommon/TComBitStream.h"
     45#include "TLibCommon/NAL.h"
    4546//! \ingroup TLibDecoder
    4647//! \{
     
    5051 * bitstream object.
    5152 */
    52 struct InputNALUnit : public NALUnit
     53class InputNALUnit : public NALUnit
    5354{
    54   InputNALUnit() : m_Bitstream(0) {};
    55   ~InputNALUnit() { delete m_Bitstream; }
     55  private:
     56    TComInputBitstream m_Bitstream;
    5657
    57   TComInputBitstream* m_Bitstream;
     58  public:
     59    InputNALUnit(const InputNALUnit &src) : NALUnit(src), m_Bitstream(src.m_Bitstream) {};
     60    InputNALUnit() : m_Bitstream() {};
     61    virtual ~InputNALUnit() { }
     62    const TComInputBitstream &getBitstream() const { return m_Bitstream; }
     63          TComInputBitstream &getBitstream()       { return m_Bitstream; }
    5864};
    5965
    60 void read(InputNALUnit& nalu, std::vector<uint8_t>& nalUnitBuf);
     66Void read(InputNALUnit& nalu);
     67Void readNalUnitHeader(InputNALUnit& nalu);
    6168
    6269//! \}
     70
     71#endif
  • trunk/source/Lib/TLibDecoder/SEIread.cpp

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
    34 /** 
     34/**
    3535 \file     SEIread.cpp
    36  \brief    reading functionality for SEI messages
     36 \brief    reading funtionality for SEI messages
    3737 */
    3838
     
    4343#include "SyntaxElementParser.h"
    4444#include "SEIread.h"
     45#include "TLibCommon/TComPicYuv.h"
     46#include <iomanip>
     47
    4548
    4649//! \ingroup TLibDecoder
    4750//! \{
    4851
     52
    4953#if ENC_DEC_TRACE
    5054Void  xTraceSEIHeader()
     
    5559Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
    5660{
    57   switch (payloadType)
    58   {
    59   case SEI::DECODED_PICTURE_HASH:
    60     fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n");
    61     break;
    62   case SEI::USER_DATA_UNREGISTERED:
    63     fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n");
    64     break;
    65   case SEI::ACTIVE_PARAMETER_SETS:
    66     fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n");
    67     break;
    68   case SEI::BUFFERING_PERIOD:
    69     fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n");
    70     break;
    71   case SEI::PICTURE_TIMING:
    72     fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n");
    73     break;
    74   case SEI::RECOVERY_POINT:
    75     fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n");
    76     break;
    77   case SEI::FRAME_PACKING:
    78     fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n");
    79     break;
    80   case SEI::DISPLAY_ORIENTATION:
    81     fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n");
    82     break;
    83   case SEI::TEMPORAL_LEVEL0_INDEX:
    84     fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n");
    85     break;
    86   case SEI::REGION_REFRESH_INFO:
    87     fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n");
    88     break;
    89   case SEI::DECODING_UNIT_INFO:
    90     fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
    91     break;
    92   case SEI::TONE_MAPPING_INFO:
    93     fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
    94     break;
    95   case SEI::SOP_DESCRIPTION:
    96     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
    97     break;
    98   case SEI::SCALABLE_NESTING:
    99     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    100     break;
    101 #if H_MV
    102   case SEI::SUB_BITSTREAM_PROPERTY:
    103     fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
    104     break;
     61  fprintf( g_hTrace, "=========== %s SEI message ===========\n", SEI::getSEIMessageString(payloadType));
     62}
    10563#endif
    106   default:
    107     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
    108     break;
    109   }
    110 }
    111 #endif
     64
     65Void SEIReader::sei_read_code(std::ostream *pOS, UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
     66{
     67  READ_CODE(uiLength, ruiCode, pSymbolName);
     68  if (pOS)
     69  {
     70    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     71  }
     72}
     73
     74Void SEIReader::sei_read_uvlc(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
     75{
     76  READ_UVLC(ruiCode, pSymbolName);
     77  if (pOS)
     78  {
     79    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     80  }
     81}
     82
     83Void SEIReader::sei_read_svlc(std::ostream *pOS, Int& ruiCode, const Char *pSymbolName)
     84{
     85  READ_SVLC(ruiCode, pSymbolName);
     86  if (pOS)
     87  {
     88    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     89  }
     90}
     91
     92Void SEIReader::sei_read_flag(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
     93{
     94  READ_FLAG(ruiCode, pSymbolName);
     95  if (pOS)
     96  {
     97    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << (ruiCode?1:0) << "\n";
     98  }
     99}
     100
     101static inline Void output_sei_message_header(SEI &sei, std::ostream *pDecodedMessageOutputStream, UInt payloadSize)
     102{
     103  if (pDecodedMessageOutputStream)
     104  {
     105    std::string seiMessageHdr(SEI::getSEIMessageString(sei.payloadType())); seiMessageHdr+=" SEI message";
     106    (*pDecodedMessageOutputStream) << std::setfill('-') << std::setw(seiMessageHdr.size()) << "-" << std::setfill(' ') << "\n" << seiMessageHdr << " (" << payloadSize << " bytes)"<< "\n";
     107  }
     108}
     109
     110#undef READ_CODE
     111#undef READ_SVLC
     112#undef READ_UVLC
     113#undef READ_FLAG
     114
    112115
    113116/**
    114117 * unmarshal a single SEI message from bitstream bs
    115118 */
    116 void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     119Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    117120{
    118121  setBitstream(bs);
     
    121124  do
    122125  {
    123     xReadSEImessage(seis, nalUnitType, sps);
     126    xReadSEImessage(seis, nalUnitType, sps, pDecodedMessageOutputStream);
     127
    124128    /* SEI messages are an integer number of bytes, something has failed
    125129    * in the parsing if bitstream not byte-aligned */
    126130    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
    127   } while (m_pcBitstream->getNumBitsLeft() > 8);
    128 
    129   UInt rbspTrailingBits;
    130   READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
    131   assert(rbspTrailingBits == 0x80);
    132 }
    133 
    134 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     131  }
     132  while (m_pcBitstream->getNumBitsLeft() > 8);
     133
     134  xReadRbspTrailingBits();
     135}
     136
     137Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    135138{
    136139#if ENC_DEC_TRACE
     
    142145  do
    143146  {
    144     READ_CODE (8, val, "payload_type");
     147    sei_read_code(NULL, 8, val, "payload_type");
    145148    payloadType += val;
    146149  } while (val==0xFF);
     
    149152  do
    150153  {
    151     READ_CODE (8, val, "payload_size");
     154    sei_read_code(NULL, 8, val, "payload_size");
    152155    payloadSize += val;
    153156  } while (val==0xFF);
     
    174177    case SEI::USER_DATA_UNREGISTERED:
    175178      sei = new SEIuserDataUnregistered;
    176       xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     179      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
    177180      break;
    178181    case SEI::ACTIVE_PARAMETER_SETS:
    179       sei = new SEIActiveParameterSets; 
    180       xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize);
    181       break; 
     182      sei = new SEIActiveParameterSets;
     183      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize, pDecodedMessageOutputStream);
     184      break;
    182185    case SEI::DECODING_UNIT_INFO:
    183186      if (!sps)
     
    187190      else
    188191      {
    189         sei = new SEIDecodingUnitInfo; 
    190         xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
    191       }
    192       break; 
     192        sei = new SEIDecodingUnitInfo;
     193        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
     194      }
     195      break;
    193196    case SEI::BUFFERING_PERIOD:
    194197      if (!sps)
     
    199202      {
    200203        sei = new SEIBufferingPeriod;
    201         xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
     204        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
    202205      }
    203206      break;
     
    210213      {
    211214        sei = new SEIPictureTiming;
    212         xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
     215        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, pDecodedMessageOutputStream);
    213216      }
    214217      break;
    215218    case SEI::RECOVERY_POINT:
    216219      sei = new SEIRecoveryPoint;
    217       xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
     220      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize, pDecodedMessageOutputStream);
    218221      break;
    219222    case SEI::FRAME_PACKING:
    220223      sei = new SEIFramePacking;
    221       xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
     224      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
     225      break;
     226    case SEI::SEGM_RECT_FRAME_PACKING:
     227      sei = new SEISegmentedRectFramePacking;
     228      xParseSEISegmentedRectFramePacking((SEISegmentedRectFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
    222229      break;
    223230    case SEI::DISPLAY_ORIENTATION:
    224231      sei = new SEIDisplayOrientation;
    225       xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
     232      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize, pDecodedMessageOutputStream);
    226233      break;
    227234    case SEI::TEMPORAL_LEVEL0_INDEX:
    228235      sei = new SEITemporalLevel0Index;
    229       xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
     236      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize, pDecodedMessageOutputStream);
    230237      break;
    231238    case SEI::REGION_REFRESH_INFO:
    232239      sei = new SEIGradualDecodingRefreshInfo;
    233       xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
     240      xParseSEIRegionRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     241      break;
     242    case SEI::NO_DISPLAY:
     243      sei = new SEINoDisplay;
     244      xParseSEINoDisplay((SEINoDisplay&) *sei, payloadSize, pDecodedMessageOutputStream);
    234245      break;
    235246    case SEI::TONE_MAPPING_INFO:
    236247      sei = new SEIToneMappingInfo;
    237       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
     248      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
    238249      break;
    239250    case SEI::SOP_DESCRIPTION:
    240251      sei = new SEISOPDescription;
    241       xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
     252      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize, pDecodedMessageOutputStream);
    242253      break;
    243254    case SEI::SCALABLE_NESTING:
    244255      sei = new SEIScalableNesting;
    245       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
    246       break;
    247 #if H_MV
    248      case SEI::SUB_BITSTREAM_PROPERTY:
    249        sei = new SEISubBitstreamProperty;
    250        xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
    251        break;
     256      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps, pDecodedMessageOutputStream);
     257      break;
     258    case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
     259      sei = new SEITempMotionConstrainedTileSets;
     260      xParseSEITempMotionConstraintsTileSets((SEITempMotionConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
     261      break;
     262    case SEI::TIME_CODE:
     263      sei = new SEITimeCode;
     264      xParseSEITimeCode((SEITimeCode&) *sei, payloadSize, pDecodedMessageOutputStream);
     265      break;
     266    case SEI::CHROMA_SAMPLING_FILTER_HINT:
     267      sei = new SEIChromaSamplingFilterHint;
     268      xParseSEIChromaSamplingFilterHint((SEIChromaSamplingFilterHint&) *sei, payloadSize/*, sps*/, pDecodedMessageOutputStream);
     269      //}
     270      break;
     271    case SEI::KNEE_FUNCTION_INFO:
     272      sei = new SEIKneeFunctionInfo;
     273      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     274      break;
     275    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
     276      sei = new SEIMasteringDisplayColourVolume;
     277      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
     278      break;
     279#if NH_MV
     280    case SEI::SUB_BITSTREAM_PROPERTY:
     281      sei = new SEISubBitstreamProperty;
     282      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, payloadSize, pDecodedMessageOutputStream );
     283      break;
    252284#endif
    253285    default:
     
    255287      {
    256288        UInt seiByte;
    257         READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
     289        sei_read_code (NULL, 8, seiByte, "unknown prefix SEI payload byte");
    258290      }
    259291      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
     292      if (pDecodedMessageOutputStream)
     293      {
     294        (*pDecodedMessageOutputStream) << "Unknown prefix SEI message (payloadType = " << payloadType << ") was found!\n";
     295      }
     296      break;
    260297    }
    261298  }
     
    266303      case SEI::USER_DATA_UNREGISTERED:
    267304        sei = new SEIuserDataUnregistered;
    268         xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     305        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
    269306        break;
    270307      case SEI::DECODED_PICTURE_HASH:
    271308        sei = new SEIDecodedPictureHash;
    272         xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
     309        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize, pDecodedMessageOutputStream);
    273310        break;
    274311      default:
     
    276313        {
    277314          UInt seiByte;
    278           READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
     315          sei_read_code( NULL, 8, seiByte, "unknown suffix SEI payload byte");
    279316        }
    280317        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
    281     }
    282   }
     318        if (pDecodedMessageOutputStream)
     319        {
     320          (*pDecodedMessageOutputStream) << "Unknown suffix SEI message (payloadType = " << payloadType << ") was found!\n";
     321        }
     322        break;
     323    }
     324  }
     325
    283326  if (sei != NULL)
    284327  {
     
    299342    {
    300343      UInt reservedPayloadExtensionData;
    301       READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
     344      sei_read_code ( pDecodedMessageOutputStream, 1, reservedPayloadExtensionData, "reserved_payload_extension_data");
    302345    }
    303346
     
    314357    {
    315358      UInt reservedPayloadExtensionData;
    316       READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
     359      sei_read_flag ( 0, reservedPayloadExtensionData, "reserved_payload_extension_data");
    317360    }
    318361
    319362    UInt dummy;
    320     READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
     363    sei_read_flag( 0, dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
    321364    while (payloadBitsRemaining)
    322365    {
    323       READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
     366      sei_read_flag( 0, dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
    324367    }
    325368  }
    326369
    327370  /* restore primary bitstream for sei_message */
    328   getBitstream()->deleteFifo();
    329371  delete getBitstream();
    330372  setBitstream(bs);
     
    335377 * of payloasSize bytes into sei.
    336378 */
    337 Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
    338 {
    339   assert(payloadSize >= 16);
     379
     380Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     381{
     382  assert(payloadSize >= ISO_IEC_11578_LEN);
    340383  UInt val;
    341 
    342   for (UInt i = 0; i < 16; i++)
    343   {
    344     READ_CODE (8, val, "uuid_iso_iec_11578");
     384  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     385
     386  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
     387  {
     388    sei_read_code( pDecodedMessageOutputStream, 8, val, "uuid_iso_iec_11578");
    345389    sei.uuid_iso_iec_11578[i] = val;
    346390  }
    347391
    348   sei.userDataLength = payloadSize - 16;
     392  sei.userDataLength = payloadSize - ISO_IEC_11578_LEN;
    349393  if (!sei.userDataLength)
    350394  {
     
    356400  for (UInt i = 0; i < sei.userDataLength; i++)
    357401  {
    358     READ_CODE (8, val, "user_data" );
     402    sei_read_code( NULL, 8, val, "user_data_payload_byte" );
    359403    sei.userData[i] = val;
     404  }
     405  if (pDecodedMessageOutputStream)
     406  {
     407    (*pDecodedMessageOutputStream) << "  User data payload size: " << sei.userDataLength << "\n";
    360408  }
    361409}
     
    365413 * of payloadSize bytes into sei.
    366414 */
    367 Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
    368 {
     415Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     416{
     417  UInt bytesRead = 0;
     418  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     419
    369420  UInt val;
    370   READ_CODE (8, val, "hash_type");
    371   sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
    372   for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
    373   {
    374     if(SEIDecodedPictureHash::MD5 == sei.method)
    375     {
    376       for (UInt i = 0; i < 16; i++)
    377       {
    378         READ_CODE(8, val, "picture_md5");
    379         sei.digest[yuvIdx][i] = val;
    380       }
    381     }
    382     else if(SEIDecodedPictureHash::CRC == sei.method)
    383     {
    384       READ_CODE(16, val, "picture_crc");
    385       sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
    386       sei.digest[yuvIdx][1] = val & 0xFF;
    387     }
    388     else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
    389     {
    390       READ_CODE(32, val, "picture_checksum");
    391       sei.digest[yuvIdx][0] = (val>>24) & 0xff;
    392       sei.digest[yuvIdx][1] = (val>>16) & 0xff;
    393       sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
    394       sei.digest[yuvIdx][3] =  val      & 0xff;
    395     }
    396   }
    397 }
    398 Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
     421  sei_read_code( pDecodedMessageOutputStream, 8, val, "hash_type");
     422  sei.method = static_cast<SEIDecodedPictureHash::Method>(val); bytesRead++;
     423
     424  const Char *traceString="\0";
     425  switch (sei.method)
     426  {
     427    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
     428    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
     429    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
     430    default: assert(false); break;
     431  }
     432
     433  if (pDecodedMessageOutputStream)
     434  {
     435    (*pDecodedMessageOutputStream) << "  " << std::setw(55) << traceString << ": " << std::hex << std::setfill('0');
     436  }
     437
     438  sei.m_pictureHash.hash.clear();
     439  for(;bytesRead < payloadSize; bytesRead++)
     440  {
     441    sei_read_code( NULL, 8, val, traceString);
     442    sei.m_pictureHash.hash.push_back((UChar)val);
     443    if (pDecodedMessageOutputStream)
     444    {
     445      (*pDecodedMessageOutputStream) << std::setw(2) << val;
     446    }
     447  }
     448
     449  if (pDecodedMessageOutputStream)
     450  {
     451    (*pDecodedMessageOutputStream) << std::dec << std::setfill(' ') << "\n";
     452  }
     453}
     454
     455Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    399456{
    400457  UInt val;
    401   READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
    402   READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
    403   READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
    404   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
     458  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     459
     460  sei_read_code( pDecodedMessageOutputStream, 4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
     461  sei_read_flag( pDecodedMessageOutputStream,    val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag     = (val != 0);
     462  sei_read_flag( pDecodedMessageOutputStream,    val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = (val != 0);
     463  sei_read_uvlc( pDecodedMessageOutputStream,    val, "num_sps_ids_minus1");              sei.numSpsIdsMinus1 = val;
    405464
    406465  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
    407466  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
    408467  {
    409     READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val;
    410   }
    411 
    412   xParseByteAlign();
    413 }
    414 
    415 Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
     468    sei_read_uvlc( pDecodedMessageOutputStream, val, "active_seq_parameter_set_id[i]");    sei.activeSeqParameterSetId[i] = val;
     469  }
     470}
     471
     472Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    416473{
    417474  UInt val;
    418   READ_UVLC(val, "decoding_unit_idx");
     475  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     476  sei_read_uvlc( pDecodedMessageOutputStream, val, "decoding_unit_idx");
    419477  sei.m_decodingUnitIdx = val;
    420478
    421   TComVUI *vui = sps->getVuiParameters();
     479  const TComVUI *vui = sps->getVuiParameters();
    422480  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
    423481  {
    424     READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
     482    sei_read_code( pDecodedMessageOutputStream, ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
    425483    sei.m_duSptCpbRemovalDelay = val;
    426484  }
     
    429487    sei.m_duSptCpbRemovalDelay = 0;
    430488  }
    431   READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
     489  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
    432490  if(sei.m_dpbOutputDuDelayPresentFlag)
    433491  {
    434     READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
     492    sei_read_code( pDecodedMessageOutputStream, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
    435493    sei.m_picSptDpbOutputDuDelay = val;
    436494  }
    437   xParseByteAlign();
    438 }
    439 
    440 Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
     495}
     496
     497Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    441498{
    442499  Int i, nalOrVcl;
    443500  UInt code;
    444501
    445   TComVUI *pVUI = sps->getVuiParameters();
    446   TComHRD *pHRD = pVUI->getHrdParameters();
    447 
    448   READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
     502  const TComVUI *pVUI = sps->getVuiParameters();
     503  const TComHRD *pHRD = pVUI->getHrdParameters();
     504
     505  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     506
     507  sei_read_uvlc( pDecodedMessageOutputStream, code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
    449508  if( !pHRD->getSubPicCpbParamsPresentFlag() )
    450509  {
    451     READ_FLAG( code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
     510    sei_read_flag( pDecodedMessageOutputStream, code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
    452511  }
    453512  if( sei.m_rapCpbParamsPresentFlag )
    454513  {
    455     READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
    456     READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
    457   }
     514    sei_read_code( pDecodedMessageOutputStream, pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
     515    sei_read_code( pDecodedMessageOutputStream, pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
     516  }
     517
    458518  //read splicing flag and cpb_removal_delay_delta
    459   READ_FLAG( code, "concatenation_flag");
     519  sei_read_flag( pDecodedMessageOutputStream, code, "concatenation_flag");
    460520  sei.m_concatenationFlag = code;
    461   READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
     521  sei_read_code( pDecodedMessageOutputStream, ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
    462522  sei.m_auCpbRemovalDelayDelta = code + 1;
     523
    463524  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    464525  {
     
    468529      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
    469530      {
    470         READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
     531        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_delay":"nal_initial_cpb_removal_delay" );
    471532        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
    472         READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
     533        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_offset":"vcl_initial_cpb_removal_offset" );
    473534        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
    474535        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
    475536        {
    476           READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
     537          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_delay":"vcl_initial_alt_cpb_removal_delay" );
    477538          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
    478           READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
     539          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_offset":"vcl_initial_alt_cpb_removal_offset" );
    479540          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
    480541        }
     
    482543    }
    483544  }
    484   xParseByteAlign();
    485 }
    486 Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
     545}
     546
     547Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    487548{
    488549  Int i;
    489550  UInt code;
    490551
    491   TComVUI *vui = sps->getVuiParameters();
    492   TComHRD *hrd = vui->getHrdParameters();
     552  const TComVUI *vui = sps->getVuiParameters();
     553  const TComHRD *hrd = vui->getHrdParameters();
     554  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
    493555
    494556  if( vui->getFrameFieldInfoPresentFlag() )
    495557  {
    496     READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
    497     READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
    498     READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
     558    sei_read_code( pDecodedMessageOutputStream, 4, code, "pic_struct" );             sei.m_picStruct            = code;
     559    sei_read_code( pDecodedMessageOutputStream, 2, code, "source_scan_type" );       sei.m_sourceScanType      = code;
     560    sei_read_flag( pDecodedMessageOutputStream,    code, "duplicate_flag" );         sei.m_duplicateFlag        = (code == 1);
    499561  }
    500562
    501563  if( hrd->getCpbDpbDelaysPresentFlag())
    502564  {
    503     READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
     565    sei_read_code( pDecodedMessageOutputStream, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
    504566    sei.m_auCpbRemovalDelay = code + 1;
    505     READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
     567    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
    506568    sei.m_picDpbOutputDelay = code;
    507569
    508570    if(hrd->getSubPicCpbParamsPresentFlag())
    509571    {
    510       READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
     572      sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
    511573      sei.m_picDpbOutputDuDelay = code;
    512574    }
     575
    513576    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
    514577    {
    515       READ_UVLC( code, "num_decoding_units_minus1");
     578      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_decoding_units_minus1");
    516579      sei.m_numDecodingUnitsMinus1 = code;
    517       READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
     580      sei_read_flag( pDecodedMessageOutputStream, code, "du_common_cpb_removal_delay_flag" );
    518581      sei.m_duCommonCpbRemovalDelayFlag = code;
    519582      if( sei.m_duCommonCpbRemovalDelayFlag )
    520583      {
    521         READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
     584        sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_increment_minus1" );
    522585        sei.m_duCommonCpbRemovalDelayMinus1 = code;
    523586      }
    524       if( sei.m_numNalusInDuMinus1 != NULL )
    525       {
    526         delete sei.m_numNalusInDuMinus1;
    527       }
    528       sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
    529       if( sei.m_duCpbRemovalDelayMinus1  != NULL )
    530       {
    531         delete sei.m_duCpbRemovalDelayMinus1;
    532       }
    533       sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
     587      sei.m_numNalusInDuMinus1.resize(sei.m_numDecodingUnitsMinus1 + 1 );
     588      sei.m_duCpbRemovalDelayMinus1.resize( sei.m_numDecodingUnitsMinus1 + 1 );
    534589
    535590      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
    536591      {
    537         READ_UVLC( code, "num_nalus_in_du_minus1");
     592        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_nalus_in_du_minus1[i]");
    538593        sei.m_numNalusInDuMinus1[ i ] = code;
    539594        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
    540595        {
    541           READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
     596          sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1[i]" );
    542597          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
    543598        }
     
    545600    }
    546601  }
    547   xParseByteAlign();
    548 }
    549 Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
     602}
     603
     604Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    550605{
    551606  Int  iCode;
    552607  UInt uiCode;
    553   READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
    554   READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
    555   READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
    556   xParseByteAlign();
    557 }
    558 Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
     608  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     609
     610  sei_read_svlc( pDecodedMessageOutputStream, iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
     611  sei_read_flag( pDecodedMessageOutputStream, uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
     612  sei_read_flag( pDecodedMessageOutputStream, uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
     613}
     614
     615Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    559616{
    560617  UInt val;
    561   READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
    562   READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
     618  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     619
     620  sei_read_uvlc( pDecodedMessageOutputStream, val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
     621  sei_read_flag( pDecodedMessageOutputStream, val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
    563622
    564623  if ( !sei.m_arrangementCancelFlag )
    565624  {
    566     READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
     625    sei_read_code( pDecodedMessageOutputStream, 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
    567626    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
    568     READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
    569 
    570     READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
    571     READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
    572     READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
    573     READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
    574     READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
    575     READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
    576     READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
     627
     628    sei_read_flag( pDecodedMessageOutputStream, val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
     629
     630    sei_read_code( pDecodedMessageOutputStream, 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
     631    sei_read_flag( pDecodedMessageOutputStream, val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
     632    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
     633    sei_read_flag( pDecodedMessageOutputStream, val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
     634    sei_read_flag( pDecodedMessageOutputStream, val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
     635    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
     636    sei_read_flag( pDecodedMessageOutputStream, val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
    577637
    578638    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
    579639    {
    580       READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
    581       READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
    582       READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
    583       READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
    584     }
    585 
    586     READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
    587     READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
    588   }
    589   READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
    590 
    591   xParseByteAlign();
    592 }
    593 
    594 Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
     640      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
     641      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
     642      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
     643      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
     644    }
     645
     646    sei_read_code( pDecodedMessageOutputStream, 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
     647    sei_read_flag( pDecodedMessageOutputStream, val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = (val != 0);
     648  }
     649  sei_read_flag( pDecodedMessageOutputStream, val, "upsampled_aspect_ratio_flag" );                  sei.m_upsampledAspectRatio = val;
     650}
     651
     652Void SEIReader::xParseSEISegmentedRectFramePacking(SEISegmentedRectFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    595653{
    596654  UInt val;
    597   READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
    598   if( !sei.cancelFlag )
    599   {
    600     READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
    601     READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
    602     READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
    603     READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
    604   }
    605   xParseByteAlign();
    606 }
    607 
    608 Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
     655  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     656  sei_read_flag( pDecodedMessageOutputStream, val,       "segmented_rect_frame_packing_arrangement_cancel_flag" );       sei.m_arrangementCancelFlag            = val;
     657  if( !sei.m_arrangementCancelFlag )
     658  {
     659    sei_read_code( pDecodedMessageOutputStream, 2, val, "segmented_rect_content_interpretation_type" );                sei.m_contentInterpretationType = val;
     660    sei_read_flag( pDecodedMessageOutputStream, val,     "segmented_rect_frame_packing_arrangement_persistence" );                              sei.m_arrangementPersistenceFlag               = val;
     661  }
     662}
     663
     664Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    609665{
    610666  UInt val;
    611   READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
    612   READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
    613   xParseByteAlign();
    614 }
    615 
    616 Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
     667  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     668  sei_read_flag( pDecodedMessageOutputStream, val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
     669  if( !sei.cancelFlag )
     670  {
     671    sei_read_flag( pDecodedMessageOutputStream, val,     "hor_flip" );                              sei.horFlip               = val;
     672    sei_read_flag( pDecodedMessageOutputStream, val,     "ver_flip" );                              sei.verFlip               = val;
     673    sei_read_code( pDecodedMessageOutputStream, 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
     674    sei_read_flag( pDecodedMessageOutputStream, val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
     675  }
     676}
     677
     678Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    617679{
    618680  UInt val;
    619   READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
    620   xParseByteAlign();
    621 }
    622 
    623 Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
     681  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     682  sei_read_code( pDecodedMessageOutputStream, 8, val, "temporal_sub_layer_zero_idx" );  sei.tl0Idx = val;
     683  sei_read_code( pDecodedMessageOutputStream, 8, val, "irap_pic_id" );  sei.rapIdx = val;
     684}
     685
     686Void SEIReader::xParseSEIRegionRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     687{
     688  UInt val;
     689  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     690  sei_read_flag( pDecodedMessageOutputStream, val, "refreshed_region_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
     691}
     692
     693Void SEIReader::xParseSEINoDisplay(SEINoDisplay& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     694{
     695  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     696  sei.m_noDisplay = true;
     697}
     698
     699Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    624700{
    625701  Int i;
    626702  UInt val;
    627   READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
    628   READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
     703  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     704  sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_id" );                         sei.m_toneMapId = val;
     705  sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
    629706
    630707  if ( !sei.m_toneMapCancelFlag )
    631708  {
    632     READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
    633     READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
    634     READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
    635     READ_UVLC( val, "model_id" );                          sei.m_modelId = val;
     709    sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
     710    sei_read_code( pDecodedMessageOutputStream, 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
     711    sei_read_code( pDecodedMessageOutputStream, 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
     712    sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_model_id" );                 sei.m_modelId = val;
    636713    switch(sei.m_modelId)
    637714    {
    638715    case 0:
    639716      {
    640         READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
    641         READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
     717        sei_read_code( pDecodedMessageOutputStream, 32, val, "min_value" );                 sei.m_minValue = val;
     718        sei_read_code( pDecodedMessageOutputStream, 32, val, "max_value" );                 sei.m_maxValue = val;
    642719        break;
    643720      }
    644721    case 1:
    645722      {
    646         READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
    647         READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
     723        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
     724        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
    648725        break;
    649726      }
     
    654731        for(i = 0; i < num; i++)
    655732        {
    656           READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
     733          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval[i]" );
    657734          sei.m_startOfCodedInterval[i] = val;
    658735        }
     
    662739    case 3:
    663740      {
    664         READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
     741        sei_read_code( pDecodedMessageOutputStream, 16, val,  "num_pivots" );                       sei.m_numPivots = val;
    665742        sei.m_codedPivotValue.resize(sei.m_numPivots);
    666743        sei.m_targetPivotValue.resize(sei.m_numPivots);
    667744        for(i = 0; i < sei.m_numPivots; i++ )
    668745        {
    669           READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
     746          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value[i]" );
    670747          sei.m_codedPivotValue[i] = val;
    671           READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
     748          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value[i]" );
    672749          sei.m_targetPivotValue[i] = val;
    673750        }
     
    676753    case 4:
    677754      {
    678         READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
     755        sei_read_code( pDecodedMessageOutputStream, 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
    679756        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
    680757        {
    681           READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
    682         }
    683         READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
     758          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
     759        }
     760        sei_read_code( pDecodedMessageOutputStream, 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
    684761        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
    685762        {
    686           READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
    687         }
    688         READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
    689         READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
    690         READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
    691         READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
    692         READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
    693         READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
    694         READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
    695         READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
     763          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
     764        }
     765        sei_read_flag( pDecodedMessageOutputStream, val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
     766        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
     767        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
     768        sei_read_code( pDecodedMessageOutputStream, 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
     769        sei_read_code( pDecodedMessageOutputStream, 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
     770        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_black_level_code_value" );          sei.m_nominalBlackLevelLumaCodeValue = val;
     771        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_white_level_code_value" );          sei.m_nominalWhiteLevelLumaCodeValue= val;
     772        sei_read_code( pDecodedMessageOutputStream, 16, val, "extended_white_level_code_value" );         sei.m_extendedWhiteLevelLumaCodeValue = val;
    696773        break;
    697774      }
     
    702779      }
    703780    }//switch model id
    704   }// if(!sei.m_toneMapCancelFlag)
    705 
    706   xParseByteAlign();
    707 }
    708 
    709 Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
     781  }// if(!sei.m_toneMapCancelFlag)
     782}
     783
     784Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    710785{
    711786  Int iCode;
    712787  UInt uiCode;
    713 
    714   READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
    715   READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
     788  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     789
     790  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
     791  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
    716792  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
    717793  {
    718     READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
    719     READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
     794    sei_read_code( pDecodedMessageOutputStream, 6, uiCode,                     "sop_vcl_nut[i]" );  sei.m_sopDescVclNaluType[i] = uiCode;
     795    sei_read_code( pDecodedMessageOutputStream, 3, sei.m_sopDescTemporalId[i], "sop_temporal_id[i]"   );  sei.m_sopDescTemporalId[i] = uiCode;
    720796    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
    721797    {
    722       READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
     798      sei_read_uvlc( pDecodedMessageOutputStream, sei.m_sopDescStRpsIdx[i],    "sop_short_term_rps_idx[i]"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
    723799    }
    724800    if (i > 0)
    725801    {
    726       READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
    727     }
    728   }
    729 
    730   xParseByteAlign();
    731 }
    732 
    733 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
     802      sei_read_svlc( pDecodedMessageOutputStream, iCode,                       "sop_poc_delta[i]"     ); sei.m_sopDescPocDelta[i] = iCode;
     803    }
     804  }
     805}
     806
     807Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    734808{
    735809  UInt uiCode;
    736810  SEIMessages seis;
    737 
    738   READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
    739   READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
     811  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     812
     813  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
     814  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
    740815  if (sei.m_nestingOpFlag)
    741816  {
    742     READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
    743     READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
     817    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
     818    sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
    744819    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
    745820    {
    746       READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
    747       READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
     821      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_max_temporal_id_plus1[i]"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
     822      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_op_idx[i]"                  ); sei.m_nestingOpIdx[i] = uiCode;
    748823    }
    749824  }
    750825  else
    751826  {
    752     READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
     827    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
    753828    if (!sei.m_allLayersFlag)
    754829    {
    755       READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
    756       READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
     830      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
     831      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
    757832      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
    758833      {
    759         READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
     834        sei_read_code( pDecodedMessageOutputStream, 6,           uiCode,     "nesting_layer_id[i]"      ); sei.m_nestingLayerId[i]   = uiCode;
    760835      }
    761836    }
     
    766841  {
    767842    UInt code;
    768     READ_FLAG( code, "nesting_zero_bit" );
    769   }
    770 
    771   sei.m_callerOwnsSEIs = false;
     843    sei_read_flag( pDecodedMessageOutputStream, code, "nesting_zero_bit" );
     844  }
    772845
    773846  // read nested SEI messages
    774   do {
    775     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
     847  do
     848  {
     849    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
    776850  } while (m_pcBitstream->getNumBitsLeft() > 8);
    777851
    778 }
    779 #if H_MV
    780 Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
    781 {
    782   UInt uiCode;
    783   READ_CODE( 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
    784   READ_UVLC(    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
     852  if (pDecodedMessageOutputStream)
     853  {
     854    (*pDecodedMessageOutputStream) << "End of scalable nesting SEI message\n";
     855  }
     856}
     857
     858#if NH_MV
     859Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
     860{
     861  UInt code;
     862  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     863  sei_read_code( pDecodedMessageOutputStream, 4, code, "active_vps_id" );                      sei.m_activeVpsId = code;
     864  sei_read_uvlc( pDecodedMessageOutputStream, code, "num_additional_sub_streams_minus1" );     sei.m_numAdditionalSubStreams = code + 1;
    785865
    786866  xResizeSubBitstreamPropertySeiArrays(sei);
    787867  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
    788868  {
    789     READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
    790     READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
    791     READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
    792     READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
    793     READ_CODE( 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
    794   }
    795   xParseByteAlign();
    796 }
     869    sei_read_code( pDecodedMessageOutputStream,   2, code, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = code;
     870    sei_read_uvlc( pDecodedMessageOutputStream,  code, "output_layer_set_idx_to_vps[i]"      ); sei.m_outputLayerSetIdxToVps[i] = code;
     871    sei_read_code( pDecodedMessageOutputStream,   3, code, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = code;
     872    sei_read_code( pDecodedMessageOutputStream,  16, code, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = code;
     873    sei_read_code( pDecodedMessageOutputStream,  16, code, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = code;
     874  } 
     875}
     876
    797877Void SEIReader::xResizeSubBitstreamPropertySeiArrays(SEISubBitstreamProperty &sei)
    798878{
     
    805885#endif
    806886
    807 Void SEIReader::xParseByteAlign()
     887
     888Void SEIReader::xParseSEITempMotionConstraintsTileSets(SEITempMotionConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    808889{
    809890  UInt code;
    810   if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    811   {
    812     READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
    813   }
    814   while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    815   {
    816     READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
    817   }
    818 }
     891  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     892  sei_read_flag( pDecodedMessageOutputStream, code, "mc_all_tiles_exact_sample_value_match_flag");  sei.m_mc_all_tiles_exact_sample_value_match_flag = (code != 0);
     893  sei_read_flag( pDecodedMessageOutputStream, code, "each_tile_one_tile_set_flag");                 sei.m_each_tile_one_tile_set_flag                = (code != 0);
     894
     895  if(!sei.m_each_tile_one_tile_set_flag)
     896  {
     897    sei_read_flag( pDecodedMessageOutputStream, code, "limited_tile_set_display_flag");  sei.m_limited_tile_set_display_flag = (code != 0);
     898    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_sets_in_message_minus1");     sei.setNumberOfTileSets(code + 1);
     899
     900    if(sei.getNumberOfTileSets() != 0)
     901    {
     902      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
     903      {
     904        sei_read_uvlc( pDecodedMessageOutputStream, code, "mcts_id");  sei.tileSetData(i).m_mcts_id = code;
     905
     906        if(sei.m_limited_tile_set_display_flag)
     907        {
     908          sei_read_flag( pDecodedMessageOutputStream, code, "display_tile_set_flag");  sei.tileSetData(i).m_display_tile_set_flag = (code != 1);
     909        }
     910
     911        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_tile_rects_in_set_minus1");  sei.tileSetData(i).setNumberOfTileRects(code + 1);
     912
     913        for(Int j=0; j<sei.tileSetData(i).getNumberOfTileRects(); j++)
     914        {
     915          sei_read_uvlc( pDecodedMessageOutputStream, code, "top_left_tile_index");      sei.tileSetData(i).topLeftTileIndex(j)     = code;
     916          sei_read_uvlc( pDecodedMessageOutputStream, code, "bottom_right_tile_index");  sei.tileSetData(i).bottomRightTileIndex(j) = code;
     917        }
     918
     919        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
     920        {
     921          sei_read_flag( pDecodedMessageOutputStream, code, "exact_sample_value_match_flag");   sei.tileSetData(i).m_exact_sample_value_match_flag    = (code != 0);
     922        }
     923        sei_read_flag( pDecodedMessageOutputStream, code, "mcts_tier_level_idc_present_flag");  sei.tileSetData(i).m_mcts_tier_level_idc_present_flag = (code != 0);
     924
     925        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
     926        {
     927          sei_read_flag( pDecodedMessageOutputStream, code,    "mcts_tier_flag"); sei.tileSetData(i).m_mcts_tier_flag = (code != 0);
     928          sei_read_code( pDecodedMessageOutputStream, 8, code, "mcts_level_idc"); sei.tileSetData(i).m_mcts_level_idc =  code;
     929        }
     930      }
     931    }
     932  }
     933  else
     934  {
     935    sei_read_flag( pDecodedMessageOutputStream, code, "max_mcs_tier_level_idc_present_flag");  sei.m_max_mcs_tier_level_idc_present_flag = code;
     936    if(sei.m_max_mcs_tier_level_idc_present_flag)
     937    {
     938      sei_read_flag( pDecodedMessageOutputStream, code, "max_mcts_tier_flag");  sei.m_max_mcts_tier_flag = code;
     939      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_mcts_level_idc"); sei.m_max_mcts_level_idc = code;
     940    }
     941  }
     942}
     943
     944Void SEIReader::xParseSEITimeCode(SEITimeCode& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     945{
     946  UInt code;
     947  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     948  sei_read_code( pDecodedMessageOutputStream, 2, code, "num_clock_ts"); sei.numClockTs = code;
     949  for(Int i = 0; i < sei.numClockTs; i++)
     950  {
     951    TComSEITimeSet currentTimeSet;
     952    sei_read_flag( pDecodedMessageOutputStream, code, "clock_time_stamp_flag[i]"); currentTimeSet.clockTimeStampFlag = code;
     953    if(currentTimeSet.clockTimeStampFlag)
     954    {
     955      sei_read_flag( pDecodedMessageOutputStream, code, "nuit_field_based_flag"); currentTimeSet.numUnitFieldBasedFlag = code;
     956      sei_read_code( pDecodedMessageOutputStream, 5, code, "counting_type"); currentTimeSet.countingType = code;
     957      sei_read_flag( pDecodedMessageOutputStream, code, "full_timestamp_flag"); currentTimeSet.fullTimeStampFlag = code;
     958      sei_read_flag( pDecodedMessageOutputStream, code, "discontinuity_flag"); currentTimeSet.discontinuityFlag = code;
     959      sei_read_flag( pDecodedMessageOutputStream, code, "cnt_dropped_flag"); currentTimeSet.cntDroppedFlag = code;
     960      sei_read_code( pDecodedMessageOutputStream, 9, code, "n_frames"); currentTimeSet.numberOfFrames = code;
     961      if(currentTimeSet.fullTimeStampFlag)
     962      {
     963        sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
     964        sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
     965        sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
     966      }
     967      else
     968      {
     969        sei_read_flag( pDecodedMessageOutputStream, code, "seconds_flag"); currentTimeSet.secondsFlag = code;
     970        if(currentTimeSet.secondsFlag)
     971        {
     972          sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
     973          sei_read_flag( pDecodedMessageOutputStream, code, "minutes_flag"); currentTimeSet.minutesFlag = code;
     974          if(currentTimeSet.minutesFlag)
     975          {
     976            sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
     977            sei_read_flag( pDecodedMessageOutputStream, code, "hours_flag"); currentTimeSet.hoursFlag = code;
     978            if(currentTimeSet.hoursFlag)
     979            {
     980              sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
     981            }
     982          }
     983        }
     984      }
     985      sei_read_code( pDecodedMessageOutputStream, 5, code, "time_offset_length"); currentTimeSet.timeOffsetLength = code;
     986      if(currentTimeSet.timeOffsetLength > 0)
     987      {
     988        sei_read_code( pDecodedMessageOutputStream, currentTimeSet.timeOffsetLength, code, "time_offset_value");
     989        if((code & (1 << (currentTimeSet.timeOffsetLength-1))) == 0)
     990        {
     991          currentTimeSet.timeOffsetValue = code;
     992        }
     993        else
     994        {
     995          code &= (1<< (currentTimeSet.timeOffsetLength-1)) - 1;
     996          currentTimeSet.timeOffsetValue = ~code + 1;
     997        }
     998      }
     999    }
     1000    sei.timeSetArray[i] = currentTimeSet;
     1001  }
     1002}
     1003
     1004Void SEIReader::xParseSEIChromaSamplingFilterHint(SEIChromaSamplingFilterHint& sei, UInt payloadSize/*, TComSPS* sps*/, std::ostream *pDecodedMessageOutputStream)
     1005{
     1006  UInt uiCode;
     1007  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1008
     1009  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "ver_chroma_filter_idc"); sei.m_verChromaFilterIdc = uiCode;
     1010  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "hor_chroma_filter_idc"); sei.m_horChromaFilterIdc = uiCode;
     1011  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ver_filtering_process_flag"); sei.m_verFilteringProcessFlag = uiCode;
     1012  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
     1013  {
     1014    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "target_format_idc"); sei.m_targetFormatIdc = uiCode;
     1015    if(sei.m_verChromaFilterIdc == 1)
     1016    {
     1017      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_vertical_filters"); sei.m_numVerticalFilters = uiCode;
     1018      if(sei.m_numVerticalFilters > 0)
     1019      {
     1020        sei.m_verTapLengthMinus1 = (Int*)malloc(sei.m_numVerticalFilters * sizeof(Int));
     1021        sei.m_verFilterCoeff = (Int**)malloc(sei.m_numVerticalFilters * sizeof(Int*));
     1022        for(Int i = 0; i < sei.m_numVerticalFilters; i ++)
     1023        {
     1024          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ver_tap_length_minus_1"); sei.m_verTapLengthMinus1[i] = uiCode;
     1025          sei.m_verFilterCoeff[i] = (Int*)malloc(sei.m_verTapLengthMinus1[i] * sizeof(Int));
     1026          for(Int j = 0; j < sei.m_verTapLengthMinus1[i]; j ++)
     1027          {
     1028            sei_read_svlc( pDecodedMessageOutputStream, sei.m_verFilterCoeff[i][j], "ver_filter_coeff");
     1029          }
     1030        }
     1031      }
     1032    }
     1033    if(sei.m_horChromaFilterIdc == 1)
     1034    {
     1035      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_horizontal_filters"); sei.m_numHorizontalFilters = uiCode;
     1036      if(sei.m_numHorizontalFilters  > 0)
     1037      {
     1038        sei.m_horTapLengthMinus1 = (Int*)malloc(sei.m_numHorizontalFilters * sizeof(Int));
     1039        sei.m_horFilterCoeff = (Int**)malloc(sei.m_numHorizontalFilters * sizeof(Int*));
     1040        for(Int i = 0; i < sei.m_numHorizontalFilters; i ++)
     1041        {
     1042          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "hor_tap_length_minus_1"); sei.m_horTapLengthMinus1[i] = uiCode;
     1043          sei.m_horFilterCoeff[i] = (Int*)malloc(sei.m_horTapLengthMinus1[i] * sizeof(Int));
     1044          for(Int j = 0; j < sei.m_horTapLengthMinus1[i]; j ++)
     1045          {
     1046            sei_read_svlc( pDecodedMessageOutputStream, sei.m_horFilterCoeff[i][j], "hor_filter_coeff");
     1047          }
     1048        }
     1049      }
     1050    }
     1051  }
     1052}
     1053
     1054Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1055{
     1056  Int i;
     1057  UInt val;
     1058  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1059
     1060  sei_read_uvlc( pDecodedMessageOutputStream, val, "knee_function_id" );                   sei.m_kneeId = val;
     1061  sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
     1062  if ( !sei.m_kneeCancelFlag )
     1063  {
     1064    sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
     1065    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
     1066    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
     1067    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
     1068    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
     1069    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
     1070    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
     1071    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
     1072    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
     1073    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
     1074    {
     1075      sei_read_code( pDecodedMessageOutputStream, 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
     1076      sei_read_code( pDecodedMessageOutputStream, 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
     1077    }
     1078  }
     1079}
     1080
     1081Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1082{
     1083  UInt code;
     1084  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1085
     1086  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
     1087  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
     1088
     1089  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
     1090  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
     1091
     1092  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
     1093  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
     1094
     1095
     1096  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
     1097  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
     1098
     1099  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
     1100  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
     1101}
     1102
    8191103//! \}
  • trunk/source/Lib/TLibDecoder/SEIread.h

    r1179 r1313  
    44 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5656  SEIReader() {};
    5757  virtual ~SEIReader() {};
    58   Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
     58  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
    5959protected:
    60   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
    61   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
    62   Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
    63   Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
    64   Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
    65   Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
    66   Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
    67   Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
    68   Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
    69   Void xParseSEIDisplayOrientation    (SEIDisplayOrientation &sei, UInt payloadSize);
    70   Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
    71   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
    72   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
    73   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
    74   Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
    75 #if H_MV
    76   Void  xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei);
    77   Void  xResizeSubBitstreamPropertySeiArrays(SEISubBitstreamProperty &sei);
     60  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     61  Void xParseSEIuserDataUnregistered          (SEIuserDataUnregistered &sei,          UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     62  Void xParseSEIActiveParameterSets           (SEIActiveParameterSets  &sei,          UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     63  Void xParseSEIDecodingUnitInfo              (SEIDecodingUnitInfo& sei,              UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     64  Void xParseSEIDecodedPictureHash            (SEIDecodedPictureHash& sei,            UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     65  Void xParseSEIBufferingPeriod               (SEIBufferingPeriod& sei,               UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     66  Void xParseSEIPictureTiming                 (SEIPictureTiming& sei,                 UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     67  Void xParseSEIRecoveryPoint                 (SEIRecoveryPoint& sei,                 UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     68  Void xParseSEIFramePacking                  (SEIFramePacking& sei,                  UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     69  Void xParseSEISegmentedRectFramePacking     (SEISegmentedRectFramePacking& sei,     UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     70  Void xParseSEIDisplayOrientation            (SEIDisplayOrientation &sei,            UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     71  Void xParseSEITemporalLevel0Index           (SEITemporalLevel0Index &sei,           UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     72  Void xParseSEIRegionRefreshInfo             (SEIGradualDecodingRefreshInfo &sei,    UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     73  Void xParseSEINoDisplay                     (SEINoDisplay &sei,                     UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     74  Void xParseSEIToneMappingInfo               (SEIToneMappingInfo& sei,               UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     75  Void xParseSEISOPDescription                (SEISOPDescription &sei,                UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     76  Void xParseSEIScalableNesting               (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     77  Void xParseSEITempMotionConstraintsTileSets (SEITempMotionConstrainedTileSets& sei, UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     78  Void xParseSEITimeCode                      (SEITimeCode& sei,                      UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     79  Void xParseSEIChromaSamplingFilterHint      (SEIChromaSamplingFilterHint& sei,      UInt payloadSize/*,TComSPS* */,       std::ostream *pDecodedMessageOutputStream);
     80  Void xParseSEIKneeFunctionInfo              (SEIKneeFunctionInfo& sei,              UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     81  Void xParseSEIMasteringDisplayColourVolume  (SEIMasteringDisplayColourVolume& sei,  UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     82#if NH_MV
     83  Void  xParseSEISubBitstreamProperty         (SEISubBitstreamProperty &sei        ,  UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
     84  Void  xResizeSubBitstreamPropertySeiArrays  (SEISubBitstreamProperty &sei);
    7885#endif
    79   Void xParseByteAlign();
     86
     87  Void sei_read_code(std::ostream *pOS, UInt uiLength, UInt& ruiCode, const Char *pSymbolName);
     88  Void sei_read_uvlc(std::ostream *pOS,                UInt& ruiCode, const Char *pSymbolName);
     89  Void sei_read_svlc(std::ostream *pOS,                Int&  ruiCode, const Char *pSymbolName);
     90  Void sei_read_flag(std::ostream *pOS,                UInt& ruiCode, const Char *pSymbolName);
    8091};
    8192
  • trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp

    r1179 r1313  
    22* License, included below. This software may be subject to other third party
    33* and contributor rights, including patent rights, and no such rights are
    4 * granted under this license. 
     4* granted under this license.
    55*
    66* Copyright (c) 2010-2015, ITU/ISO/IEC
     
    4343#include "TLibCommon/TComBitStream.h"
    4444#include "SyntaxElementParser.h"
     45#if RExt__DECODER_DEBUG_BIT_STATISTICS
     46#include "TLibCommon/TComCodingStatistics.h"
     47#endif
    4548
    4649#if ENC_DEC_TRACE
     
    4851Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
    4952{
     53#if RExt__DECODER_DEBUG_BIT_STATISTICS
     54  xReadCode (length, rValue, pSymbolName);
     55#else
    5056  xReadCode (length, rValue);
     57#endif
    5158#if H_MV_ENC_DEC_TRAC
    5259  if ( g_disableHLSTrace || !g_HLSTraceEnable )
     
    5663  if ( !g_disableNumbering )
    5764  {
    58 #endif
     65    incSymbolCounter();
     66    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
     67  }
     68#else
     69    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     70#endif
     71  if (length < 10)
     72  {
     73    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
     74  }
     75  else
     76  {
     77    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
     78  }
     79  fflush ( g_hTrace );
     80}
     81
     82Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
     83{
     84#if RExt__DECODER_DEBUG_BIT_STATISTICS
     85  xReadUvlc (rValue, pSymbolName);
     86#else
     87  xReadUvlc (rValue);
     88#endif
     89#if H_MV_ENC_DEC_TRAC
     90  if ( g_disableHLSTrace || !g_HLSTraceEnable )
     91  {
     92    return;
     93  }
     94  if ( !g_disableNumbering )
     95  {
     96  incSymbolCounter();
     97  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
     98  }
     99#else
    59100  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     101#endif
     102  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
     103  fflush ( g_hTrace );
     104}
     105
     106Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
     107{
     108#if RExt__DECODER_DEBUG_BIT_STATISTICS
     109  xReadSvlc (rValue, pSymbolName);
     110#else
     111  xReadSvlc (rValue);
     112#endif
    60113#if H_MV_ENC_DEC_TRAC
    61   }
    62 #endif
    63 
    64   if (length < 10)
    65   {
    66     fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
    67   }
    68   else
    69   {
    70     fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
    71   }
     114  if ( g_disableHLSTrace || !g_HLSTraceEnable )
     115  {
     116    return;
     117  }
     118  if ( !g_disableNumbering )
     119  { 
     120    incSymbolCounter();
     121    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
     122  }
     123#else
     124    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     125#endif
     126  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
    72127  fflush ( g_hTrace );
    73128}
    74129
    75 Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
    76 {
    77   xReadUvlc (rValue);
     130Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
     131{
     132#if RExt__DECODER_DEBUG_BIT_STATISTICS
     133  xReadFlag (rValue, pSymbolName);
     134#else
     135  xReadFlag (rValue);
     136#endif
    78137#if H_MV_ENC_DEC_TRAC
    79   if ( g_disableHLSTrace  || !g_HLSTraceEnable )
     138  if ( g_disableHLSTrace || !g_HLSTraceEnable )
    80139  {
    81140    return;
     
    83142  if ( !g_disableNumbering )
    84143  {
    85 #endif
     144    incSymbolCounter();
     145    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
     146  }
     147#else
    86148  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    87 #if H_MV_ENC_DEC_TRAC
    88   }
    89 #endif
    90   fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
     149#endif
     150  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
    91151  fflush ( g_hTrace );
    92152}
    93153
    94 Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
    95 {
    96   xReadSvlc(rValue);
    97 #if H_MV_ENC_DEC_TRAC
    98   if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
    99   {
    100     return;
    101   }
    102   if ( !g_disableNumbering )
    103   {
    104 #endif
    105   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    106 #if H_MV_ENC_DEC_TRAC
    107   }
    108 #endif
    109 
    110   fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
    111   fflush ( g_hTrace );
    112 }
    113 
    114 Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
    115 {
    116   xReadFlag(rValue);
    117 #if H_MV_ENC_DEC_TRAC
    118   if ( g_disableHLSTrace  || !g_HLSTraceEnable )
    119   {
    120     return;
    121   }
    122   if ( !g_disableNumbering )
    123   {
    124 #endif
    125   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    126 #if H_MV_ENC_DEC_TRAC
    127   }
    128 #endif
    129   fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
    130   fflush ( g_hTrace );
     154Void  xTraceAccessUnitDelimiter ()
     155{
     156  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
     157}
     158
     159Void xTraceFillerData ()
     160{
     161  fprintf( g_hTrace, "=========== Filler Data ===========\n");
    131162}
    132163
     
    137168// Protected member functions
    138169// ====================================================================================================================
    139 
     170#if RExt__DECODER_DEBUG_BIT_STATISTICS
     171Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
     172#else
    140173Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
     174#endif
    141175{
    142176  assert ( uiLength > 0 );
    143177  m_pcBitstream->read (uiLength, ruiCode);
    144 }
    145 
     178#if RExt__DECODER_DEBUG_BIT_STATISTICS
     179  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
     180#endif
     181}
     182
     183#if RExt__DECODER_DEBUG_BIT_STATISTICS
     184Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
     185#else
    146186Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
     187#endif
    147188{
    148189  UInt uiVal = 0;
     
    150191  UInt uiLength;
    151192  m_pcBitstream->read( 1, uiCode );
     193#if RExt__DECODER_DEBUG_BIT_STATISTICS
     194  UInt totalLen=1;
     195#endif
    152196
    153197  if( 0 == uiCode )
     
    164208
    165209    uiVal += (1 << uiLength)-1;
     210#if RExt__DECODER_DEBUG_BIT_STATISTICS
     211    totalLen+=uiLength+uiLength;
     212#endif
    166213  }
    167214
    168215  ruiVal = uiVal;
    169 }
    170 
     216#if RExt__DECODER_DEBUG_BIT_STATISTICS
     217  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
     218#endif
     219}
     220
     221#if RExt__DECODER_DEBUG_BIT_STATISTICS
     222Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
     223#else
    171224Void SyntaxElementParser::xReadSvlc( Int& riVal)
     225#endif
    172226{
    173227  UInt uiBits = 0;
    174228  m_pcBitstream->read( 1, uiBits );
     229#if RExt__DECODER_DEBUG_BIT_STATISTICS
     230  UInt totalLen=1;
     231#endif
    175232  if( 0 == uiBits )
    176233  {
     
    187244    uiBits += (1 << uiLength);
    188245    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
     246#if RExt__DECODER_DEBUG_BIT_STATISTICS
     247    totalLen+=uiLength+uiLength;
     248#endif
    189249  }
    190250  else
     
    192252    riVal = 0;
    193253  }
    194 }
    195 
     254#if RExt__DECODER_DEBUG_BIT_STATISTICS
     255  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
     256#endif
     257}
     258
     259#if RExt__DECODER_DEBUG_BIT_STATISTICS
     260Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
     261#else
    196262Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
     263#endif
    197264{
    198265  m_pcBitstream->read( 1, ruiCode );
     266#if RExt__DECODER_DEBUG_BIT_STATISTICS
     267  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
     268#endif
     269}
     270
     271Void SyntaxElementParser::xReadRbspTrailingBits()
     272{
     273  UInt bit;
     274  READ_FLAG( bit, "rbsp_stop_one_bit");
     275  assert (bit==1);
     276  Int cnt = 0;
     277  while (m_pcBitstream->getNumBitsUntilByteAligned())
     278  {
     279    READ_FLAG( bit, "rbsp_alignment_zero_bit");
     280    assert (bit==0);
     281    cnt++;
     282  }
     283  assert(cnt<8);
     284}
     285
     286Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
     287{
     288  setBitstream(bs);
     289
     290#if ENC_DEC_TRACE
     291  xTraceAccessUnitDelimiter();
     292#endif
     293
     294  READ_CODE (3, picType, "pic_type");
     295  xReadRbspTrailingBits();
     296}
     297
     298Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
     299{
     300  setBitstream(bs);
     301#if ENC_DEC_TRACE
     302  xTraceFillerData();
     303#endif
     304  UInt ffByte;
     305  fdSize = 0;
     306  while( m_pcBitstream->getNumBitsLeft() >8 )
     307  {
     308    READ_CODE (8, ffByte, "ff_byte");
     309    assert (ffByte==0xff);
     310    fdSize++;
     311  }
     312  xReadRbspTrailingBits();
    199313}
    200314
  • trunk/source/Lib/TLibDecoder/SyntaxElementParser.h

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4242#pragma once
    4343#endif // _MSC_VER > 1000
    44 
    45 #include "../TLibCommon/TComRom.h"
    46 
     44#include "TLibCommon/TComRom.h"
    4745#if ENC_DEC_TRACE
    4846
     
    5452#else
    5553
     54#if RExt__DECODER_DEBUG_BIT_STATISTICS
     55
     56#define READ_CODE(length, code, name)     xReadCode ( length, code, name )
     57#define READ_UVLC(        code, name)     xReadUvlc (         code, name )
     58#define READ_SVLC(        code, name)     xReadSvlc (         code, name )
     59#define READ_FLAG(        code, name)     xReadFlag (         code, name )
     60
     61#else
     62
    5663#define READ_CODE(length, code, name)     xReadCode ( length, code )
    5764#define READ_UVLC(        code, name)     xReadUvlc (         code )
    5865#define READ_SVLC(        code, name)     xReadSvlc (         code )
    5966#define READ_FLAG(        code, name)     xReadFlag (         code )
     67
     68#endif
    6069
    6170#endif
     
    7887  virtual ~SyntaxElementParser() {};
    7988
     89#if RExt__DECODER_DEBUG_BIT_STATISTICS
     90  Void  xReadCode    ( UInt   length, UInt& val, const Char *pSymbolName );
     91  Void  xReadUvlc    ( UInt&  val, const Char *pSymbolName );
     92  Void  xReadSvlc    ( Int&   val, const Char *pSymbolName );
     93  Void  xReadFlag    ( UInt&  val, const Char *pSymbolName );
     94#else
    8095  Void  xReadCode    ( UInt   length, UInt& val );
    8196  Void  xReadUvlc    ( UInt&  val );
    8297  Void  xReadSvlc    ( Int&   val );
    8398  Void  xReadFlag    ( UInt&  val );
     99#endif
    84100#if ENC_DEC_TRACE
    85101  Void  xReadCodeTr  (UInt  length, UInt& rValue, const Char *pSymbolName);
     
    91107  Void  setBitstream ( TComInputBitstream* p )   { m_pcBitstream = p; }
    92108  TComInputBitstream* getBitstream() { return m_pcBitstream; }
     109
     110protected:
     111  Void xReadRbspTrailingBits();
    93112};
     113
     114class AUDReader: public SyntaxElementParser
     115{
     116public:
     117  AUDReader() {};
     118  virtual ~AUDReader() {};
     119  Void parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType);
     120};
     121
     122class FDReader: public SyntaxElementParser
     123{
     124public:
     125  FDReader() {};
     126  virtual ~FDReader() {};
     127  Void parseFillerData(TComInputBitstream* bs, UInt &fdSize);
     128};
     129
    94130
    95131//! \}
  • trunk/source/Lib/TLibDecoder/TDecBinCoder.h

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3636*/
    3737
    38 #ifndef __TDEC_BIN_CODER__
    39 #define __TDEC_BIN_CODER__
     38#ifndef __TDECBINCODER__
     39#define __TDECBINCODER__
    4040
    4141#include "TLibCommon/ContextModel.h"
    4242#include "TLibCommon/TComBitStream.h"
     43
     44#if RExt__DECODER_DEBUG_BIT_STATISTICS
     45class TComCodingStatisticsClassType;
     46#endif
    4347
    4448//! \ingroup TLibDecoder
     
    5559  virtual Void  finish            ()                                          = 0;
    5660
     61#if RExt__DECODER_DEBUG_BIT_STATISTICS
     62  virtual Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel, const class TComCodingStatisticsClassType &whichStat )  = 0;
     63  virtual Void  decodeBinEP       ( UInt& ruiBin                          , const class TComCodingStatisticsClassType &whichStat )  = 0;
     64  virtual Void  decodeBinsEP      ( UInt& ruiBins, Int numBins            , const class TComCodingStatisticsClassType &whichStat )  = 0;
     65#else
    5766  virtual Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel )  = 0;
    5867  virtual Void  decodeBinEP       ( UInt& ruiBin                           )  = 0;
    5968  virtual Void  decodeBinsEP      ( UInt& ruiBins, Int numBins             )  = 0;
     69#endif
     70
     71  virtual Void  align             ()                                          = 0;
     72
    6073  virtual Void  decodeBinTrm      ( UInt& ruiBin                           )  = 0;
    61  
    62   virtual Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode)              = 0;
     74
     75  virtual Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode)             = 0;
    6376
    6477  virtual ~TDecBinIf() {}
    6578
    66   virtual Void  copyState         ( TDecBinIf* pcTDecBinIf )                  = 0;
    67   virtual TDecBinCABAC*   getTDecBinCABAC   ()  { return 0; }
     79  virtual Void  copyState         ( const TDecBinIf* pcTDecBinIf )            = 0;
     80  virtual TDecBinCABAC*   getTDecBinCABAC   ()             { return 0; }
     81  virtual const TDecBinCABAC*   getTDecBinCABAC   () const { return 0; }
    6882};
    6983
  • trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737
    3838#include "TDecBinCoderCABAC.h"
    39 #include "../TLibCommon/TComRom.h"
     39#include "TLibCommon/Debug.h"
     40#if RExt__DECODER_DEBUG_BIT_STATISTICS
     41#include "TLibCommon/TComCodingStatistics.h"
     42#endif
    4043
    4144//! \ingroup TLibDecoder
     
    6770{
    6871  assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
     72#if RExt__DECODER_DEBUG_BIT_STATISTICS
     73  TComCodingStatistics::UpdateCABACStat(STATS__CABAC_INITIALISATION, 512, 510, 0);
     74#endif
    6975  m_uiRange    = 510;
    7076  m_bitsNeeded = -8;
     
    8995 */
    9096Void
    91 TDecBinCABAC::copyState( TDecBinIf* pcTDecBinIf )
    92 {
    93   TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
     97TDecBinCABAC::copyState( const TDecBinIf* pcTDecBinIf )
     98{
     99  const TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
    94100  m_uiRange   = pcTDecBinCABAC->m_uiRange;
    95101  m_uiValue   = pcTDecBinCABAC->m_uiValue;
     
    98104
    99105
    100 Void
    101 TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel )
    102 {
     106
     107#if RExt__DECODER_DEBUG_BIT_STATISTICS
     108Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel, const TComCodingStatisticsClassType &whichStat )
     109#else
     110Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel )
     111#endif
     112{
     113#if DEBUG_CABAC_BINS
     114  const UInt startingRange = m_uiRange;
     115#endif
     116
    103117  UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) - 4 ];
    104118  m_uiRange -= uiLPS;
    105119  UInt scaledRange = m_uiRange << 7;
    106  
     120
    107121  if( m_uiValue < scaledRange )
    108122  {
    109123    // MPS path
    110124    ruiBin = rcCtxModel.getMps();
     125#if RExt__DECODER_DEBUG_BIT_STATISTICS
     126    TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, m_uiRange, Int(ruiBin));
     127#endif
    111128    rcCtxModel.updateMPS();
    112    
    113     if ( scaledRange >= ( 256 << 7 ) )
    114     {
    115       return;
    116     }
    117    
    118     m_uiRange = scaledRange >> 6;
    119     m_uiValue += m_uiValue;
    120    
    121     if ( ++m_bitsNeeded == 0 )
    122     {
    123       m_bitsNeeded = -8;
    124       m_uiValue += m_pcTComBitstream->readByte();     
     129
     130    if ( scaledRange < ( 256 << 7 ) )
     131    {
     132      m_uiRange = scaledRange >> 6;
     133      m_uiValue += m_uiValue;
     134
     135      if ( ++m_bitsNeeded == 0 )
     136      {
     137        m_bitsNeeded = -8;
     138        m_uiValue += m_pcTComBitstream->readByte();
     139      }
    125140    }
    126141  }
     
    128143  {
    129144    // LPS path
     145    ruiBin      = 1 - rcCtxModel.getMps();
     146#if RExt__DECODER_DEBUG_BIT_STATISTICS
     147    TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, uiLPS, Int(ruiBin));
     148#endif
    130149    Int numBits = TComCABACTables::sm_aucRenormTable[ uiLPS >> 3 ];
    131150    m_uiValue   = ( m_uiValue - scaledRange ) << numBits;
    132151    m_uiRange   = uiLPS << numBits;
    133     ruiBin      = 1 - rcCtxModel.getMps();
    134152    rcCtxModel.updateLPS();
    135    
     153
    136154    m_bitsNeeded += numBits;
    137    
     155
    138156    if ( m_bitsNeeded >= 0 )
    139157    {
     
    142160    }
    143161  }
    144 }
    145 
    146 Void
    147 TDecBinCABAC::decodeBinEP( UInt& ruiBin )
    148 {
     162
     163#if DEBUG_CABAC_BINS
     164  if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine)
     165  {
     166    std::cout << g_debugCounter << ": coding bin value " << ruiBin << ", range = [" << startingRange << "->" << m_uiRange << "]\n";
     167  }
     168
     169  if (g_debugCounter >= debugCabacBinTargetLine)
     170  {
     171    Char breakPointThis;
     172    breakPointThis = 7;
     173  }
     174  if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow))
     175  {
     176    exit(0);
     177  }
     178  g_debugCounter++;
     179#endif
     180}
     181
     182
     183#if RExt__DECODER_DEBUG_BIT_STATISTICS
     184Void TDecBinCABAC::decodeBinEP( UInt& ruiBin, const TComCodingStatisticsClassType &whichStat )
     185#else
     186Void TDecBinCABAC::decodeBinEP( UInt& ruiBin )
     187#endif
     188{
     189  if (m_uiRange == 256)
     190  {
     191#if RExt__DECODER_DEBUG_BIT_STATISTICS
     192    decodeAlignedBinsEP(ruiBin, 1, whichStat);
     193#else
     194    decodeAlignedBinsEP(ruiBin, 1);
     195#endif
     196    return;
     197  }
     198
    149199  m_uiValue += m_uiValue;
    150  
     200
    151201  if ( ++m_bitsNeeded >= 0 )
    152202  {
     
    154204    m_uiValue += m_pcTComBitstream->readByte();
    155205  }
    156  
     206
    157207  ruiBin = 0;
    158208  UInt scaledRange = m_uiRange << 7;
     
    162212    m_uiValue -= scaledRange;
    163213  }
    164 }
    165 
     214#if RExt__DECODER_DEBUG_BIT_STATISTICS
     215  TComCodingStatistics::IncrementStatisticEP(whichStat, 1, Int(ruiBin));
     216#endif
     217}
     218
     219#if RExt__DECODER_DEBUG_BIT_STATISTICS
     220Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins, const TComCodingStatisticsClassType &whichStat )
     221#else
    166222Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins )
    167 {
     223#endif
     224{
     225  if (m_uiRange == 256)
     226  {
     227#if RExt__DECODER_DEBUG_BIT_STATISTICS
     228    decodeAlignedBinsEP(ruiBin, numBins, whichStat);
     229#else
     230    decodeAlignedBinsEP(ruiBin, numBins);
     231#endif
     232    return;
     233  }
     234
    168235  UInt bins = 0;
    169  
     236#if RExt__DECODER_DEBUG_BIT_STATISTICS
     237  Int origNumBins=numBins;
     238#endif
    170239  while ( numBins > 8 )
    171240  {
    172241    m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
    173    
     242
    174243    UInt scaledRange = m_uiRange << 15;
    175244    for ( Int i = 0; i < 8; i++ )
     
    185254    numBins -= 8;
    186255  }
    187  
     256
    188257  m_bitsNeeded += numBins;
    189258  m_uiValue <<= numBins;
    190  
     259
    191260  if ( m_bitsNeeded >= 0 )
    192261  {
     
    194263    m_bitsNeeded -= 8;
    195264  }
    196  
     265
    197266  UInt scaledRange = m_uiRange << ( numBins + 7 );
    198267  for ( Int i = 0; i < numBins; i++ )
     
    206275    }
    207276  }
    208  
     277
    209278  ruiBin = bins;
     279#if RExt__DECODER_DEBUG_BIT_STATISTICS
     280  TComCodingStatistics::IncrementStatisticEP(whichStat, origNumBins, Int(ruiBin));
     281#endif
     282}
     283
     284Void TDecBinCABAC::align()
     285{
     286#if RExt__DECODER_DEBUG_BIT_STATISTICS
     287  TComCodingStatistics::UpdateCABACStat(STATS__CABAC_EP_BIT_ALIGNMENT, m_uiRange, 256, 0);
     288#endif
     289  m_uiRange = 256;
     290}
     291
     292#if RExt__DECODER_DEBUG_BIT_STATISTICS
     293Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins, const class TComCodingStatisticsClassType &whichStat )
     294#else
     295Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins )
     296#endif
     297{
     298  Int binsRemaining = numBins;
     299  ruiBins = 0;
     300
     301  assert(m_uiRange == 256); //aligned decode only works when range = 256
     302
     303  while (binsRemaining > 0)
     304  {
     305    const UInt binsToRead = std::min<UInt>(binsRemaining, 8); //read bytes if able to take advantage of the system's byte-read function
     306    const UInt binMask    = (1 << binsToRead) - 1;
     307
     308    //The MSB of m_uiValue is known to be 0 because range is 256. Therefore:
     309    // > The comparison against the symbol range of 128 is simply a test on the next-most-significant bit
     310    // > "Subtracting" the symbol range if the decoded bin is 1 simply involves clearing that bit.
     311    //
     312    //As a result, the required bins are simply the <binsToRead> next-most-significant bits of m_uiValue
     313    //(m_uiValue is stored MSB-aligned in a 16-bit buffer - hence the shift of 15)
     314    //
     315    //   m_uiValue = |0|V|V|V|V|V|V|V|V|B|B|B|B|B|B|B|        (V = usable bit, B = potential buffered bit (buffer refills when m_bitsNeeded >= 0))
     316    //
     317    const UInt newBins = (m_uiValue >> (15 - binsToRead)) & binMask;
     318
     319    ruiBins   = (ruiBins   << binsToRead) | newBins;
     320    m_uiValue = (m_uiValue << binsToRead) & 0x7FFF;
     321
     322    binsRemaining -= binsToRead;
     323    m_bitsNeeded  += binsToRead;
     324
     325    if (m_bitsNeeded >= 0)
     326    {
     327      m_uiValue    |= m_pcTComBitstream->readByte() << m_bitsNeeded;
     328      m_bitsNeeded -= 8;
     329    }
     330  }
     331
     332#if RExt__DECODER_DEBUG_BIT_STATISTICS
     333  TComCodingStatistics::IncrementStatisticEP(whichStat, numBins, Int(ruiBins));
     334#endif
    210335}
    211336
     
    218343  {
    219344    ruiBin = 1;
     345#if RExt__DECODER_DEBUG_BIT_STATISTICS
     346    TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, 2, ruiBin);
     347    TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, -m_bitsNeeded, 0);
     348#endif
    220349  }
    221350  else
    222351  {
    223352    ruiBin = 0;
     353#if RExt__DECODER_DEBUG_BIT_STATISTICS
     354    TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, m_uiRange, ruiBin);
     355#endif
    224356    if ( scaledRange < ( 256 << 7 ) )
    225357    {
    226358      m_uiRange = scaledRange >> 6;
    227359      m_uiValue += m_uiValue;
    228      
     360
    229361      if ( ++m_bitsNeeded == 0 )
    230362      {
    231363        m_bitsNeeded = -8;
    232         m_uiValue += m_pcTComBitstream->readByte();     
     364        m_uiValue += m_pcTComBitstream->readByte();
    233365      }
    234366    }
     
    245377  assert ( uiLength > 0 );
    246378  m_pcTComBitstream->read (uiLength, ruiCode);
     379#if RExt__DECODER_DEBUG_BIT_STATISTICS
     380  TComCodingStatistics::IncrementStatisticEP(STATS__CABAC_PCM_CODE_BITS, uiLength, ruiCode);
     381#endif
    247382}
    248383//! \}
  • trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3636*/
    3737
    38 #ifndef __TDEC_BIN_CODER_CABAC__
    39 #define __TDEC_BIN_CODER_CABAC__
     38#ifndef __TDECBINCODERCABAC__
     39#define __TDECBINCODERCABAC__
    4040
    4141#include "TLibCommon/TComCABACTables.h"
     
    5050  TDecBinCABAC ();
    5151  virtual ~TDecBinCABAC();
    52  
     52
    5353  Void  init              ( TComInputBitstream* pcTComBitstream );
    5454  Void  uninit            ();
    55  
     55
    5656  Void  start             ();
    5757  Void  finish            ();
    58  
     58
     59#if RExt__DECODER_DEBUG_BIT_STATISTICS
     60  Void  decodeBin          ( UInt& ruiBin, ContextModel& rcCtxModel, const class TComCodingStatisticsClassType &whichStat );
     61  Void  decodeBinEP        ( UInt& ruiBin                          , const class TComCodingStatisticsClassType &whichStat );
     62  Void  decodeBinsEP       ( UInt& ruiBin, Int numBins             , const class TComCodingStatisticsClassType &whichStat );
     63  Void  decodeAlignedBinsEP( UInt& ruiBins, Int numBins            , const class TComCodingStatisticsClassType &whichStat );
     64#else
    5965  Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel );
    6066  Void  decodeBinEP       ( UInt& ruiBin                           );
    6167  Void  decodeBinsEP      ( UInt& ruiBin, Int numBins              );
     68  Void  decodeAlignedBinsEP( UInt& ruiBins, Int numBins             );
     69#endif
     70
     71  Void  align             ();
     72
    6273  Void  decodeBinTrm      ( UInt& ruiBin                           );
    63  
     74
    6475  Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode );
    65  
    66   Void  copyState         ( TDecBinIf* pcTDecBinIf );
    67   TDecBinCABAC* getTDecBinCABAC()  { return this; }
     76
     77  Void  copyState         ( const TDecBinIf* pcTDecBinIf );
     78  TDecBinCABAC* getTDecBinCABAC()             { return this; }
     79  const TDecBinCABAC* getTDecBinCABAC() const { return this; }
    6880
    6981private:
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r1196 r1313  
    22* License, included below. This software may be subject to other third party
    33* and contributor rights, including patent rights, and no such rights are
    4 * granted under this license. 
     4* granted under this license.
    55*
    66* Copyright (c) 2010-2015, ITU/ISO/IEC
     
    3939#include "SEIread.h"
    4040#include "TDecSlice.h"
    41 #if H_3D
     41#include "TLibCommon/TComChromaFormat.h"
     42#if RExt__DECODER_DEBUG_BIT_STATISTICS
     43#include "TLibCommon/TComCodingStatistics.h"
     44#endif
     45#if NH_MV
    4246#include "TDecTop.h"
    4347#endif
     48
    4449//! \ingroup TLibDecoder
    4550//! \{
    4651
    4752#if ENC_DEC_TRACE
    48 
    49 Void  xTraceSPSHeader (TComSPS *pSPS)
    50 {
    51 #if H_MV_ENC_DEC_TRAC
    52   if ( g_disableHLSTrace )
    53   {
    54     return;
    55   }
    56   // To avoid mismatches
    57   fprintf( g_hTrace, "=========== Sequence Parameter Set LayerId: %d ===========\n", pSPS->getLayerId() );
    58 #else
    59   fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
    60 #endif
    61 }
    62 
    63 Void  xTracePPSHeader (TComPPS *pPPS)
    64 {
    65 #if H_MV_ENC_DEC_TRAC
    66   if ( g_disableHLSTrace )
    67   {
    68     return;
    69   }
    70   fprintf( g_hTrace, "=========== Picture Parameter Set LayerId: %d ===========\n", pPPS->getLayerId() );
    71 #else
    72   fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
    73 #endif
    74 }
    75 
    76 Void  xTraceSliceHeader (TComSlice *pSlice)
    77 {
    78 #if H_MV_ENC_DEC_TRAC
    79   if ( g_disableHLSTrace )
    80   {
    81     return;
    82   }
    83 #endif
    84   fprintf( g_hTrace, "=========== Slice ===========\n");
    85 }
    86 
    87 #endif
    88 
     53#if !H_MV_ENC_DEC_TRAC
     54Void  xTraceVPSHeader ()
     55{
     56  fprintf( g_hTrace, "=========== Video Parameter Set     ===========\n" );
     57}
     58
     59Void  xTraceSPSHeader ()
     60{
     61  fprintf( g_hTrace, "=========== Sequence Parameter Set  ===========\n" );
     62}
     63
     64Void  xTracePPSHeader ()
     65{
     66  fprintf( g_hTrace, "=========== Picture Parameter Set  ===========\n");
     67}
     68#endif
     69#endif
    8970// ====================================================================================================================
    9071// Constructor / destructor / create / destroy
     
    9778TDecCavlc::~TDecCavlc()
    9879{
     80
    9981}
    10082
     
    10385// ====================================================================================================================
    10486
    105 void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
     87Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
    10688{
    10789  UInt code;
     
    11799  }
    118100
    119   if (interRPSPred) 
     101  if (interRPSPred)
    120102  {
    121103    UInt bit;
     
    138120    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
    139121    {
    140       READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 
     122      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
    141123      Int refIdc = bit;
    142       if (refIdc == 0) 
     124      if (refIdc == 0)
    143125      {
    144126        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
     
    155137          k0++;
    156138        }
    157         else 
     139        else
    158140        {
    159141          k1++;
    160142        }
    161143        k++;
    162       } 
    163       rps->setRefIdc(j,refIdc); 
    164     }
    165     rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
     144      }
     145      rps->setRefIdc(j,refIdc);
     146    }
     147    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
    166148    rps->setNumberOfPictures(k);
    167149    rps->setNumberOfNegativePictures(k0);
     
    199181}
    200182
    201 #if H_3D
    202 Void TDecCavlc::parsePPS(TComPPS* pcPPS, TComVPS* pcVPS )
     183Void TDecCavlc::parsePPS(TComPPS* pcPPS)
     184{
     185#if ENC_DEC_TRACE
     186#if H_MV_ENC_DEC_TRAC
     187  tracePSHeader( "PPS", pcPPS->getLayerId() );
    203188#else
    204 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
    205 #endif
    206 {
    207 #if ENC_DEC_TRACE 
    208   xTracePPSHeader (pcPPS);
     189  xTracePPSHeader ();
     190#endif
    209191#endif
    210192  UInt  uiCode;
     
    215197  assert(uiCode <= 63);
    216198  pcPPS->setPPSId (uiCode);
    217  
     199
    218200  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
    219201  assert(uiCode <= 15);
    220202  pcPPS->setSPSId (uiCode);
    221  
     203
    222204  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
     205
    223206  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
    224207
    225208  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
     209
    226210  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
    227211
     
    231215  assert(uiCode <= 14);
    232216  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
    233  
     217
    234218  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
    235219  assert(uiCode <= 14);
    236220  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
    237  
     221
    238222  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
    239223  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
    240   READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
    241   pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
     224  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
     225  pcPPS->setUseTransformSkip ( uiCode ? true : false );
    242226
    243227  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
     
    252236  }
    253237  READ_SVLC( iCode, "pps_cb_qp_offset");
    254   pcPPS->setChromaCbQpOffset(iCode);
    255   assert( pcPPS->getChromaCbQpOffset() >= -12 );
    256   assert( pcPPS->getChromaCbQpOffset() <=  12 );
     238  pcPPS->setQpOffset(COMPONENT_Cb, iCode);
     239  assert( pcPPS->getQpOffset(COMPONENT_Cb) >= -12 );
     240  assert( pcPPS->getQpOffset(COMPONENT_Cb) <=  12 );
    257241
    258242  READ_SVLC( iCode, "pps_cr_qp_offset");
    259   pcPPS->setChromaCrQpOffset(iCode);
    260   assert( pcPPS->getChromaCrQpOffset() >= -12 );
    261   assert( pcPPS->getChromaCrQpOffset() <=  12 );
     243  pcPPS->setQpOffset(COMPONENT_Cr, iCode);
     244  assert( pcPPS->getQpOffset(COMPONENT_Cr) >= -12 );
     245  assert( pcPPS->getQpOffset(COMPONENT_Cr) <=  12 );
     246
     247  assert(MAX_NUM_COMPONENT<=3);
    262248
    263249  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
     
    273259  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
    274260  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
    275  
     261
    276262  if( pcPPS->getTilesEnabledFlag() )
    277263  {
     
    280266    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
    281267
    282     if( !pcPPS->getTileUniformSpacingFlag())
    283     {
    284       std::vector<Int> columnWidth(pcPPS->getNumTileColumnsMinus1());
    285       for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
    286       {
    287         READ_UVLC( uiCode, "column_width_minus1" ); 
    288         columnWidth[i] = uiCode+1;
    289       }
    290       pcPPS->setTileColumnWidth(columnWidth);
    291 
    292       std::vector<Int> rowHeight (pcPPS->getTileNumRowsMinus1());
    293       for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
    294       {
    295         READ_UVLC( uiCode, "row_height_minus1" );
    296         rowHeight[i] = uiCode + 1;
    297       }
    298       pcPPS->setTileRowHeight(rowHeight);
    299     }
    300 
    301     if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
     268    const UInt tileColumnsMinus1 = pcPPS->getNumTileColumnsMinus1();
     269    const UInt tileRowsMinus1    = pcPPS->getNumTileRowsMinus1();
     270 
     271    if ( !pcPPS->getTileUniformSpacingFlag())
     272    {
     273      if (tileColumnsMinus1 > 0)
     274      {
     275        std::vector<Int> columnWidth(tileColumnsMinus1);
     276        for(UInt i = 0; i < tileColumnsMinus1; i++)
     277        {
     278          READ_UVLC( uiCode, "column_width_minus1" ); 
     279          columnWidth[i] = uiCode+1;
     280        }
     281        pcPPS->setTileColumnWidth(columnWidth);
     282      }
     283
     284      if (tileRowsMinus1 > 0)
     285      {
     286        std::vector<Int> rowHeight (tileRowsMinus1);
     287        for(UInt i = 0; i < tileRowsMinus1; i++)
     288        {
     289          READ_UVLC( uiCode, "row_height_minus1" );
     290          rowHeight[i] = uiCode + 1;
     291        }
     292        pcPPS->setTileRowHeight(rowHeight);
     293      }
     294    }
     295
     296    if ((tileColumnsMinus1 + tileRowsMinus1) != 0)
    302297    {
    303298      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
    304299    }
    305300  }
    306   READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
     301  READ_FLAG( uiCode, "pps_loop_filter_across_slices_enabled_flag" );   pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
    307302  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
    308303  if(pcPPS->getDeblockingFilterControlPresentFlag())
     
    319314  if(pcPPS->getScalingListPresentFlag ())
    320315  {
    321     parseScalingList( pcPPS->getScalingList() );
    322   }
     316    parseScalingList( &(pcPPS->getScalingList()) );
     317  }
     318
    323319  READ_FLAG( uiCode, "lists_modification_present_flag");
    324320  pcPPS->setListsModificationPresentFlag(uiCode);
     
    329325  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
    330326  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
    331  
    332 #if H_MV
     327
    333328  READ_FLAG( uiCode, "pps_extension_present_flag");
    334 #else
    335   READ_FLAG( uiCode, "pps_extension_flag");
    336 #endif
    337329  if (uiCode)
    338330  {
    339 
    340 #if H_MV
     331#if NH_MV
    341332    READ_FLAG( uiCode, "pps_range_extensions_flag" ); pcPPS->setPpsRangeExtensionsFlag( uiCode == 1 );
    342333    READ_FLAG( uiCode, "pps_multilayer_extension_flag" ); pcPPS->setPpsMultilayerExtensionFlag( uiCode == 1 );
    343 #if !H_3D
    344     READ_CODE( 6, uiCode, "pps_extension_6bits" ); pcPPS->setPpsExtension6bits( uiCode );
    345 #else
    346334    READ_FLAG( uiCode, "pps_3d_extension_flag" ); pcPPS->setPps3dExtensionFlag( uiCode == 1 );
    347335    READ_CODE( 5, uiCode, "pps_extension_5bits" ); pcPPS->setPpsExtension5bits( uiCode );
    348 #endif
    349336    if ( pcPPS->getPpsRangeExtensionsFlag() )
    350337    {
    351       assert(0);
    352     }
     338      TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();     
     339
     340      if (pcPPS->getUseTransformSkip())
     341      {
     342        READ_UVLC( uiCode, "log2_max_transform_skip_block_size_minus2");
     343        ppsRangeExtension.setLog2MaxTransformSkipBlockSize(uiCode+2);
     344      }
     345
     346      READ_FLAG( uiCode, "cross_component_prediction_enabled_flag");
     347      ppsRangeExtension.setCrossComponentPredictionEnabledFlag(uiCode != 0);
     348
     349      READ_FLAG( uiCode, "chroma_qp_offset_list_enabled_flag");
     350      if (uiCode == 0)
     351      {
     352        ppsRangeExtension.clearChromaQpOffsetList();
     353        ppsRangeExtension.setDiffCuChromaQpOffsetDepth(0);
     354      }
     355      else
     356      {
     357        READ_UVLC(uiCode, "diff_cu_chroma_qp_offset_depth"); ppsRangeExtension.setDiffCuChromaQpOffsetDepth(uiCode);
     358        UInt tableSizeMinus1 = 0;
     359        READ_UVLC(tableSizeMinus1, "chroma_qp_offset_list_len_minus1");
     360        assert(tableSizeMinus1 < MAX_QP_OFFSET_LIST_SIZE);
     361
     362        for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx <= (tableSizeMinus1); cuChromaQpOffsetIdx++)
     363        {
     364          Int cbOffset;
     365          Int crOffset;
     366          READ_SVLC(cbOffset, "cb_qp_offset_list[i]");
     367          assert(cbOffset >= -12 && cbOffset <= 12);
     368          READ_SVLC(crOffset, "cr_qp_offset_list[i]");
     369          assert(crOffset >= -12 && crOffset <= 12);
     370          // table uses +1 for index (see comment inside the function)
     371          ppsRangeExtension.setChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1, cbOffset, crOffset);
     372        }
     373        assert(ppsRangeExtension.getChromaQpOffsetListLen() == tableSizeMinus1 + 1);
     374      }
     375
     376      READ_UVLC( uiCode, "log2_sao_offset_scale_luma");
     377      ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, uiCode);
     378      READ_UVLC( uiCode, "log2_sao_offset_scale_chroma");
     379      ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, uiCode);    }
    353380
    354381    if ( pcPPS->getPpsMultilayerExtensionFlag() )
    355382    {
    356       parsePPSMultilayerExtension( pcPPS );
    357     }
    358 #if !H_3D
    359     if ( pcPPS->getPpsExtension6bits() )
    360     {
    361 #else
     383      parsePpsMultilayerExtension( pcPPS );
     384    }
     385
    362386    if ( pcPPS->getPps3dExtensionFlag() )
    363387    {
    364       parsePPSExtension( pcPPS, pcVPS );
    365     }
     388#if NH_3D
     389      parsePps3dExtension( pcPPS );
     390#endif
     391    }
     392#if NH_3D
    366393    if ( pcPPS->getPpsExtension5bits() )
    367     {
    368 #endif
    369 
    370 #endif
    371 
     394#else
     395    if ( pcPPS->getPpsExtension5bits() || pcPPS->getPps3dExtensionFlag() )
     396#endif
     397    {
    372398      while ( xMoreRbspData() )
    373399      {
    374400        READ_FLAG( uiCode, "pps_extension_data_flag");
    375401      }
    376 #if H_MV
    377     }
    378 #endif
    379   }
    380 }
    381 
    382 
    383 #if H_3D
    384 Void TDecCavlc::parsePPSExtension( TComPPS* pcPPS, TComVPS* pcVPS )
    385 {
    386   //Ed.(GT): pcVPS should not be used here. Needs to be fixed.
    387   UInt uiCode = 0;
    388   TComDLT* pcDLT = new TComDLT;
    389 
    390   READ_FLAG(uiCode, "dlt_present_flag");
    391   pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
    392 
    393   if ( pcDLT->getDltPresentFlag() )
    394   {
    395     READ_CODE(6, uiCode, "pps_depth_layers_minus1");
    396     pcDLT->setNumDepthViews( uiCode );
    397 
    398     READ_CODE(4, uiCode, "pps_bit_depth_for_depth_views_minus8");
    399     pcDLT->setDepthViewBitDepth( (uiCode+8) );
    400 
    401     for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    402     {
    403       if ( i != 0 )
    404       {
    405         if( pcVPS->getDepthId( i ) == 1 )
    406         {
    407           READ_FLAG(uiCode, "dlt_flag[i]");
    408           pcDLT->setUseDLTFlag(i, (uiCode == 1) ? true : false);
    409 
    410           if ( pcDLT->getUseDLTFlag( i ) )
    411           {
    412             Bool bDltBitMapRepFlag    = false;
    413             UInt uiMaxDiff            = 0xffffffff;
    414             UInt uiMinDiff            = 0;
    415             UInt uiCodeLength         = 0;
    416 
    417             READ_FLAG(uiCode, "inter_view_dlt_pred_enable_flag[ i ]");
    418 
    419             if( uiCode )
     402    }
     403
     404#else
     405#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     406    static const char *syntaxStrings[]={ "pps_range_extension_flag",
     407                                         "pps_multilayer_extension_flag",
     408                                         "pps_extension_6bits[0]",
     409                                         "pps_extension_6bits[1]",
     410                                         "pps_extension_6bits[2]",
     411                                         "pps_extension_6bits[3]",
     412                                         "pps_extension_6bits[4]",
     413                                         "pps_extension_6bits[5]" };
     414#endif
     415
     416    Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS];
     417    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
     418    {
     419      READ_FLAG( uiCode, syntaxStrings[i] );
     420      pps_extension_flags[i] = uiCode!=0;
     421    }
     422
     423    Bool bSkipTrailingExtensionBits=false;
     424    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     425    {
     426      if (pps_extension_flags[i])
     427      {
     428        switch (PPSExtensionFlagIndex(i))
     429        {
     430          case PPS_EXT__REXT:
    420431            {
    421                 assert( pcDLT->getUseDLTFlag( 1 ));
     432              TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();
     433            assert(!bSkipTrailingExtensionBits);
     434
     435            if (pcPPS->getUseTransformSkip())
     436            {
     437              READ_UVLC( uiCode, "log2_max_transform_skip_block_size_minus2");
     438                ppsRangeExtension.setLog2MaxTransformSkipBlockSize(uiCode+2);
    422439            }
    423             pcDLT->setInterViewDltPredEnableFlag( i, (uiCode == 1) ? true : false );
    424 
    425             if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
     440
     441            READ_FLAG( uiCode, "cross_component_prediction_enabled_flag");
     442              ppsRangeExtension.setCrossComponentPredictionEnabledFlag(uiCode != 0);
     443
     444            READ_FLAG( uiCode, "chroma_qp_offset_list_enabled_flag");
     445            if (uiCode == 0)
    426446            {
    427               READ_FLAG(uiCode, "dlt_bit_map_rep_flag[ layerId ]");
    428               bDltBitMapRepFlag = (uiCode == 1) ? true : false;
     447                ppsRangeExtension.clearChromaQpOffsetList();
     448                ppsRangeExtension.setDiffCuChromaQpOffsetDepth(0);
    429449            }
    430450            else
    431451            {
    432               bDltBitMapRepFlag = false;
     452                READ_UVLC(uiCode, "diff_cu_chroma_qp_offset_depth"); ppsRangeExtension.setDiffCuChromaQpOffsetDepth(uiCode);
     453              UInt tableSizeMinus1 = 0;
     454              READ_UVLC(tableSizeMinus1, "chroma_qp_offset_list_len_minus1");
     455              assert(tableSizeMinus1 < MAX_QP_OFFSET_LIST_SIZE);
     456
     457              for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx <= (tableSizeMinus1); cuChromaQpOffsetIdx++)
     458              {
     459                Int cbOffset;
     460                Int crOffset;
     461                READ_SVLC(cbOffset, "cb_qp_offset_list[i]");
     462                assert(cbOffset >= -12 && cbOffset <= 12);
     463                READ_SVLC(crOffset, "cr_qp_offset_list[i]");
     464                assert(crOffset >= -12 && crOffset <= 12);
     465                // table uses +1 for index (see comment inside the function)
     466                  ppsRangeExtension.setChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1, cbOffset, crOffset);
     467              }
     468                assert(ppsRangeExtension.getChromaQpOffsetListLen() == tableSizeMinus1 + 1);
     469            }
     470
     471            READ_UVLC( uiCode, "log2_sao_offset_scale_luma");
     472              ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, uiCode);
     473            READ_UVLC( uiCode, "log2_sao_offset_scale_chroma");
     474              ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, uiCode);
     475            }
     476            break;
     477          default:
     478            bSkipTrailingExtensionBits=true;
     479            break;
     480        }
     481      }
     482    }
     483    if (bSkipTrailingExtensionBits)
     484    {
     485      while ( xMoreRbspData() )
     486      {
     487        READ_FLAG( uiCode, "pps_extension_data_flag");
     488      }
     489    }
     490#endif
     491  }
     492  xReadRbspTrailingBits();
     493}
     494
     495#if NH_3D
     496Void TDecCavlc::parsePps3dExtension( TComPPS* pcPPS )
     497{
     498#if NH_3D_DLT
     499  UInt uiCode = 0;
     500  //
     501  TComDLT* pcDLT = pcPPS->getDLT();
     502
     503  READ_FLAG(uiCode, "dlts_present_flag");
     504  pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
     505
     506  if ( pcDLT->getDltPresentFlag() )
     507  {
     508    READ_CODE(6, uiCode, "pps_depth_layers_minus1");
     509#if NH_3D_VER141_DEC_COMP_FLAG
     510    pcDLT->setNumDepthViews( uiCode );
     511#else
     512    pcDLT->setNumDepthViews( uiCode+1 );
     513#endif
     514   
     515    READ_CODE(4, uiCode, "pps_bit_depth_for_depth_layers_minus8");
     516    pcDLT->setDepthViewBitDepth( (uiCode+8) );
     517   
     518#if NH_3D_DLT_FIX
     519    for( Int i = 0; i <= pcDLT->getNumDepthViews()-1; i++ )
     520#else
     521    for( Int i = 0; i <= pcDLT->getNumDepthViews(); i++ )
     522#endif
     523    {
     524      Int layerId = pcDLT->getDepthIdxToLayerId(i);
     525     
     526      READ_FLAG(uiCode, "dlt_flag[i]");
     527      pcDLT->setUseDLTFlag(layerId, (uiCode == 1) ? true : false);
     528     
     529      if ( pcDLT->getUseDLTFlag( layerId ) )
     530      {
     531        Bool bDltBitMapRepFlag    = false;
     532        UInt uiMaxDiff            = MAX_INT;
     533        UInt uiMinDiff            = 0;
     534        UInt uiCodeLength         = 0;
     535       
     536        READ_FLAG(uiCode, "dlt_pred_flag[i]");
     537       
     538        if( uiCode )
     539        {
     540          assert( pcDLT->getUseDLTFlag( 1 ));
     541        }
     542        pcDLT->setInterViewDltPredEnableFlag( layerId, (uiCode == 1) ? true : false );
     543       
     544        if ( pcDLT->getInterViewDltPredEnableFlag( layerId ) == false )
     545        {
     546          READ_FLAG(uiCode, "dlt_val_flags_present_flag[i]");
     547          bDltBitMapRepFlag = (uiCode == 1) ? true : false;
     548        }
     549        else
     550        {
     551          bDltBitMapRepFlag = false;
     552        }
     553       
     554        UInt uiNumDepthValues = 0;
     555        std::vector<Int> aiIdx2DepthValue(256, 0);
     556       
     557        // Bit map
     558        if ( bDltBitMapRepFlag )
     559        {
     560          for (UInt d=0; d<256; d++)
     561          {
     562            READ_FLAG(uiCode, "dlt_value_flag[i][j]");
     563            if (uiCode == 1)
     564            {
     565              aiIdx2DepthValue[uiNumDepthValues] = d;
     566              uiNumDepthValues++;
     567            }
     568          }
     569        }
     570        // Diff Coding
     571        else
     572        {
     573          READ_CODE(8, uiNumDepthValues, "num_val_delta_dlt");   // num_entry
     574         
     575          {
     576            // 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.
     577           
     578            if (uiNumDepthValues > 1)
     579            {
     580              READ_CODE(8, uiCode, "max_diff");
     581              uiMaxDiff = uiCode;
     582            }
     583            else
     584            {
     585              uiMaxDiff = 0;           // when there is only one value in DLT
    433586            }
    434587           
    435             UInt uiNumDepthValues = 0;
    436             Int  aiIdx2DepthValue[256];
    437 
    438             // Bit map
    439             if ( bDltBitMapRepFlag )
     588            if (uiNumDepthValues > 2)
    440589            {
    441               for (UInt d=0; d<256; d++)
     590              uiCodeLength = (UInt) gCeilLog2(uiMaxDiff + 1);
     591              READ_CODE(uiCodeLength, uiCode, "min_diff_minus1");
     592              uiMinDiff = uiCode + 1;
     593            }
     594            else
     595            {
     596              uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
     597            }
     598           
     599            READ_CODE(8, uiCode, "delta_dlt_val0");   // entry0
     600            aiIdx2DepthValue[0] = uiCode;
     601           
     602            if (uiMaxDiff == uiMinDiff)
     603            {
     604              for (UInt d=1; d<uiNumDepthValues; d++)
    442605              {
    443                 READ_FLAG(uiCode, "dlt_bit_map_flag[ layerId ][ j ]");
    444                 if (uiCode == 1)
    445                 {
    446                   aiIdx2DepthValue[uiNumDepthValues] = d;
    447                   uiNumDepthValues++;
    448                 }
     606                aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
    449607              }
    450608            }
    451             // Diff Coding
    452609            else
    453610            {
    454               READ_CODE(8, uiNumDepthValues, "num_depth_values_in_dlt[i]");   // num_entry
    455 
     611              uiCodeLength = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1);
     612              for (UInt d=1; d<uiNumDepthValues; d++)
    456613              {
    457                 // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
    458 
    459                 if (uiNumDepthValues > 1)
    460                 {
    461                   READ_CODE(8, uiCode, "max_diff[ layerId ]");
    462                   uiMaxDiff = uiCode;
    463                 }
    464                 else
    465                 {
    466                   uiMaxDiff = 0;           // when there is only one value in DLT
    467                 }
    468 
    469                 if (uiNumDepthValues > 2)
    470                 {
    471                   uiCodeLength = (UInt) ceil(Log2(uiMaxDiff + 1));
    472                   READ_CODE(uiCodeLength, uiCode, "min_diff_minus1[ layerId ]");
    473                   uiMinDiff = uiCode + 1;
    474                 }
    475                 else
    476                 {
    477                   uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
    478                 }
    479 
    480                 READ_CODE(8, uiCode, "dlt_depth_value0[layerId]");   // entry0
    481                 aiIdx2DepthValue[0] = uiCode;
    482 
    483                 if (uiMaxDiff == uiMinDiff)
    484                 {
    485                   for (UInt d=1; d<uiNumDepthValues; d++)
    486                   {
    487                     aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
    488                   }
    489                 }
    490                 else
    491                 {
    492                   uiCodeLength = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
    493                   for (UInt d=1; d<uiNumDepthValues; d++)
    494                   {
    495                     READ_CODE(uiCodeLength, uiCode, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");
    496                     aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
    497                   }
    498                 }
    499 
     614                READ_CODE(uiCodeLength, uiCode, "delta_val_diff_minus_min[k]");
     615                aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
    500616              }
    501617            }
    502618           
    503             if( pcDLT->getInterViewDltPredEnableFlag( i ) )
    504             {
    505               // interpret decoded values as delta DLT
    506               AOF( pcVPS->getDepthId( 1 ) == 1 );
    507               AOF( i > 1 );
    508               // assumes ref layer id to be 1
    509               Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
    510               UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
    511               pcDLT->setDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
    512             }
    513             else
    514             {
    515               // store final DLT
    516               pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
    517             }
    518 
    519619          }
    520620        }
    521       }
    522     }
    523   }
    524 
    525   pcPPS->setDLT( pcDLT );
    526 }
    527 #endif
     621       
     622        if( pcDLT->getInterViewDltPredEnableFlag( layerId ) )
     623        {
     624          // interpret decoded values as delta DLT
     625          AOF( layerId > 1 );
     626          // assumes ref layer id to be 1
     627          std::vector<Int> viRefDLT = pcDLT->idx2DepthValue( 1 );
     628          UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
     629          pcDLT->setDeltaDLT(layerId, viRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
     630        }
     631        else
     632        {
     633          // store final DLT
     634          pcDLT->setDepthLUTs(layerId, aiIdx2DepthValue, uiNumDepthValues);
     635        }
     636      }
     637    }
     638  }
     639#endif
     640}
     641#endif
     642
    528643
    529644Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
     
    541656    {
    542657      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
    543       READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
     658      READ_CODE(16, uiCode, "sar_height");                              pcVUI->setSarHeight(uiCode);
    544659    }
    545660  }
     
    552667
    553668  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
    554 #if H_MV
     669#if NH_MV
    555670  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() );
    556671#endif
     
    564679      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
    565680      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
    566       READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
     681      READ_CODE(8, uiCode, "matrix_coeffs");                          pcVUI->setMatrixCoefficients(uiCode);
    567682    }
    568683  }
     
    585700  {
    586701    Window &defDisp = pcVUI->getDefaultDisplayWindow();
    587 #if H_MV
     702#if NH_MV
    588703    defDisp.setScaledFlag( false );
    589704    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
     
    598713#endif
    599714  }
     715
    600716  TimingInfo *timingInfo = pcVUI->getTimingInfo();
    601717  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     
    609725      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    610726    }
    611   READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
    612   if( pcVUI->getHrdParametersPresentFlag() )
    613   {
    614     parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
    615   }
    616   }
     727
     728    READ_FLAG(     uiCode, "vui_hrd_parameters_present_flag");        pcVUI->setHrdParametersPresentFlag(uiCode);
     729    if( pcVUI->getHrdParametersPresentFlag() )
     730    {
     731      parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     732    }
     733  }
     734
    617735  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
    618736  if (pcVUI->getBitstreamRestrictionFlag())
     
    621739    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
    622740    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
    623     READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
     741    READ_UVLC(   uiCode, "min_spatial_segmentation_idc");             pcVUI->setMinSpatialSegmentationIdc(uiCode);
    624742    assert(uiCode < 4096);
    625743    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
    626     READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
     744    READ_UVLC(   uiCode, "max_bits_per_min_cu_denom" );               pcVUI->setMaxBitsPerMinCuDenom(uiCode);
    627745    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
    628746    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
     
    639757    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
    640758    {
    641       READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
     759      READ_FLAG( uiCode, "sub_pic_hrd_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
    642760      if( hrd->getSubPicCpbParamsPresentFlag() )
    643761      {
    644762        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
    645         READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
     763        READ_CODE( 5, uiCode, "du_cpb_removal_delay_increment_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
    646764        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
    647765        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
     
    670788      hrd->setFixedPicRateWithinCvsFlag( i, true );
    671789    }
     790
    672791    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
    673792    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
     793
    674794    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
    675795    {
     
    677797    }
    678798    else
    679     {     
     799    {
    680800      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
    681801    }
    682802    if (!hrd->getLowDelayHrdFlag( i ))
    683803    {
    684       READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
    685     }
     804      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
     805    }
     806
    686807    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    687808    {
     
    707828Void TDecCavlc::parseSPS(TComSPS* pcSPS)
    708829{
    709 #if ENC_DEC_TRACE 
    710   xTraceSPSHeader (pcSPS);
     830#if ENC_DEC_TRACE
     831#if H_MV_ENC_DEC_TRAC
     832  tracePSHeader( "SPS", pcSPS->getLayerId() );
     833#else
     834  xTraceSPSHeader ();
     835#endif
    711836#endif
    712837
     
    714839  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
    715840
    716 #if H_MV
     841#if NH_MV
    717842  if ( pcSPS->getLayerId() == 0 )
    718843  {
    719844#endif
    720     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
    721     assert(uiCode <= 6);
    722 #if H_MV
     845  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     846  assert(uiCode <= 6);
     847#if NH_MV
    723848  }
    724849  else
     
    731856#endif
    732857
    733     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
    734     if ( pcSPS->getMaxTLayers() == 1 )
    735     {
    736       // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
    737       assert( uiCode == 1 );
    738     }
    739 
    740     parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    741 #if H_MV
     858  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );           pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
     859  if ( pcSPS->getMaxTLayers() == 1 )
     860  {
     861    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
     862    assert( uiCode == 1 );
     863  }
     864
     865  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     866#if NH_MV
    742867    pcSPS->getPTL()->inferGeneralValues ( true, 0, NULL );
    743868    pcSPS->getPTL()->inferSubLayerValues( pcSPS->getMaxTLayers() - 1, 0, NULL );
     
    746871  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
    747872  assert(uiCode <= 15);
    748 #if H_MV
     873#if NH_MV
    749874  if ( pcSPS->getMultiLayerExtSpsFlag() )
    750875  {
     
    758883  {
    759884#endif
    760     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
    761     assert(uiCode <= 3);
    762     // 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
    763 #if !H_3D_DISABLE_CHROMA
    764     assert (uiCode == 1);
    765 #endif
    766     if( uiCode == 3 )
    767     {
    768       READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
    769     }
    770 
    771     READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
    772     READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     885
     886  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
     887  assert(uiCode <= 3);
     888  if( pcSPS->getChromaFormatIdc() == CHROMA_444 )
     889  {
     890    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
     891  }
     892
     893  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
     894  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
    773895  READ_FLAG(     uiCode, "conformance_window_flag");
    774896  if (uiCode != 0)
    775897  {
    776898    Window &conf = pcSPS->getConformanceWindow();
    777 #if H_MV
     899#if NH_MV
    778900    // Needs to be scaled later, when ChromaFormatIdc is known.
    779901    conf.setScaledFlag( false );
     
    791913  }
    792914
    793 #if H_MV
     915#if NH_MV
    794916  if ( !pcSPS->getMultiLayerExtSpsFlag() )
    795917  {
    796918#endif
    797     READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    798     assert(uiCode <= 6);
    799     pcSPS->setBitDepthY( uiCode + 8 );
    800     pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
    801 
    802     READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
    803     assert(uiCode <= 6);
    804     pcSPS->setBitDepthC( uiCode + 8 );
    805     pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
    806 #if H_MV
     919
     920  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
     921#if O0043_BEST_EFFORT_DECODING
     922  pcSPS->setStreamBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
     923  const UInt forceDecodeBitDepth = pcSPS->getForceDecodeBitDepth();
     924  if (forceDecodeBitDepth != 0)
     925  {
     926    uiCode = forceDecodeBitDepth - 8;
     927  }
     928#endif
     929  assert(uiCode <= 8);
     930  pcSPS->setBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
     931
     932#if O0043_BEST_EFFORT_DECODING
     933  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*(pcSPS->getStreamBitDepth(CHANNEL_TYPE_LUMA)-8)) );
     934#else
     935  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*uiCode) );
     936#endif
     937
     938  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
     939#if O0043_BEST_EFFORT_DECODING
     940  pcSPS->setStreamBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
     941  if (forceDecodeBitDepth != 0)
     942  {
     943    uiCode = forceDecodeBitDepth - 8;
     944  }
     945#endif
     946  assert(uiCode <= 8);
     947  pcSPS->setBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
     948#if O0043_BEST_EFFORT_DECODING
     949  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*(pcSPS->getStreamBitDepth(CHANNEL_TYPE_CHROMA)-8)) );
     950#else
     951  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*uiCode) );
     952#endif
     953#if NH_MV
    807954  }
    808955#endif
     
    811958  assert(uiCode <= 12);
    812959
    813 #if H_MV
     960#if NH_MV
    814961  if ( !pcSPS->getMultiLayerExtSpsFlag())
    815962  { 
    816963#endif
    817     UInt subLayerOrderingInfoPresentFlag;
    818     READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
    819 
    820     for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    821     {
    822       READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
    823       pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
    824       READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
    825       pcSPS->setNumReorderPics(uiCode, i);
    826       READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
    827       pcSPS->setMaxLatencyIncrease( uiCode, i );
    828 
    829       if (!subLayerOrderingInfoPresentFlag)
    830       {
    831         for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
    832         {
    833           pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
    834           pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
    835           pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
    836         }
    837         break;
    838       }
    839     }
    840 #if H_MV
    841   }
    842 #endif
    843 
    844   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
     964  UInt subLayerOrderingInfoPresentFlag;
     965  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
     966
     967  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     968  {
     969    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
     970    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
     971    READ_UVLC ( uiCode, "sps_max_num_reorder_pics[i]" );
     972    pcSPS->setNumReorderPics(uiCode, i);
     973    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
     974    pcSPS->setMaxLatencyIncrease( uiCode, i );
     975
     976    if (!subLayerOrderingInfoPresentFlag)
     977    {
     978      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
     979      {
     980        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
     981        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
     982        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
     983      }
     984      break;
     985    }
     986  }
     987#if NH_MV
     988  }
     989#endif
     990
     991  READ_UVLC( uiCode, "log2_min_luma_coding_block_size_minus3" );
    845992  Int log2MinCUSize = uiCode + 3;
    846993  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
    847   READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
     994  READ_UVLC( uiCode, "log2_diff_max_min_luma_coding_block_size" );
    848995  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
    849 
     996 
    850997  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
    851998  {
    852999    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
    8531000  }
    854 
     1001 
    8551002  Int maxCUDepthDelta = uiCode;
    856   pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
     1003  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
    8571004  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
    858   READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
    859 
    860   READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
     1005  READ_UVLC( uiCode, "log2_min_luma_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
     1006
     1007  READ_UVLC( uiCode, "log2_diff_max_min_luma_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
    8611008  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
    8621009
     
    8651012
    8661013  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
    867   pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
     1014  pcSPS->setMaxTotalCUDepth( maxCUDepthDelta + addCuDepth  + getMaxCUDepthOffset(pcSPS->getChromaFormatIdc(), pcSPS->getQuadtreeTULog2MinSize()) );
    8681015
    8691016  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
    8701017  if(pcSPS->getScalingListFlag())
    8711018  {
    872 #if H_MV
     1019#if NH_MV
    8731020    if ( pcSPS->getMultiLayerExtSpsFlag() )
    8741021    {   
     
    8831030    {   
    8841031#endif
    885       READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
    886       if(pcSPS->getScalingListPresentFlag ())
    887       {
    888         parseScalingList( pcSPS->getScalingList() );
    889       }
    890 #if H_MV
     1032    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     1033    if(pcSPS->getScalingListPresentFlag ())
     1034    {
     1035      parseScalingList( &(pcSPS->getScalingList()) );
     1036    }
     1037#if NH_MV
    8911038    }
    8921039#endif
     
    8981045  if( pcSPS->getUsePCM() )
    8991046  {
    900     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
    901     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
     1047    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_LUMA, 1 + uiCode );
     1048    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_CHROMA, 1 + uiCode );
    9021049    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
    9031050    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
     
    9181065  }
    9191066  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
    920   if (pcSPS->getLongTermRefsPresent()) 
    921   {
    922     READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
     1067  if (pcSPS->getLongTermRefsPresent())
     1068  {
     1069    READ_UVLC( uiCode, "num_long_term_ref_pics_sps" );
    9231070    pcSPS->setNumLongTermRefPicSPS(uiCode);
    9241071    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
     
    9411088  }
    9421089
    943 
    944 #if H_MV
    9451090  READ_FLAG( uiCode, "sps_extension_present_flag");
     1091#if NH_MV
    9461092  pcSPS->setSpsExtensionPresentFlag( uiCode );
    9471093  if (pcSPS->getSpsExtensionPresentFlag( ) )
     1094  { 
     1095    READ_FLAG( uiCode, "sps_range_extensions_flag" );     pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
     1096    READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
     1097    READ_FLAG( uiCode   , "sps_3d_extension_flag" );      pcSPS->setSps3dExtensionFlag( uiCode == 1 );
     1098    READ_CODE( 5, uiCode, "sps_extension_5bits" )  ;      pcSPS->setSpsExtension5bits( uiCode );
     1099
     1100    if ( pcSPS->getSpsRangeExtensionsFlag() )
     1101    {
     1102              TComSPSRExt &spsRangeExtension = pcSPS->getSpsRangeExtension();
     1103              READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     spsRangeExtension.setTransformSkipRotationEnabledFlag(uiCode != 0);
     1104              READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      spsRangeExtension.setTransformSkipContextEnabledFlag (uiCode != 0);
     1105              READ_FLAG( uiCode, "implicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
     1106              READ_FLAG( uiCode, "explicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
     1107              READ_FLAG( uiCode, "extended_precision_processing_flag");       spsRangeExtension.setExtendedPrecisionProcessingFlag (uiCode != 0);
     1108              READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            spsRangeExtension.setIntraSmoothingDisabledFlag      (uiCode != 0);
     1109              READ_FLAG( uiCode, "high_precision_offsets_enabled_flag");      spsRangeExtension.setHighPrecisionOffsetsEnabledFlag (uiCode != 0);
     1110              READ_FLAG( uiCode, "persistent_rice_adaptation_enabled_flag");  spsRangeExtension.setPersistentRiceAdaptationEnabledFlag (uiCode != 0);
     1111              READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      spsRangeExtension.setCabacBypassAlignmentEnabledFlag  (uiCode != 0);
     1112    }
     1113
     1114    if ( pcSPS->getSpsMultilayerExtensionFlag() )
     1115    {
     1116      parseSpsMultilayerExtension( pcSPS );
     1117    }
     1118
     1119    if ( pcSPS->getSps3dExtensionFlag() )
     1120    {
     1121#if NH_3D
     1122      parseSps3dExtension( pcSPS );
     1123#endif
     1124    }
     1125
     1126#if NH_3D
     1127    if ( pcSPS->getSpsExtension5bits() )
    9481128#else
    949   READ_FLAG( uiCode, "sps_extension_flag");
     1129    if ( pcSPS->getSpsExtension5bits() || pcSPS->getSps3dExtensionFlag() )
     1130#endif
     1131    {
     1132      while ( xMoreRbspData() )
     1133      {
     1134        READ_FLAG( uiCode, "sps_extension_data_flag");
     1135      }
     1136    }
     1137  }
     1138#else
    9501139  if (uiCode)
    951 #endif
    952   {
    953 #if H_MV
    954     READ_FLAG( uiCode, "sps_range_extensions_flag" ); pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
    955     READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
    956 #if !H_3D
    957     READ_CODE( 6, uiCode, "sps_extension_6bits" ); pcSPS->setSpsExtension6bits( uiCode );
    958 #else
    959     READ_FLAG( uiCode, "sps_3d_extension_flag" ); pcSPS->setSps3dExtensionFlag( uiCode == 1 );
    960     READ_CODE( 5, uiCode, "sps_extension_5bits" ); pcSPS->setSpsExtension5bits( uiCode );
    961 #endif
    962   }
    963 
    964   if ( pcSPS->getSpsRangeExtensionsFlag() )
    965   {
    966     assert( 0 );
    967   }
    968 
    969   if ( pcSPS->getSpsMultilayerExtensionFlag() )
    970   {
    971     parseSPSExtension( pcSPS );
    972   }
    973 
    974 #if H_3D
    975   if ( pcSPS->getSps3dExtensionFlag() )
    976   {
    977     parseSPS3dExtension( pcSPS );
    978   }
    979 
    980   if ( pcSPS->getSpsExtension5bits() )
    981   {
    982 #else
    983   if ( pcSPS->getSpsExtension6bits() )
    984   {
    985 #endif
    986 
    987 #endif
    988     while ( xMoreRbspData() )
    989     {
    990       READ_FLAG( uiCode, "sps_extension_data_flag");
    991     }
    992   }
    993 }
    994 
    995 #if H_MV
    996 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
     1140  {
     1141
     1142#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     1143    static const char *syntaxStrings[]={ "sps_range_extension_flag",
     1144                                         "sps_multilayer_extension_flag",
     1145                                         "sps_extension_6bits[0]",
     1146                                         "sps_extension_6bits[1]",
     1147                                         "sps_extension_6bits[2]",
     1148                                         "sps_extension_6bits[3]",
     1149                                         "sps_extension_6bits[4]",
     1150                                         "sps_extension_6bits[5]" };
     1151#endif
     1152    Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS];
     1153
     1154    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
     1155    {
     1156      READ_FLAG( uiCode, syntaxStrings[i] );
     1157      sps_extension_flags[i] = uiCode!=0;
     1158    }
     1159
     1160    Bool bSkipTrailingExtensionBits=false;
     1161    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     1162    {
     1163      if (sps_extension_flags[i])
     1164      {
     1165        switch (SPSExtensionFlagIndex(i))
     1166        {
     1167          case SPS_EXT__REXT:
     1168            assert(!bSkipTrailingExtensionBits);
     1169            {
     1170              TComSPSRExt &spsRangeExtension = pcSPS->getSpsRangeExtension();
     1171              READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     spsRangeExtension.setTransformSkipRotationEnabledFlag(uiCode != 0);
     1172              READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      spsRangeExtension.setTransformSkipContextEnabledFlag (uiCode != 0);
     1173              READ_FLAG( uiCode, "implicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
     1174              READ_FLAG( uiCode, "explicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
     1175              READ_FLAG( uiCode, "extended_precision_processing_flag");       spsRangeExtension.setExtendedPrecisionProcessingFlag (uiCode != 0);
     1176              READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            spsRangeExtension.setIntraSmoothingDisabledFlag      (uiCode != 0);
     1177              READ_FLAG( uiCode, "high_precision_offsets_enabled_flag");      spsRangeExtension.setHighPrecisionOffsetsEnabledFlag (uiCode != 0);
     1178              READ_FLAG( uiCode, "persistent_rice_adaptation_enabled_flag");  spsRangeExtension.setPersistentRiceAdaptationEnabledFlag (uiCode != 0);
     1179              READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      spsRangeExtension.setCabacBypassAlignmentEnabledFlag  (uiCode != 0);
     1180            }
     1181            break;
     1182          default:
     1183            bSkipTrailingExtensionBits=true;
     1184            break;
     1185        }
     1186      }
     1187    }
     1188    if (bSkipTrailingExtensionBits)
     1189    {
     1190      while ( xMoreRbspData() )
     1191      {
     1192        READ_FLAG( uiCode, "sps_extension_data_flag");
     1193      }
     1194    }
     1195  }
     1196#endif
     1197  xReadRbspTrailingBits();
     1198}
     1199
     1200#if NH_MV
     1201Void TDecCavlc::parseSpsMultilayerExtension( TComSPS* pcSPS )
    9971202{
    9981203  UInt uiCode;
    999   READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
    1000  
    1001 }
    1002 
    1003 #if H_3D
    1004 Void TDecCavlc::parseSPS3dExtension( TComSPS* pcSPS )
     1204  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false); 
     1205}
     1206
     1207#if NH_3D
     1208Void TDecCavlc::parseSps3dExtension( TComSPS* pcSPS )
    10051209{
    1006   TComSps3dExtension* sps3dExt = pcSPS->getSps3dExtension();
     1210  TComSps3dExtension sps3dExt;
    10071211  UInt uiCode;
    10081212  for( Int d = 0; d  <=  1; d++ )
    10091213  {
    1010     READ_FLAG( uiCode, "iv_mv_pred_flag" ); sps3dExt->setIvMvPredFlag( d, uiCode == 1 );
    1011     READ_FLAG( uiCode, "iv_mv_scaling_flag" ); sps3dExt->setIvMvScalingFlag( d, uiCode == 1 );
     1214    READ_FLAG( uiCode, "iv_mv_pred_flag" ); sps3dExt.setIvMvPredFlag( d, uiCode == 1 );
     1215    READ_FLAG( uiCode, "iv_mv_scaling_flag" ); sps3dExt.setIvMvScalingFlag( d, uiCode == 1 );
    10121216    if( d  ==  0 )
    10131217    {
    1014       READ_UVLC( uiCode, "log2_sub_pb_size_minus3" ); sps3dExt->setLog2SubPbSizeMinus3( d, uiCode );
    1015       READ_FLAG( uiCode, "iv_res_pred_flag" ); sps3dExt->setIvResPredFlag( d, uiCode == 1 );
    1016       READ_FLAG( uiCode, "depth_refinement_flag" ); sps3dExt->setDepthRefinementFlag( d, uiCode == 1 );
    1017       READ_FLAG( uiCode, "view_synthesis_pred_flag" ); sps3dExt->setViewSynthesisPredFlag( d, uiCode == 1 );
    1018       READ_FLAG( uiCode, "depth_based_blk_part_flag" ); sps3dExt->setDepthBasedBlkPartFlag( d, uiCode == 1 );
     1218      READ_UVLC( uiCode, "log2_sub_pb_size_minus3" ); sps3dExt.setLog2SubPbSizeMinus3( d, uiCode );
     1219      READ_FLAG( uiCode, "iv_res_pred_flag" ); sps3dExt.setIvResPredFlag( d, uiCode == 1 );
     1220      READ_FLAG( uiCode, "depth_refinement_flag" ); sps3dExt.setDepthRefinementFlag( d, uiCode == 1 );
     1221      READ_FLAG( uiCode, "view_synthesis_pred_flag" ); sps3dExt.setViewSynthesisPredFlag( d, uiCode == 1 );
     1222      READ_FLAG( uiCode, "depth_based_blk_part_flag" ); sps3dExt.setDepthBasedBlkPartFlag( d, uiCode == 1 );
    10191223    }
    10201224    else
    10211225    {
    1022       READ_FLAG( uiCode, "mpi_flag" ); sps3dExt->setMpiFlag( d, uiCode == 1 );
    1023       READ_UVLC( uiCode, "log2_mpi_sub_pb_size_minus3" ); sps3dExt->setLog2MpiSubPbSizeMinus3( d, uiCode );
    1024       READ_FLAG( uiCode, "intra_contour_flag" ); sps3dExt->setIntraContourFlag( d, uiCode == 1 );
    1025       READ_FLAG( uiCode, "intra_sdc_wedge_flag" ); sps3dExt->setIntraSdcWedgeFlag( d, uiCode == 1 );
    1026       READ_FLAG( uiCode, "qt_pred_flag" ); sps3dExt->setQtPredFlag( d, uiCode == 1 );
    1027       READ_FLAG( uiCode, "inter_sdc_flag" ); sps3dExt->setInterSdcFlag( d, uiCode == 1 );
    1028       READ_FLAG( uiCode, "intra_skip_flag" ); sps3dExt->setDepthIntraSkipFlag( d, uiCode == 1 );
    1029     }
    1030   }
    1031 }
    1032 #endif
    1033 
    1034 Void TDecCavlc::parsePPSMultilayerExtension(TComPPS* pcPPS)
     1226      READ_FLAG( uiCode, "mpi_flag" ); sps3dExt.setMpiFlag( d, uiCode == 1 );
     1227      READ_UVLC( uiCode, "log2_mpi_sub_pb_size_minus3" ); sps3dExt.setLog2MpiSubPbSizeMinus3( d, uiCode );
     1228      READ_FLAG( uiCode, "intra_contour_flag" ); sps3dExt.setIntraContourFlag( d, uiCode == 1 );
     1229      READ_FLAG( uiCode, "intra_sdc_wedge_flag" ); sps3dExt.setIntraSdcWedgeFlag( d, uiCode == 1 );
     1230      READ_FLAG( uiCode, "qt_pred_flag" ); sps3dExt.setQtPredFlag( d, uiCode == 1 );
     1231      READ_FLAG( uiCode, "inter_sdc_flag" ); sps3dExt.setInterSdcFlag( d, uiCode == 1 );
     1232      READ_FLAG( uiCode, "intra_skip_flag" ); sps3dExt.setDepthIntraSkipFlag( d, uiCode == 1 );
     1233    }
     1234  }
     1235  pcSPS->setSps3dExtension( sps3dExt );
     1236}
     1237#endif
     1238
     1239Void TDecCavlc::parsePpsMultilayerExtension(TComPPS* pcPPS)
    10351240{
    10361241  UInt uiCode = 0;
     
    10871292Void TDecCavlc::parseVPS(TComVPS* pcVPS)
    10881293{
     1294#if ENC_DEC_TRACE
     1295#if H_MV_ENC_DEC_TRAC
     1296  tracePSHeader( "VPS", getDecTop()->getLayerId() );
     1297#else
     1298  xTraceVPSHeader ();
     1299#endif
     1300#endif
     1301
    10891302  UInt  uiCode;
    1090  
     1303
    10911304  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
    1092 #if H_MV
     1305#if NH_MV
    10931306  READ_FLAG( uiCode, "vps_base_layer_internal_flag" );            pcVPS->setVpsBaseLayerInternalFlag( uiCode == 1 );
    10941307  READ_FLAG( uiCode, "vps_base_layer_available_flag" );           pcVPS->setVpsBaseLayerAvailableFlag( uiCode == 1 );
    10951308#else
    1096   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
    1097 #endif
    1098 #if H_MV
     1309  READ_FLAG( uiCode,      "vps_base_layer_internal_flag" );       assert(uiCode == 1);
     1310  READ_FLAG( uiCode,      "vps_base_layer_available_flag" );      assert(uiCode == 1);
     1311#endif
     1312#if NH_MV
    10991313  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
    11001314#else
    1101   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
     1315  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );
    11021316#endif
    11031317  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
    11041318  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    11051319  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
    1106 
    1107   READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
     1320  READ_CODE( 16, uiCode,  "vps_reserved_0xffff_16bits" );         assert(uiCode == 0xffff);
    11081321  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
    1109 #if H_MV
     1322#if NH_MV
    11101323  pcVPS->getPTL()->inferGeneralValues ( true, 0, NULL );
    11111324  pcVPS->getPTL()->inferSubLayerValues( pcVPS->getMaxTLayers() - 1, 0, NULL );
     
    11151328  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
    11161329  {
    1117     READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
    1118     READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
     1330    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );    pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
     1331    READ_UVLC( uiCode,  "vps_max_num_reorder_pics[i]" );            pcVPS->setNumReorderPics( uiCode, i );
    11191332    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
    11201333
     
    11321345
    11331346  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
    1134 #if H_MV
     1347#if NH_MV
    11351348  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
    11361349  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
     
    11421355#else
    11431356  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
    1144   READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
    1145   READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
     1357  READ_CODE( 6, uiCode, "vps_max_layer_id" );                        pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
     1358  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
    11461359  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
    11471360  {
     
    11501363#endif
    11511364    {
    1152       READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
    1153     }
    1154   }
    1155 #if H_MV
     1365      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
     1366    }
     1367  }
     1368#if NH_MV
    11561369  pcVPS->deriveLayerSetLayerIdList();
    11571370#endif
     1371
    11581372  TimingInfo *timingInfo = pcVPS->getTimingInfo();
    11591373  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     
    11671381      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    11681382    }
     1383
    11691384    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
    11701385
     
    11751390    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
    11761391    {
    1177       READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
     1392      READ_UVLC( uiCode, "hrd_layer_set_idx[i]" );                  pcVPS->setHrdOpSetIdx( uiCode, i );
    11781393      if( i > 0 )
    11791394      {
    1180         READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
     1395        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
    11811396      }
    11821397      else
     
    11881403    }
    11891404  }
    1190 #if H_MV
     1405#if NH_MV
    11911406  READ_FLAG( uiCode,  "vps_extension_flag" );                      pcVPS->setVpsExtensionFlag( uiCode == 1 ? true : false );
    11921407  if ( pcVPS->getVpsExtensionFlag() )
     
    11961411#endif
    11971412  {
    1198 #if H_MV
     1413#if NH_MV
    11991414    m_pcBitstream->readOutTrailingBits();
    12001415    parseVPSExtension( pcVPS );   
     
    12021417    if (uiCode)
    12031418    {
    1204 #if H_3D
     1419#if NH_3D
    12051420      READ_FLAG( uiCode,  "vps_3d_extension_flag" );
    12061421      if ( uiCode )
     
    12081423        m_pcBitstream->readOutTrailingBits();
    12091424        pcVPS->createCamPars(pcVPS->getNumViews());
    1210         parseVPS3dExtension( pcVPS );   
     1425        parseVps3dExtension( pcVPS );   
    12111426      }
    12121427      READ_FLAG( uiCode,  "vps_extension3_flag" );
     
    12191434          READ_FLAG( uiCode, "vps_extension_data_flag");
    12201435        }
    1221 #if H_MV
    1222 #if H_3D
    1223       }
    1224 #endif
    1225     }
    1226 #endif
    1227   }
    1228   return;
    1229 }
    1230 
    1231 #if H_MV
     1436#if NH_MV
     1437#if NH_3D
     1438      }
     1439#endif
     1440    }
     1441#endif
     1442  }
     1443
     1444  xReadRbspTrailingBits();
     1445}
     1446
     1447#if NH_MV
    12321448Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
    12331449{
     
    13061522  }
    13071523
    1308 #if H_3D
     1524#if NH_3D
    13091525  pcVPS->initViewCompLayer( );
    13101526#endif
     
    14411657  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
    14421658
     1659  std::vector<TComRepFormat> repFormats;
     1660  repFormats.resize( pcVPS->getVpsNumRepFormatsMinus1() + 1 );
    14431661  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
    1444   {
    1445     assert( pcVPS->getRepFormat(i) == NULL );
    1446     TComRepFormat* curRepFormat = new TComRepFormat();
    1447     TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL;
    1448     parseRepFormat( i, curRepFormat ,  prevRepFormat);
    1449     pcVPS->setRepFormat(i, curRepFormat );
    1450   }
     1662  {     
     1663    TComRepFormat* curRepFormat = &repFormats[i];
     1664    TComRepFormat* prevRepFormat = i > 0 ? &repFormats[ i - 1] : NULL;
     1665    parseRepFormat( i, curRepFormat ,  prevRepFormat);     
     1666  }
     1667  pcVPS->setRepFormat( repFormats );
    14511668
    14521669  if ( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
     
    15141731  }
    15151732  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
     1733 
     1734  TComVPSVUI vpsVui;
    15161735  if( pcVPS->getVpsVuiPresentFlag() )
    15171736  {
    15181737    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
    1519     parseVPSVUI( pcVPS );
     1738    parseVPSVUI( pcVPS, &vpsVui );
    15201739  }     
    15211740  else
    1522   {
    1523     TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1524     assert( pcVPSVUI );
    1525     pcVPSVUI->inferVpsVui( false );
    1526   }
     1741  {   
     1742    // inference of syntax elements that differ from default inference (as done in constructor), when VPS VUI is not present   
     1743    vpsVui.setCrossLayerIrapAlignedFlag( false );
     1744  }
     1745  pcVPS->setVPSVUI( vpsVui );
    15271746  pcVPS->checkVPSExtensionSyntax();
    15281747}
    15291748
    1530 Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
     1749Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, const TComRepFormat* pcPrevRepFormat )
    15311750{
    15321751  assert( pcRepFormat );
     
    15521771  else
    15531772  {
    1554     pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false );
     1773    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat );
    15551774  }
    15561775  READ_FLAG( uiCode, "conformance_window_vps_flag" ); pcRepFormat->setConformanceWindowVpsFlag( uiCode == 1 );
     
    15651784
    15661785
    1567 Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
     1786Void TDecCavlc::parseVPSVUI( const TComVPS* pcVPS, TComVPSVUI* vpsVui )
    15681787{
    15691788  assert( pcVPS );
    1570 
    1571   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1572 
    1573   assert( pcVPSVUI );
     1789  assert( vpsVui );
     1790 
     1791  vpsVui->init(pcVPS->getNumAddLayerSets(),pcVPS->getMaxSubLayersMinus1() + 1, pcVPS->getMaxLayersMinus1() + 1 ); 
    15741792
    15751793  UInt uiCode;
    1576   READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
    1577   if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
     1794  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); vpsVui->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
     1795  if ( !vpsVui->getCrossLayerPicTypeAlignedFlag() )
    15781796  { 
    1579     READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
    1580   }
    1581   if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
    1582   {
    1583     READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
    1584   }
    1585   READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
    1586   READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
    1587   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
     1797    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); vpsVui->setCrossLayerIrapAlignedFlag( uiCode == 1 );
     1798  }
     1799  if( vpsVui->getCrossLayerIrapAlignedFlag( ) )
     1800  {
     1801    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); vpsVui->setAllLayersIdrAlignedFlag( uiCode == 1 );
     1802  }
     1803  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); vpsVui->setBitRatePresentVpsFlag( uiCode == 1 );
     1804  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); vpsVui->setPicRatePresentVpsFlag( uiCode == 1 );
     1805  if( vpsVui->getBitRatePresentVpsFlag( )  ||  vpsVui->getPicRatePresentVpsFlag( ) )
    15881806  {
    15891807    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <  pcVPS->getNumLayerSets(); i++ )
     
    15911809      for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ )
    15921810      {
    1593         if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
    1594         {
    1595           READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
    1596         }
    1597         if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
    1598         {
    1599           READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
    1600         }
    1601         if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
    1602         {
    1603           READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
    1604           READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
    1605         }
    1606         if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
    1607         {
    1608           READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
    1609           READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
    1610         }
    1611       }
    1612     }
    1613   }
    1614 
    1615   READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
    1616   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
    1617   {
    1618     READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
     1811        if( vpsVui->getBitRatePresentVpsFlag( ) )
     1812        {
     1813          READ_FLAG( uiCode, "bit_rate_present_flag" ); vpsVui->setBitRatePresentFlag( i, j, uiCode == 1 );           
     1814        }
     1815        if( vpsVui->getPicRatePresentVpsFlag( )  )
     1816        {
     1817          READ_FLAG( uiCode, "pic_rate_present_flag" ); vpsVui->setPicRatePresentFlag( i, j, uiCode == 1 );
     1818        }
     1819        if( vpsVui->getBitRatePresentFlag( i, j ) )
     1820        {
     1821          READ_CODE( 16, uiCode, "avg_bit_rate" ); vpsVui->setAvgBitRate( i, j, uiCode );
     1822          READ_CODE( 16, uiCode, "max_bit_rate" ); vpsVui->setMaxBitRate( i, j, uiCode );
     1823        }
     1824        if( vpsVui->getPicRatePresentFlag( i, j ) )
     1825        {
     1826          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); vpsVui->setConstantPicRateIdc( i, j, uiCode );
     1827          READ_CODE( 16, uiCode, "avg_pic_rate" );          vpsVui->setAvgPicRate( i, j, uiCode );
     1828        }
     1829      }
     1830    }
     1831  }
     1832
     1833  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vpsVui->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
     1834  if( vpsVui->getVideoSignalInfoIdxPresentFlag() )
     1835  {
     1836    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); vpsVui->setVpsNumVideoSignalInfoMinus1( uiCode );
    16191837  }
    16201838  else
    16211839  {
    1622     pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1 );
    1623   }
    1624 
    1625   for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
    1626   {
    1627     assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL );
    1628     TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
    1629     parseVideoSignalInfo( curVideoSignalInfo );
    1630     pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo );
    1631   }
    1632 
    1633   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
     1840    vpsVui->setVpsNumVideoSignalInfoMinus1( (pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag()) ? 0 : 1 );
     1841  }
     1842
     1843  std::vector<TComVideoSignalInfo> videoSignalInfos;
     1844  videoSignalInfos.resize(vpsVui->getVpsNumVideoSignalInfoMinus1() + 1 );
     1845
     1846  for( Int i = 0; i <= vpsVui->getVpsNumVideoSignalInfoMinus1(); i++ )
     1847  {
     1848    parseVideoSignalInfo( &videoSignalInfos[i] );     
     1849  }
     1850  vpsVui->setVideoSignalInfo( videoSignalInfos );
     1851
     1852  if( vpsVui->getVideoSignalInfoIdxPresentFlag() && vpsVui->getVpsNumVideoSignalInfoMinus1() > 0 )
    16341853  {
    16351854    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16361855    {
    1637       READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
    1638     }
    1639   }
    1640   else if ( !pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     1856      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); vpsVui->setVpsVideoSignalInfoIdx( i, uiCode );
     1857    }
     1858  }
     1859  else if ( !vpsVui->getVideoSignalInfoIdxPresentFlag() )
    16411860  {
    16421861    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16431862    {
    1644       pcVPSVUI->setVpsVideoSignalInfoIdx( i, i );
     1863      vpsVui->setVpsVideoSignalInfoIdx( i, i );
    16451864    }
    16461865  }
     
    16491868    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16501869    {
    1651       pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 );
    1652     }
    1653   }
    1654 
    1655   READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
    1656   if( !pcVPSVUI->getTilesNotInUseFlag() )
     1870      vpsVui->setVpsVideoSignalInfoIdx( i, 0 );
     1871    }
     1872  }
     1873
     1874  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vpsVui->setTilesNotInUseFlag( uiCode == 1 );
     1875  if( !vpsVui->getTilesNotInUseFlag() )
    16571876  {     
    16581877    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
    16591878    {
    1660       READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
    1661       if( pcVPSVUI->getTilesInUseFlag( i ) ) 
    1662       {
    1663         READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
     1879      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); vpsVui->setTilesInUseFlag( i, uiCode == 1 );
     1880      if( vpsVui->getTilesInUseFlag( i ) ) 
     1881      {
     1882        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); vpsVui->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
    16641883      }
    16651884    } 
     
    16691888      {
    16701889        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getIdDirectRefLayer(pcVPS->getLayerIdInNuh( i ) , j  )); 
    1671         if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
    1672         {
    1673           READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
     1890        if( vpsVui->getTilesInUseFlag( i )  &&  vpsVui->getTilesInUseFlag( layerIdx ) ) 
     1891        {
     1892          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vpsVui->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
    16741893        }
    16751894      } 
     
    16771896  } 
    16781897 
    1679   READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
     1898  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vpsVui->setWppNotInUseFlag( uiCode == 1 );
    16801899 
    1681   if( !pcVPSVUI->getWppNotInUseFlag( ))
     1900  if( !vpsVui->getWppNotInUseFlag( ))
    16821901  {
    16831902    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
    16841903    {
    1685       READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
    1686     }
    1687   }
    1688   READ_FLAG( uiCode, "single_layer_for_non_irap_flag" ); pcVPSVUI->setSingleLayerForNonIrapFlag( uiCode == 1 );
    1689   READ_FLAG( uiCode, "higher_layer_irap_skip_flag" ); pcVPSVUI->setHigherLayerIrapSkipFlag( uiCode == 1 );
    1690   READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
    1691 
    1692   if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
     1904      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); vpsVui->setWppInUseFlag( i, uiCode == 1 );
     1905    }
     1906  }
     1907  READ_FLAG( uiCode, "single_layer_for_non_irap_flag" ); vpsVui->setSingleLayerForNonIrapFlag( uiCode == 1 );
     1908  READ_FLAG( uiCode, "higher_layer_irap_skip_flag" ); vpsVui->setHigherLayerIrapSkipFlag( uiCode == 1 );
     1909  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vpsVui->setIlpRestrictedRefLayersFlag( uiCode == 1 );
     1910
     1911  if( vpsVui->getIlpRestrictedRefLayersFlag( ) )
    16931912  {
    16941913    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     
    16981917        if( pcVPS->getVpsBaseLayerInternalFlag() || pcVPS->getIdDirectRefLayer( pcVPS->getLayerIdInNuh( i ), j ) > 0 )
    16991918        {       
    1700           READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
    1701           if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
     1919          READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); vpsVui->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
     1920          if( vpsVui->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
    17021921          {
    1703             READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
    1704             if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
     1922            READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); vpsVui->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
     1923            if( vpsVui->getCtuBasedOffsetEnabledFlag( i, j ) )
    17051924            {
    1706               READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
     1925              READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); vpsVui->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
    17071926            }
    17081927          }
     
    17121931  }
    17131932
    1714   READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
    1715   if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
    1716   {
    1717     assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);
    1718     parseVpsVuiBspHrdParameters( pcVPS );
     1933  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); vpsVui->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
     1934  if ( vpsVui->getVpsVuiBspHrdPresentFlag( ) )
     1935  {
     1936    assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);   
     1937    parseVpsVuiBspHrdParameters( pcVPS, vpsVui );   
    17191938  }
    17201939  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     
    17221941    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 )
    17231942    {
    1724       READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
    1725     }
    1726   }
    1727 }
    1728 
    1729 Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
    1730 {
    1731   assert( pcVPS );
    1732 
    1733   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1734 
    1735   assert( pcVPSVUI );
    1736 
    1737   TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters();
    1738   assert( vpsVuiBspHrdP == NULL );
    1739   vpsVuiBspHrdP = new TComVpsVuiBspHrdParameters;
    1740   pcVPSVUI->setVpsVuiBspHrdParameters( vpsVuiBspHrdP );
     1943      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); vpsVui->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
     1944    }
     1945  } 
     1946}
     1947
     1948Void TDecCavlc::parseVpsVuiBspHrdParameters( const TComVPS* pcVPS, TComVPSVUI* vpsVui )
     1949{
     1950  assert( pcVPS  );
     1951  assert( vpsVui );
     1952
     1953  TComVpsVuiBspHrdParameters  vpsVuiBspHrdP;   
     1954 
    17411955  UInt uiCode;
    1742   READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vpsVuiBspHrdP->setVpsNumAddHrdParams( uiCode );
    1743   vpsVuiBspHrdP->createAfterVpsNumAddHrdParams( pcVPS );
    1744   for( Int i = pcVPS->getNumHrdParameters(); i < pcVPS->getNumHrdParameters() + vpsVuiBspHrdP->getVpsNumAddHrdParams(); i++ )
     1956  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vpsVuiBspHrdP.setVpsNumAddHrdParams( uiCode );
     1957  vpsVuiBspHrdP.createAfterVpsNumAddHrdParams( pcVPS );
     1958  for( Int i = pcVPS->getNumHrdParameters(); i < pcVPS->getNumHrdParameters() + vpsVuiBspHrdP.getVpsNumAddHrdParams(); i++ )
    17451959  { 
    17461960    if( i > 0 ) 
    17471961    {
    1748       READ_FLAG( uiCode, "cprms_add_present_flag" ); vpsVuiBspHrdP->setCprmsAddPresentFlag( i, uiCode == 1 );
     1962      READ_FLAG( uiCode, "cprms_add_present_flag" ); vpsVuiBspHrdP.setCprmsAddPresentFlag( i, uiCode == 1 );
    17491963    }
    17501964    else
    17511965    {
    1752        vpsVuiBspHrdP->setCprmsAddPresentFlag( i, true );
    1753     }
    1754 
    1755     READ_UVLC( uiCode, "num_sub_layer_hrd_minus1" ); vpsVuiBspHrdP->setNumSubLayerHrdMinus1( i, uiCode );
    1756     TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i );
    1757     parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getCprmsAddPresentFlag( i ), vpsVuiBspHrdP->getNumSubLayerHrdMinus1( i ) );     
    1758   }
    1759 
    1760   vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( 0, 0, 0);
    1761   vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( 0, 0 );
     1966       vpsVuiBspHrdP.setCprmsAddPresentFlag( i, true );
     1967    }
     1968
     1969    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1" ); vpsVuiBspHrdP.setNumSubLayerHrdMinus1( i, uiCode );
     1970   
     1971    TComHRD hrdParameters;
     1972    parseHrdParameters( &hrdParameters, vpsVuiBspHrdP.getCprmsAddPresentFlag( i ), vpsVuiBspHrdP.getNumSubLayerHrdMinus1( i ) );     
     1973    vpsVuiBspHrdP.setHrdParametermeters( i, hrdParameters );
     1974  }
     1975
     1976  vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( 0, 0, 0);
     1977  vpsVuiBspHrdP.createAfterNumPartitionsInSchemeMinus1( pcVPS, 0, 0 );
    17621978
    17631979  for( Int h = 0; h < pcVPS->getNumOutputLayerSets(); h++ )
     
    17651981    if ( h == 0)
    17661982    {
    1767       vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, 0 );
     1983      vpsVuiBspHrdP.setNumSignalledPartitioningSchemes( h, 0 );
    17681984    }
    17691985    else
    17701986    {
    1771       READ_UVLC( uiCode, "num_signalled_partitioning_schemes" ); vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, uiCode );
     1987      READ_UVLC( uiCode, "num_signalled_partitioning_schemes" ); vpsVuiBspHrdP.setNumSignalledPartitioningSchemes( h, uiCode );
    17721988    }   
    1773     vpsVuiBspHrdP->createAfterNumSignalledPartitioningSchemes( h );
    1774 
    1775     for( Int j = 0; j < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; j++ )
     1989    vpsVuiBspHrdP.createAfterNumSignalledPartitioningSchemes( pcVPS, h );
     1990
     1991    for( Int j = 0; j < vpsVuiBspHrdP.getNumSignalledPartitioningSchemes( h ) + 1; j++ )
    17761992    {
    17771993      if ( j == 0 && h == 0 )
    17781994      {
    1779         vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
     1995        vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, uiCode );
    17801996      }
    17811997      else if( j == 0 )
    17821998      {
    1783         vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, pcVPS->getNumLayersInIdList( h ) - 1 );
     1999        vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, pcVPS->getNumLayersInIdList( h ) - 1 );
    17842000      }
    17852001      else
    17862002      {
    1787         READ_UVLC( uiCode, "num_partitions_in_scheme_minus1" ); vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
    1788       }
    1789       vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( h, j );
    1790 
    1791       for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ ) 
     2003        READ_UVLC( uiCode, "num_partitions_in_scheme_minus1" ); vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, uiCode );
     2004      }
     2005      vpsVuiBspHrdP.createAfterNumPartitionsInSchemeMinus1(pcVPS, h, j );
     2006
     2007      for( Int k = 0; k  <=  vpsVuiBspHrdP.getNumPartitionsInSchemeMinus1( h, j ); k++ ) 
    17922008      {
    17932009        for( Int r = 0; r < pcVPS->getNumLayersInIdList(pcVPS->olsIdxToLsIdx( h ) )   ; r++ ) 
     
    17952011          if( h == 0 && j == 0 && k == 0 && r == 0 )
    17962012          {
    1797              vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, true );
     2013             vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, true );
    17982014          }
    17992015          else if ( h > 0 && j == 0 )
    18002016          {
    1801              vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, (k == r) );
     2017             vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, (k == r) );
    18022018          }
    18032019          else
    18042020          {
    1805             READ_FLAG( uiCode, "layer_included_in_partition_flag" ); vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, uiCode == 1 );
     2021            READ_FLAG( uiCode, "layer_included_in_partition_flag" ); vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, uiCode == 1 );
    18062022          }         
    18072023        }
     
    18102026    if ( h > 0 )
    18112027    {
    1812       for( Int i = 0; i < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; i++ ) 
     2028      for( Int i = 0; i < vpsVuiBspHrdP.getNumSignalledPartitioningSchemes( h ) + 1; i++ ) 
    18132029      {
    18142030        for( Int t = 0; t  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( pcVPS->olsIdxToLsIdx( i ) ); t++ )
    18152031        { 
    1816           READ_UVLC( uiCode, "num_bsp_schedules_minus1" ); vpsVuiBspHrdP->setNumBspSchedulesMinus1( h, i, t, uiCode );
    1817           vpsVuiBspHrdP->createAfterNumBspSchedulesMinus1( h, i, t );
    1818           for( Int j = 0; j  <=  vpsVuiBspHrdP->getNumBspSchedulesMinus1( h, i, t ); j++ ) 
     2032          READ_UVLC( uiCode, "num_bsp_schedules_minus1" ); vpsVuiBspHrdP.setNumBspSchedulesMinus1( h, i, t, uiCode );
     2033          vpsVuiBspHrdP.createAfterNumBspSchedulesMinus1(pcVPS, h, i, t );
     2034          for( Int j = 0; j  <=  vpsVuiBspHrdP.getNumBspSchedulesMinus1( h, i, t ); j++ ) 
    18192035          {
    1820             for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ )
     2036            for( Int k = 0; k  <=  vpsVuiBspHrdP.getNumPartitionsInSchemeMinus1( h, j ); k++ )
    18212037            { 
    1822               READ_CODE( vpsVuiBspHrdP->getBspHrdIdxLen( pcVPS ), uiCode, "bsp_hrd_idx" ); vpsVuiBspHrdP->setBspHrdIdx( h, i, t, j, k, uiCode );
    1823               READ_UVLC( uiCode, "bsp_sched_idx" ); vpsVuiBspHrdP->setBspSchedIdx( h, i, t, j, k, uiCode );
     2038              READ_CODE( vpsVuiBspHrdP.getBspHrdIdxLen( pcVPS ), uiCode, "bsp_hrd_idx" ); vpsVuiBspHrdP.setBspHrdIdx( h, i, t, j, k, uiCode );
     2039              READ_UVLC( uiCode, "bsp_sched_idx" ); vpsVuiBspHrdP.setBspSchedIdx( h, i, t, j, k, uiCode );
    18242040            } 
    18252041          }
     
    18282044    }
    18292045  } 
     2046  vpsVui->setVpsVuiBspHrdParameters( vpsVuiBspHrdP );
    18302047}
    18312048
     
    18432060{
    18442061  UInt uiCode;
    1845   TComDpbSize* dpbSize = vps->getDpbSize();
    1846   assert ( dpbSize != 0 );
     2062  TComDpbSize dpbSize;
     2063 
     2064  dpbSize.init( vps->getNumOutputLayerSets(), vps->getVpsMaxLayerId() + 1, vps->getMaxSubLayersMinus1() + 1 ) ;
    18472065
    18482066  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
    18492067  { 
    18502068    Int currLsIdx = vps->olsIdxToLsIdx( i );
    1851     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
     2069    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize.setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
    18522070    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
    18532071    { 
    1854       if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
    1855       {
    1856         READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
    1857       }
    1858       if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
     2072      if( j > 0  &&  dpbSize.getSubLayerDpbInfoPresentFlag( i, j )  ) 
     2073      {
     2074        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize.setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
     2075      }
     2076      if( dpbSize.getSubLayerDpbInfoPresentFlag( i, j ) )
    18592077      { 
    18602078        for( Int k = 0; k < vps->getNumLayersInIdList( currLsIdx ); k++ )   
     
    18622080          if ( vps->getNecessaryLayerFlag( i, k ) && ( vps->getVpsBaseLayerInternalFlag() || ( vps->getLayerSetLayerIdList(vps->olsIdxToLsIdx(i),k) != 0 ) ))
    18632081          {
    1864             READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
     2082            READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
    18652083          }
    18662084          else
     
    18682086            if ( vps->getNecessaryLayerFlag( i, k ) && ( j == 0 ) && ( k == 0 ))
    18692087            {
    1870               dpbSize->setMaxVpsDecPicBufferingMinus1(i ,k, j, 0 );
     2088              dpbSize.setMaxVpsDecPicBufferingMinus1(i ,k, j, 0 );
    18712089            }
    18722090          }
    18732091        }
    1874         READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
    1875         READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
     2092        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize.setMaxVpsNumReorderPics( i, j, uiCode );
     2093        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
    18762094      }
    18772095      else
     
    18832101            if ( vps->getNecessaryLayerFlag(i, k ) )
    18842102            {           
    1885               dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
     2103              dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize.getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
    18862104            }
    18872105          }
    1888           dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
    1889           dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
     2106          dpbSize.setMaxVpsNumReorderPics      ( i, j, dpbSize.getMaxVpsNumReorderPics      ( i, j - 1 ) );
     2107          dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, dpbSize.getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
    18902108        }
    18912109      }
    18922110    } 
    18932111  } 
    1894 }
    1895 
    1896 #if H_3D
    1897 Void TDecCavlc::parseVPS3dExtension( TComVPS* pcVPS )
     2112  vps->setDpbSize( dpbSize );
     2113}
     2114
     2115#if NH_3D
     2116Void TDecCavlc::parseVps3dExtension( TComVPS* pcVPS )
    18982117{
    18992118  UInt uiCode;   
     
    19292148#endif
    19302149#endif
    1931 #if H_MV
    1932 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx)
    1933 #else
    1934 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
    1935 #endif
     2150
     2151Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)
    19362152{
    19372153  UInt  uiCode;
     
    19392155
    19402156#if ENC_DEC_TRACE
    1941   xTraceSliceHeader(rpcSlice);
     2157#if NH_MV
     2158  tracePSHeader( "Slice", pcSlice->getLayerId() );
     2159#else
     2160  xTraceSliceHeader();
     2161#endif
    19422162#endif
    19432163  TComPPS* pps = NULL;
    19442164  TComSPS* sps = NULL;
    1945 #if H_MV
     2165#if NH_MV
    19462166  TComVPS* vps = NULL;
    19472167#endif
     
    19492169  UInt firstSliceSegmentInPic;
    19502170  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
    1951   if( rpcSlice->getRapPicFlag())
    1952   { 
     2171  if( pcSlice->getRapPicFlag())
     2172  {
    19532173    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
    1954 #if SETTING_NO_OUT_PIC_PRIOR
    1955     rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
    1956 #else
    1957     rpcSlice->setNoOutputPicPrior( false );
    1958 #endif
    1959   }
    1960 
    1961   READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
    1962   pps = parameterSetManager->getPrefetchedPPS(uiCode);
     2174    pcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
     2175  }
     2176  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  pcSlice->setPPSId(uiCode);
     2177  pps = parameterSetManager->getPPS(uiCode);
    19632178  //!KS: need to add error handling code here, if PPS is not available
    19642179  assert(pps!=0);
    1965   sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
     2180  sps = parameterSetManager->getSPS(pps->getSPSId());
    19662181  //!KS: need to add error handling code here, if SPS is not available
    19672182  assert(sps!=0);
    1968 #if H_MV
    1969   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
    1970   assert( vps != NULL );
    1971  
    1972   sps->inferRepFormat  ( vps , rpcSlice->getLayerId() );
     2183#if NH_MV 
     2184  vps = parameterSetManager->getVPS(sps->getVPSId());
     2185  assert( vps != NULL ); 
     2186  m_decTop->initFromActiveVps( vps );
     2187  Int targetOlsIdx = m_decTop->getTargetOlsIdx();
     2188
     2189  // Do inference
     2190  sps->inferRepFormat  ( vps , pcSlice->getLayerId(), false );
    19732191  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
    1974   sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, rpcSlice->getLayerId(), false );
     2192  sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, pcSlice->getLayerId(), false );
     2193
     2194  if( sps->getMultiLayerExtSpsFlag() )
     2195  {
     2196    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
     2197  }
    19752198
    19762199  if ( sps->getVuiParametersPresentFlag() )
    19772200  {
    1978     sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() );
    1979   }
    1980   rpcSlice->setVPS(vps);     
    1981   rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
    1982   rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
    1983 #if H_3D 
    1984   rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
    1985 #endif
    1986 #endif
    1987   rpcSlice->setSPS(sps);
    1988   rpcSlice->setPPS(pps);
     2201    sps->getVuiParameters()->inferVideoSignalInfo( vps, pcSlice->getLayerId() );
     2202  }
     2203
     2204
     2205  pcSlice->setVPS(vps);     
     2206  pcSlice->setSPS(sps);
     2207  pcSlice->setPPS(pps);
     2208
     2209  pcSlice->setViewId   ( vps->getViewId   ( pcSlice->getLayerId() )      );
     2210  pcSlice->setViewIndex( vps->getViewIndex( pcSlice->getLayerId() )      ); 
     2211#if NH_3D
     2212  pcSlice->setIsDepth  ( vps->getDepthId  ( pcSlice->getLayerId() ) == 1 );
     2213#endif
     2214#endif
     2215
     2216  const ChromaFormat chFmt = sps->getChromaFormatIdc();
     2217  const UInt numValidComp=getNumberValidComponents(chFmt);
     2218  const Bool bChroma=(chFmt!=CHROMA_400);
     2219
    19892220  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
    19902221  {
    1991     READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
     2222    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       pcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
    19922223  }
    19932224  else
    19942225  {
    1995     rpcSlice->setDependentSliceSegmentFlag(false);
     2226    pcSlice->setDependentSliceSegmentFlag(false);
    19962227  }
    19972228  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
    1998   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
    19992229  UInt sliceSegmentAddress = 0;
    20002230  Int bitsSliceSegmentAddress = 0;
     
    20092239  }
    20102240  //set uiCode to equal slice start address (or dependent slice start address)
    2011   Int startCuAddress = maxParts*sliceSegmentAddress;
    2012   rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
    2013   rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
    2014 
    2015   if (rpcSlice->getDependentSliceSegmentFlag())
    2016   {
    2017     rpcSlice->setNextSlice          ( false );
    2018     rpcSlice->setNextSliceSegment ( true  );
    2019   }
    2020   else
    2021   {
    2022     rpcSlice->setNextSlice          ( true  );
    2023     rpcSlice->setNextSliceSegment ( false );
    2024 
    2025     rpcSlice->setSliceCurStartCUAddr(startCuAddress);
    2026     rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
    2027   }
    2028  
    2029 #if H_MV
     2241  pcSlice->setSliceSegmentCurStartCtuTsAddr( sliceSegmentAddress );// this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     2242  pcSlice->setSliceSegmentCurEndCtuTsAddr(numCTUs);                // Set end as the last CTU of the picture.
     2243
     2244#if NH_MV
    20302245    UInt slicePicOrderCntLsb = 0;
    20312246#endif
    20322247
    2033   if(!rpcSlice->getDependentSliceSegmentFlag())
    2034   {
    2035 #if H_MV   
     2248
     2249  if (!pcSlice->getDependentSliceSegmentFlag())
     2250  {
     2251    pcSlice->setSliceCurStartCtuTsAddr(sliceSegmentAddress); // this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     2252    pcSlice->setSliceCurEndCtuTsAddr(numCTUs);
     2253  }
     2254
     2255  if(!pcSlice->getDependentSliceSegmentFlag())
     2256  {
     2257#if NH_MV   
    20362258    Int esb = 0; //Don't use i, otherwise will shadow something below
    20372259
    2038     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     2260    if ( pps->getNumExtraSliceHeaderBits() > esb )
    20392261    {
    20402262      esb++;
    2041       READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
     2263      READ_FLAG( uiCode, "discardable_flag" ); pcSlice->setDiscardableFlag( uiCode == 1 );
    20422264      if ( uiCode == 1 )
    20432265      {
    2044         assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
    2045           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
    2046           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
    2047           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
    2048           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
    2049       }
    2050     }
    2051 
    2052     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     2266        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
     2267          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
     2268          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
     2269          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
     2270          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
     2271      }
     2272    }
     2273
     2274    if ( pps->getNumExtraSliceHeaderBits() > esb )
    20532275    {
    20542276      esb++;
    2055       READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
    2056     }
    2057     rpcSlice->checkCrossLayerBlaFlag( );
    2058 
    2059 
    2060     for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
     2277      READ_FLAG( uiCode, "cross_layer_bla_flag" ); pcSlice->setCrossLayerBlaFlag( uiCode == 1 );
     2278    }
     2279    pcSlice->checkCrossLayerBlaFlag( );
     2280
     2281
     2282    for (; esb < pps->getNumExtraSliceHeaderBits(); esb++)   
    20612283#else
    2062     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
    2063 #endif     
    2064     {
    2065       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
    2066     }
    2067 
    2068     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
     2284    for (Int i = 0; i < pps->getNumExtraSliceHeaderBits(); i++)
     2285#endif
     2286    {
     2287      READ_FLAG(uiCode, "slice_reserved_flag[]"); // ignored
     2288    }
     2289
     2290    READ_UVLC (    uiCode, "slice_type" );            pcSlice->setSliceType((SliceType)uiCode);
    20692291    if( pps->getOutputFlagPresentFlag() )
    20702292    {
    2071       READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
     2293      READ_FLAG( uiCode, "pic_output_flag" );    pcSlice->setPicOutputFlag( uiCode ? true : false );
    20722294    }
    20732295    else
    20742296    {
    2075       rpcSlice->setPicOutputFlag( true );
    2076     }
    2077     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
    2078 
    2079 #if H_3D_DISABLE_CHROMA
    2080     assert (sps->getChromaFormatIdc() == 1 || rpcSlice->getIsDepth() );
    2081     assert (sps->getChromaFormatIdc() == 0 || !rpcSlice->getIsDepth() );
    2082 #else
    2083     assert (sps->getChromaFormatIdc() == 1 );
    2084 #endif
    2085     // if( separate_colour_plane_flag  ==  1 )
    2086     //   colour_plane_id                                      u(2)
    2087 
    2088 
    2089 #if H_MV
     2297      pcSlice->setPicOutputFlag( true );
     2298    }
     2299
     2300    // if (separate_colour_plane_flag == 1)
     2301    //   read colour_plane_id
     2302    //   (separate_colour_plane_flag == 1) is not supported in this version of the standard.
     2303
     2304#if NH_MV
    20902305    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
    2091     if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
     2306    if ( (pcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( pcSlice->getLayerIdInVps())) || !pcSlice->getIdrPicFlag() )
    20922307    {
    20932308      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
    20942309    }   
    2095     rpcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb );
     2310    pcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb );
    20962311
    20972312    Bool picOrderCntMSBZeroFlag = false;     
    20982313
    20992314    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
    2100     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   );
    2101     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL );
    2102     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   );
    2103     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag();
     2315    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   );
     2316    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL );
     2317    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   );
     2318    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   pcSlice->getIdrPicFlag();
    21042319
    21052320    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
     
    21092324    if ( !picOrderCntMSBZeroFlag )
    21102325    {
    2111       Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
     2326      Int prevPicOrderCnt    = prevTid0POC;
    21122327      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
    21132328      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
     
    21282343    }
    21292344     
    2130     rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
    2131     if ( rpcSlice->getPocResetFlag() ) 
    2132     {
    2133       rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() );
    2134       rpcSlice->setPOC              ( 0 );
     2345    pcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
     2346    if ( pcSlice->getPocResetFlag() ) 
     2347    {
     2348      pcSlice->setPocBeforeReset   ( pcSlice->getPOC() );
     2349      pcSlice->setPOC              ( 0 );
    21352350    }     
    21362351#endif
    21372352
    2138     if( rpcSlice->getIdrPicFlag() )
    2139     {
    2140 #if !H_MV
    2141       rpcSlice->setPOC(0);
    2142 #endif
    2143       TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
    2144       rps->setNumberOfNegativePictures(0);
    2145       rps->setNumberOfPositivePictures(0);
    2146       rps->setNumberOfLongtermPictures(0);
    2147       rps->setNumberOfPictures(0);
    2148       rpcSlice->setRPS(rps);
    2149 #if H_MV
    2150       rpcSlice->setEnableTMVPFlag(false);
     2353    if( pcSlice->getIdrPicFlag() )
     2354    {
     2355#if !NH_MV
     2356      pcSlice->setPOC(0);
     2357#endif
     2358      TComReferencePictureSet* rps = pcSlice->getLocalRPS();
     2359      (*rps)=TComReferencePictureSet();
     2360      pcSlice->setRPS(rps);
     2361#if NH_MV
     2362      pcSlice->setEnableTMVPFlag(false);
    21512363#endif
    21522364    }
    21532365    else
    21542366    {
    2155 #if !H_MV
    2156       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
     2367#if !NH_MV
     2368      READ_CODE(sps->getBitsForPOC(), uiCode, "slice_pic_order_cnt_lsb");
    21572369      Int iPOClsb = uiCode;
    2158       Int iPrevPOC = rpcSlice->getPrevTid0POC();
     2370      Int iPrevPOC = prevTid0POC;
    21592371      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
    21602372      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
     
    21652377        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
    21662378      }
    2167       else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
     2379      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
    21682380      {
    21692381        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
     
    21732385        iPOCmsb = iPrevPOCmsb;
    21742386      }
    2175       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    2176         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    2177         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     2387      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     2388        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     2389        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    21782390      {
    21792391        // For BLA picture types, POCmsb is set to 0.
    21802392        iPOCmsb = 0;
    21812393      }
    2182       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
     2394      pcSlice->setPOC              (iPOCmsb+iPOClsb);
    21832395#endif
    21842396      TComReferencePictureSet* rps;
    2185       rps = rpcSlice->getLocalRPS();
    2186       rpcSlice->setRPS(rps);
     2397      rps = pcSlice->getLocalRPS();
     2398      (*rps)=TComReferencePictureSet();
     2399
     2400      pcSlice->setRPS(rps);
    21872401      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
    21882402      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
    2189       {       
     2403      {
    21902404        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
    2191 #if H_MV
     2405#if NH_MV
    21922406        if ( !rps->getInterRPSPrediction( ) )
    21932407        { // check sum of num_positive_pics and num_negative_pics
     
    21952409            vps->getVpsExtensionFlag(),
    21962410            MAX_INT,  // To be replaced by MaxDbpSize
    2197             rpcSlice->getLayerId(),
     2411            pcSlice->getLayerId(),
    21982412            sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
    21992413        }
    22002414#endif
     2415
    22012416      }
    22022417      else // use reference to short-term reference picture set in PPS
    22032418      {
    22042419        Int numBits = 0;
    2205         while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     2420        while ((1 << numBits) < sps->getRPSList()->getNumberOfReferencePictureSets())
    22062421        {
    22072422          numBits++;
     
    22142429        {
    22152430          uiCode = 0;
     2431       
    22162432        }
    22172433        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
     
    22222438        UInt numOfLtrp = 0;
    22232439        UInt numLtrpInSPS = 0;
    2224         if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     2440        if (sps->getNumLongTermRefPicSPS() > 0)
    22252441        {
    22262442          READ_UVLC( uiCode, "num_long_term_sps");
     
    22302446        }
    22312447        Int bitsForLtrpInSPS = 0;
    2232         while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     2448        while (sps->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
    22332449        {
    22342450          bitsForLtrpInSPS++;
     
    22372453        numOfLtrp += uiCode;
    22382454        rps->setNumberOfLongtermPictures(numOfLtrp);
    2239         Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
    2240         Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
     2455        Int maxPicOrderCntLSB = 1 << sps->getBitsForPOC();
     2456        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
    22412457        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
    22422458        {
     
    22492465              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
    22502466            }
    2251             Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
    2252 
    2253             pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
     2467            Bool usedByCurrFromSPS=sps->getUsedByCurrPicLtSPSFlag(uiCode);
     2468
     2469            pocLsbLt = sps->getLtRefPicPocLsbSps(uiCode);
    22542470            rps->setUsed(j,usedByCurrFromSPS);
    22552471          }
    22562472          else
    22572473          {
    2258             READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
     2474            READ_CODE(sps->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
    22592475            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
    22602476          }
    22612477          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
    22622478          Bool mSBPresentFlag = uiCode ? true : false;
    2263           if(mSBPresentFlag)                 
     2479          if(mSBPresentFlag)
    22642480          {
    22652481            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
     
    22762492            else
    22772493            {
    2278               deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
     2494              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
    22792495            }
    22802496
    2281             Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
     2497            Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
    22822498                                        - iPOClsb + pocLsbLt;
    2283             rps->setPOC     (j, pocLTCurr); 
    2284             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
    2285             rps->setCheckLTMSBPresent(j,true); 
     2499            rps->setPOC     (j, pocLTCurr);
     2500            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
     2501            rps->setCheckLTMSBPresent(j,true);
    22862502          }
    22872503          else
    22882504          {
    22892505            rps->setPOC     (j, pocLsbLt);
    2290             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
    2291             rps->setCheckLTMSBPresent(j,false); 
    2292            
     2506            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLsbLt);
     2507            rps->setCheckLTMSBPresent(j,false);
     2508
    22932509            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
    22942510            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
     
    23002516        }
    23012517        offset += rps->getNumberOfLongtermPictures();
    2302         rps->setNumberOfPictures(offset);       
    2303       } 
    2304 #if H_MV
     2518        rps->setNumberOfPictures(offset);
     2519      }
     2520#if NH_MV
    23052521      if ( !rps->getInterRPSPrediction( ) )
    23062522      { // check sum of NumPositivePics, NumNegativePics, num_long_term_sps and num_long_term_pics
     
    23082524          vps->getVpsExtensionFlag(),
    23092525            MAX_INT,  // To be replaced by MaxDbpsize
    2310           rpcSlice->getLayerId(),
     2526          pcSlice->getLayerId(),
    23112527          sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
    23122528      }
    23132529#endif
    2314       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    2315         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    2316         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     2530
     2531      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     2532        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     2533        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    23172534      {
    23182535        // In the case of BLA picture types, rps data is read from slice header but ignored
    2319         rps = rpcSlice->getLocalRPS();
    2320         rps->setNumberOfNegativePictures(0);
    2321         rps->setNumberOfPositivePictures(0);
    2322         rps->setNumberOfLongtermPictures(0);
    2323         rps->setNumberOfPictures(0);
    2324         rpcSlice->setRPS(rps);
    2325       }
    2326       if (rpcSlice->getSPS()->getTMVPFlagsPresent())
    2327       {
    2328 #if H_MV
     2536        rps = pcSlice->getLocalRPS();
     2537        (*rps)=TComReferencePictureSet();
     2538        pcSlice->setRPS(rps);
     2539      }
     2540      if (sps->getTMVPFlagsPresent())
     2541      {
     2542#if NH_MV
    23292543        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
    23302544#else
    2331         READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
    2332 #endif
    2333         rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     2545        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
     2546#endif
     2547        pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
    23342548      }
    23352549      else
    23362550      {
    2337         rpcSlice->setEnableTMVPFlag(false);
    2338       }
    2339     }
    2340 #if H_MV
     2551        pcSlice->setEnableTMVPFlag(false);
     2552      }
     2553    }
     2554#if NH_MV
    23412555    Bool interLayerPredLayerIdcPresentFlag = false;
    2342     Int layerId       = rpcSlice->getLayerId();
    2343 #if H_3D
    2344     if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumRefListLayers( layerId ) > 0 )
     2556    Int layerId       = pcSlice->getLayerId();
     2557#if NH_3D
     2558    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumRefListLayers( layerId ) > 0 )
    23452559#else
    2346     if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
     2560    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
    23472561#endif
    23482562    {   
    2349       READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
    2350 #if H_3D
    2351       if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumRefListLayers( layerId ) > 1 )
     2563      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); pcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
     2564#if NH_3D
     2565      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumRefListLayers( layerId ) > 1 )
    23522566#else
    2353       if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
     2567      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
    23542568#endif
    23552569      {           
    23562570        if( !vps->getMaxOneActiveRefLayerFlag()) 
    23572571        {
    2358           READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );