Changeset 1029 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibDecoder


Ignore:
Timestamp:
26 Feb 2015, 00:21:54 (11 years ago)
Author:
seregin
Message:

merge with SHM-upgrade branch

Location:
branches/SHM-dev
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev

  • branches/SHM-dev/source

  • branches/SHM-dev/source/Lib/TLibDecoder/AnnexBread.cpp

    r595 r1029  
    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++;
  • branches/SHM-dev/source/Lib/TLibDecoder/AnnexBread.h

    r713 r1029  
    3939#pragma once
    4040
     41#ifndef __ANNEXBREAD__
     42#define __ANNEXBREAD__
     43
    4144#include <stdint.h>
    4245#include <istream>
     
    7275   * modified externally to this class
    7376   */
    74   void reset()
     77  Void reset()
    7578  {
    7679    m_NumFutureBytes = 0;
     
    154157  }
    155158
     159#if RExt__DECODER_DEBUG_BIT_STATISTICS
     160  UInt GetNumBufferedBytes() const { return m_NumFutureBytes; }
     161#endif
     162
    156163private:
    157164  UInt m_NumFutureBytes; /* number of valid bytes in m_FutureBytes */
     
    185192
    186193//! \}
     194
     195#endif
  • branches/SHM-dev/source/Lib/TLibDecoder/NALread.cpp

    r815 r1029  
    4545#include "TLibCommon/NAL.h"
    4646#include "TLibCommon/TComBitStream.h"
     47#if RExt__DECODER_DEBUG_BIT_STATISTICS
     48#include "TLibCommon/TComCodingStatistics.h"
     49#endif
    4750
    4851using namespace std;
     
    5053//! \ingroup TLibDecoder
    5154//! \{
    52 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
     55static Void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
    5356{
    5457  UInt zeroCount = 0;
     
    6669      it_read++;
    6770      zeroCount = 0;
     71#if RExt__DECODER_DEBUG_BIT_STATISTICS
     72      TComCodingStatistics::IncrementStatisticEP(STATS__EMULATION_PREVENTION_3_BYTES, 8, 0);
     73#endif
    6874      if (it_read == nalUnitBuf.end())
    6975      {
     
    7682  }
    7783  assert(zeroCount == 0);
    78  
     84
    7985  if (isVclNalUnit)
    8086  {
    8187    // Remove cabac_zero_word from payload if present
    8288    Int n = 0;
    83    
     89
    8490    while (it_write[-1] == 0x00)
    8591    {
     
    8793      n++;
    8894    }
    89    
     95
    9096    if (n > 0)
    9197    {
    92       printf("\nDetected %d instances of cabac_zero_word", n/2);     
     98      printf("\nDetected %d instances of cabac_zero_word\n", n/2);
    9399    }
    94100  }
     
    111117#endif
    112118  nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
     119#if RExt__DECODER_DEBUG_BIT_STATISTICS
     120  TComCodingStatistics::IncrementStatisticEP(STATS__NAL_UNIT_HEADER_BITS, 1+6+6+3, 0);
     121#endif
    113122
    114123  if ( nalu.m_temporalId )
     
    143152         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    144153         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
    145          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N
    146          );
     154         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
    147155#else
    148156    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
     
    156164 * a bitstream
    157165 */
    158 void read(InputNALUnit& nalu, vector<uint8_t>& nalUnitBuf)
     166Void read(InputNALUnit& nalu, vector<uint8_t>& nalUnitBuf)
    159167{
    160168  /* perform anti-emulation prevention */
    161169  TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
    162170  convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0);
    163  
     171
    164172  nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
    165173  nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
  • branches/SHM-dev/source/Lib/TLibDecoder/NALread.h

    r595 r1029  
    3939#pragma once
    4040
     41#ifndef __NALREAD__
     42#define __NALREAD__
     43
    4144#include "TLibCommon/TypeDef.h"
    4245#include "TLibCommon/TComBitStream.h"
     
    5861};
    5962
    60 void read(InputNALUnit& nalu, std::vector<uint8_t>& nalUnitBuf);
     63Void read(InputNALUnit& nalu, std::vector<uint8_t>& nalUnitBuf);
    6164
    6265//! \}
     66
     67#endif
  • branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp

    r912 r1029  
    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 #if P0050_KNEE_FUNCTION_SEI
    96   case SEI::KNEE_FUNCTION_INFO:
    97     fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
    98     break;
    99 #endif
    100 #if Q0074_COLOUR_REMAPPING_SEI
    101   case SEI::COLOUR_REMAPPING_INFO:
    102     fprintf( g_hTrace, "===========Colour Remapping Information SEI message ===========\n");
    103     break;
    104 #endif
    105   case SEI::SOP_DESCRIPTION:
    106     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
    107     break;
    108   case SEI::SCALABLE_NESTING:
    109     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    110     break;
    111 #if SVC_EXTENSION
    112 #if LAYERS_NOT_PRESENT_SEI
    113   case SEI::LAYERS_NOT_PRESENT:
    114     fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
    115     break;
    116 #endif
    117 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    118   case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
    119     fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
    120     break;
    121 #endif
    122 #if SUB_BITSTREAM_PROPERTY_SEI
    123   case SEI::SUB_BITSTREAM_PROPERTY:
    124     fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
    125     break;
    126 #endif
    127 #if O0164_MULTI_LAYER_HRD
    128   case SEI::BSP_NESTING:
    129     fprintf( g_hTrace, "=========== Bitstream parition nesting SEI message ===========\n");
    130     break;
    131   case SEI::BSP_INITIAL_ARRIVAL_TIME:
    132     fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
    133     break;
    134 #if !REMOVE_BSP_HRD_SEI
    135   case SEI::BSP_HRD:
    136     fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
    137     break;
    138 #endif
    139 #endif
    140 #if Q0078_ADD_LAYER_SETS
    141   case SEI::OUTPUT_LAYER_SET_NESTING:
    142     fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
    143     break;
    144   case SEI::VPS_REWRITING:
    145     fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
    146     break;
    147 #endif
    148 #if Q0096_OVERLAY_SEI
    149   case SEI::OVERLAY_INFO:
    150     fprintf( g_hTrace, "=========== Overlay Information SEI message ===========\n");
    151     break;
    152 #endif
    153 #endif //SVC_EXTENSION
    154   default:
    155     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
    156     break;
    157   }
    158 }
    159 #endif
     61  fprintf( g_hTrace, "=========== %s SEI message ===========\n", SEI::getSEIMessageString(payloadType));
     62}
     63#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)      (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     69}
     70
     71Void SEIReader::sei_read_uvlc(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
     72{
     73  READ_UVLC(ruiCode, pSymbolName);
     74  if (pOS)      (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     75}
     76
     77Void SEIReader::sei_read_svlc(std::ostream *pOS, Int& ruiCode, const Char *pSymbolName)
     78{
     79  READ_SVLC(ruiCode, pSymbolName);
     80  if (pOS)      (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
     81}
     82
     83Void SEIReader::sei_read_flag(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
     84{
     85  READ_FLAG(ruiCode, pSymbolName);
     86  if (pOS)      (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << (ruiCode?1:0) << "\n";
     87}
     88
     89static inline Void output_sei_message_header(SEI &sei, std::ostream *pDecodedMessageOutputStream, UInt payloadSize)
     90{
     91  if (pDecodedMessageOutputStream)
     92  {
     93    std::string seiMessageHdr(SEI::getSEIMessageString(sei.payloadType())); seiMessageHdr+=" SEI message";
     94    (*pDecodedMessageOutputStream) << std::setfill('-') << std::setw(seiMessageHdr.size()) << "-" << std::setfill(' ') << "\n" << seiMessageHdr << "\n";
     95  }
     96}
     97
     98#undef READ_CODE
     99#undef READ_SVLC
     100#undef READ_UVLC
     101#undef READ_FLAG
     102
    160103
    161104/**
     
    163106 */
    164107#if LAYERS_NOT_PRESENT_SEI
    165 void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
    166 #else
    167 void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     108Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
     109#else
     110Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    168111#endif
    169112{
     
    174117  {
    175118#if LAYERS_NOT_PRESENT_SEI
    176     xReadSEImessage(seis, nalUnitType, vps, sps);
    177 #else
    178     xReadSEImessage(seis, nalUnitType, sps);
     119    xReadSEImessage(seis, nalUnitType, vps, sps, pDecodedMessageOutputStream);
     120#else
     121    xReadSEImessage(seis, nalUnitType, sps, pDecodedMessageOutputStream);
    179122#endif
    180123    /* SEI messages are an integer number of bytes, something has failed
     
    184127
    185128  UInt rbspTrailingBits;
    186   READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
     129  sei_read_code(NULL, 8, rbspTrailingBits, "rbsp_trailing_bits");
    187130  assert(rbspTrailingBits == 0x80);
    188131}
     
    190133#if O0164_MULTI_LAYER_HRD
    191134#if LAYERS_NOT_PRESENT_SEI
    192 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei)
    193 #else
    194 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei)
     135Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei)
     136#else
     137Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei)
    195138#endif
    196139#else
    197140#if LAYERS_NOT_PRESENT_SEI
    198 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
    199 #else
    200 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     141Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
     142#else
     143Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    201144#endif
    202145#endif
     
    210153  do
    211154  {
    212     READ_CODE (8, val, "payload_type");
     155    sei_read_code(NULL, 8, val, "payload_type");
    213156    payloadType += val;
    214157  } while (val==0xFF);
     
    217160  do
    218161  {
    219     READ_CODE (8, val, "payload_size");
     162    sei_read_code(NULL, 8, val, "payload_size");
    220163    payloadSize += val;
    221164  } while (val==0xFF);
     
    242185    case SEI::USER_DATA_UNREGISTERED:
    243186      sei = new SEIuserDataUnregistered;
    244       xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     187      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
    245188      break;
    246189    case SEI::ACTIVE_PARAMETER_SETS:
    247       sei = new SEIActiveParameterSets; 
    248       xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize);
    249       break; 
     190      sei = new SEIActiveParameterSets;
     191      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize, pDecodedMessageOutputStream);
     192      break;
    250193    case SEI::DECODING_UNIT_INFO:
    251194      if (!sps)
     
    255198      else
    256199      {
    257         sei = new SEIDecodingUnitInfo; 
     200        sei = new SEIDecodingUnitInfo;
    258201#if VPS_VUI_BSP_HRD_PARAMS
    259         xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
    260 #else
    261         xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
    262 #endif
    263       }
    264       break; 
     202        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
     203#else       
     204        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
     205#endif
     206      }
     207      break;
    265208    case SEI::BUFFERING_PERIOD:
    266209      if (!sps)
     
    272215        sei = new SEIBufferingPeriod;
    273216#if VPS_VUI_BSP_HRD_PARAMS
    274         xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
    275 #else
    276         xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
     217        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
     218#else
     219        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
    277220#endif
    278221      }
     
    287230        sei = new SEIPictureTiming;
    288231#if VPS_VUI_BSP_HRD_PARAMS
    289         xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
    290 #else
    291         xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
     232        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
     233#else
     234        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, pDecodedMessageOutputStream);
    292235#endif
    293236      }
     
    295238    case SEI::RECOVERY_POINT:
    296239      sei = new SEIRecoveryPoint;
    297       xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
     240      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize, pDecodedMessageOutputStream);
    298241      break;
    299242    case SEI::FRAME_PACKING:
    300243      sei = new SEIFramePacking;
    301       xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
     244      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
     245      break;
     246    case SEI::SEGM_RECT_FRAME_PACKING:
     247      sei = new SEISegmentedRectFramePacking;
     248      xParseSEISegmentedRectFramePacking((SEISegmentedRectFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
    302249      break;
    303250    case SEI::DISPLAY_ORIENTATION:
    304251      sei = new SEIDisplayOrientation;
    305       xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
     252      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize, pDecodedMessageOutputStream);
    306253      break;
    307254    case SEI::TEMPORAL_LEVEL0_INDEX:
    308255      sei = new SEITemporalLevel0Index;
    309       xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
     256      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize, pDecodedMessageOutputStream);
    310257      break;
    311258    case SEI::REGION_REFRESH_INFO:
    312259      sei = new SEIGradualDecodingRefreshInfo;
    313       xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
     260      xParseSEIRegionRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     261      break;
     262    case SEI::NO_DISPLAY:
     263      sei = new SEINoDisplay;
     264      xParseSEINoDisplay((SEINoDisplay&) *sei, payloadSize, pDecodedMessageOutputStream);
    314265      break;
    315266    case SEI::TONE_MAPPING_INFO:
    316267      sei = new SEIToneMappingInfo;
    317       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
    318       break;
    319 #if P0050_KNEE_FUNCTION_SEI
     268      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     269      break;
     270    case SEI::SOP_DESCRIPTION:
     271      sei = new SEISOPDescription;
     272      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize, pDecodedMessageOutputStream);
     273      break;
     274    case SEI::SCALABLE_NESTING:
     275      sei = new SEIScalableNesting;
     276#if LAYERS_NOT_PRESENT_SEI
     277      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps, pDecodedMessageOutputStream);
     278#else
     279      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps, pDecodedMessageOutputStream);
     280#endif
     281      break;
     282    case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
     283      sei = new SEITempMotionConstrainedTileSets;
     284      xParseSEITempMotionConstraintsTileSets((SEITempMotionConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
     285      break;
     286    case SEI::TIME_CODE:
     287      sei = new SEITimeCode;
     288      xParseSEITimeCode((SEITimeCode&) *sei, payloadSize, pDecodedMessageOutputStream);
     289      break;
     290    case SEI::CHROMA_SAMPLING_FILTER_HINT:
     291      sei = new SEIChromaSamplingFilterHint;
     292      xParseSEIChromaSamplingFilterHint((SEIChromaSamplingFilterHint&) *sei, payloadSize/*, sps*/, pDecodedMessageOutputStream);
     293      //}
     294      break;
    320295    case SEI::KNEE_FUNCTION_INFO:
    321296      sei = new SEIKneeFunctionInfo;
    322       xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize);
    323       break;
    324 #endif
     297      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     298      break;
     299    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
     300      sei = new SEIMasteringDisplayColourVolume;
     301      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
     302      break;
    325303#if Q0074_COLOUR_REMAPPING_SEI
    326304    case SEI::COLOUR_REMAPPING_INFO:
    327305      sei = new SEIColourRemappingInfo;
    328       xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize);
    329       break;
    330 #endif
    331     case SEI::SOP_DESCRIPTION:
    332       sei = new SEISOPDescription;
    333       xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
    334       break;
    335     case SEI::SCALABLE_NESTING:
    336       sei = new SEIScalableNesting;
    337 #if LAYERS_NOT_PRESENT_SEI
    338       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps);
    339 #else
    340       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
    341 #endif
    342       break;
     306      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
     307      break;
     308#endif
    343309#if SVC_EXTENSION
    344310#if LAYERS_NOT_PRESENT_SEI
     
    351317      {
    352318        sei = new SEILayersNotPresent;
    353         xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps);
     319        xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps, pDecodedMessageOutputStream);
    354320      }
    355321      break;
     
    358324    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
    359325      sei = new SEIInterLayerConstrainedTileSets;
    360       xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize);
     326      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
    361327      break;
    362328#endif
     
    365331     sei = new SEISubBitstreamProperty;
    366332#if OLS_IDX_CHK
    367      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, vps);
    368 #else
    369      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
     333     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, vps, pDecodedMessageOutputStream);
     334#else
     335     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, pDecodedMessageOutputStream);
    370336#endif
    371337     break;
     
    375341     sei = new SEIBspNesting;
    376342#if LAYERS_NOT_PRESENT_SEI
    377      xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei);
    378 #else
    379      xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei);
     343     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei, pDecodedMessageOutputStream);
     344#else
     345     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei, pDecodedMessageOutputStream);
    380346#endif
    381347     break;
    382348   case SEI::BSP_INITIAL_ARRIVAL_TIME:
    383349     sei = new SEIBspInitialArrivalTime;
    384      xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei);
     350     xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei, pDecodedMessageOutputStream);
    385351     break;
    386352#if !REMOVE_BSP_HRD_SEI
    387353   case SEI::BSP_HRD:
    388354     sei = new SEIBspHrd;
    389      xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
     355     xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei, pDecodedMessageOutputStream);
    390356     break;
    391357#endif
     
    395361     sei = new SEIOutputLayerSetNesting;
    396362#if LAYERS_NOT_PRESENT_SEI
    397      xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps);
    398 #else
    399      xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps);
     363     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps, pDecodedMessageOutputStream);
     364#else
     365     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps, pDecodedMessageOutputStream);
    400366#endif
    401367     break;
    402368   case SEI::VPS_REWRITING:
    403369     sei = new SEIVPSRewriting;
    404      xParseSEIVPSRewriting((SEIVPSRewriting&)*sei);
     370     xParseSEIVPSRewriting((SEIVPSRewriting&)*sei, pDecodedMessageOutputStream);
    405371     break;
    406372#endif
     
    408374   case SEI::TMVP_CONSTRAINTS:
    409375     sei =  new SEITMVPConstrains;
    410      xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize);
     376     xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize, pDecodedMessageOutputStream);
    411377     break;
    412378#endif
     
    414380   case SEI::FRAME_FIELD_INFO:
    415381     sei =  new SEIFrameFieldInfo;
    416      xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize);
     382     xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
    417383     break;
    418384#endif
     
    420386   case SEI::OVERLAY_INFO:
    421387     sei = new SEIOverlayInfo;
    422      xParseSEIOverlayInfo((SEIOverlayInfo&) *sei, payloadSize);
     388     xParseSEIOverlayInfo((SEIOverlayInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
    423389     break;
    424390#endif
     
    429395      {
    430396        UInt seiByte;
    431         READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
     397        sei_read_code (NULL, 8, seiByte, "unknown prefix SEI payload byte");
    432398      }
    433399      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
     400      if (pDecodedMessageOutputStream)
     401      {
     402        (*pDecodedMessageOutputStream) << "Unknown prefix SEI message (payloadType = " << payloadType << ") was found!\n";
     403      }
     404      break;
    434405    }
    435406  }
     
    440411      case SEI::USER_DATA_UNREGISTERED:
    441412        sei = new SEIuserDataUnregistered;
    442         xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     413        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
    443414        break;
    444415      case SEI::DECODED_PICTURE_HASH:
    445416        sei = new SEIDecodedPictureHash;
    446         xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
     417        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize, pDecodedMessageOutputStream);
    447418        break;
    448419      default:
     
    450421        {
    451422          UInt seiByte;
    452           READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
     423          sei_read_code( NULL, 8, seiByte, "unknown suffix SEI payload byte");
    453424        }
    454425        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
    455     }
    456   }
     426        if (pDecodedMessageOutputStream)
     427        {
     428          (*pDecodedMessageOutputStream) << "Unknown suffix SEI message (payloadType = " << payloadType << ") was found!\n";
     429        }
     430        break;
     431    }
     432  }
     433
    457434  if (sei != NULL)
    458435  {
     
    473450    {
    474451      UInt reservedPayloadExtensionData;
    475       READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
     452      sei_read_code ( pDecodedMessageOutputStream, 1, reservedPayloadExtensionData, "reserved_payload_extension_data");
    476453    }
    477454
     
    488465    {
    489466      UInt reservedPayloadExtensionData;
    490       READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
     467      sei_read_flag ( 0, reservedPayloadExtensionData, "reserved_payload_extension_data");
    491468    }
    492469
    493470    UInt dummy;
    494     READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
     471    sei_read_flag( 0, dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
    495472    while (payloadBitsRemaining)
    496473    {
    497       READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
     474      sei_read_flag( 0, dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
    498475    }
    499476  }
     
    505482}
    506483
    507 #if P0138_USE_ALT_CPB_PARAMS_FLAG
    508 /**
    509  * Check if SEI message contains payload extension
    510  */
    511 Bool SEIReader::xPayloadExtensionPresent()
    512 {
    513   Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
    514   Bool payloadExtensionPresent = false;
    515 
    516   if (payloadBitsRemaining > 8)
    517   {
    518     payloadExtensionPresent = true;
    519   }
    520   else
    521   {
    522     Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
    523     while (payloadBitsRemaining && (finalBits & 1) == 0)
    524     {
    525       payloadBitsRemaining--;
    526       finalBits >>= 1;
    527     }
    528     payloadBitsRemaining--;
    529     if (payloadBitsRemaining > 0)
    530     {
    531       payloadExtensionPresent = true;
    532     }
    533   }
    534 
    535   return payloadExtensionPresent;
    536 }
    537 #endif
    538 
    539484/**
    540485 * parse bitstream bs and unpack a user_data_unregistered SEI message
    541486 * of payloasSize bytes into sei.
    542487 */
    543 Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
    544 {
    545   assert(payloadSize >= 16);
     488
     489Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     490{
     491  assert(payloadSize >= ISO_IEC_11578_LEN);
    546492  UInt val;
    547 
    548   for (UInt i = 0; i < 16; i++)
    549   {
    550     READ_CODE (8, val, "uuid_iso_iec_11578");
     493  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     494
     495  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
     496  {
     497    sei_read_code( pDecodedMessageOutputStream, 8, val, "uuid_iso_iec_11578");
    551498    sei.uuid_iso_iec_11578[i] = val;
    552499  }
    553500
    554   sei.userDataLength = payloadSize - 16;
     501  sei.userDataLength = payloadSize - ISO_IEC_11578_LEN;
    555502  if (!sei.userDataLength)
    556503  {
     
    562509  for (UInt i = 0; i < sei.userDataLength; i++)
    563510  {
    564     READ_CODE (8, val, "user_data" );
     511    sei_read_code( pDecodedMessageOutputStream, 8, val, "user_data" );
    565512    sei.userData[i] = val;
    566513  }
     
    571518 * of payloadSize bytes into sei.
    572519 */
    573 Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
    574 {
     520Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     521{
     522  UInt bytesRead = 0;
     523  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     524
    575525  UInt val;
    576   READ_CODE (8, val, "hash_type");
    577   sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
    578   for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
    579   {
    580     if(SEIDecodedPictureHash::MD5 == sei.method)
    581     {
    582       for (UInt i = 0; i < 16; i++)
    583       {
    584         READ_CODE(8, val, "picture_md5");
    585         sei.digest[yuvIdx][i] = val;
    586       }
    587     }
    588     else if(SEIDecodedPictureHash::CRC == sei.method)
    589     {
    590       READ_CODE(16, val, "picture_crc");
    591       sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
    592       sei.digest[yuvIdx][1] = val & 0xFF;
    593     }
    594     else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
    595     {
    596       READ_CODE(32, val, "picture_checksum");
    597       sei.digest[yuvIdx][0] = (val>>24) & 0xff;
    598       sei.digest[yuvIdx][1] = (val>>16) & 0xff;
    599       sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
    600       sei.digest[yuvIdx][3] =  val      & 0xff;
    601     }
    602   }
    603 }
    604 Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
     526  sei_read_code( pDecodedMessageOutputStream, 8, val, "hash_type");
     527  sei.method = static_cast<SEIDecodedPictureHash::Method>(val); bytesRead++;
     528
     529  const Char *traceString="\0";
     530  switch (sei.method)
     531  {
     532    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
     533    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
     534    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
     535    default: assert(false); break;
     536  }
     537
     538  if (pDecodedMessageOutputStream) (*pDecodedMessageOutputStream) << "  " << std::setw(55) << traceString << ": " << std::hex << std::setfill('0');
     539
     540  sei.m_digest.hash.clear();
     541  for(;bytesRead < payloadSize; bytesRead++)
     542  {
     543    sei_read_code( NULL, 8, val, traceString);
     544    sei.m_digest.hash.push_back((UChar)val);
     545    if (pDecodedMessageOutputStream) (*pDecodedMessageOutputStream) << std::setw(2) << val;
     546  }
     547
     548  if (pDecodedMessageOutputStream) (*pDecodedMessageOutputStream) << std::dec << std::setfill(' ') << "\n";
     549}
     550
     551Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    605552{
    606553  UInt val;
    607   READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
    608   READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
    609   READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
    610   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
     554  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     555
     556  sei_read_code( pDecodedMessageOutputStream, 4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
     557  sei_read_flag( pDecodedMessageOutputStream,    val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag     = (val != 0);
     558  sei_read_flag( pDecodedMessageOutputStream,    val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = (val != 0);
     559  sei_read_uvlc( pDecodedMessageOutputStream,    val, "num_sps_ids_minus1");              sei.numSpsIdsMinus1 = val;
    611560
    612561  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
     
    616565  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
    617566  {
    618     READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val;
     567    sei_read_uvlc( pDecodedMessageOutputStream, val, "active_seq_parameter_set_id[i]");    sei.activeSeqParameterSetId[i] = val;
    619568  }
    620569#if R0247_SEI_ACTIVE
    621570  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
    622571  {
    623     READ_UVLC(val, "layer_sps_idx"); sei.layerSpsIdx[i] = val;
    624   }
    625 #endif
    626   xParseByteAlign();
     572    sei_read_uvlc( pDecodedMessageOutputStream, val, "layer_sps_idx"); sei.layerSpsIdx[i] = val;
     573  }
     574#endif 
    627575}
    628576
    629577#if VPS_VUI_BSP_HRD_PARAMS
    630 Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
    631 #else
    632 Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
     578Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps,std::ostream *pDecodedMessageOutputStream)
     579#else
     580Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    633581#endif
    634582{
    635583  UInt val;
    636   READ_UVLC(val, "decoding_unit_idx");
     584  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     585  sei_read_uvlc( pDecodedMessageOutputStream, val, "decoding_unit_idx");
    637586  sei.m_decodingUnitIdx = val;
    638587
     
    674623    hrd = vui->getHrdParameters();
    675624  }
    676 #else
    677   TComVUI *vui = sps->getVuiParameters();
    678   TComHrd *hrd = vui->getHrdParameters();
    679 #endif
     625
    680626  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
    681627  {
    682     READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
     628    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
    683629    sei.m_duSptCpbRemovalDelay = val;
    684630  }
     
    687633    sei.m_duSptCpbRemovalDelay = 0;
    688634  }
    689   READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
     635  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
    690636  if(sei.m_dpbOutputDuDelayPresentFlag)
    691637  {
    692     READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
     638    sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
    693639    sei.m_picSptDpbOutputDuDelay = val;
    694640  }
    695   xParseByteAlign();
     641#else
     642  TComVUI *vui = sps->getVuiParameters(); 
     643
     644  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
     645  {
     646    sei_read_code( pDecodedMessageOutputStream, ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
     647    sei.m_duSptCpbRemovalDelay = val;
     648  }
     649  else
     650  {
     651    sei.m_duSptCpbRemovalDelay = 0;
     652  }
     653  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
     654  if(sei.m_dpbOutputDuDelayPresentFlag)
     655  {
     656    sei_read_code( pDecodedMessageOutputStream, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
     657    sei.m_picSptDpbOutputDuDelay = val;
     658  }
     659#endif
    696660}
    697661
    698662#if VPS_VUI_BSP_HRD_PARAMS
    699 Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
    700 #else
    701 Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
     663Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
     664#else
     665Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    702666#endif
    703667{
     
    747711#endif
    748712
    749   READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
     713  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     714
     715  sei_read_uvlc( pDecodedMessageOutputStream, code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
    750716  if( !pHRD->getSubPicCpbParamsPresentFlag() )
    751717  {
    752     READ_FLAG( code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
     718    sei_read_flag( pDecodedMessageOutputStream, code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
    753719  }
    754720  if( sei.m_rapCpbParamsPresentFlag )
    755721  {
    756     READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
    757     READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
    758   }
     722    sei_read_code( pDecodedMessageOutputStream, pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
     723    sei_read_code( pDecodedMessageOutputStream, pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
     724  }
     725
    759726  //read splicing flag and cpb_removal_delay_delta
    760   READ_FLAG( code, "concatenation_flag");
     727  sei_read_flag( pDecodedMessageOutputStream, code, "concatenation_flag");
    761728  sei.m_concatenationFlag = code;
    762   READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
     729  sei_read_code( pDecodedMessageOutputStream, ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
    763730  sei.m_auCpbRemovalDelayDelta = code + 1;
     731
    764732  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    765733  {
     
    769737      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
    770738      {
    771         READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
     739        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_delay":"nal_initial_cpb_removal_delay" );
    772740        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
    773         READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
     741        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_offset":"vcl_initial_cpb_removal_offset" );
    774742        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
    775743        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
    776744        {
    777           READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
     745          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_delay":"vcl_initial_alt_cpb_removal_delay" );
    778746          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
    779           READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
     747          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_offset":"vcl_initial_alt_cpb_removal_offset" );
    780748          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
    781749        }
     
    789757  if (xPayloadExtensionPresent())
    790758  {
    791     READ_FLAG (code, "use_alt_cpb_params_flag");
     759    sei_read_flag( pDecodedMessageOutputStream, code, "use_alt_cpb_params_flag");
    792760    sei.m_useAltCpbParamsFlag = code;
    793761    sei.m_useAltCpbParamsFlagPresent = true;
    794762  }
    795763#endif
    796 
    797   xParseByteAlign();
    798 }
     764}
     765
    799766#if VPS_VUI_BSP_HRD_PARAMS
    800 Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
    801 #else
    802 Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
     767Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
     768#else
     769Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    803770#endif
    804771{
     
    851818  TComHRD *hrd = vui->getHrdParameters();
    852819#endif
     820  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
    853821
    854822  if( vui->getFrameFieldInfoPresentFlag() )
    855823  {
    856     READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
    857     READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
    858     READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
     824    sei_read_code( pDecodedMessageOutputStream, 4, code, "pic_struct" );             sei.m_picStruct            = code;
     825    sei_read_code( pDecodedMessageOutputStream, 2, code, "source_scan_type" );       sei.m_sourceScanType      = code;
     826    sei_read_flag( pDecodedMessageOutputStream,    code, "duplicate_flag" );         sei.m_duplicateFlag        = (code == 1);
    859827  }
    860828
    861829  if( hrd->getCpbDpbDelaysPresentFlag())
    862830  {
    863     READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
     831    sei_read_code( pDecodedMessageOutputStream, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
    864832    sei.m_auCpbRemovalDelay = code + 1;
    865     READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
     833    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
    866834    sei.m_picDpbOutputDelay = code;
    867835
    868836    if(hrd->getSubPicCpbParamsPresentFlag())
    869837    {
    870       READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
     838      sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
    871839      sei.m_picDpbOutputDuDelay = code;
    872840    }
     841
    873842    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
    874843    {
    875       READ_UVLC( code, "num_decoding_units_minus1");
     844      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_decoding_units_minus1");
    876845      sei.m_numDecodingUnitsMinus1 = code;
    877       READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
     846      sei_read_flag( pDecodedMessageOutputStream, code, "du_common_cpb_removal_delay_flag" );
    878847      sei.m_duCommonCpbRemovalDelayFlag = code;
    879848      if( sei.m_duCommonCpbRemovalDelayFlag )
    880849      {
    881         READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
     850        sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_increment_minus1" );
    882851        sei.m_duCommonCpbRemovalDelayMinus1 = code;
    883852      }
     
    895864      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
    896865      {
    897         READ_UVLC( code, "num_nalus_in_du_minus1");
     866        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_nalus_in_du_minus1[i]");
    898867        sei.m_numNalusInDuMinus1[ i ] = code;
    899868        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
    900869        {
    901           READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
     870          sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1[i]" );
    902871          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
    903872        }
     
    905874    }
    906875  }
    907   xParseByteAlign();
    908 }
    909 Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
     876}
     877
     878Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    910879{
    911880  Int  iCode;
    912881  UInt uiCode;
    913   READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
    914   READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
    915   READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
    916   xParseByteAlign();
    917 }
    918 Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
     882  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     883
     884  sei_read_svlc( pDecodedMessageOutputStream, iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
     885  sei_read_flag( pDecodedMessageOutputStream, uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
     886  sei_read_flag( pDecodedMessageOutputStream, uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
     887}
     888
     889Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    919890{
    920891  UInt val;
    921   READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
    922   READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
     892  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     893
     894  sei_read_uvlc( pDecodedMessageOutputStream, val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
     895  sei_read_flag( pDecodedMessageOutputStream, val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
    923896
    924897  if ( !sei.m_arrangementCancelFlag )
    925898  {
    926     READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
     899    sei_read_code( pDecodedMessageOutputStream, 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
    927900    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
    928     READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
    929 
    930     READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
    931     READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
    932     READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
    933     READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
    934     READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
    935     READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
    936     READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
     901
     902    sei_read_flag( pDecodedMessageOutputStream, val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
     903
     904    sei_read_code( pDecodedMessageOutputStream, 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
     905    sei_read_flag( pDecodedMessageOutputStream, val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
     906    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
     907    sei_read_flag( pDecodedMessageOutputStream, val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
     908    sei_read_flag( pDecodedMessageOutputStream, val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
     909    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
     910    sei_read_flag( pDecodedMessageOutputStream, val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
    937911
    938912    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
    939913    {
    940       READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
    941       READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
    942       READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
    943       READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
    944     }
    945 
    946     READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
    947     READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
    948   }
    949   READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
    950 
    951   xParseByteAlign();
    952 }
    953 
    954 Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
     914      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
     915      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
     916      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
     917      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
     918    }
     919
     920    sei_read_code( pDecodedMessageOutputStream, 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
     921    sei_read_flag( pDecodedMessageOutputStream, val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = (val != 0);
     922  }
     923  sei_read_flag( pDecodedMessageOutputStream, val, "upsampled_aspect_ratio_flag" );                  sei.m_upsampledAspectRatio = val;
     924}
     925
     926Void SEIReader::xParseSEISegmentedRectFramePacking(SEISegmentedRectFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    955927{
    956928  UInt val;
    957   READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
    958   if( !sei.cancelFlag )
    959   {
    960     READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
    961     READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
    962     READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
    963     READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
    964   }
    965   xParseByteAlign();
    966 }
    967 
    968 Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
     929  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     930  sei_read_flag( pDecodedMessageOutputStream, val,       "segmented_rect_frame_packing_arrangement_cancel_flag" );       sei.m_arrangementCancelFlag            = val;
     931  if( !sei.m_arrangementCancelFlag )
     932  {
     933    sei_read_code( pDecodedMessageOutputStream, 2, val, "segmented_rect_content_interpretation_type" );                sei.m_contentInterpretationType = val;
     934    sei_read_flag( pDecodedMessageOutputStream, val,     "segmented_rect_frame_packing_arrangement_persistence" );                              sei.m_arrangementPersistenceFlag               = val;
     935  }
     936}
     937
     938Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    969939{
    970940  UInt val;
    971   READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
    972   READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
    973   xParseByteAlign();
    974 }
    975 
    976 Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
     941  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     942  sei_read_flag( pDecodedMessageOutputStream, val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
     943  if( !sei.cancelFlag )
     944  {
     945    sei_read_flag( pDecodedMessageOutputStream, val,     "hor_flip" );                              sei.horFlip               = val;
     946    sei_read_flag( pDecodedMessageOutputStream, val,     "ver_flip" );                              sei.verFlip               = val;
     947    sei_read_code( pDecodedMessageOutputStream, 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
     948    sei_read_flag( pDecodedMessageOutputStream, val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
     949  }
     950}
     951
     952Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    977953{
    978954  UInt val;
    979   READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
    980   xParseByteAlign();
    981 }
    982 
    983 Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
     955  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     956  sei_read_code( pDecodedMessageOutputStream, 8, val, "temporal_sub_layer_zero_idx" );  sei.tl0Idx = val;
     957  sei_read_code( pDecodedMessageOutputStream, 8, val, "irap_pic_id" );  sei.rapIdx = val;
     958}
     959
     960Void SEIReader::xParseSEIRegionRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     961{
     962  UInt val;
     963  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     964  sei_read_flag( pDecodedMessageOutputStream, val, "refreshed_region_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
     965}
     966
     967Void SEIReader::xParseSEINoDisplay(SEINoDisplay& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     968{
     969  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     970  sei.m_noDisplay = true;
     971}
     972
     973Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    984974{
    985975  Int i;
    986976  UInt val;
    987   READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
    988   READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
     977  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     978  sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_id" );                         sei.m_toneMapId = val;
     979  sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
    989980
    990981  if ( !sei.m_toneMapCancelFlag )
    991982  {
    992     READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
    993     READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
    994     READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
    995     READ_UVLC( val, "model_id" );                          sei.m_modelId = val;
     983    sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
     984    sei_read_code( pDecodedMessageOutputStream, 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
     985    sei_read_code( pDecodedMessageOutputStream, 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
     986    sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_model_id" );                 sei.m_modelId = val;
    996987    switch(sei.m_modelId)
    997988    {
    998989    case 0:
    999990      {
    1000         READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
    1001         READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
     991        sei_read_code( pDecodedMessageOutputStream, 32, val, "min_value" );                 sei.m_minValue = val;
     992        sei_read_code( pDecodedMessageOutputStream, 32, val, "max_value" );                 sei.m_maxValue = val;
    1002993        break;
    1003994      }
    1004995    case 1:
    1005996      {
    1006         READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
    1007         READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
     997        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
     998        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
    1008999        break;
    10091000      }
     
    10141005        for(i = 0; i < num; i++)
    10151006        {
    1016           READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
     1007          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval[i]" );
    10171008          sei.m_startOfCodedInterval[i] = val;
    10181009        }
     
    10221013    case 3:
    10231014      {
    1024         READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
     1015        sei_read_code( pDecodedMessageOutputStream, 16, val,  "num_pivots" );                       sei.m_numPivots = val;
    10251016        sei.m_codedPivotValue.resize(sei.m_numPivots);
    10261017        sei.m_targetPivotValue.resize(sei.m_numPivots);
    10271018        for(i = 0; i < sei.m_numPivots; i++ )
    10281019        {
    1029           READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
     1020          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value[i]" );
    10301021          sei.m_codedPivotValue[i] = val;
    1031           READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
     1022          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value[i]" );
    10321023          sei.m_targetPivotValue[i] = val;
    10331024        }
     
    10361027    case 4:
    10371028      {
    1038         READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
     1029        sei_read_code( pDecodedMessageOutputStream, 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
    10391030        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
    10401031        {
    1041           READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
    1042         }
    1043         READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
     1032          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
     1033        }
     1034        sei_read_code( pDecodedMessageOutputStream, 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
    10441035        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
    10451036        {
    1046           READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
    1047         }
    1048         READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
    1049         READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
    1050         READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
    1051         READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
    1052         READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
    1053         READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
    1054         READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
    1055         READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
     1037          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
     1038        }
     1039        sei_read_flag( pDecodedMessageOutputStream, val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
     1040        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
     1041        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
     1042        sei_read_code( pDecodedMessageOutputStream, 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
     1043        sei_read_code( pDecodedMessageOutputStream, 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
     1044        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_black_level_code_value" );          sei.m_nominalBlackLevelLumaCodeValue = val;
     1045        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_white_level_code_value" );          sei.m_nominalWhiteLevelLumaCodeValue= val;
     1046        sei_read_code( pDecodedMessageOutputStream, 16, val, "extended_white_level_code_value" );         sei.m_extendedWhiteLevelLumaCodeValue = val;
    10561047        break;
    10571048      }
     
    10621053      }
    10631054    }//switch model id
    1064   }// if(!sei.m_toneMapCancelFlag)
    1065 
    1066   xParseByteAlign();
    1067 }
    1068 
    1069 #if P0050_KNEE_FUNCTION_SEI
    1070 Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt /*payloadSize*/){
     1055  }// if(!sei.m_toneMapCancelFlag)
     1056}
     1057
     1058Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1059{
     1060  Int iCode;
     1061  UInt uiCode;
     1062  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1063
     1064  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
     1065  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
     1066  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
     1067  {
     1068    sei_read_code( pDecodedMessageOutputStream, 6, uiCode,                     "sop_vcl_nut[i]" );  sei.m_sopDescVclNaluType[i] = uiCode;
     1069    sei_read_code( pDecodedMessageOutputStream, 3, sei.m_sopDescTemporalId[i], "sop_temporal_id[i]"   );  sei.m_sopDescTemporalId[i] = uiCode;
     1070    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
     1071    {
     1072      sei_read_uvlc( pDecodedMessageOutputStream, sei.m_sopDescStRpsIdx[i],    "sop_short_term_rps_idx[i]"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
     1073    }
     1074    if (i > 0)
     1075    {
     1076      sei_read_svlc( pDecodedMessageOutputStream, iCode,                       "sop_poc_delta[i]"     ); sei.m_sopDescPocDelta[i] = iCode;
     1077    }
     1078  }
     1079}
     1080
     1081#if LAYERS_NOT_PRESENT_SEI
     1082Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
     1083#else
     1084Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
     1085#endif
     1086{
     1087  UInt uiCode;
     1088  SEIMessages seis;
     1089  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1090
     1091  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
     1092  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
     1093  if (sei.m_nestingOpFlag)
     1094  {
     1095    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
     1096    sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
     1097    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
     1098    {
     1099      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_max_temporal_id_plus1[i]"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
     1100      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_op_idx[i]"                  ); sei.m_nestingOpIdx[i] = uiCode;
     1101    }
     1102  }
     1103  else
     1104  {
     1105    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
     1106    if (!sei.m_allLayersFlag)
     1107    {
     1108      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
     1109      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
     1110      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
     1111      {
     1112        sei_read_code( pDecodedMessageOutputStream, 6,           uiCode,     "nesting_layer_id[i]"      ); sei.m_nestingLayerId[i]   = uiCode;
     1113      }
     1114    }
     1115  }
     1116
     1117  // byte alignment
     1118  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     1119  {
     1120    UInt code;
     1121    sei_read_flag( pDecodedMessageOutputStream, code, "nesting_zero_bit" );
     1122  }
     1123
     1124  sei.m_callerOwnsSEIs = false;
     1125
     1126  // read nested SEI messages
     1127  do {
     1128#if O0164_MULTI_LAYER_HRD
     1129#if LAYERS_NOT_PRESENT_SEI
     1130    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &sei);
     1131#else
     1132    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream, &sei);
     1133#endif
     1134#else
     1135#if LAYERS_NOT_PRESENT_SEI
     1136    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
     1137#else
     1138    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
     1139#endif
     1140#endif
     1141  } while (m_pcBitstream->getNumBitsLeft() > 8);
     1142
     1143  if (pDecodedMessageOutputStream) (*pDecodedMessageOutputStream) << "End of scalable nesting SEI message\n";
     1144}
     1145
     1146Void SEIReader::xParseSEITempMotionConstraintsTileSets(SEITempMotionConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1147{
     1148  UInt code;
     1149  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1150  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);
     1151  sei_read_flag( pDecodedMessageOutputStream, code, "each_tile_one_tile_set_flag");                 sei.m_each_tile_one_tile_set_flag                = (code != 0);
     1152
     1153  if(!sei.m_each_tile_one_tile_set_flag)
     1154  {
     1155    sei_read_flag( pDecodedMessageOutputStream, code, "limited_tile_set_display_flag");  sei.m_limited_tile_set_display_flag = (code != 0);
     1156    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_sets_in_message_minus1");     sei.setNumberOfTileSets(code + 1);
     1157
     1158    if(sei.getNumberOfTileSets() != 0)
     1159    {
     1160      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
     1161      {
     1162        sei_read_uvlc( pDecodedMessageOutputStream, code, "mcts_id");  sei.tileSetData(i).m_mcts_id = code;
     1163
     1164        if(sei.m_limited_tile_set_display_flag)
     1165        {
     1166          sei_read_flag( pDecodedMessageOutputStream, code, "display_tile_set_flag");  sei.tileSetData(i).m_display_tile_set_flag = (code != 1);
     1167        }
     1168
     1169        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_tile_rects_in_set_minus1");  sei.tileSetData(i).setNumberOfTileRects(code + 1);
     1170
     1171        for(Int j=0; j<sei.tileSetData(i).getNumberOfTileRects(); j++)
     1172        {
     1173          sei_read_uvlc( pDecodedMessageOutputStream, code, "top_left_tile_index");      sei.tileSetData(i).topLeftTileIndex(j)     = code;
     1174          sei_read_uvlc( pDecodedMessageOutputStream, code, "bottom_right_tile_index");  sei.tileSetData(i).bottomRightTileIndex(j) = code;
     1175        }
     1176
     1177        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
     1178        {
     1179          sei_read_flag( pDecodedMessageOutputStream, code, "exact_sample_value_match_flag");   sei.tileSetData(i).m_exact_sample_value_match_flag    = (code != 0);
     1180        }
     1181        sei_read_flag( pDecodedMessageOutputStream, code, "mcts_tier_level_idc_present_flag");  sei.tileSetData(i).m_mcts_tier_level_idc_present_flag = (code != 0);
     1182
     1183        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
     1184        {
     1185          sei_read_flag( pDecodedMessageOutputStream, code,    "mcts_tier_flag"); sei.tileSetData(i).m_mcts_tier_flag = (code != 0);
     1186          sei_read_code( pDecodedMessageOutputStream, 8, code, "mcts_level_idc"); sei.tileSetData(i).m_mcts_level_idc =  code;
     1187        }
     1188      }
     1189    }
     1190  }
     1191  else
     1192  {
     1193    sei_read_flag( pDecodedMessageOutputStream, code, "max_mcs_tier_level_idc_present_flag");  sei.m_max_mcs_tier_level_idc_present_flag = code;
     1194    if(sei.m_max_mcs_tier_level_idc_present_flag)
     1195    {
     1196      sei_read_flag( pDecodedMessageOutputStream, code, "max_mcts_tier_flag");  sei.m_max_mcts_tier_flag = code;
     1197      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_mcts_level_idc"); sei.m_max_mcts_level_idc = code;
     1198    }
     1199  }
     1200}
     1201
     1202Void SEIReader::xParseSEITimeCode(SEITimeCode& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1203{
     1204  UInt code;
     1205  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1206  sei_read_code( pDecodedMessageOutputStream, 2, code, "num_clock_ts"); sei.numClockTs = code;
     1207  for(Int i = 0; i < sei.numClockTs; i++)
     1208  {
     1209    TComSEITimeSet currentTimeSet;
     1210    sei_read_flag( pDecodedMessageOutputStream, code, "clock_time_stamp_flag[i]"); currentTimeSet.clockTimeStampFlag = code;
     1211    if(currentTimeSet.clockTimeStampFlag)
     1212    {
     1213      sei_read_flag( pDecodedMessageOutputStream, code, "nuit_field_based_flag"); currentTimeSet.numUnitFieldBasedFlag = code;
     1214      sei_read_code( pDecodedMessageOutputStream, 5, code, "counting_type"); currentTimeSet.countingType = code;
     1215      sei_read_flag( pDecodedMessageOutputStream, code, "full_timestamp_flag"); currentTimeSet.fullTimeStampFlag = code;
     1216      sei_read_flag( pDecodedMessageOutputStream, code, "discontinuity_flag"); currentTimeSet.discontinuityFlag = code;
     1217      sei_read_flag( pDecodedMessageOutputStream, code, "cnt_dropped_flag"); currentTimeSet.cntDroppedFlag = code;
     1218      sei_read_code( pDecodedMessageOutputStream, 9, code, "n_frames"); currentTimeSet.numberOfFrames = code;
     1219      if(currentTimeSet.fullTimeStampFlag)
     1220      {
     1221        sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
     1222        sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
     1223        sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
     1224      }
     1225      else
     1226      {
     1227        sei_read_flag( pDecodedMessageOutputStream, code, "seconds_flag"); currentTimeSet.secondsFlag = code;
     1228        if(currentTimeSet.secondsFlag)
     1229        {
     1230          sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
     1231          sei_read_flag( pDecodedMessageOutputStream, code, "minutes_flag"); currentTimeSet.minutesFlag = code;
     1232          if(currentTimeSet.minutesFlag)
     1233          {
     1234            sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
     1235            sei_read_flag( pDecodedMessageOutputStream, code, "hours_flag"); currentTimeSet.hoursFlag = code;
     1236            if(currentTimeSet.hoursFlag)
     1237              sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
     1238          }
     1239        }
     1240      }
     1241      sei_read_code( pDecodedMessageOutputStream, 5, code, "time_offset_length"); currentTimeSet.timeOffsetLength = code;
     1242      if(currentTimeSet.timeOffsetLength > 0)
     1243      {
     1244        sei_read_code( pDecodedMessageOutputStream, currentTimeSet.timeOffsetLength, code, "time_offset_value");
     1245        if((code & (1 << (currentTimeSet.timeOffsetLength-1))) == 0)
     1246        {
     1247          currentTimeSet.timeOffsetValue = code;
     1248        }
     1249        else
     1250        {
     1251          code &= (1<< (currentTimeSet.timeOffsetLength-1)) - 1;
     1252          currentTimeSet.timeOffsetValue = ~code + 1;
     1253        }
     1254      }
     1255    }
     1256    sei.timeSetArray[i] = currentTimeSet;
     1257  }
     1258}
     1259
     1260Void SEIReader::xParseSEIChromaSamplingFilterHint(SEIChromaSamplingFilterHint& sei, UInt payloadSize/*, TComSPS* sps*/, std::ostream *pDecodedMessageOutputStream)
     1261{
     1262  UInt uiCode;
     1263  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1264
     1265  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "ver_chroma_filter_idc"); sei.m_verChromaFilterIdc = uiCode;
     1266  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "hor_chroma_filter_idc"); sei.m_horChromaFilterIdc = uiCode;
     1267  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ver_filtering_process_flag"); sei.m_verFilteringProcessFlag = uiCode;
     1268  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
     1269  {
     1270    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "target_format_idc"); sei.m_targetFormatIdc = uiCode;
     1271    if(sei.m_verChromaFilterIdc == 1)
     1272    {
     1273      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_vertical_filters"); sei.m_numVerticalFilters = uiCode;
     1274      if(sei.m_numVerticalFilters > 0)
     1275      {
     1276        sei.m_verTapLengthMinus1 = (Int*)malloc(sei.m_numVerticalFilters * sizeof(Int));
     1277        sei.m_verFilterCoeff = (Int**)malloc(sei.m_numVerticalFilters * sizeof(Int*));
     1278        for(Int i = 0; i < sei.m_numVerticalFilters; i ++)
     1279        {
     1280          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ver_tap_length_minus_1"); sei.m_verTapLengthMinus1[i] = uiCode;
     1281          sei.m_verFilterCoeff[i] = (Int*)malloc(sei.m_verTapLengthMinus1[i] * sizeof(Int));
     1282          for(Int j = 0; j < sei.m_verTapLengthMinus1[i]; j ++)
     1283          {
     1284            sei_read_svlc( pDecodedMessageOutputStream, sei.m_verFilterCoeff[i][j], "ver_filter_coeff");
     1285          }
     1286        }
     1287      }
     1288    }
     1289    if(sei.m_horChromaFilterIdc == 1)
     1290    {
     1291      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_horizontal_filters"); sei.m_numHorizontalFilters = uiCode;
     1292      if(sei.m_numHorizontalFilters  > 0)
     1293      {
     1294        sei.m_horTapLengthMinus1 = (Int*)malloc(sei.m_numHorizontalFilters * sizeof(Int));
     1295        sei.m_horFilterCoeff = (Int**)malloc(sei.m_numHorizontalFilters * sizeof(Int*));
     1296        for(Int i = 0; i < sei.m_numHorizontalFilters; i ++)
     1297        {
     1298          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "hor_tap_length_minus_1"); sei.m_horTapLengthMinus1[i] = uiCode;
     1299          sei.m_horFilterCoeff[i] = (Int*)malloc(sei.m_horTapLengthMinus1[i] * sizeof(Int));
     1300          for(Int j = 0; j < sei.m_horTapLengthMinus1[i]; j ++)
     1301          {
     1302            sei_read_svlc( pDecodedMessageOutputStream, sei.m_horFilterCoeff[i][j], "hor_filter_coeff");
     1303          }
     1304        }
     1305      }
     1306    }
     1307  }
     1308}
     1309
     1310Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1311{
    10711312  Int i;
    10721313  UInt val;
    1073   READ_UVLC( val, "knee_function_id" );                   sei.m_kneeId = val;
    1074   READ_FLAG( val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
     1314  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1315
     1316  sei_read_uvlc( pDecodedMessageOutputStream, val, "knee_function_id" );                   sei.m_kneeId = val;
     1317  sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
    10751318  if ( !sei.m_kneeCancelFlag )
    10761319  {
    1077     READ_FLAG( val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
    1078     READ_FLAG( val, "mapping_flag" );                     sei.m_kneeMappingFlag = val;
    1079     READ_CODE( 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
    1080     READ_CODE( 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
    1081     READ_CODE( 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
    1082     READ_CODE( 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
    1083     READ_UVLC( val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
     1320    sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
     1321    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
     1322    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
     1323    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
     1324    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
     1325    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
    10841326    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
    10851327    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
     
    10871329    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
    10881330    {
    1089       READ_CODE( 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
    1090       READ_CODE( 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
    1091     }
    1092   }
    1093 }
    1094 #endif
     1331      sei_read_code( pDecodedMessageOutputStream, 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
     1332      sei_read_code( pDecodedMessageOutputStream, 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
     1333    }
     1334  }
     1335}
     1336
     1337Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     1338{
     1339  UInt code;
     1340  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
     1341
     1342  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
     1343  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
     1344
     1345  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
     1346  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
     1347
     1348  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
     1349  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
     1350
     1351
     1352  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
     1353  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
     1354
     1355  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
     1356  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
     1357}
    10951358
    10961359#if Q0074_COLOUR_REMAPPING_SEI
    1097 Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/)
     1360Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
    10981361{
    10991362  UInt  uiVal;
    11001363  Int   iVal;
    11011364
    1102   READ_UVLC( uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
    1103   READ_FLAG( uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
     1365  sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
     1366  sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
    11041367  if( !sei.m_colourRemapCancelFlag )
    11051368  {
    1106     READ_FLAG( uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
    1107     READ_FLAG( uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
     1369    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
     1370    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
    11081371    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
    11091372    {
    1110       READ_FLAG( uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
    1111       READ_CODE( 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
    1112       READ_CODE( 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
    1113       READ_CODE( 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
    1114     }
    1115     READ_CODE( 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
    1116     READ_CODE( 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
     1373      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
     1374      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
     1375      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
     1376      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
     1377    }
     1378    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
     1379    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
    11171380 
    11181381    for( Int c=0 ; c<3 ; c++ )
    11191382    {
    1120       READ_CODE( 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
     1383      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
    11211384      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
    11221385      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
     
    11241387        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
    11251388        {
    1126           READ_CODE( (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
    1127           READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
     1389          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
     1390          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
    11281391        }
    11291392      else // pre_lut_num_val_minus1[c] == 0
     
    11361399    }
    11371400
    1138     READ_FLAG( uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
     1401    sei_read_flag( pDecodedMessageOutputStream, uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
    11391402    if( sei.m_colourRemapMatrixPresentFlag )
    11401403    {
    1141       READ_CODE( 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
     1404      sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
    11421405      for ( Int c=0 ; c<3 ; c++ )
    11431406        for ( Int i=0 ; i<3 ; i++ )
    11441407        {
    1145           READ_SVLC( iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
     1408          sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
    11461409        }
    11471410    }
     
    11551418    for( Int c=0 ; c<3 ; c++ )
    11561419    {
    1157       READ_CODE( 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
     1420      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
    11581421      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
    11591422      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
     
    11611424        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
    11621425        {
    1163           READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
    1164           READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
     1426          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
     1427          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
    11651428        }
    11661429      else
     
    11731436    }
    11741437  }
    1175 
    1176   xParseByteAlign();
    1177 }
    1178 #endif
    1179 
    1180 Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
    1181 {
    1182   Int iCode;
    1183   UInt uiCode;
    1184 
    1185   READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
    1186   READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
    1187   for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
    1188   {
    1189     READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
    1190     READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
    1191     if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
    1192     {
    1193       READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
    1194     }
    1195     if (i > 0)
    1196     {
    1197       READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
    1198     }
    1199   }
    1200 
    1201   xParseByteAlign();
    1202 }
    1203 
    1204 #if Q0189_TMVP_CONSTRAINTS
    1205 Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize)
    1206 {
    1207   UInt uiCode;
    1208   READ_UVLC( uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
    1209   READ_UVLC( uiCode,           "no_intra_layer_col_pic_flag"            ); sei.no_intra_layer_col_pic_flag = uiCode;
    1210   xParseByteAlign();
    1211 }
    1212 #endif
    1213 
    1214 #if Q0247_FRAME_FIELD_INFO
    1215 Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize)
    1216 {
    1217   UInt code;
    1218   READ_CODE( 4, code, "ffinfo_pic_struct" );             sei.m_ffinfo_picStruct            = code;
    1219   READ_CODE( 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
    1220   READ_FLAG(    code, "ffinfo_duplicate_flag" );         sei.m_ffinfo_duplicateFlag    = ( code == 1 ? true : false );
    1221   xParseByteAlign();
    1222 }
    1223 #endif
    1224 
    1225 #if LAYERS_NOT_PRESENT_SEI
    1226 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
    1227 #else
    1228 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
    1229 #endif
    1230 {
    1231   UInt uiCode;
    1232   SEIMessages seis;
    1233 
    1234   READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
    1235   READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
    1236   if (sei.m_nestingOpFlag)
    1237   {
    1238     READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
    1239     READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
    1240     for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
    1241     {
    1242       READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
    1243       READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
    1244     }
    1245   }
    1246   else
    1247   {
    1248     READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
    1249     if (!sei.m_allLayersFlag)
    1250     {
    1251       READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
    1252       READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
    1253       for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
    1254       {
    1255         READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
    1256       }
    1257     }
    1258   }
    1259 
    1260   // byte alignment
    1261   while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    1262   {
    1263     UInt code;
    1264     READ_FLAG( code, "nesting_zero_bit" );
    1265   }
    1266 
    1267   sei.m_callerOwnsSEIs = false;
    1268 
    1269   // read nested SEI messages
    1270   do {
    1271 #if O0164_MULTI_LAYER_HRD
    1272 #if LAYERS_NOT_PRESENT_SEI
    1273     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &sei);
    1274 #else
    1275     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &sei);
    1276 #endif
    1277 #else
    1278 #if LAYERS_NOT_PRESENT_SEI
    1279     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
    1280 #else
    1281     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
    1282 #endif
    1283 #endif
    1284   } while (m_pcBitstream->getNumBitsLeft() > 8);
    1285 
    1286 }
    1287 
    1288 Void SEIReader::xParseByteAlign()
    1289 {
    1290   UInt code;
    1291   if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    1292   {
    1293     READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
    1294   }
    1295   while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    1296   {
    1297     READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
    1298   }
    1299 }
     1438}
     1439#endif
     1440
    13001441
    13011442#if SVC_EXTENSION
    13021443#if LAYERS_NOT_PRESENT_SEI
    1303 Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps)
     1444Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
    13041445{
    13051446  UInt uiCode;
    13061447  UInt i = 0;
    13071448
    1308   READ_UVLC( uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
     1449  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
    13091450  assert(vps->getVPSId() == sei.m_activeVpsId);
    13101451  sei.m_vpsMaxLayers = vps->getMaxLayers();
    13111452  for (; i < sei.m_vpsMaxLayers; i++)
    13121453  {
    1313     READ_FLAG( uiCode,         "layer_not_present_flag"   ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false;
     1454    sei_read_flag( pDecodedMessageOutputStream, uiCode,         "layer_not_present_flag"   ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false;
    13141455  }
    13151456  for (; i < MAX_LAYERS; i++)
     
    13171458    sei.m_layerNotPresentFlag[i] = false;
    13181459  }
    1319   xParseByteAlign();
    1320 }
    1321 #endif
     1460}
     1461#endif
     1462
    13221463#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    1323 Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize)
     1464Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
    13241465{
    13251466  UInt uiCode;
    13261467
    1327   READ_FLAG( uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
    1328   READ_FLAG( uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
     1468  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
     1469  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
    13291470  if( !sei.m_ilOneTilePerTileSetFlag )
    13301471  {
    1331     READ_UVLC( uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
     1472    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
    13321473    if( sei.m_ilNumSetsInMessageMinus1 )
    13331474    {
    1334       READ_FLAG( uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
     1475      sei_read_flag( pDecodedMessageOutputStream, uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
    13351476    }
    13361477    else
     
    13411482    for( UInt i = 0; i < numSignificantSets; i++ )
    13421483    {
    1343       READ_UVLC( uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
    1344       READ_UVLC( uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
     1484      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
     1485      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
    13451486      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
    13461487      {
    1347         READ_UVLC( uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
    1348         READ_UVLC( uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
    1349       }
    1350       READ_CODE( 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
     1488        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
     1489        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
     1490      }
     1491      sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
    13511492      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
    13521493      {
    1353         READ_FLAG( uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
     1494        sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
    13541495      }
    13551496    }
     
    13571498  else
    13581499  {
    1359     READ_CODE( 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
    1360   }
    1361 
    1362   xParseByteAlign();
    1363 }
    1364 #endif
     1500    sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
     1501  }
     1502}
     1503#endif
     1504
    13651505#if SUB_BITSTREAM_PROPERTY_SEI
    13661506#if OLS_IDX_CHK
    1367 Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, TComVPS *vps)
    1368 #else
    1369 Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
     1507Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
     1508#else
     1509Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, std::ostream *pDecodedMessageOutputStream)
    13701510#endif
    13711511{
    13721512  UInt uiCode;
    1373   READ_CODE( 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
    1374   READ_UVLC(    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
     1513  sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
     1514  sei_read_uvlc( pDecodedMessageOutputStream,    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
    13751515
    13761516  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
    13771517  {
    1378     READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
    1379     READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  );
     1518    sei_read_code( pDecodedMessageOutputStream,  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
     1519    sei_read_uvlc( pDecodedMessageOutputStream,     uiCode, "output_layer_set_idx_to_vps[i]"  );
    13801520#if OLS_IDX_CHK
    13811521      // The value of output_layer_set_idx_to_vps[ i ]  shall be in the range of 0 to NumOutputLayerSets − 1, inclusive.
     
    13831523#endif
    13841524      sei.m_outputLayerSetIdxToVps[i] = uiCode;
    1385     READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
    1386     READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
    1387     READ_CODE( 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
    1388   }
    1389   xParseByteAlign();
     1525    sei_read_code( pDecodedMessageOutputStream,  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
     1526    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
     1527    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
     1528  } 
    13901529}
    13911530#endif
     
    13931532#if O0164_MULTI_LAYER_HRD
    13941533#if LAYERS_NOT_PRESENT_SEI
    1395 Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
    1396 #else
    1397 Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei)
     1534Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
     1535#else
     1536Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
    13981537#endif
    13991538{
    14001539  UInt uiCode;
    1401   READ_UVLC( uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
     1540  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
    14021541
    14031542  // byte alignment
     
    14051544  {
    14061545    UInt code;
    1407     READ_FLAG( code, "bsp_nesting_zero_bit" );
     1546    sei_read_flag( pDecodedMessageOutputStream, code, "bsp_nesting_zero_bit" );
    14081547  }
    14091548
     
    14131552#if NESTING_SEI_EXTENSIBILITY
    14141553  Int numSeiMessages = 0;
    1415   READ_UVLC( uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
     1554  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
    14161555  numSeiMessages = uiCode;
    14171556  for(Int i = 0; i < numSeiMessages; i++)
    14181557  {
    1419     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
     1558    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &nestingSei, &sei);
    14201559  }
    14211560#else
    14221561  do {
    14231562#if LAYERS_NOT_PRESENT_SEI
    1424     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
    1425 #else
    1426     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &nestingSei);
     1563    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &nestingSei, &sei);
     1564#else
     1565    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream, &nestingSei);
    14271566#endif
    14281567  } while (m_pcBitstream->getNumBitsLeft() > 8);
     
    14301569}
    14311570
    1432 Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
     1571Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei, std::ostream *pDecodedMessageOutputStream)
    14331572{
    14341573  assert(vps->getVpsVuiPresentFlag());
     
    14631602    for(UInt i = 0; i < maxValues; i++)
    14641603    {
    1465       READ_CODE( syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
     1604      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
    14661605    }
    14671606  }
     
    14701609    for(UInt i = 0; i < maxValues; i++)
    14711610    {
    1472       READ_CODE( syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
     1611      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
    14731612    }
    14741613  }
     
    15031642    for(UInt i = 0; i < schedCombCnt; i++)
    15041643    {
    1505       READ_CODE( len, uiCode, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
     1644      sei_read_code( pDecodedMessageOutputStream, len, uiCode, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
    15061645    }
    15071646  }
     
    15141653    for(UInt i = 0; i < schedCombCnt; i++)
    15151654    {
    1516       READ_CODE( len, uiCode, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
     1655      sei_read_code( pDecodedMessageOutputStream, len, uiCode, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
    15171656    }
    15181657  }
     
    15211660
    15221661#if !REMOVE_BSP_HRD_SEI
    1523 Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
     1662Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
    15241663{
    15251664  UInt uiCode;
    1526   READ_UVLC( uiCode, "sei_num_bsp_hrd_parameters_minus1" ); sei.m_seiNumBspHrdParametersMinus1 = uiCode;
     1665  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "sei_num_bsp_hrd_parameters_minus1" ); sei.m_seiNumBspHrdParametersMinus1 = uiCode;
    15271666  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
    15281667  {
    15291668    if (i > 0)
    15301669    {
    1531       READ_FLAG( uiCode, "sei_bsp_cprms_present_flag" ); sei.m_seiBspCprmsPresentFlag[i] = uiCode;
     1670      sei_read_flag( pDecodedMessageOutputStream, uiCode, "sei_bsp_cprms_present_flag" ); sei.m_seiBspCprmsPresentFlag[i] = uiCode;
    15321671    }
    15331672    xParseHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1);
     
    15361675  {
    15371676    UInt lsIdx = nestingSei.m_nestingOpIdx[h];
    1538     READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
     1677    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
    15391678#if HRD_BPB
    15401679    Int chkPart=0;
     
    15601699        {
    15611700#endif
    1562           READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
     1701          sei_read_flag( pDecodedMessageOutputStream, uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
    15631702        }
    15641703#if !HRD_BPB
     
    15881727#endif
    15891728     
    1590     READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
     1729    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
    15911730    for (i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
    15921731    {
    15931732      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
    15941733      {
    1595         READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
     1734        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
    15961735#if HRD_BPB
    15971736        assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1);
    15981737#endif
    1599         READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
     1738        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
    16001739#if HRD_BPB
    16011740        assert(uiCode <= sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 ));
     
    16081747#endif
    16091748
    1610 Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
     1749Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1, std::ostream *pDecodedMessageOutputStream)
    16111750{
    16121751  UInt  uiCode;
    16131752  if( commonInfPresentFlag )
    16141753  {
    1615     READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
    1616     READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
     1754    sei_read_flag( pDecodedMessageOutputStream, uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
     1755    sei_read_flag( pDecodedMessageOutputStream, uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
    16171756    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
    16181757    {
    1619       READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
     1758      sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
    16201759      if( hrd->getSubPicCpbParamsPresentFlag() )
    16211760      {
    1622         READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
    1623         READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
    1624         READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
    1625         READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
    1626       }
    1627       READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
    1628       READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
     1761        sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
     1762        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
     1763        sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
     1764        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
     1765      }
     1766      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
     1767      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
    16291768      if( hrd->getSubPicCpbParamsPresentFlag() )
    16301769      {
    1631         READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
    1632       }
    1633       READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
    1634       READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
    1635       READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
     1770        sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
     1771      }
     1772      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
     1773      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
     1774      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
    16361775    }
    16371776  }
     
    16391778  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
    16401779  {
    1641     READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
     1780    sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
    16421781    if( !hrd->getFixedPicRateFlag( i ) )
    16431782    {
    1644       READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
     1783       sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
    16451784    }
    16461785    else
     
    16521791    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
    16531792    {
    1654       READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
     1793      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
    16551794    }
    16561795    else
    16571796    {
    1658       READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
     1797      sei_read_flag( pDecodedMessageOutputStream, uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
    16591798    }
    16601799    if (!hrd->getLowDelayHrdFlag( i ))
    16611800    {
    1662       READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
     1801      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
    16631802    }
    16641803    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     
    16691808        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
    16701809        {
    1671           READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
    1672           READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
     1810          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
     1811          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
    16731812          if( hrd->getSubPicCpbParamsPresentFlag() )
    16741813          {
    1675             READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
    1676             READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
     1814            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
     1815            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
    16771816          }
    1678           READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
     1817           sei_read_flag( pDecodedMessageOutputStream, uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
    16791818        }
    16801819      }
     
    16871826
    16881827#if LAYERS_NOT_PRESENT_SEI
    1689 Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
    1690 #else
    1691 Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps)
     1828Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
     1829#else
     1830Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
    16921831#endif
    16931832{
     
    16951834  SEIMessages seis;
    16961835
    1697   READ_FLAG(uiCode, "ols_flag"); sei.m_olsFlag = uiCode;
    1698   READ_UVLC(uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode;
     1836  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ols_flag"); sei.m_olsFlag = uiCode;
     1837  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode;
    16991838
    17001839  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
    17011840  {
    1702     READ_UVLC(uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode;
     1841    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode;
    17031842  }
    17041843
     
    17071846  {
    17081847    UInt code;
    1709     READ_FLAG(code, "ols_nesting_zero_bit");
     1848    sei_read_flag( pDecodedMessageOutputStream, code, "ols_nesting_zero_bit");
    17101849  }
    17111850
     
    17161855#if O0164_MULTI_LAYER_HRD
    17171856#if LAYERS_NOT_PRESENT_SEI
    1718     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
    1719 #else
    1720     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
     1857    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
     1858#else
     1859    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
    17211860#endif
    17221861#else
    17231862#if LAYERS_NOT_PRESENT_SEI
    1724     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
    1725 #else
    1726     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
     1863    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
     1864#else
     1865    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
    17271866#endif
    17281867#endif
     
    17311870}
    17321871
    1733 Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei)
     1872Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei, std::ostream *pDecodedMessageOutputStream )
    17341873{
    17351874}
     
    17381877
    17391878#if Q0096_OVERLAY_SEI
    1740 Void SEIReader::xParseSEIOverlayInfo(SEIOverlayInfo& sei, UInt /*payloadSize*/){
     1879Void SEIReader::xParseSEIOverlayInfo(SEIOverlayInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
     1880{
    17411881  Int i, j;
    17421882  UInt val;
    1743   READ_FLAG( val, "overlay_info_cancel_flag" );                 sei.m_overlayInfoCancelFlag = val;
     1883  sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_cancel_flag" );                 sei.m_overlayInfoCancelFlag = val;
    17441884  if ( !sei.m_overlayInfoCancelFlag )
    17451885  {
    1746     READ_UVLC( val, "overlay_content_aux_id_minus128" );            sei.m_overlayContentAuxIdMinus128 = val;
    1747     READ_UVLC( val, "overlay_label_aux_id_minus128" );              sei.m_overlayLabelAuxIdMinus128 = val;
    1748     READ_UVLC( val, "overlay_alpha_aux_id_minus128" );              sei.m_overlayAlphaAuxIdMinus128 = val;
    1749     READ_UVLC( val, "overlay_element_label_value_length_minus8" );  sei.m_overlayElementLabelValueLengthMinus8 = val;
    1750     READ_UVLC( val, "num_overlays_minus1" );                        sei.m_numOverlaysMinus1 = val;
     1886    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_content_aux_id_minus128" );            sei.m_overlayContentAuxIdMinus128 = val;
     1887    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_label_aux_id_minus128" );              sei.m_overlayLabelAuxIdMinus128 = val;
     1888    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_alpha_aux_id_minus128" );              sei.m_overlayAlphaAuxIdMinus128 = val;
     1889    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_element_label_value_length_minus8" );  sei.m_overlayElementLabelValueLengthMinus8 = val;
     1890    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlays_minus1" );                        sei.m_numOverlaysMinus1 = val;
    17511891
    17521892    assert( sei.m_numOverlaysMinus1 < MAX_OVERLAYS );
     
    17631903    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
    17641904    {
    1765       READ_UVLC( val, "overlay_idx" );                      sei.m_overlayIdx[i] = val;
    1766       READ_FLAG( val, "language_overlay_present_flag" );    sei.m_languageOverlayPresentFlag[i] = val;
    1767       READ_CODE( 6, val, "overlay_content_layer_id");       sei.m_overlayContentLayerId[i] = val;
    1768       READ_FLAG( val, "overlay_label_present_flag" );       sei.m_overlayLabelPresentFlag[i] = val;
     1905      sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_idx" );                      sei.m_overlayIdx[i] = val;
     1906      sei_read_flag( pDecodedMessageOutputStream, val, "language_overlay_present_flag" );    sei.m_languageOverlayPresentFlag[i] = val;
     1907      sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_content_layer_id");       sei.m_overlayContentLayerId[i] = val;
     1908      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_label_present_flag" );       sei.m_overlayLabelPresentFlag[i] = val;
    17691909      if ( sei.m_overlayLabelPresentFlag[i] )
    17701910      {
    1771         READ_CODE( 6, val, "overlay_label_layer_id");     sei.m_overlayLabelLayerId[i] = val;
    1772       }
    1773       READ_FLAG( val, "overlay_alpha_present_flag" );       sei.m_overlayAlphaPresentFlag[i] = val;
     1911        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_label_layer_id");     sei.m_overlayLabelLayerId[i] = val;
     1912      }
     1913      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_alpha_present_flag" );       sei.m_overlayAlphaPresentFlag[i] = val;
    17741914      if ( sei.m_overlayAlphaPresentFlag[i] )
    17751915      {
    1776         READ_CODE( 6, val, "overlay_alpha_layer_id");     sei.m_overlayAlphaLayerId[i] = val;
     1916        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_alpha_layer_id");     sei.m_overlayAlphaLayerId[i] = val;
    17771917      }
    17781918      if ( sei.m_overlayLabelPresentFlag[i] )
    17791919      {
    1780         READ_UVLC( val, "num_overlay_elements_minus1");   sei.m_numOverlayElementsMinus1[i] = val;
     1920        sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlay_elements_minus1");   sei.m_numOverlayElementsMinus1[i] = val;
    17811921        assert( sei.m_numOverlayElementsMinus1[i] < MAX_OVERLAY_ELEMENTS );
    17821922        sei.m_overlayElementLabelMin[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
     
    17841924        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++ )
    17851925        {
    1786           READ_CODE(sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_min"); sei.m_overlayElementLabelMin[i][j] = val;
    1787           READ_CODE(sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_max"); sei.m_overlayElementLabelMax[i][j] = val;
     1926          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_min"); sei.m_overlayElementLabelMin[i][j] = val;
     1927          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_max"); sei.m_overlayElementLabelMax[i][j] = val;
    17881928        }     
    17891929      }
     
    17971937    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
    17981938    {
    1799       READ_FLAG( val, "overlay_zero_bit" );
     1939      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_zero_bit" );
    18001940      assert( val==0 );
    18011941    }
     
    18351975      }
    18361976    }
    1837     READ_FLAG( val, "overlay_info_persistence_flag" );        sei.m_overlayInfoPersistenceFlag = val;
    1838   }
    1839   xParseByteAlign();
    1840 }
    1841 #endif
     1977    sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_persistence_flag" );        sei.m_overlayInfoPersistenceFlag = val;
     1978  } 
     1979}
     1980#endif
     1981
     1982#if P0138_USE_ALT_CPB_PARAMS_FLAG
     1983/**
     1984 * Check if SEI message contains payload extension
     1985 */
     1986Bool SEIReader::xPayloadExtensionPresent()
     1987{
     1988  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
     1989  Bool payloadExtensionPresent = false;
     1990
     1991  if (payloadBitsRemaining > 8)
     1992  {
     1993    payloadExtensionPresent = true;
     1994  }
     1995  else
     1996  {
     1997    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
     1998    while (payloadBitsRemaining && (finalBits & 1) == 0)
     1999    {
     2000      payloadBitsRemaining--;
     2001      finalBits >>= 1;
     2002    }
     2003    payloadBitsRemaining--;
     2004    if (payloadBitsRemaining > 0)
     2005    {
     2006      payloadExtensionPresent = true;
     2007    }
     2008  }
     2009
     2010  return payloadExtensionPresent;
     2011}
     2012#endif
     2013
     2014#if Q0189_TMVP_CONSTRAINTS
     2015Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     2016{
     2017  UInt uiCode;
     2018  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
     2019  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "no_intra_layer_col_pic_flag"          ); sei.no_intra_layer_col_pic_flag = uiCode;
     2020}
     2021#endif
     2022
     2023#if Q0247_FRAME_FIELD_INFO
     2024Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
     2025{
     2026  UInt code;
     2027  sei_read_code( pDecodedMessageOutputStream, 4, code, "ffinfo_pic_struct"       );       sei.m_ffinfo_picStruct      = code;
     2028  sei_read_code( pDecodedMessageOutputStream, 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
     2029  sei_read_flag( pDecodedMessageOutputStream,    code, "ffinfo_duplicate_flag"   );       sei.m_ffinfo_duplicateFlag  = ( code == 1 ? true : false );
     2030}
     2031#endif
     2032
    18422033
    18432034#endif //SVC_EXTENSION
  • branches/SHM-dev/source/Lib/TLibDecoder/SEIread.h

    r912 r1029  
    5757  virtual ~SEIReader() {};
    5858#if LAYERS_NOT_PRESENT_SEI
    59   Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
     59  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
    6060#else
    61   Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
     61  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
    6262#endif
    6363protected:
    6464#if O0164_MULTI_LAYER_HRD
    6565#if LAYERS_NOT_PRESENT_SEI
    66   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei=NULL, const SEIBspNesting *bspNestingSei=NULL);
     66  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei=NULL, const SEIBspNesting *bspNestingSei=NULL);
    6767#else
    68   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei=NULL);
     68  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, , std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei=NULL);
    6969#endif
    7070#else
    7171#if LAYERS_NOT_PRESENT_SEI
    72   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
     72  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
    7373#else
    74   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
     74  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
    7575#endif
     76#endif
     77  Void xParseSEIuserDataUnregistered          (SEIuserDataUnregistered &sei,          UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     78  Void xParseSEIActiveParameterSets           (SEIActiveParameterSets  &sei,          UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     79  Void xParseSEIDecodedPictureHash            (SEIDecodedPictureHash& sei,            UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     80#if VPS_VUI_BSP_HRD_PARAMS
     81  Void xParseSEIDecodingUnitInfo              (SEIDecodingUnitInfo& sei,              UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream);
     82  Void xParseSEIBufferingPeriod               (SEIBufferingPeriod& sei,               UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream);
     83  Void xParseSEIPictureTiming                 (SEIPictureTiming& sei,                 UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream);
     84#else
     85  Void xParseSEIDecodingUnitInfo              (SEIDecodingUnitInfo& sei,              UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     86  Void xParseSEIBufferingPeriod               (SEIBufferingPeriod& sei,               UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     87  Void xParseSEIPictureTiming                 (SEIPictureTiming& sei,                 UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     88#endif
     89  Void xParseSEIRecoveryPoint                 (SEIRecoveryPoint& sei,                 UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     90  Void xParseSEIFramePacking                  (SEIFramePacking& sei,                  UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     91  Void xParseSEISegmentedRectFramePacking     (SEISegmentedRectFramePacking& sei,     UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     92  Void xParseSEIDisplayOrientation            (SEIDisplayOrientation &sei,            UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     93  Void xParseSEITemporalLevel0Index           (SEITemporalLevel0Index &sei,           UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     94  Void xParseSEIRegionRefreshInfo             (SEIGradualDecodingRefreshInfo &sei,    UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     95  Void xParseSEINoDisplay                     (SEINoDisplay &sei,                     UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     96  Void xParseSEIToneMappingInfo               (SEIToneMappingInfo& sei,               UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     97  Void xParseSEISOPDescription                (SEISOPDescription &sei,                UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     98#if !LAYERS_NOT_PRESENT_SEI
     99  Void xParseSEIScalableNesting               (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     100#endif
     101  Void xParseSEITempMotionConstraintsTileSets (SEITempMotionConstrainedTileSets& sei, UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     102  Void xParseSEITimeCode                      (SEITimeCode& sei,                      UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     103  Void xParseSEIChromaSamplingFilterHint      (SEIChromaSamplingFilterHint& sei,      UInt payloadSize/*,TComSPS* */, std::ostream *pDecodedMessageOutputStream);
     104  Void xParseSEIKneeFunctionInfo              (SEIKneeFunctionInfo& sei,              UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     105  Void xParseSEIMasteringDisplayColourVolume  (SEIMasteringDisplayColourVolume& sei,  UInt payloadSize,               std::ostream *pDecodedMessageOutputStream);
     106
     107  Void sei_read_code(std::ostream *pOS, UInt uiLength, UInt& ruiCode, const Char *pSymbolName);
     108  Void sei_read_uvlc(std::ostream *pOS,                UInt& ruiCode, const Char *pSymbolName);
     109  Void sei_read_svlc(std::ostream *pOS,                Int&  ruiCode, const Char *pSymbolName);
     110  Void sei_read_flag(std::ostream *pOS,                UInt& ruiCode, const Char *pSymbolName);
     111
     112#if Q0074_COLOUR_REMAPPING_SEI
     113  Void xParseSEIColourRemappingInfo           (SEIColourRemappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
     114#endif
     115#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     116  Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
     117#endif
     118#if SUB_BITSTREAM_PROPERTY_SEI
     119#if OLS_IDX_CHK
     120Void   xParseSEISubBitstreamProperty          (SEISubBitstreamProperty &sei, TComVPS *vps, std::ostream *pDecodedMessageOutputStream);
     121#else
     122Void   xParseSEISubBitstreamProperty          (SEISubBitstreamProperty &sei, std::ostream *pDecodedMessageOutputStream);
     123#endif
     124#endif
     125#if LAYERS_NOT_PRESENT_SEI
     126  Void xParseSEILayersNotPresent              (SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps ,std::ostream *pDecodedMessageOutputStream);
     127  Void xParseSEIScalableNesting               (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     128#endif
     129#if O0164_MULTI_LAYER_HRD
     130#if LAYERS_NOT_PRESENT_SEI
     131  Void xParseSEIBspNesting                    (SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream);
     132#else
     133  Void xParseSEIBspNesting                    (SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei ,std::ostream *pDecodedMessageOutputStream);
     134#endif
     135  Void xParseSEIBspInitialArrivalTime         (SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei, std::ostream *pDecodedMessageOutputStream);
     136#if !REMOVE_BSP_HRD_SEI
     137  Void xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream);
     138#endif
     139  Void xParseHrdParameters                    (TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1, std::ostream *pDecodedMessageOutputStream);
     140#endif
     141#if Q0078_ADD_LAYER_SETS
     142#if LAYERS_NOT_PRESENT_SEI
     143  Void xParseSEIOutputLayerSetNesting         (SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     144#else
     145  Void xParseSEIOutputLayerSetNesting         (SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
     146#endif
     147  Void xParseSEIVPSRewriting                  (SEIVPSRewriting &sei, std::ostream *pDecodedMessageOutputStream);
     148#endif
     149
     150#if Q0189_TMVP_CONSTRAINTS
     151  Void xParseSEITMVPConstraints               (SEITMVPConstrains& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
     152#endif
     153#if Q0247_FRAME_FIELD_INFO
     154  Void xParseSEIFrameFieldInfo                (SEIFrameFieldInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
     155#endif
     156#if Q0096_OVERLAY_SEI
     157  Void xParseSEIOverlayInfo                   (SEIOverlayInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
    76158#endif
    77159#if P0138_USE_ALT_CPB_PARAMS_FLAG
    78160  Bool xPayloadExtensionPresent       ();
    79161#endif
    80   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
    81   Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
    82   Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
    83 #if VPS_VUI_BSP_HRD_PARAMS
    84   Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
    85   Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
    86   Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
    87 #else
    88   Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
    89   Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
    90   Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
    91 #endif
    92   Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
    93   Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
    94   Void xParseSEIDisplayOrientation    (SEIDisplayOrientation &sei, UInt payloadSize);
    95   Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
    96   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
    97   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
    98 #if P0050_KNEE_FUNCTION_SEI
    99   Void xParseSEIKneeFunctionInfo      (SEIKneeFunctionInfo& sei, UInt payloadSize);
    100 #endif
    101 #if Q0074_COLOUR_REMAPPING_SEI
    102   Void xParseSEIColourRemappingInfo   (SEIColourRemappingInfo& sei, UInt payloadSize);
    103 #endif
    104   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
    105 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    106   Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize);
    107 #endif
    108 #if SUB_BITSTREAM_PROPERTY_SEI
    109 #if OLS_IDX_CHK
    110 Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei, TComVPS *vps);
    111 #else
    112 Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei);
    113 #endif
    114 #endif
    115 #if LAYERS_NOT_PRESENT_SEI
    116   Void xParseSEILayersNotPresent      (SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps);
    117   Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps);
    118 #else
    119   Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
    120 #endif
    121 #if O0164_MULTI_LAYER_HRD
    122 #if LAYERS_NOT_PRESENT_SEI
    123   Void xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei);
    124 #else
    125   Void xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei);
    126 #endif
    127   Void xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
    128 #if !REMOVE_BSP_HRD_SEI
    129   Void xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
    130 #endif
    131   Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
    132 #endif
    133 #if Q0078_ADD_LAYER_SETS
    134 #if LAYERS_NOT_PRESENT_SEI
    135   Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
    136 #else
    137   Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps);
    138 #endif
    139   Void xParseSEIVPSRewriting(SEIVPSRewriting &sei);
    140 #endif
    141 
    142 #if Q0189_TMVP_CONSTRAINTS
    143   Void xParseSEITMVPConstraints    (SEITMVPConstrains& sei, UInt payloadSize);
    144 #endif
    145 #if Q0247_FRAME_FIELD_INFO
    146   Void xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize);
    147 #endif
    148 #if Q0096_OVERLAY_SEI
    149   Void xParseSEIOverlayInfo           (SEIOverlayInfo& sei, UInt payloadSize);
    150 #endif
    151   Void xParseByteAlign();
    152162};
    153163
  • branches/SHM-dev/source/Lib/TLibDecoder/SyntaxElementParser.cpp

    r912 r1029  
    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-2014, 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  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    5259  if (length < 10)
    5360  {
    54     fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
     61    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
    5562  }
    5663  else
     
    6370Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
    6471{
     72#if RExt__DECODER_DEBUG_BIT_STATISTICS
     73  xReadUvlc (rValue, pSymbolName);
     74#else
    6575  xReadUvlc (rValue);
    66   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    67   fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
     76#endif
     77  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     78  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
    6879  fflush ( g_hTrace );
    6980}
     
    7182Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
    7283{
    73   xReadSvlc(rValue);
    74   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    75   fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
     84#if RExt__DECODER_DEBUG_BIT_STATISTICS
     85  xReadSvlc (rValue, pSymbolName);
     86#else
     87  xReadSvlc (rValue);
     88#endif
     89  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     90  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
    7691  fflush ( g_hTrace );
    7792}
     
    7994Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
    8095{
    81   xReadFlag(rValue);
    82   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    83   fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
     96#if RExt__DECODER_DEBUG_BIT_STATISTICS
     97  xReadFlag (rValue, pSymbolName);
     98#else
     99  xReadFlag (rValue);
     100#endif
     101  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
     102  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
    84103  fflush ( g_hTrace );
    85104}
     
    101120// Protected member functions
    102121// ====================================================================================================================
    103 
     122#if RExt__DECODER_DEBUG_BIT_STATISTICS
     123Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
     124#else
    104125Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
     126#endif
    105127{
    106128  assert ( uiLength > 0 );
    107129  m_pcBitstream->read (uiLength, ruiCode);
    108 }
    109 
     130#if RExt__DECODER_DEBUG_BIT_STATISTICS
     131  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
     132#endif
     133}
     134
     135#if RExt__DECODER_DEBUG_BIT_STATISTICS
     136Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
     137#else
    110138Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
     139#endif
    111140{
    112141  UInt uiVal = 0;
     
    114143  UInt uiLength;
    115144  m_pcBitstream->read( 1, uiCode );
     145#if RExt__DECODER_DEBUG_BIT_STATISTICS
     146  UInt totalLen=1;
     147#endif
    116148
    117149  if( 0 == uiCode )
     
    128160
    129161    uiVal += (1 << uiLength)-1;
     162#if RExt__DECODER_DEBUG_BIT_STATISTICS
     163    totalLen+=uiLength+uiLength;
     164#endif
    130165  }
    131166
    132167  ruiVal = uiVal;
    133 }
    134 
     168#if RExt__DECODER_DEBUG_BIT_STATISTICS
     169  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
     170#endif
     171}
     172
     173#if RExt__DECODER_DEBUG_BIT_STATISTICS
     174Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
     175#else
    135176Void SyntaxElementParser::xReadSvlc( Int& riVal)
     177#endif
    136178{
    137179  UInt uiBits = 0;
    138180  m_pcBitstream->read( 1, uiBits );
     181#if RExt__DECODER_DEBUG_BIT_STATISTICS
     182  UInt totalLen=1;
     183#endif
    139184  if( 0 == uiBits )
    140185  {
     
    151196    uiBits += (1 << uiLength);
    152197    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
     198#if RExt__DECODER_DEBUG_BIT_STATISTICS
     199    totalLen+=uiLength+uiLength;
     200#endif
    153201  }
    154202  else
     
    156204    riVal = 0;
    157205  }
    158 }
    159 
     206#if RExt__DECODER_DEBUG_BIT_STATISTICS
     207  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
     208#endif
     209}
     210
     211#if RExt__DECODER_DEBUG_BIT_STATISTICS
     212Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
     213#else
    160214Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
     215#endif
    161216{
    162217  m_pcBitstream->read( 1, ruiCode );
     218#if RExt__DECODER_DEBUG_BIT_STATISTICS
     219  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
     220#endif
    163221}
    164222
    165223#if Q0096_OVERLAY_SEI
    166 Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength)
     224#if RExt__DECODER_DEBUG_BIT_STATISTICS
     225Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength, const Char *pSymbolName)
     226#else
     227Void  SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength)
     228#endif
    167229{
    168230  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position
  • branches/SHM-dev/source/Lib/TLibDecoder/SyntaxElementParser.h

    r912 r1029  
    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-2014, ITU/ISO/IEC
     
    5757#else
    5858
     59#if RExt__DECODER_DEBUG_BIT_STATISTICS
     60
     61#define READ_CODE(length, code, name)     xReadCode ( length, code, name )
     62#define READ_UVLC(        code, name)     xReadUvlc (         code, name )
     63#define READ_SVLC(        code, name)     xReadSvlc (         code, name )
     64#define READ_FLAG(        code, name)     xReadFlag (         code, name )
     65#if Q0096_OVERLAY_SEI
     66#define READ_STRING(bufSize, code, length, name)   xReadString ( bufSize, code, length, name )
     67#endif
     68
     69#else
     70
    5971#define READ_CODE(length, code, name)     xReadCode ( length, code )
    6072#define READ_UVLC(        code, name)     xReadUvlc (         code )
     
    6375#if Q0096_OVERLAY_SEI
    6476#define READ_STRING(bufSize, code, length, name)   xReadString ( bufSize, code, length )
     77#endif
    6578#endif
    6679
     
    8497  virtual ~SyntaxElementParser() {};
    8598
     99#if RExt__DECODER_DEBUG_BIT_STATISTICS
     100  Void  xReadCode    ( UInt   length, UInt& val, const Char *pSymbolName );
     101  Void  xReadUvlc    ( UInt&  val, const Char *pSymbolName );
     102  Void  xReadSvlc    ( Int&   val, const Char *pSymbolName );
     103  Void  xReadFlag    ( UInt&  val, const Char *pSymbolName );
     104#if Q0096_OVERLAY_SEI
     105  Void  xReadString  (UInt bufSize, UChar *pValue, UInt& rLength, const Char *pSymbolName);
     106#endif
     107#else
    86108  Void  xReadCode    ( UInt   length, UInt& val );
    87109  Void  xReadUvlc    ( UInt&  val );
     
    90112#if Q0096_OVERLAY_SEI
    91113  Void  xReadString  (UInt bufSize, UChar *val, UInt& length);
     114#endif
    92115#endif
    93116#if ENC_DEC_TRACE
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecBinCoder.h

    r595 r1029  
    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-2014, ITU/ISO/IEC
     
    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
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp

    r595 r1029  
    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-2014, ITU/ISO/IEC
     
    3737
    3838#include "TDecBinCoderCABAC.h"
     39#include "TLibCommon/Debug.h"
     40#if RExt__DECODER_DEBUG_BIT_STATISTICS
     41#include "TLibCommon/TComCodingStatistics.h"
     42#endif
    3943
    4044//! \ingroup TLibDecoder
     
    6670{
    6771  assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
     72#if RExt__DECODER_DEBUG_BIT_STATISTICS
     73  TComCodingStatistics::UpdateCABACStat(STATS__CABAC_INITIALISATION, 512, 510, 0);
     74#endif
    6875  m_uiRange    = 510;
    6976  m_bitsNeeded = -8;
     
    8895 */
    8996Void
    90 TDecBinCABAC::copyState( TDecBinIf* pcTDecBinIf )
    91 {
    92   TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
     97TDecBinCABAC::copyState( const TDecBinIf* pcTDecBinIf )
     98{
     99  const TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
    93100  m_uiRange   = pcTDecBinCABAC->m_uiRange;
    94101  m_uiValue   = pcTDecBinCABAC->m_uiValue;
     
    97104
    98105
    99 Void
    100 TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel )
    101 {
     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#ifdef DEBUG_CABAC_BINS
     114  const UInt startingRange = m_uiRange;
     115#endif
     116
    102117  UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) - 4 ];
    103118  m_uiRange -= uiLPS;
    104119  UInt scaledRange = m_uiRange << 7;
    105  
     120
    106121  if( m_uiValue < scaledRange )
    107122  {
    108123    // MPS path
    109124    ruiBin = rcCtxModel.getMps();
     125#if RExt__DECODER_DEBUG_BIT_STATISTICS
     126    TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, m_uiRange, Int(ruiBin));
     127#endif
    110128    rcCtxModel.updateMPS();
    111    
    112     if ( scaledRange >= ( 256 << 7 ) )
    113     {
    114       return;
    115     }
    116    
    117     m_uiRange = scaledRange >> 6;
    118     m_uiValue += m_uiValue;
    119    
    120     if ( ++m_bitsNeeded == 0 )
    121     {
    122       m_bitsNeeded = -8;
    123       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      }
    124140    }
    125141  }
     
    127143  {
    128144    // 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
    129149    Int numBits = TComCABACTables::sm_aucRenormTable[ uiLPS >> 3 ];
    130150    m_uiValue   = ( m_uiValue - scaledRange ) << numBits;
    131151    m_uiRange   = uiLPS << numBits;
    132     ruiBin      = 1 - rcCtxModel.getMps();
    133152    rcCtxModel.updateLPS();
    134    
     153
    135154    m_bitsNeeded += numBits;
    136    
     155
    137156    if ( m_bitsNeeded >= 0 )
    138157    {
     
    141160    }
    142161  }
    143 }
    144 
    145 Void
    146 TDecBinCABAC::decodeBinEP( UInt& ruiBin )
    147 {
     162
     163#ifdef DEBUG_CABAC_BINS
     164  if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine)
     165    std::cout << g_debugCounter << ": coding bin value " << ruiBin << ", range = [" << startingRange << "->" << m_uiRange << "]\n";
     166
     167  if (g_debugCounter >= debugCabacBinTargetLine)
     168  {
     169    Char breakPointThis;
     170    breakPointThis = 7;
     171  }
     172  if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow)) exit(0);
     173  g_debugCounter++;
     174#endif
     175}
     176
     177
     178#if RExt__DECODER_DEBUG_BIT_STATISTICS
     179Void TDecBinCABAC::decodeBinEP( UInt& ruiBin, const TComCodingStatisticsClassType &whichStat )
     180#else
     181Void TDecBinCABAC::decodeBinEP( UInt& ruiBin )
     182#endif
     183{
     184  if (m_uiRange == 256)
     185  {
     186#if RExt__DECODER_DEBUG_BIT_STATISTICS
     187    decodeAlignedBinsEP(ruiBin, 1, whichStat);
     188#else
     189    decodeAlignedBinsEP(ruiBin, 1);
     190#endif
     191    return;
     192  }
     193
    148194  m_uiValue += m_uiValue;
    149  
     195
    150196  if ( ++m_bitsNeeded >= 0 )
    151197  {
     
    153199    m_uiValue += m_pcTComBitstream->readByte();
    154200  }
    155  
     201
    156202  ruiBin = 0;
    157203  UInt scaledRange = m_uiRange << 7;
     
    161207    m_uiValue -= scaledRange;
    162208  }
    163 }
    164 
     209#if RExt__DECODER_DEBUG_BIT_STATISTICS
     210  TComCodingStatistics::IncrementStatisticEP(whichStat, 1, Int(ruiBin));
     211#endif
     212}
     213
     214#if RExt__DECODER_DEBUG_BIT_STATISTICS
     215Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins, const TComCodingStatisticsClassType &whichStat )
     216#else
    165217Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins )
    166 {
     218#endif
     219{
     220  if (m_uiRange == 256)
     221  {
     222#if RExt__DECODER_DEBUG_BIT_STATISTICS
     223    decodeAlignedBinsEP(ruiBin, numBins, whichStat);
     224#else
     225    decodeAlignedBinsEP(ruiBin, numBins);
     226#endif
     227    return;
     228  }
     229
    167230  UInt bins = 0;
    168  
     231#if RExt__DECODER_DEBUG_BIT_STATISTICS
     232  Int origNumBins=numBins;
     233#endif
    169234  while ( numBins > 8 )
    170235  {
    171236    m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
    172    
     237
    173238    UInt scaledRange = m_uiRange << 15;
    174239    for ( Int i = 0; i < 8; i++ )
     
    184249    numBins -= 8;
    185250  }
    186  
     251
    187252  m_bitsNeeded += numBins;
    188253  m_uiValue <<= numBins;
    189  
     254
    190255  if ( m_bitsNeeded >= 0 )
    191256  {
     
    193258    m_bitsNeeded -= 8;
    194259  }
    195  
     260
    196261  UInt scaledRange = m_uiRange << ( numBins + 7 );
    197262  for ( Int i = 0; i < numBins; i++ )
     
    205270    }
    206271  }
    207  
     272
    208273  ruiBin = bins;
     274#if RExt__DECODER_DEBUG_BIT_STATISTICS
     275  TComCodingStatistics::IncrementStatisticEP(whichStat, origNumBins, Int(ruiBin));
     276#endif
     277}
     278
     279Void TDecBinCABAC::align()
     280{
     281#if RExt__DECODER_DEBUG_BIT_STATISTICS
     282  TComCodingStatistics::UpdateCABACStat(STATS__CABAC_EP_BIT_ALIGNMENT, m_uiRange, 256, 0);
     283#endif
     284  m_uiRange = 256;
     285}
     286
     287#if RExt__DECODER_DEBUG_BIT_STATISTICS
     288Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins, const class TComCodingStatisticsClassType &whichStat )
     289#else
     290Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins )
     291#endif
     292{
     293  Int binsRemaining = numBins;
     294  ruiBins = 0;
     295
     296  assert(m_uiRange == 256); //aligned decode only works when range = 256
     297
     298  while (binsRemaining > 0)
     299  {
     300    const UInt binsToRead = std::min<UInt>(binsRemaining, 8); //read bytes if able to take advantage of the system's byte-read function
     301    const UInt binMask    = (1 << binsToRead) - 1;
     302
     303    //The MSB of m_uiValue is known to be 0 because range is 256. Therefore:
     304    // > The comparison against the symbol range of 128 is simply a test on the next-most-significant bit
     305    // > "Subtracting" the symbol range if the decoded bin is 1 simply involves clearing that bit.
     306    //
     307    //As a result, the required bins are simply the <binsToRead> next-most-significant bits of m_uiValue
     308    //(m_uiValue is stored MSB-aligned in a 16-bit buffer - hence the shift of 15)
     309    //
     310    //   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))
     311    //
     312    const UInt newBins = (m_uiValue >> (15 - binsToRead)) & binMask;
     313
     314    ruiBins   = (ruiBins   << binsToRead) | newBins;
     315    m_uiValue = (m_uiValue << binsToRead) & 0x7FFF;
     316
     317    binsRemaining -= binsToRead;
     318    m_bitsNeeded  += binsToRead;
     319
     320    if (m_bitsNeeded >= 0)
     321    {
     322      m_uiValue    |= m_pcTComBitstream->readByte() << m_bitsNeeded;
     323      m_bitsNeeded -= 8;
     324    }
     325  }
     326
     327#if RExt__DECODER_DEBUG_BIT_STATISTICS
     328  TComCodingStatistics::IncrementStatisticEP(whichStat, numBins, Int(ruiBins));
     329#endif
    209330}
    210331
     
    217338  {
    218339    ruiBin = 1;
     340#if RExt__DECODER_DEBUG_BIT_STATISTICS
     341    TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, 2, ruiBin);
     342    TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, -m_bitsNeeded, 0);
     343#endif
    219344  }
    220345  else
    221346  {
    222347    ruiBin = 0;
     348#if RExt__DECODER_DEBUG_BIT_STATISTICS
     349    TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, m_uiRange, ruiBin);
     350#endif
    223351    if ( scaledRange < ( 256 << 7 ) )
    224352    {
    225353      m_uiRange = scaledRange >> 6;
    226354      m_uiValue += m_uiValue;
    227      
     355
    228356      if ( ++m_bitsNeeded == 0 )
    229357      {
    230358        m_bitsNeeded = -8;
    231         m_uiValue += m_pcTComBitstream->readByte();     
     359        m_uiValue += m_pcTComBitstream->readByte();
    232360      }
    233361    }
     
    244372  assert ( uiLength > 0 );
    245373  m_pcTComBitstream->read (uiLength, ruiCode);
     374#if RExt__DECODER_DEBUG_BIT_STATISTICS
     375  TComCodingStatistics::IncrementStatisticEP(STATS__CABAC_PCM_CODE_BITS, uiLength, ruiCode);
     376#endif
    246377}
    247378//! \}
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecBinCoderCABAC.h

    r595 r1029  
    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-2014, ITU/ISO/IEC
     
    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:
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r1025 r1029  
    3939#include "SEIread.h"
    4040#include "TDecSlice.h"
     41#include "TLibCommon/TComChromaFormat.h"
     42#if RExt__DECODER_DEBUG_BIT_STATISTICS
     43#include "TLibCommon/TComCodingStatistics.h"
     44#endif
    4145#if Q0048_CGS_3D_ASYMLUT
    4246#include "../TLibCommon/TCom3DAsymLUT.h"
     
    8286// ====================================================================================================================
    8387
    84 void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
     88Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
    8589{
    8690  UInt code;
     
    178182}
    179183
    180 Void TDecCavlc::parsePPS(TComPPS* pcPPS
    181184#if Q0048_CGS_3D_ASYMLUT
    182   , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
    183 #endif
    184   )
     185Void TDecCavlc::parsePPS(TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT, Int nLayerID)
     186#else
     187Void TDecCavlc::parsePPS(TComPPS* pcPPS)
     188#endif
     189
    185190{
    186191#if ENC_DEC_TRACE
     
    200205
    201206  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
     207
    202208  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
    203209
    204210  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
     211
    205212  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
    206213
     
    231238  }
    232239  READ_SVLC( iCode, "pps_cb_qp_offset");
    233   pcPPS->setChromaCbQpOffset(iCode);
    234   assert( pcPPS->getChromaCbQpOffset() >= -12 );
    235   assert( pcPPS->getChromaCbQpOffset() <=  12 );
     240  pcPPS->setQpOffset(COMPONENT_Cb, iCode);
     241  assert( pcPPS->getQpOffset(COMPONENT_Cb) >= -12 );
     242  assert( pcPPS->getQpOffset(COMPONENT_Cb) <=  12 );
    236243
    237244  READ_SVLC( iCode, "pps_cr_qp_offset");
    238   pcPPS->setChromaCrQpOffset(iCode);
    239   assert( pcPPS->getChromaCrQpOffset() >= -12 );
    240   assert( pcPPS->getChromaCrQpOffset() <=  12 );
     245  pcPPS->setQpOffset(COMPONENT_Cr, iCode);
     246  assert( pcPPS->getQpOffset(COMPONENT_Cr) >= -12 );
     247  assert( pcPPS->getQpOffset(COMPONENT_Cr) <=  12 );
     248
     249  assert(MAX_NUM_COMPONENT<=3);
    241250
    242251  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
     
    259268    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
    260269
    261     if( !pcPPS->getTileUniformSpacingFlag())
    262     {
    263       std::vector<Int> columnWidth(pcPPS->getNumTileColumnsMinus1());
    264       for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
    265       {
    266         READ_UVLC( uiCode, "column_width_minus1" );
    267         columnWidth[i] = uiCode+1;
    268       }
    269       pcPPS->setTileColumnWidth(columnWidth);
    270 
    271       std::vector<Int> rowHeight (pcPPS->getTileNumRowsMinus1());
    272       for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
    273       {
    274         READ_UVLC( uiCode, "row_height_minus1" );
    275         rowHeight[i] = uiCode + 1;
    276       }
    277       pcPPS->setTileRowHeight(rowHeight);
    278     }
    279 
    280     if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
     270    const UInt tileColumnsMinus1 = pcPPS->getNumTileColumnsMinus1();
     271    const UInt tileRowsMinus1    = pcPPS->getNumTileRowsMinus1();
     272 
     273    if ( !pcPPS->getTileUniformSpacingFlag())
     274    {
     275      if (tileColumnsMinus1 > 0)
     276      {
     277        std::vector<Int> columnWidth(tileColumnsMinus1);
     278        for(UInt i = 0; i < tileColumnsMinus1; i++)
     279        {
     280          READ_UVLC( uiCode, "column_width_minus1" ); 
     281          columnWidth[i] = uiCode+1;
     282        }
     283        pcPPS->setTileColumnWidth(columnWidth);
     284      }
     285
     286      if (tileRowsMinus1 > 0)
     287      {
     288        std::vector<Int> rowHeight (tileRowsMinus1);
     289        for(UInt i = 0; i < tileRowsMinus1; i++)
     290        {
     291          READ_UVLC( uiCode, "row_height_minus1" );
     292          rowHeight[i] = uiCode + 1;
     293        }
     294        pcPPS->setTileRowHeight(rowHeight);
     295      }
     296    }
     297
     298    if ((tileColumnsMinus1 + tileRowsMinus1) != 0)
    281299    {
    282300      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
     
    295313    }
    296314  }
    297 #if !R0042_PROFILE_INDICATION
    298 #if SCALINGLIST_INFERRING
    299   if( pcPPS->getLayerId() > 0 )
    300   {
    301     READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
    302     pcPPS->setInferScalingListFlag( uiCode );
    303   }
    304 
    305   if( pcPPS->getInferScalingListFlag() )
    306   {
    307     READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setScalingListRefLayerId( uiCode );
    308 
    309     // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    310     assert( pcPPS->getScalingListRefLayerId() <= 62 );
    311 
    312     pcPPS->setScalingListPresentFlag( false );
    313   }
    314   else
    315   {
    316 #endif
    317 #endif
    318 
    319     READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
    320 
    321     if(pcPPS->getScalingListPresentFlag ())
    322     {
    323       parseScalingList( pcPPS->getScalingList() );
    324     }
    325 #if !R0042_PROFILE_INDICATION
    326 #if SCALINGLIST_INFERRING
    327   }
    328 #endif
    329 #endif
     315  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
     316  if(pcPPS->getScalingListPresentFlag ())
     317  {
     318    parseScalingList( pcPPS->getScalingList() );
     319  }
    330320
    331321  READ_FLAG( uiCode, "lists_modification_present_flag");
     
    338328  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
    339329
    340 #if !R0042_PROFILE_INDICATION
    341   READ_FLAG( uiCode, "pps_extension_flag");
    342 #else
    343330  READ_FLAG( uiCode, "pps_extension_present_flag");
    344   UInt ppsExtension6bits = 0;
    345 #endif
    346 
    347 #if !R0042_PROFILE_INDICATION
    348 #if POC_RESET_INFO_INFERENCE
    349   pcPPS->setExtensionFlag( uiCode ? true : false );
    350 
    351   if( pcPPS->getExtensionFlag() )
    352 #else
    353   if (uiCode)
    354 #endif 
    355   {
    356 #if P0166_MODIFIED_PPS_EXTENSION
    357     UInt ppsExtensionTypeFlag[8];
    358     for (UInt i = 0; i < 8; i++)
    359     {
    360       READ_FLAG( ppsExtensionTypeFlag[i], "pps_extension_type_flag" );
    361     }
    362 #if !POC_RESET_IDC
    363     if (ppsExtensionTypeFlag[1])
    364     {
    365 #else
    366     if( ppsExtensionTypeFlag[0] )
    367     {
    368       READ_FLAG( uiCode, "poc_reset_info_present_flag" );
    369       pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
    370 #if REF_REGION_OFFSET
    371       READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
    372       for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
    373       {
    374         READ_CODE( 6, uiCode,  "scaled_ref_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
    375         READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
    376         if (uiCode)
    377         {
    378           Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
    379           READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    380           READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
    381           READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
    382           READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    383 #if P0312_VERT_PHASE_ADJ
    384           READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
    385 #endif
    386         }
    387         READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
    388         if (uiCode)
    389         {
    390           Window& refWindow = pcPPS->getRefLayerWindow(i);
    391           READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
    392           READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
    393           READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
    394           READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
    395         }
    396 #if R0209_GENERIC_PHASE
    397         READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
    398         if (uiCode)
    399         {
    400           READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
    401           READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
    402           READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
    403           READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
    404         }
    405 #endif
    406       }
    407 #else
    408 #if MOVE_SCALED_OFFSET_TO_PPS
    409       READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
    410       for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
    411       {
    412         Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
    413 #if O0098_SCALED_REF_LAYER_ID
    414         READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
    415 #endif
    416         READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    417         READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
    418         READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
    419         READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    420 #if P0312_VERT_PHASE_ADJ
    421         READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
    422 #endif
    423       }
    424 #endif
    425 #endif
    426 #if Q0048_CGS_3D_ASYMLUT
    427       READ_FLAG( uiCode , "colour_mapping_enabled_flag" );
    428       pcPPS->setCGSFlag( uiCode );
    429       if( pcPPS->getCGSFlag() )
    430       {
    431         xParse3DAsymLUT( pc3DAsymLUT );
    432         pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
    433         pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
    434       }
    435 #endif
    436 #endif
    437     }
    438 #if POC_RESET_INFO_INFERENCE
    439     else  // Extension type 0 absent
    440     {
    441       pcPPS->setPocResetInfoPresentFlag( false );
    442     }
    443 #endif
    444     if (ppsExtensionTypeFlag[7])
    445     {
    446 #endif
    447 
    448       while ( xMoreRbspData() )
    449       {
    450         READ_FLAG( uiCode, "pps_extension_data_flag");
    451       }
    452 #if P0166_MODIFIED_PPS_EXTENSION
    453     }
    454 #endif
    455   }
    456 #if POC_RESET_INFO_INFERENCE
    457   if( !pcPPS->getExtensionFlag() )
    458   {
    459     pcPPS->setPocResetInfoPresentFlag( false );
    460   }
    461 #endif
    462 #else
     331
     332#if SVC_EXTENSION
    463333  pcPPS->setExtensionFlag( uiCode ? true : false );
    464334  if( pcPPS->getExtensionFlag() )
    465   {
    466     READ_FLAG( uiCode, "pps_range_extension_flag" );
    467     assert(uiCode == 0);
    468     READ_FLAG( uiCode, "pps_multilayer_extension_flag" );
    469     assert(uiCode == 1);
     335#else
     336  if (uiCode)
     337#endif
     338  {
     339    Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS];
     340    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
     341    {
     342      READ_FLAG( uiCode, "pps_extension_flag[]" );
     343      pps_extension_flags[i] = uiCode!=0;
     344    }
     345
     346    Bool bSkipTrailingExtensionBits=false;
     347    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     348    {
     349      if (pps_extension_flags[i])
     350      {
     351        switch (PPSExtensionFlagIndex(i))
     352        {
     353          case PPS_EXT__REXT:
     354            assert(!bSkipTrailingExtensionBits);
     355
     356            if (pcPPS->getUseTransformSkip())
     357            {
     358              READ_UVLC( uiCode, "log2_transform_skip_max_size_minus2");
     359              pcPPS->setTransformSkipLog2MaxSize(uiCode+2);
     360            }
     361
     362            READ_FLAG( uiCode, "cross_component_prediction_flag");
     363            pcPPS->setUseCrossComponentPrediction(uiCode != 0);
     364
     365            READ_FLAG( uiCode, "chroma_qp_adjustment_enabled_flag");
     366            if (uiCode == 0)
     367            {
     368              pcPPS->clearChromaQpAdjTable();
     369              pcPPS->setMaxCuChromaQpAdjDepth(0);
     370            }
     371            else
     372            {
     373              READ_UVLC(uiCode, "diff_cu_chroma_qp_adjustment_depth"); pcPPS->setMaxCuChromaQpAdjDepth(uiCode);
     374              UInt tableSizeMinus1 = 0;
     375              READ_UVLC(tableSizeMinus1, "chroma_qp_adjustment_table_size_minus1");
     376              /* skip zero index */
     377              for (Int chromaQpAdjustmentIndex = 1; chromaQpAdjustmentIndex <= (tableSizeMinus1 + 1); chromaQpAdjustmentIndex++)
     378              {
     379                Int cbOffset;
     380                Int crOffset;
     381                READ_SVLC(cbOffset, "cb_qp_adjustnemt[i]");
     382                READ_SVLC(crOffset, "cr_qp_adjustnemt[i]");
     383                pcPPS->setChromaQpAdjTableAt(chromaQpAdjustmentIndex, cbOffset, crOffset);
     384              }
     385              assert(pcPPS->getChromaQpAdjTableSize() == tableSizeMinus1 + 1);
     386            }
     387
     388            READ_UVLC( uiCode, "sao_luma_bit_shift");
     389            pcPPS->setSaoOffsetBitShift(CHANNEL_TYPE_LUMA, uiCode);
     390            READ_UVLC( uiCode, "sao_chroma_bit_shift");
     391            pcPPS->setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, uiCode);
     392            break;
     393
    470394#if SVC_EXTENSION
    471     READ_CODE(6, ppsExtension6bits, "pps_extension_6bits");
    472 #else
    473     READ_CODE(6, uiCode, "pps_extension_6bits");
    474     assert(uiCode == 0);
    475 #endif
    476 
    477     READ_FLAG( uiCode, "poc_reset_info_present_flag" );
    478     pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
     395          case PPS_EXT__MLAYER:
     396            READ_FLAG( uiCode, "poc_reset_info_present_flag" );
     397            pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
    479398
    480399#if SCALINGLIST_INFERRING
    481     READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
    482     pcPPS->setInferScalingListFlag( uiCode );
    483 
    484     if( pcPPS->getInferScalingListFlag() )
    485     {
    486       READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" );
    487       pcPPS->setScalingListRefLayerId( uiCode );
    488       // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    489       assert( pcPPS->getScalingListRefLayerId() <= 62 );
    490       pcPPS->setScalingListPresentFlag( false );
    491     }
     400            READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
     401            pcPPS->setInferScalingListFlag( uiCode );
     402
     403            if( pcPPS->getInferScalingListFlag() )
     404            {
     405              READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" );
     406              pcPPS->setScalingListRefLayerId( uiCode );
     407              // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     408              assert( pcPPS->getScalingListRefLayerId() <= 62 );
     409              pcPPS->setScalingListPresentFlag( false );
     410            }
    492411#endif
    493412
    494413#if REF_REGION_OFFSET
    495     READ_UVLC( uiCode,      "num_ref_loc_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
    496     for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
    497     {
    498       READ_CODE( 6, uiCode,  "ref_loc_offset_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
    499       READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
    500       if (uiCode)
    501       {
    502         Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
    503         READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    504         READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
    505         READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
    506         READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     414            READ_UVLC( uiCode,      "num_ref_loc_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     415            for(Int k = 0; k < pcPPS->getNumScaledRefLayerOffsets(); k++)
     416            {
     417              READ_CODE( 6, uiCode,  "ref_loc_offset_layer_id" );  pcPPS->setScaledRefLayerId( k, uiCode );
     418              READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( k, uiCode );
     419              if (uiCode)
     420              {
     421                Window& scaledWindow = pcPPS->getScaledRefLayerWindow(k);
     422                READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     423                READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     424                READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     425                READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    507426#if P0312_VERT_PHASE_ADJ
    508         READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
    509 #endif
    510       }
    511       READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
    512       if (uiCode)
    513       {
    514         Window& refWindow = pcPPS->getRefLayerWindow(i);
    515         READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
    516         READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
    517         READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
    518         READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
    519       }
     427                READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
     428#endif
     429              }
     430              READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( k, uiCode );
     431              if (uiCode)
     432              {
     433                Window& refWindow = pcPPS->getRefLayerWindow(k);
     434                READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
     435                READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
     436                READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
     437                READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
     438              }
    520439#if R0209_GENERIC_PHASE
    521       READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
    522       if (uiCode)
    523       {
    524         READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
    525         READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
    526         READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
    527         READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
    528       }
    529 #endif
    530     }
     440              READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( k, uiCode );
     441              if (uiCode)
     442              {
     443                READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( k, uiCode );
     444                READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( k, uiCode );
     445                READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (k, uiCode - 8);
     446                READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (k, uiCode - 8);
     447              }
     448#endif
     449            }
    531450#else
    532451#if MOVE_SCALED_OFFSET_TO_PPS
    533       READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
    534       for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
    535       {
    536         Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     452            READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     453            for(Int k = 0; k < pcPPS->getNumScaledRefLayerOffsets(); k++)
     454            {
     455              Window& scaledWindow = pcPPS->getScaledRefLayerWindow(k);
    537456#if O0098_SCALED_REF_LAYER_ID
    538         READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
    539 #endif
    540         READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    541         READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
    542         READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
    543         READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     457              READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( k, uiCode );
     458#endif
     459              READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     460              READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     461              READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     462              READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    544463#if P0312_VERT_PHASE_ADJ
    545         READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
    546 #endif
    547       }
     464              READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(k), uiCode);
     465#endif
     466            }
    548467#endif
    549468#endif
    550469#if Q0048_CGS_3D_ASYMLUT
    551       READ_FLAG( uiCode , "colour_mapping_enabled_flag" );
    552       pcPPS->setCGSFlag( uiCode );
    553       if( pcPPS->getCGSFlag() )
    554       {
     470            READ_FLAG( uiCode , "colour_mapping_enabled_flag" );
     471            pcPPS->setCGSFlag( uiCode );
     472            if( pcPPS->getCGSFlag() )
     473            {
    555474#if R0157_RESTRICT_PPSID_FOR_CGS_LUT
    556         // when pps_pic_parameter_set_id greater than or equal to 8, colour_mapping_enabled_flag shall be equal to 0
    557         assert( pcPPS->getPPSId() < 8 );
    558 #endif
    559         xParse3DAsymLUT( pc3DAsymLUT );
    560         pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
    561         pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
    562       }
    563 #endif
    564   }
    565 
    566 #if SVC_EXTENSION
    567   if( ppsExtension6bits )
    568   {
    569     while( xMoreRbspData() )
    570     {
    571       READ_FLAG( uiCode, "pps_extension_data_flag" );
    572     }
    573   }
    574 #endif
    575 #endif
    576 
     475              // when pps_pic_parameter_set_id greater than or equal to 8, colour_mapping_enabled_flag shall be equal to 0
     476              assert( pcPPS->getPPSId() < 8 );
     477#endif
     478              xParse3DAsymLUT( pc3DAsymLUT );
     479              pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
     480              pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
     481            }
     482#endif
     483            break;
     484#endif
     485          default:
     486            bSkipTrailingExtensionBits=true;
     487            break;
     488        }
     489      }
     490    }
     491    if (bSkipTrailingExtensionBits)
     492    {
     493      while ( xMoreRbspData() )
     494      {
     495        READ_FLAG( uiCode, "pps_extension_data_flag");
     496      }
     497    }
     498  }
    577499}
    578500
     
    637559    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
    638560  }
     561
    639562  TimingInfo *timingInfo = pcVUI->getTimingInfo();
    640563  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     
    654577      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    655578    }
     579
    656580    READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
    657581    if( pcVUI->getHrdParametersPresentFlag() )
     
    660584    }
    661585  }
     586
    662587  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
    663588  if (pcVUI->getBitstreamRestrictionFlag())
     
    722647      hrd->setFixedPicRateWithinCvsFlag( i, true );
    723648    }
     649
    724650    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
    725651    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
     652
    726653    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
    727654    {
     
    736663      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
    737664    }
     665
    738666    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    739667    {
    740668      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
    741         ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
     669          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
    742670      {
    743671        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
     
    757685}
    758686
    759 #if SVC_EXTENSION && !SPS_DPB_PARAMS
    760 Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
    761 #else
    762687Void TDecCavlc::parseSPS(TComSPS* pcSPS)
    763 #endif
    764688{
    765689#if ENC_DEC_TRACE
     
    767691#endif
    768692
    769 #if R0042_PROFILE_INDICATION
    770   UInt uiTmp = 0;
    771   Bool bMultiLayerExtSpsFlag;
    772 #endif
    773693  UInt  uiCode;
    774694  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
     695
    775696#if SVC_EXTENSION
     697  UInt uiTmp = 0;
     698 
    776699  if(pcSPS->getLayerId() == 0)
    777700  {
    778701#endif
    779     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
    780     assert(uiCode <= 6);
     702  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     703  assert(uiCode <= 6);
    781704#if SVC_EXTENSION
    782705  }
    783 #if R0042_PROFILE_INDICATION
    784706  else
    785707  {
    786708    READ_CODE( 3,  uiCode, "sps_ext_or_max_sub_layers_minus1" );     uiTmp = uiCode;
    787     if(!( pcSPS->getLayerId() != 0 && uiTmp == 7 ))
    788     {
    789       pcSPS->setMaxTLayers(uiTmp+1);
    790     }
    791   }
    792 #endif
    793 #if !SPS_DPB_PARAMS
    794   if(pcSPS->getLayerId() != 0)
    795   {
    796     pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
    797   }
    798 #endif
    799 #endif
    800 
     709
     710    if( uiTmp != 7 )
     711    {
     712      pcSPS->setMaxTLayers(uiTmp + 1);
     713    }
     714  }
     715
     716  Bool V1CompatibleSPSFlag = !( pcSPS->getLayerId() != 0 && uiTmp == 7 );
     717
     718  if( V1CompatibleSPSFlag )
     719  {
     720#endif
     721  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );           pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
     722  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    801723#if SVC_EXTENSION
    802 #if R0042_PROFILE_INDICATION
    803   bMultiLayerExtSpsFlag = ( pcSPS->getLayerId() != 0 && uiTmp == 7 );
    804 #endif
    805 #endif
    806 
    807 #if SVC_EXTENSION
    808 #if !R0042_PROFILE_INDICATION
    809   if(pcSPS->getLayerId() == 0)
    810 #else
    811   if(!bMultiLayerExtSpsFlag)
    812 #endif
    813   {
    814 #endif
    815     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
    816 #if SVC_EXTENSION
    817   }
    818 #if !SPS_DPB_PARAMS
    819   else
    820   {
    821     pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
    822   }
    823 #endif
    824 #endif
    825 
    826 #if !Q0177_SPS_TEMP_NESTING_FIX   //This part is not needed anymore as it is already covered by implementation in TDecTop::xActivateParameterSets()
     724  }
     725#else
    827726  if ( pcSPS->getMaxTLayers() == 1 )
    828727  {
    829728    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
    830 #if SVC_EXTENSION
    831 #if !SPS_DPB_PARAMS
    832     assert( pcSPS->getTemporalIdNestingFlag() == true );
    833 #endif
    834 #else
    835729    assert( uiCode == 1 );
    836 #endif
    837   }
    838 #endif
    839 
    840 #ifdef SPS_PTL_FIX
    841 #if !R0042_PROFILE_INDICATION
    842   if ( pcSPS->getLayerId() == 0)
    843 #else
    844   if(!bMultiLayerExtSpsFlag)
    845 #endif
    846   {
    847     parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    848   }
    849 #else
    850   parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     730  }
    851731#endif
    852732
     
    854734  assert(uiCode <= 15);
    855735
    856 #if REPN_FORMAT_IN_VPS
    857 #if !R0042_PROFILE_INDICATION
    858   if( pcSPS->getLayerId() > 0 )
    859 #else
    860   if( bMultiLayerExtSpsFlag)
    861 #endif
     736#if SVC_EXTENSION
     737  if( !V1CompatibleSPSFlag )
    862738  {
    863739    READ_FLAG( uiCode, "update_rep_format_flag" );
    864740    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
    865 #if R0042_PROFILE_INDICATION   
    866     if( bMultiLayerExtSpsFlag && uiCode)
     741   
     742    if( pcSPS->getUpdateRepFormatFlag() )
    867743    {
    868744      READ_CODE(8, uiCode, "sps_rep_format_idx");
    869745      pcSPS->setUpdateRepFormatIndex(uiCode);
    870746    }
    871 #endif
    872747  }
    873748  else
    874749  {
    875 #if REP_FORMAT_FIX
    876750    pcSPS->setUpdateRepFormatFlag( false );
    877 #else
    878     pcSPS->setUpdateRepFormatFlag( true );
    879 #endif
    880   }
    881 
    882 #if R0042_PROFILE_INDICATION 
    883   if( !bMultiLayerExtSpsFlag )
    884   {
    885 #else
    886 #if O0096_REP_FORMAT_INDEX
    887   if( pcSPS->getLayerId() == 0 )
    888 #else
    889   if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
    890 #endif
    891 #endif
    892   {
    893 #endif
    894 #if AUXILIARY_PICTURES
    895     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
    896 #else
    897     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
    898 #endif
    899     assert(uiCode <= 3);
    900     // 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
    901     assert (uiCode == 1);
    902     if( uiCode == 3 )
    903     {
    904       READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
    905     }
    906 
    907     READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
    908     READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     751#endif
     752  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
     753  assert(uiCode <= 3);
     754
     755  if( pcSPS->getChromaFormatIdc() == CHROMA_444 )
     756  {
     757    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
     758  }
     759
     760  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
     761  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     762  READ_FLAG(     uiCode, "conformance_window_flag");
     763  if (uiCode != 0)
     764  {
     765    Window &conf = pcSPS->getConformanceWindow();
    909766#if REPN_FORMAT_IN_VPS
    910   }
    911 #if O0096_REP_FORMAT_INDEX
    912 #if !R0042_PROFILE_INDICATION
    913   else if ( pcSPS->getUpdateRepFormatFlag() )
    914   {
    915     READ_CODE(8, uiCode, "update_rep_format_index");
    916     pcSPS->setUpdateRepFormatIndex(uiCode);
    917   }
    918 #endif
    919 #endif
    920 #endif
    921 
    922 #if R0156_CONF_WINDOW_IN_REP_FORMAT
    923 #if REPN_FORMAT_IN_VPS
    924 #if !R0042_PROFILE_INDICATION 
    925 #if O0096_REP_FORMAT_INDEX
    926   if( pcSPS->getLayerId() == 0 )
    927 #else
    928   if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
    929 #endif
    930 #endif
    931   {
    932 #endif
    933 #endif
    934     READ_FLAG(     uiCode, "conformance_window_flag");
    935     if (uiCode != 0)
    936     {
    937       Window &conf = pcSPS->getConformanceWindow();
    938 #if REPN_FORMAT_IN_VPS
    939       READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
    940       READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
    941       READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
    942       READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
    943 #else
    944       READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
    945       READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
    946       READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
    947       READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
    948 #endif
    949     }
    950 #if R0156_CONF_WINDOW_IN_REP_FORMAT
    951 #if REPN_FORMAT_IN_VPS
    952   }
    953 #endif
    954 #endif
    955 
    956 #if REPN_FORMAT_IN_VPS
    957 #if !R0042_PROFILE_INDICATION 
    958 #if O0096_REP_FORMAT_INDEX
    959   if( pcSPS->getLayerId() == 0 )
    960 #else
    961   if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
    962 #endif
    963 #endif
    964   {
    965 #endif
    966     READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    967     assert(uiCode <= 6);
    968     pcSPS->setBitDepthY( uiCode + 8 );
    969     pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
    970 
    971     READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
    972     assert(uiCode <= 6);
    973     pcSPS->setBitDepthC( uiCode + 8 );
    974     pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
    975 #if REPN_FORMAT_IN_VPS
    976   }
    977 #endif
    978 #if R0042_PROFILE_INDICATION 
    979   }
    980 #endif
     767    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
     768    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
     769    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
     770    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
     771#else
     772    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     773    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     774    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     775    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     776#endif
     777  }
     778
     779  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
     780#if O0043_BEST_EFFORT_DECODING
     781  const UInt forceDecodeBitDepth = pcSPS->getForceDecodeBitDepth();
     782  g_bitDepthInStream[CHANNEL_TYPE_LUMA] = 8 + uiCode;
     783  if (forceDecodeBitDepth != 0)
     784  {
     785    uiCode = forceDecodeBitDepth - 8;
     786  }
     787#endif
     788  assert(uiCode <= 8);
     789
     790  pcSPS->setBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
     791#if O0043_BEST_EFFORT_DECODING
     792  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*(g_bitDepthInStream[CHANNEL_TYPE_LUMA]-8)) );
     793#else
     794  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*uiCode) );
     795#endif
     796
     797  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
     798#if O0043_BEST_EFFORT_DECODING
     799  g_bitDepthInStream[CHANNEL_TYPE_CHROMA] = 8 + uiCode;
     800  if (forceDecodeBitDepth != 0)
     801  {
     802    uiCode = forceDecodeBitDepth - 8;
     803  }
     804#endif
     805  assert(uiCode <= 8);
     806  pcSPS->setBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
     807#if O0043_BEST_EFFORT_DECODING
     808  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*(g_bitDepthInStream[CHANNEL_TYPE_CHROMA]-8)) );
     809#else
     810  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*uiCode) );
     811#endif
     812
     813#if SVC_EXTENSION
     814  }
     815#endif
     816
    981817
    982818  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
    983819  assert(uiCode <= 12);
    984820
    985 #if SPS_DPB_PARAMS
    986 #if !R0042_PROFILE_INDICATION
    987   if( pcSPS->getLayerId() == 0 ) 
    988   {
    989 #else
    990   if( !bMultiLayerExtSpsFlag ) 
    991   {
    992 #endif
    993 #endif
    994     UInt subLayerOrderingInfoPresentFlag;
    995     READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
    996 
    997     for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    998     {
    999       READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
    1000       pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
    1001       READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
    1002       pcSPS->setNumReorderPics(uiCode, i);
    1003       READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
    1004       pcSPS->setMaxLatencyIncrease( uiCode, i );
    1005 
    1006       if (!subLayerOrderingInfoPresentFlag)
    1007       {
    1008         for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
    1009         {
    1010           pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
    1011           pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
    1012           pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
    1013         }
    1014         break;
    1015       }
    1016     }
    1017 #if SPS_DPB_PARAMS
     821#if SVC_EXTENSION
     822  if( V1CompatibleSPSFlag ) 
     823  {
     824#endif
     825  UInt subLayerOrderingInfoPresentFlag;
     826  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
     827
     828  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     829  {
     830    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
     831    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
     832    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
     833    pcSPS->setNumReorderPics(uiCode, i);
     834    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
     835    pcSPS->setMaxLatencyIncrease( uiCode, i );
     836
     837    if (!subLayerOrderingInfoPresentFlag)
     838    {
     839      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
     840      {
     841        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
     842        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
     843        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
     844      }
     845      break;
     846    }
     847  }
     848#if SVC_EXTENSION
    1018849  }
    1019850#endif
     
    1023854  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
    1024855  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
    1025 
     856 
    1026857  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
    1027858  {
    1028859    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
    1029860  }
    1030 
     861 
    1031862  Int maxCUDepthDelta = uiCode;
    1032863  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
     
    1041872
    1042873  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
    1043   pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
     874  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth  + getMaxCUDepthOffset(pcSPS->getChromaFormatIdc(), pcSPS->getQuadtreeTULog2MinSize()) );
     875
    1044876  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
    1045 
    1046877  if(pcSPS->getScalingListFlag())
    1047878  {
    1048 #if SCALINGLIST_INFERRING
    1049 #if !R0042_PROFILE_INDICATION
    1050     if( pcSPS->getLayerId() > 0 )
    1051 #else
    1052     if( bMultiLayerExtSpsFlag )
    1053 #endif
     879#if SVC_EXTENSION
     880    if( !V1CompatibleSPSFlag )
    1054881    {
    1055882      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
     
    1068895    {
    1069896#endif
    1070       READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
    1071       if(pcSPS->getScalingListPresentFlag ())
    1072       {
    1073         parseScalingList( pcSPS->getScalingList() );
    1074       }
    1075 #if SCALINGLIST_INFERRING
     897    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     898    if(pcSPS->getScalingListPresentFlag ())
     899    {
     900      parseScalingList( pcSPS->getScalingList() );
     901    }
     902#if SVC_EXTENSION
    1076903    }
    1077904#endif
     
    1083910  if( pcSPS->getUsePCM() )
    1084911  {
    1085     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
    1086     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
     912    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_LUMA, 1 + uiCode );
     913    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_CHROMA, 1 + uiCode );
    1087914    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
    1088915    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
     
    1116943  }
    1117944  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
     945
    1118946  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
    1119947
     
    1125953  }
    1126954
    1127   READ_FLAG( uiCode, "sps_extension_flag");
     955  READ_FLAG( uiCode, "sps_extension_present_flag");
    1128956
    1129957#if SVC_EXTENSION
    1130958  pcSPS->setExtensionFlag( uiCode ? true : false );
    1131   UInt spsExtension6bits = 0;
    1132959
    1133960  if( pcSPS->getExtensionFlag() )
    1134   {
    1135 #if !R0042_PROFILE_INDICATION
    1136 #if O0142_CONDITIONAL_SPS_EXTENSION
    1137     UInt spsExtensionTypeFlag[8];
    1138     for (UInt i = 0; i < 8; i++)
    1139     {
    1140       READ_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
    1141     }
    1142     if (spsExtensionTypeFlag[1])
    1143     {
    1144       parseSPSExtension( pcSPS );
    1145     }
    1146     if (spsExtensionTypeFlag[7])
    1147     {
    1148 #else
    1149     parseSPSExtension( pcSPS );
    1150     READ_FLAG( uiCode, "sps_extension2_flag");
    1151     if(uiCode)
    1152     {
    1153 #endif
     961#else
     962  if (uiCode)
     963#endif
     964  {
     965    Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS];
     966    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
     967    {
     968      READ_FLAG( uiCode, "sps_extension_flag[]" );
     969      sps_extension_flags[i] = uiCode!=0;
     970    }
     971
     972    Bool bSkipTrailingExtensionBits=false;
     973    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     974    {
     975      if (sps_extension_flags[i])
     976      {
     977        switch (SPSExtensionFlagIndex(i))
     978        {
     979          case SPS_EXT__REXT:
     980            assert(!bSkipTrailingExtensionBits);
     981
     982            READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     pcSPS->setUseResidualRotation                    (uiCode != 0);
     983            READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      pcSPS->setUseSingleSignificanceMapContext        (uiCode != 0);
     984            READ_FLAG( uiCode, "residual_dpcm_implicit_enabled_flag");      pcSPS->setUseResidualDPCM(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
     985            READ_FLAG( uiCode, "residual_dpcm_explicit_enabled_flag");      pcSPS->setUseResidualDPCM(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
     986            READ_FLAG( uiCode, "extended_precision_processing_flag");       pcSPS->setUseExtendedPrecision                   (uiCode != 0);
     987            READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            pcSPS->setDisableIntraReferenceSmoothing         (uiCode != 0);
     988            READ_FLAG( uiCode, "high_precision_prediction_weighting_flag"); pcSPS->setUseHighPrecisionPredictionWeighting    (uiCode != 0);
     989            READ_FLAG( uiCode, "golomb_rice_parameter_adaptation_flag");    pcSPS->setUseGolombRiceParameterAdaptation       (uiCode != 0);
     990            READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      pcSPS->setAlignCABACBeforeBypass                 (uiCode != 0);
     991            break;
     992#if SVC_EXTENSION
     993          case SPS_EXT__MLAYER:
     994            parseSPSExtension( pcSPS );
     995            break;
     996#endif
     997          default:
     998            bSkipTrailingExtensionBits=true;
     999            break;
     1000        }
     1001      }
     1002    }
     1003    if (bSkipTrailingExtensionBits)
     1004    {
    11541005      while ( xMoreRbspData() )
    11551006      {
     
    11571008      }
    11581009    }
    1159     }
    1160 #else
    1161     READ_FLAG( uiCode, "sps_range_extension_flag" );
    1162     assert(uiCode == 0);
    1163     READ_FLAG( uiCode, "sps_multilayer_extension_flag" );
    1164     assert(uiCode == 1);
    1165     READ_CODE(6, spsExtension6bits, "sps_extension_6bits");
    1166     parseSPSExtension( pcSPS );
    1167   }
    1168 #endif
    1169   if( spsExtension6bits )
    1170   {
    1171     while( xMoreRbspData() )
    1172     {
    1173       READ_FLAG( uiCode, "sps_extension_data_flag" );
    1174     }
    1175   }
    1176 #else
    1177   if (uiCode)
    1178   {
    1179     while ( xMoreRbspData() )
    1180     {
    1181       READ_FLAG( uiCode, "sps_extension_data_flag");
    1182     }
    1183   }
    1184 #endif
    1185 }
    1186 
    1187 #if SVC_EXTENSION
    1188 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
    1189 {
    1190   UInt uiCode;
    1191   // more syntax elements to be parsed here
    1192 
    1193   READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
    1194   // Vertical MV component restriction is not used in SHVC CTC
    1195   assert( uiCode == 0 );
    1196 
    1197 #if !MOVE_SCALED_OFFSET_TO_PPS
    1198   if( pcSPS->getLayerId() > 0 )
    1199   {
    1200     Int iCode;
    1201     READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
    1202     for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
    1203     {
    1204       Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
    1205 #if O0098_SCALED_REF_LAYER_ID
    1206       READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
    1207 #endif
    1208       READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    1209       READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
    1210       READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
    1211       READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    1212 #if P0312_VERT_PHASE_ADJ
    1213       READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);   
    1214 #endif
    1215     }
    1216   }
    1217 #endif
    1218 }
    1219 #endif
     1010  }
     1011}
    12201012
    12211013Void TDecCavlc::parseVPS(TComVPS* pcVPS)
     
    12391031  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
    12401032#endif
    1241   assert(pcVPS->getBaseLayerInternalFlag() || pcVPS->getMaxLayers() > 1);
     1033  assert( pcVPS->getBaseLayerInternalFlag() || pcVPS->getMaxLayers() > 1 );
    12421034#else
    12431035  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
    12441036#endif
    1245   READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode+1 <= MAX_TLAYER);
     1037  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
    12461038  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    12471039  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
     
    13191111      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    13201112    }
     1113
    13211114    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
    13221115
     
    13831176
    13841177  return;
     1178}
     1179
     1180Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManagerDecoder *parameterSetManager)
     1181{
     1182  UInt  uiCode;
     1183  Int   iCode;
     1184
     1185#if ENC_DEC_TRACE
     1186  xTraceSliceHeader(pcSlice);
     1187#endif
     1188  TComPPS* pps = NULL;
     1189  TComSPS* sps = NULL;
     1190
     1191  UInt firstSliceSegmentInPic;
     1192  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
     1193  if( pcSlice->getRapPicFlag())
     1194  {
     1195    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
     1196    pcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
     1197  }
     1198  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  pcSlice->setPPSId(uiCode);
     1199  pps = parameterSetManager->getPrefetchedPPS(uiCode);
     1200  //!KS: need to add error handling code here, if PPS is not available
     1201  assert(pps!=0);
     1202  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
     1203  //!KS: need to add error handling code here, if SPS is not available
     1204  assert(sps!=0);
     1205  pcSlice->setSPS(sps);
     1206  pcSlice->setPPS(pps);
     1207
     1208  const ChromaFormat chFmt = sps->getChromaFormatIdc();
     1209  const UInt numValidComp=getNumberValidComponents(chFmt);
     1210  const Bool bChroma=(chFmt!=CHROMA_400);
     1211
     1212  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
     1213  {
     1214    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       pcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
     1215  }
     1216  else
     1217  {
     1218    pcSlice->setDependentSliceSegmentFlag(false);
     1219  }
     1220#if REPN_FORMAT_IN_VPS
     1221  Int numCTUs = ((pcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((pcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
     1222#else
     1223  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
     1224#endif 
     1225  UInt sliceSegmentAddress = 0;
     1226  Int bitsSliceSegmentAddress = 0;
     1227  while(numCTUs>(1<<bitsSliceSegmentAddress))
     1228  {
     1229    bitsSliceSegmentAddress++;
     1230  }
     1231
     1232  if(!firstSliceSegmentInPic)
     1233  {
     1234    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
     1235  }
     1236  //set uiCode to equal slice start address (or dependent slice start address)
     1237  pcSlice->setSliceSegmentCurStartCtuTsAddr( sliceSegmentAddress );// this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     1238  pcSlice->setSliceSegmentCurEndCtuTsAddr(numCTUs);                // Set end as the last CTU of the picture.
     1239
     1240  if (!pcSlice->getDependentSliceSegmentFlag())
     1241  {
     1242    pcSlice->setSliceCurStartCtuTsAddr(sliceSegmentAddress); // this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     1243    pcSlice->setSliceCurEndCtuTsAddr(numCTUs);
     1244  }
     1245
     1246#if Q0142_POC_LSB_NOT_PRESENT
     1247#if SHM_FIX7
     1248  Int iPOClsb = 0;
     1249#endif
     1250#endif
     1251
     1252  if(!pcSlice->getDependentSliceSegmentFlag())
     1253  {
     1254#if SVC_EXTENSION
     1255#if POC_RESET_FLAG
     1256    Int iBits = 0;
     1257    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1258    {
     1259      READ_FLAG(uiCode, "poc_reset_flag");      pcSlice->setPocResetFlag( uiCode ? true : false );
     1260      iBits++;
     1261    }
     1262    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1263    {
     1264#if DISCARDABLE_PIC_RPS
     1265      READ_FLAG(uiCode, "discardable_flag"); pcSlice->setDiscardableFlag( uiCode ? true : false );
     1266#else
     1267      READ_FLAG(uiCode, "discardable_flag"); // ignored
     1268#endif
     1269      iBits++;
     1270    }
     1271#if O0149_CROSS_LAYER_BLA_FLAG
     1272    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1273    {
     1274      READ_FLAG(uiCode, "cross_layer_bla_flag");  pcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
     1275      iBits++;
     1276    }
     1277#endif
     1278    for (; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
     1279    {
     1280      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     1281    }
     1282#else
     1283#if CROSS_LAYER_BLA_FLAG_FIX
     1284    Int iBits = 0;
     1285    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1286#else
     1287    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     1288#endif
     1289    {
     1290      READ_FLAG(uiCode, "discardable_flag"); // ignored
     1291#if NON_REF_NAL_TYPE_DISCARDABLE
     1292      pcSlice->setDiscardableFlag( uiCode ? true : false );
     1293      if (uiCode)
     1294      {
     1295        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
     1296          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
     1297          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
     1298          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
     1299          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
     1300      }
     1301#endif
     1302#if CROSS_LAYER_BLA_FLAG_FIX
     1303      iBits++;
     1304#endif
     1305    }
     1306#if CROSS_LAYER_BLA_FLAG_FIX
     1307    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1308    {
     1309      READ_FLAG(uiCode, "cross_layer_bla_flag");  pcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
     1310      iBits++;
     1311    }
     1312    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
     1313#else
     1314    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     1315#endif
     1316    {
     1317      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     1318    }
     1319#endif
     1320#else //SVC_EXTENSION
     1321    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     1322    {
     1323      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     1324    }
     1325#endif //SVC_EXTENSION
     1326
     1327    READ_UVLC (    uiCode, "slice_type" );            pcSlice->setSliceType((SliceType)uiCode);
     1328    if( pps->getOutputFlagPresentFlag() )
     1329    {
     1330      READ_FLAG( uiCode, "pic_output_flag" );    pcSlice->setPicOutputFlag( uiCode ? true : false );
     1331    }
     1332    else
     1333    {
     1334      pcSlice->setPicOutputFlag( true );
     1335    }
     1336
     1337    if( pcSlice->getIdrPicFlag() )
     1338    {
     1339      pcSlice->setPOC(0);
     1340      TComReferencePictureSet* rps = pcSlice->getLocalRPS();
     1341      rps->setNumberOfNegativePictures(0);
     1342      rps->setNumberOfPositivePictures(0);
     1343      rps->setNumberOfLongtermPictures(0);
     1344      rps->setNumberOfPictures(0);
     1345      pcSlice->setRPS(rps);
     1346    }
     1347#if N0065_LAYER_POC_ALIGNMENT
     1348#if O0062_POC_LSB_NOT_PRESENT_FLAG
     1349    if( ( pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag() )
     1350#else
     1351    if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
     1352#endif
     1353#else
     1354    else
     1355#endif
     1356    {
     1357      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
     1358#if POC_RESET_IDC_DECODER
     1359      pcSlice->setPicOrderCntLsb( uiCode );
     1360#endif
     1361#if SVC_EXTENSION
     1362      iPOClsb = uiCode;
     1363#else
     1364      Int iPOClsb = uiCode;
     1365#endif
     1366      Int iPrevPOC = pcSlice->getPrevTid0POC();
     1367      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
     1368      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
     1369      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
     1370      Int iPOCmsb;
     1371      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
     1372      {
     1373        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
     1374      }
     1375      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
     1376      {
     1377        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
     1378      }
     1379      else
     1380      {
     1381        iPOCmsb = iPrevPOCmsb;
     1382      }
     1383      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1384        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1385        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     1386      {
     1387        // For BLA picture types, POCmsb is set to 0.
     1388        iPOCmsb = 0;
     1389      }
     1390      pcSlice->setPOC              (iPOCmsb+iPOClsb);
     1391
     1392#if N0065_LAYER_POC_ALIGNMENT
     1393    }
     1394#if POC_RESET_IDC_DECODER
     1395    else
     1396    {
     1397      pcSlice->setPicOrderCntLsb( 0 );
     1398    }
     1399#endif
     1400    if( !pcSlice->getIdrPicFlag() )
     1401    {
     1402#endif
     1403      TComReferencePictureSet* rps;
     1404      rps = pcSlice->getLocalRPS();
     1405      pcSlice->setRPS(rps);
     1406      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
     1407      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
     1408      {
     1409        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
     1410      }
     1411      else // use reference to short-term reference picture set in PPS
     1412      {
     1413        Int numBits = 0;
     1414        while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     1415        {
     1416          numBits++;
     1417        }
     1418        if (numBits > 0)
     1419        {
     1420          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
     1421        }
     1422        else
     1423        {
     1424          uiCode = 0;
     1425       
     1426        }
     1427        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
     1428      }
     1429      if(sps->getLongTermRefsPresent())
     1430      {
     1431        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
     1432        UInt numOfLtrp = 0;
     1433        UInt numLtrpInSPS = 0;
     1434        if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     1435        {
     1436          READ_UVLC( uiCode, "num_long_term_sps");
     1437          numLtrpInSPS = uiCode;
     1438          numOfLtrp += numLtrpInSPS;
     1439          rps->setNumberOfLongtermPictures(numOfLtrp);
     1440        }
     1441        Int bitsForLtrpInSPS = 0;
     1442        while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     1443        {
     1444          bitsForLtrpInSPS++;
     1445        }
     1446        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
     1447        numOfLtrp += uiCode;
     1448        rps->setNumberOfLongtermPictures(numOfLtrp);
     1449        Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC();
     1450        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
     1451        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
     1452        {
     1453          Int pocLsbLt;
     1454          if (k < numLtrpInSPS)
     1455          {
     1456            uiCode = 0;
     1457            if (bitsForLtrpInSPS > 0)
     1458            {
     1459              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
     1460            }
     1461            Int usedByCurrFromSPS=pcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
     1462
     1463            pocLsbLt = pcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
     1464            rps->setUsed(j,usedByCurrFromSPS);
     1465          }
     1466          else
     1467          {
     1468            READ_CODE(pcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
     1469            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
     1470          }
     1471          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
     1472          Bool mSBPresentFlag = uiCode ? true : false;
     1473          if(mSBPresentFlag)
     1474          {
     1475            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
     1476            Bool deltaFlag = false;
     1477            //            First LTRP                               || First LTRP from SH
     1478            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
     1479            {
     1480              deltaFlag = true;
     1481            }
     1482            if(deltaFlag)
     1483            {
     1484              deltaPocMSBCycleLT = uiCode;
     1485            }
     1486            else
     1487            {
     1488              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
     1489            }
     1490
     1491            Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
     1492                                        - iPOClsb + pocLsbLt;
     1493            rps->setPOC     (j, pocLTCurr);
     1494            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
     1495            rps->setCheckLTMSBPresent(j,true);
     1496          }
     1497          else
     1498          {
     1499            rps->setPOC     (j, pocLsbLt);
     1500            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLsbLt);
     1501            rps->setCheckLTMSBPresent(j,false);
     1502
     1503            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
     1504            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
     1505            {
     1506              deltaPocMSBCycleLT = 0;
     1507            }
     1508          }
     1509          prevDeltaMSB = deltaPocMSBCycleLT;
     1510        }
     1511        offset += rps->getNumberOfLongtermPictures();
     1512        rps->setNumberOfPictures(offset);
     1513      }
     1514#if DPB_CONSTRAINTS
     1515      if(pcSlice->getVPS()->getVpsExtensionFlag()==1)
     1516      {
     1517#if Q0078_ADD_LAYER_SETS
     1518        for (Int ii = 1; ii < (pcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
     1519#else
     1520        for (Int ii=1; ii< pcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
     1521#endif
     1522        {
     1523          Int layerSetIdxForOutputLayerSet = pcSlice->getVPS()->getOutputLayerSetIdx( ii );
     1524          Int chkAssert=0;
     1525          for(Int kk = 0; kk < pcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
     1526          {
     1527#if R0235_SMALLEST_LAYER_ID
     1528            if( pcSlice->getVPS()->getNecessaryLayerFlag(ii, kk) && pcSlice->getLayerId() == pcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk) )
     1529#else
     1530            if(pcSlice->getLayerId() == pcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
     1531#endif
     1532            {
     1533              chkAssert=1;
     1534            }
     1535          }
     1536          if(chkAssert)
     1537          {
     1538            // There may be something wrong here (layer id assumed to be layer idx?)
     1539            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
     1540            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
     1541            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
     1542          }
     1543        }
     1544
     1545
     1546      }
     1547      if(pcSlice->getLayerId() == 0)
     1548      {
     1549        assert(rps->getNumberOfNegativePictures() <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1) );
     1550        assert(rps->getNumberOfPositivePictures() <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
     1551        assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1));
     1552      }
     1553#endif
     1554      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1555        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1556        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     1557      {
     1558        // In the case of BLA picture types, rps data is read from slice header but ignored
     1559        rps = pcSlice->getLocalRPS();
     1560        rps->setNumberOfNegativePictures(0);
     1561        rps->setNumberOfPositivePictures(0);
     1562        rps->setNumberOfLongtermPictures(0);
     1563        rps->setNumberOfPictures(0);
     1564        pcSlice->setRPS(rps);
     1565      }
     1566      if (pcSlice->getSPS()->getTMVPFlagsPresent())
     1567      {
     1568        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
     1569        pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     1570      }
     1571      else
     1572      {
     1573        pcSlice->setEnableTMVPFlag(false);
     1574      }
     1575    }
     1576
     1577#if SVC_EXTENSION
     1578    pcSlice->setActiveNumILRRefIdx(0);
     1579    if((pcSlice->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
     1580    {
     1581      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
     1582      pcSlice->setInterLayerPredEnabledFlag(uiCode);
     1583      if( pcSlice->getInterLayerPredEnabledFlag())
     1584      {
     1585        if(pcSlice->getNumILRRefIdx() > 1)
     1586        {
     1587          Int numBits = 1;
     1588          while ((1 << numBits) < pcSlice->getNumILRRefIdx())
     1589          {
     1590            numBits++;
     1591          }
     1592          if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
     1593          {
     1594            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
     1595            pcSlice->setActiveNumILRRefIdx(uiCode + 1);
     1596          }
     1597          else
     1598          {
     1599#if P0079_DERIVE_NUMACTIVE_REF_PICS
     1600            for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
     1601            {
     1602#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
     1603              if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
     1604                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
     1605#else
     1606              if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
     1607                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
     1608#endif
     1609              {         
     1610                pcSlice->setActiveNumILRRefIdx(1);
     1611                break;
     1612              }
     1613            }
     1614#else
     1615            pcSlice->setActiveNumILRRefIdx(1);
     1616#endif
     1617          }
     1618
     1619          if( pcSlice->getActiveNumILRRefIdx() == pcSlice->getNumILRRefIdx() )
     1620          {
     1621            for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1622            {
     1623              pcSlice->setInterLayerPredLayerIdc(i,i);
     1624            }
     1625          }
     1626          else
     1627          {
     1628            for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1629            {
     1630              READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
     1631              pcSlice->setInterLayerPredLayerIdc(uiCode,i);
     1632            }
     1633          }
     1634        }
     1635        else
     1636        {
     1637#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     1638#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
     1639          if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
     1640            (pcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  pcSlice->getTLayer()) )
     1641#else
     1642          if( (pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,pcSlice->getLayerId()) >  pcSlice->getTLayer()) &&
     1643            (pcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  pcSlice->getTLayer()) )
     1644#endif
     1645          {
     1646#endif
     1647            pcSlice->setActiveNumILRRefIdx(1);
     1648            pcSlice->setInterLayerPredLayerIdc(0,0);
     1649#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     1650          }
     1651#endif
     1652        }
     1653      }
     1654    }
     1655    else if( pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (pcSlice->getLayerId() > 0 ))
     1656    {
     1657      pcSlice->setInterLayerPredEnabledFlag(true);
     1658
     1659#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     1660      Int   numRefLayerPics = 0;
     1661      Int   i = 0;
     1662      Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
     1663      for(i = 0, numRefLayerPics = 0;  i < pcSlice->getNumILRRefIdx(); i++ )
     1664      {
     1665#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
     1666        if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
     1667          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
     1668#else
     1669        if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
     1670          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
     1671#endif
     1672        {         
     1673          refLayerPicIdc[ numRefLayerPics++ ] = i;
     1674        }
     1675      }
     1676      pcSlice->setActiveNumILRRefIdx(numRefLayerPics);
     1677      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1678      {
     1679        pcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
     1680      }     
     1681#else
     1682      pcSlice->setActiveNumILRRefIdx(pcSlice->getNumILRRefIdx());
     1683      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1684      {
     1685        pcSlice->setInterLayerPredLayerIdc(i,i);
     1686      }
     1687#endif
     1688    }
     1689#if P0312_VERT_PHASE_ADJ
     1690    for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1691    {
     1692      UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     1693#if !MOVE_SCALED_OFFSET_TO_PPS
     1694      if( pcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
     1695#else
     1696      if( pcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
     1697#endif
     1698      {
     1699        READ_FLAG( uiCode, "vert_phase_position_flag" ); pcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
     1700      }
     1701    }
     1702#endif
     1703#endif //SVC_EXTENSION
     1704
     1705    if(sps->getUseSAO())
     1706    {
     1707      READ_FLAG(uiCode, "slice_sao_luma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_LUMA, (Bool)uiCode);
     1708#if SVC_EXTENSION
     1709      ChromaFormat format;
     1710      if( sps->getLayerId() == 0 )
     1711      {
     1712        format = sps->getChromaFormatIdc();
     1713      }
     1714      else
     1715      {
     1716        format = pcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : pcSlice->getVPS()->getVpsRepFormatIdx( pcSlice->getVPS()->getLayerIdInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
     1717#if Q0195_REP_FORMAT_CLEANUP
     1718        assert( (sps->getUpdateRepFormatFlag()==false && pcSlice->getVPS()->getVpsNumRepFormats()==1) || pcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
     1719#endif
     1720      }
     1721      if (format != CHROMA_400)
     1722#else
     1723      if (bChroma)
     1724#endif
     1725      {
     1726        READ_FLAG(uiCode, "slice_sao_chroma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, (Bool)uiCode);
     1727      }
     1728#if SVC_EXTENSION
     1729      else
     1730      {
     1731        pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, false);
     1732      }
     1733#endif
     1734    }
     1735
     1736    if (pcSlice->getIdrPicFlag())
     1737    {
     1738      pcSlice->setEnableTMVPFlag(false);
     1739    }
     1740    if (!pcSlice->isIntra())
     1741    {
     1742
     1743      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
     1744      if (uiCode)
     1745      {
     1746        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
     1747        if (pcSlice->isInterB())
     1748        {
     1749          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
     1750        }
     1751        else
     1752        {
     1753          pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     1754        }
     1755      }
     1756      else
     1757      {
     1758        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getPPS()->getNumRefIdxL0DefaultActive());
     1759        if (pcSlice->isInterB())
     1760        {
     1761          pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getPPS()->getNumRefIdxL1DefaultActive());
     1762        }
     1763        else
     1764        {
     1765          pcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
     1766        }
     1767      }
     1768    }
     1769    // }
     1770    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     1771    if(!pcSlice->isIntra())
     1772    {
     1773      if( !pcSlice->getPPS()->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
     1774      {
     1775        refPicListModification->setRefPicListModificationFlagL0( 0 );
     1776      }
     1777      else
     1778      {
     1779        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
     1780      }
     1781
     1782      if(refPicListModification->getRefPicListModificationFlagL0())
     1783      {
     1784        uiCode = 0;
     1785        Int i = 0;
     1786        Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList();
     1787        if ( numRpsCurrTempList0 > 1 )
     1788        {
     1789          Int length = 1;
     1790          numRpsCurrTempList0 --;
     1791          while ( numRpsCurrTempList0 >>= 1)
     1792          {
     1793            length ++;
     1794          }
     1795          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     1796          {
     1797            READ_CODE( length, uiCode, "list_entry_l0" );
     1798            refPicListModification->setRefPicSetIdxL0(i, uiCode );
     1799          }
     1800        }
     1801        else
     1802        {
     1803          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     1804          {
     1805            refPicListModification->setRefPicSetIdxL0(i, 0 );
     1806          }
     1807        }
     1808      }
     1809    }
     1810    else
     1811    {
     1812      refPicListModification->setRefPicListModificationFlagL0(0);
     1813    }
     1814    if(pcSlice->isInterB())
     1815    {
     1816      if( !pcSlice->getPPS()->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
     1817      {
     1818        refPicListModification->setRefPicListModificationFlagL1( 0 );
     1819      }
     1820      else
     1821      {
     1822        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
     1823      }
     1824      if(refPicListModification->getRefPicListModificationFlagL1())
     1825      {
     1826        uiCode = 0;
     1827        Int i = 0;
     1828        Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList();
     1829        if ( numRpsCurrTempList1 > 1 )
     1830        {
     1831          Int length = 1;
     1832          numRpsCurrTempList1 --;
     1833          while ( numRpsCurrTempList1 >>= 1)
     1834          {
     1835            length ++;
     1836          }
     1837          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     1838          {
     1839            READ_CODE( length, uiCode, "list_entry_l1" );
     1840            refPicListModification->setRefPicSetIdxL1(i, uiCode );
     1841          }
     1842        }
     1843        else
     1844        {
     1845          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     1846          {
     1847            refPicListModification->setRefPicSetIdxL1(i, 0 );
     1848          }
     1849        }
     1850      }
     1851    }
     1852    else
     1853    {
     1854      refPicListModification->setRefPicListModificationFlagL1(0);
     1855    }
     1856    if (pcSlice->isInterB())
     1857    {
     1858      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       pcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
     1859    }
     1860
     1861    pcSlice->setCabacInitFlag( false ); // default
     1862    if(pps->getCabacInitPresentFlag() && !pcSlice->isIntra())
     1863    {
     1864      READ_FLAG(uiCode, "cabac_init_flag");
     1865      pcSlice->setCabacInitFlag( uiCode ? true : false );
     1866    }
     1867
     1868    if ( pcSlice->getEnableTMVPFlag() )
     1869    {
     1870#if SVC_EXTENSION && REF_IDX_MFM
     1871      // set motion mapping flag
     1872      pcSlice->setMFMEnabledFlag( ( pcSlice->getNumMotionPredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() && !pcSlice->isIntra() ) ? true : false );
     1873#endif
     1874      if ( pcSlice->getSliceType() == B_SLICE )
     1875      {
     1876        READ_FLAG( uiCode, "collocated_from_l0_flag" );
     1877        pcSlice->setColFromL0Flag(uiCode);
     1878      }
     1879      else
     1880      {
     1881        pcSlice->setColFromL0Flag( 1 );
     1882      }
     1883
     1884      if ( pcSlice->getSliceType() != I_SLICE &&
     1885          ((pcSlice->getColFromL0Flag() == 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
     1886           (pcSlice->getColFromL0Flag() == 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
     1887      {
     1888        READ_UVLC( uiCode, "collocated_ref_idx" );
     1889        pcSlice->setColRefIdx(uiCode);
     1890      }
     1891      else
     1892      {
     1893        pcSlice->setColRefIdx(0);
     1894      }
     1895    }
     1896    if ( (pps->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     1897    {
     1898      xParsePredWeightTable(pcSlice);
     1899      pcSlice->initWpScaling();
     1900    }
     1901    if (!pcSlice->isIntra())
     1902    {
     1903      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
     1904      pcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
     1905    }
     1906
     1907    READ_SVLC( iCode, "slice_qp_delta" );
     1908    pcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
     1909
     1910#if REPN_FORMAT_IN_VPS
     1911#if O0194_DIFFERENT_BITDEPTH_EL_BL
     1912    g_bitDepthLayer[CHANNEL_TYPE_LUMA][pcSlice->getLayerId()] = pcSlice->getBitDepthY();
     1913    g_bitDepthLayer[CHANNEL_TYPE_CHROMA][pcSlice->getLayerId()] = pcSlice->getBitDepthC();
     1914#endif
     1915    assert( pcSlice->getSliceQp() >= -pcSlice->getQpBDOffsetY() );
     1916#else   
     1917    assert( pcSlice->getSliceQp() >= -sps->getQpBDOffset(CHANNEL_TYPE_LUMA) );
     1918#endif
     1919    assert( pcSlice->getSliceQp() <=  51 );
     1920
     1921    if (pcSlice->getPPS()->getSliceChromaQpFlag())
     1922    {
     1923      if (numValidComp>COMPONENT_Cb)
     1924      {
     1925        READ_SVLC( iCode, "slice_qp_delta_cb" );
     1926        pcSlice->setSliceChromaQpDelta(COMPONENT_Cb, iCode );
     1927        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) >= -12 );
     1928        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) <=  12 );
     1929        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) >= -12 );
     1930        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) <=  12 );
     1931      }
     1932
     1933      if (numValidComp>COMPONENT_Cr)
     1934      {
     1935        READ_SVLC( iCode, "slice_qp_delta_cr" );
     1936        pcSlice->setSliceChromaQpDelta(COMPONENT_Cr, iCode );
     1937        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) >= -12 );
     1938        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) <=  12 );
     1939        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) >= -12 );
     1940        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) <=  12 );
     1941      }
     1942    }
     1943
     1944    if (pcSlice->getPPS()->getChromaQpAdjTableSize() > 0)
     1945    {
     1946      READ_FLAG(uiCode, "slice_chroma_qp_adjustment_enabled_flag"); pcSlice->setUseChromaQpAdj(uiCode != 0);
     1947    }
     1948    else pcSlice->setUseChromaQpAdj(false);
     1949
     1950    if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
     1951    {
     1952      if(pcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
     1953      {
     1954        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        pcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
     1955      }
     1956      else
     1957      {
     1958        pcSlice->setDeblockingFilterOverrideFlag(0);
     1959      }
     1960      if(pcSlice->getDeblockingFilterOverrideFlag())
     1961      {
     1962        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   pcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
     1963        if(!pcSlice->getDeblockingFilterDisable())
     1964        {
     1965          READ_SVLC( iCode, "slice_beta_offset_div2" );                       pcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
     1966          assert(pcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
     1967                 pcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
     1968          READ_SVLC( iCode, "slice_tc_offset_div2" );                         pcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
     1969          assert(pcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
     1970                 pcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
     1971        }
     1972      }
     1973      else
     1974      {
     1975        pcSlice->setDeblockingFilterDisable   ( pcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
     1976        pcSlice->setDeblockingFilterBetaOffsetDiv2( pcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     1977        pcSlice->setDeblockingFilterTcOffsetDiv2  ( pcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
     1978      }
     1979    }
     1980    else
     1981    {
     1982      pcSlice->setDeblockingFilterDisable       ( false );
     1983      pcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
     1984      pcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
     1985    }
     1986
     1987    Bool isSAOEnabled = pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA) || (bChroma && pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA)));
     1988    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
     1989
     1990    if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     1991    {
     1992      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
     1993    }
     1994    else
     1995    {
     1996      uiCode = pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
     1997    }
     1998    pcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
     1999
     2000  }
     2001
     2002  std::vector<UInt> entryPointOffset;
     2003  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     2004  {
     2005    UInt numEntryPointOffsets;
     2006    UInt offsetLenMinus1;
     2007    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets");
     2008    if (numEntryPointOffsets>0)
     2009    {
     2010      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
     2011      entryPointOffset.resize(numEntryPointOffsets);
     2012      for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     2013      {
     2014        READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
     2015        entryPointOffset[ idx ] = uiCode + 1;
     2016      }
     2017    }
     2018  }
     2019
     2020#if POC_RESET_IDC_SIGNALLING
     2021  Int sliceHeaderExtensionLength = 0;
     2022  if(pps->getSliceHeaderExtensionPresentFlag())
     2023  {
     2024    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
     2025  }
     2026  else
     2027  {
     2028    sliceHeaderExtensionLength = 0;
     2029#if INFERENCE_POC_MSB_VAL_PRESENT
     2030    pcSlice->setPocMsbValPresentFlag( false );
     2031#endif
     2032  }
     2033  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
     2034  if( sliceHeaderExtensionLength > 0 )
     2035  {
     2036    if( pcSlice->getPPS()->getPocResetInfoPresentFlag() )
     2037    {
     2038      READ_CODE( 2, uiCode,       "poc_reset_idc"); pcSlice->setPocResetIdc(uiCode);
     2039#if POC_RESET_RESTRICTIONS
     2040      /* The value of poc_reset_idc shall not be equal to 1 or 2 for a RASL picture, a RADL picture,
     2041      a sub-layer non-reference picture, or a picture that has TemporalId greater than 0,
     2042      or a picture that has discardable_flag equal to 1. */
     2043      if( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 )
     2044      {
     2045        assert( !pcSlice->isRASL() );
     2046        assert( !pcSlice->isRADL() );
     2047        assert( !pcSlice->isSLNR() );
     2048        assert( pcSlice->getTLayer() == 0 );
     2049        assert( pcSlice->getDiscardableFlag() == 0 );
     2050      }
     2051
     2052      // The value of poc_reset_idc of a CRA or BLA picture shall be less than 3.
     2053      if( pcSlice->getPocResetIdc() == 3)
     2054      {
     2055        assert( ! ( pcSlice->isCRA() || pcSlice->isBLA() ) );
     2056      }
     2057#endif
     2058    }
     2059    else
     2060    {
     2061      pcSlice->setPocResetIdc( 0 );
     2062    }
     2063#if Q0142_POC_LSB_NOT_PRESENT
     2064    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId()) ) && iPOClsb > 0 )
     2065    {
     2066      assert( pcSlice->getPocResetIdc() != 2 );
     2067    }
     2068#endif
     2069    if( pcSlice->getPocResetIdc() > 0 )
     2070    {
     2071      READ_CODE(6, uiCode,      "poc_reset_period_id"); pcSlice->setPocResetPeriodId(uiCode);
     2072    }
     2073    else
     2074    {
     2075
     2076      pcSlice->setPocResetPeriodId( 0 );
     2077    }
     2078
     2079    if (pcSlice->getPocResetIdc() == 3)
     2080    {
     2081      READ_FLAG( uiCode,        "full_poc_reset_flag"); pcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
     2082      READ_CODE(pcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); pcSlice->setPocLsbVal(uiCode);
     2083#if Q0142_POC_LSB_NOT_PRESENT
     2084      if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId()) ) && pcSlice->getFullPocResetFlag() )
     2085      {
     2086        assert( pcSlice->getPocLsbVal() == 0 );
     2087      }
     2088#endif
     2089    }
     2090
     2091    // Derive the value of PocMsbValRequiredFlag
     2092#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2093    pcSlice->setPocMsbValRequiredFlag( (pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag())
     2094      && (!pcSlice->getVPS()->getVpsPocLsbAlignedFlag() ||
     2095      (pcSlice->getVPS()->getVpsPocLsbAlignedFlag() && pcSlice->getVPS()->getNumDirectRefLayers(pcSlice->getLayerId()) == 0))
     2096      );
     2097#else
     2098    pcSlice->setPocMsbValRequiredFlag( pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag() );
     2099#endif
     2100
     2101#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2102    if (!pcSlice->getPocMsbValRequiredFlag() && pcSlice->getVPS()->getVpsPocLsbAlignedFlag())
     2103#else
     2104    if (!pcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */)
     2105#endif
     2106    {
     2107#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2108      READ_FLAG(uiCode, "poc_msb_cycle_val_present_flag"); pcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
     2109#else
     2110      READ_FLAG(uiCode, "poc_msb_val_present_flag"); pcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
     2111#endif
     2112    }
     2113    else
     2114    {
     2115#if POC_MSB_VAL_PRESENT_FLAG_SEM
     2116      if( sliceHeaderExtensionLength == 0 )
     2117      {
     2118        pcSlice->setPocMsbValPresentFlag( false );
     2119      }
     2120      else if( pcSlice->getPocMsbValRequiredFlag() )
     2121#else
     2122      if( pcSlice->getPocMsbValRequiredFlag() )
     2123#endif
     2124      {
     2125        pcSlice->setPocMsbValPresentFlag( true );
     2126      }
     2127      else
     2128      {
     2129        pcSlice->setPocMsbValPresentFlag( false );
     2130      }
     2131    }
     2132
     2133#if !POC_RESET_IDC_DECODER
     2134    Int maxPocLsb  = 1 << pcSlice->getSPS()->getBitsForPOC();
     2135#endif
     2136    if( pcSlice->getPocMsbValPresentFlag() )
     2137    {
     2138#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2139      READ_UVLC( uiCode,    "poc_msb_cycle_val");             pcSlice->setPocMsbVal( uiCode );
     2140#else
     2141      READ_UVLC( uiCode,    "poc_msb_val");             pcSlice->setPocMsbVal( uiCode );
     2142#endif
     2143
     2144#if !POC_RESET_IDC_DECODER
     2145      // Update POC of the slice based on this MSB val
     2146      Int pocLsb     = pcSlice->getPOC() % maxPocLsb;
     2147      pcSlice->setPOC((pcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
     2148    }
     2149    else
     2150    {
     2151      pcSlice->setPocMsbVal( pcSlice->getPOC() / maxPocLsb );
     2152#endif
     2153    }
     2154
     2155    // Read remaining bits in the slice header extension.
     2156    UInt endBits = m_pcBitstream->getNumBitsRead();
     2157    Int counter = (endBits - startBits) % 8;
     2158    if( counter )
     2159    {
     2160      counter = 8 - counter;
     2161    }
     2162
     2163    while( counter )
     2164    {
     2165#if Q0146_SSH_EXT_DATA_BIT
     2166      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
     2167#else
     2168      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
     2169#endif
     2170      counter--;
     2171    }
     2172  }
     2173#else
     2174  if(pps->getSliceHeaderExtensionPresentFlag())
     2175  {
     2176    READ_UVLC(uiCode,"slice_header_extension_length");
     2177    for(Int i=0; i<uiCode; i++)
     2178    {
     2179      UInt ignore;
     2180      READ_CODE(8,ignore,"slice_header_extension_data_byte");
     2181    }
     2182  }
     2183#endif
     2184#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2185  TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,m_pcBitstream->readByteAlignment(),0);
     2186#else
     2187  m_pcBitstream->readByteAlignment();
     2188#endif
     2189
     2190  pcSlice->clearSubstreamSizes();
     2191
     2192  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     2193  {
     2194    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
     2195
     2196    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
     2197    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     2198    {
     2199      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
     2200      {
     2201        endOfSliceHeaderLocation++;
     2202      }
     2203    }
     2204
     2205    Int  curEntryPointOffset     = 0;
     2206    Int  prevEntryPointOffset    = 0;
     2207    for (UInt idx=0; idx<entryPointOffset.size(); idx++)
     2208    {
     2209      curEntryPointOffset += entryPointOffset[ idx ];
     2210
     2211      Int emulationPreventionByteCount = 0;
     2212      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     2213      {
     2214        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
     2215             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
     2216        {
     2217          emulationPreventionByteCount++;
     2218        }
     2219      }
     2220
     2221      entryPointOffset[ idx ] -= emulationPreventionByteCount;
     2222      prevEntryPointOffset = curEntryPointOffset;
     2223      pcSlice->addSubstreamSize(entryPointOffset [ idx ] );
     2224    }
     2225  }
     2226
     2227  return;
     2228}
     2229
     2230Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
     2231{
     2232  UInt uiCode;
     2233  if(profilePresentFlag)
     2234  {
     2235    parseProfileTier(rpcPTL->getGeneralPTL());
     2236  }
     2237  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(Level::Name(uiCode));
     2238
     2239  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
     2240  {
     2241#if MULTIPLE_PTL_SUPPORT
     2242    READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
     2243#else
     2244    if(profilePresentFlag)
     2245    {
     2246      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
     2247    }
     2248#endif
     2249    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
     2250  }
     2251
     2252  if (maxNumSubLayersMinus1 > 0)
     2253  {
     2254    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
     2255    {
     2256      READ_CODE(2, uiCode, "reserved_zero_2bits");
     2257      assert(uiCode == 0);
     2258    }
     2259  }
     2260
     2261  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
     2262  {
     2263#if MULTIPLE_PTL_SUPPORT
     2264    if( rpcPTL->getSubLayerProfilePresentFlag(i) )
     2265#else
     2266    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
     2267#endif
     2268    {
     2269      parseProfileTier(rpcPTL->getSubLayerPTL(i));
     2270    }
     2271    if(rpcPTL->getSubLayerLevelPresentFlag(i))
     2272    {
     2273      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(Level::Name(uiCode));
     2274    }
     2275  }
     2276}
     2277
     2278Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
     2279{
     2280  UInt uiCode;
     2281  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
     2282  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? Level::HIGH : Level::MAIN);
     2283  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (Profile::Name(uiCode));
     2284  for(Int j = 0; j < 32; j++)
     2285  {
     2286    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
     2287  }
     2288  READ_FLAG(uiCode, "general_progressive_source_flag");
     2289  ptl->setProgressiveSourceFlag(uiCode ? true : false);
     2290
     2291  READ_FLAG(uiCode, "general_interlaced_source_flag");
     2292  ptl->setInterlacedSourceFlag(uiCode ? true : false);
     2293
     2294  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
     2295  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
     2296
     2297  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
     2298  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
     2299
     2300  if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT )
     2301  {
     2302    UInt maxBitDepth=16;
     2303    READ_FLAG(    uiCode, "general_max_12bit_constraint_flag" ); if (uiCode) maxBitDepth=12;
     2304    READ_FLAG(    uiCode, "general_max_10bit_constraint_flag" ); if (uiCode) maxBitDepth=10;
     2305    READ_FLAG(    uiCode, "general_max_8bit_constraint_flag"  ); if (uiCode) maxBitDepth=8;
     2306    ptl->setBitDepthConstraint(maxBitDepth);
     2307    ChromaFormat chromaFmtConstraint=CHROMA_444;
     2308    READ_FLAG(    uiCode, "general_max_422chroma_constraint_flag"  ); if (uiCode) chromaFmtConstraint=CHROMA_422;
     2309    READ_FLAG(    uiCode, "general_max_420chroma_constraint_flag"  ); if (uiCode) chromaFmtConstraint=CHROMA_420;
     2310    READ_FLAG(    uiCode, "general_max_monochrome_constraint_flag" ); if (uiCode) chromaFmtConstraint=CHROMA_400;
     2311    ptl->setChromaFormatConstraint(chromaFmtConstraint);
     2312    READ_FLAG(    uiCode, "general_intra_constraint_flag");          ptl->setIntraConstraintFlag(uiCode != 0);
     2313    READ_FLAG(    uiCode, "general_one_picture_only_constraint_flag");
     2314    READ_FLAG(    uiCode, "general_lower_bit_rate_constraint_flag"); ptl->setLowerBitRateConstraintFlag(uiCode != 0);
     2315#if MULTIPLE_PTL_SUPPORT
     2316    READ_CODE(32, uiCode, "general_reserved_zero_34bits");  READ_CODE(2, uiCode, "general_reserved_zero_34bits");
     2317  }
     2318  else if( ptl->getProfileIdc() == Profile::SCALABLEMAIN )
     2319  {
     2320    READ_FLAG(    uiCode, "general_max_12bit_constraint_flag" ); assert (uiCode == 1);
     2321    READ_FLAG(    uiCode, "general_max_10bit_constraint_flag" ); assert (uiCode == 1);
     2322    READ_FLAG(    uiCode, "general_max_8bit_constraint_flag"  ); ptl->setProfileIdc  ((uiCode) ? Profile::SCALABLEMAIN : Profile::SCALABLEMAIN10);
     2323    READ_FLAG(    uiCode, "general_max_422chroma_constraint_flag"  ); assert (uiCode == 1);
     2324    READ_FLAG(    uiCode, "general_max_420chroma_constraint_flag"  ); assert (uiCode == 1);
     2325    READ_FLAG(    uiCode, "general_max_monochrome_constraint_flag" ); assert (uiCode == 0);
     2326    READ_FLAG(    uiCode, "general_intra_constraint_flag"); assert (uiCode == 0);
     2327    READ_FLAG(    uiCode, "general_one_picture_only_constraint_flag"); assert (uiCode == 0);
     2328    READ_FLAG(    uiCode, "general_lower_bit_rate_constraint_flag"); assert (uiCode == 1);
     2329    READ_CODE(32, uiCode, "general_reserved_zero_34bits");  READ_CODE(2, uiCode, "general_reserved_zero_34bits");
     2330  }
     2331  else
     2332  {
     2333    ptl->setBitDepthConstraint((ptl->getProfileIdc() == Profile::MAIN10)?10:8);
     2334    ptl->setChromaFormatConstraint(CHROMA_420);
     2335    ptl->setIntraConstraintFlag(false);
     2336    ptl->setLowerBitRateConstraintFlag(true);
     2337    READ_CODE(32,  uiCode, "general_reserved_zero_43bits");  READ_CODE(11,  uiCode, "general_reserved_zero_43bits");
     2338  }
     2339
     2340  if( ( ptl->getProfileIdc() >= 1 && ptl->getProfileIdc() <= 5 ) ||
     2341      ptl->getProfileCompatibilityFlag(1) || ptl->getProfileCompatibilityFlag(2) ||
     2342      ptl->getProfileCompatibilityFlag(3) || ptl->getProfileCompatibilityFlag(4) ||
     2343      ptl->getProfileCompatibilityFlag(5)                                           )
     2344  {
     2345    READ_FLAG(uiCode, "general_inbld_flag");
     2346  }
     2347  else
     2348  {
     2349    READ_FLAG(uiCode, "general_reserved_zero_bit");
     2350  }
     2351#else
     2352    READ_CODE(16, uiCode, "XXX_reserved_zero_35bits[0..15]");
     2353    READ_CODE(16, uiCode, "XXX_reserved_zero_35bits[16..31]");
     2354    READ_CODE(3,  uiCode, "XXX_reserved_zero_35bits[32..34]");
     2355  }
     2356  else
     2357  {
     2358    ptl->setBitDepthConstraint((ptl->getProfileIdc() == Profile::MAIN10)?10:8);
     2359    ptl->setChromaFormatConstraint(CHROMA_420);
     2360    ptl->setIntraConstraintFlag(false);
     2361    ptl->setLowerBitRateConstraintFlag(true);
     2362    READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
     2363    READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
     2364    READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
     2365  }
     2366#endif
     2367}
     2368
     2369Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
     2370{
     2371  ruiBit = false;
     2372  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
     2373  if(iBitsLeft <= 8)
     2374  {
     2375    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
     2376    if (uiPeekValue == (1<<(iBitsLeft-1)))
     2377    {
     2378      ruiBit = true;
     2379    }
     2380  }
     2381}
     2382
     2383Void TDecCavlc::parseRemainingBytes( Bool noTrailingBytesExpected )
     2384{
     2385  if (noTrailingBytesExpected)
     2386  {
     2387    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
     2388    assert (numberOfRemainingSubstreamBytes == 0);
     2389  }
     2390  else
     2391  {
     2392    while (m_pcBitstream->getNumBitsLeft())
     2393    {
     2394      UInt trailingNullByte=m_pcBitstream->readByte();
     2395      if (trailingNullByte!=0)
     2396      {
     2397        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
     2398        assert(trailingNullByte==0);
     2399      }
     2400    }
     2401  }
     2402}
     2403
     2404Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2405{
     2406  assert(0);
     2407}
     2408
     2409Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2410{
     2411  assert(0);
     2412}
     2413
     2414Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
     2415{
     2416  assert(0);
     2417}
     2418
     2419Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2420{
     2421  assert(0);
     2422}
     2423
     2424Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2425{
     2426  assert(0);
     2427}
     2428
     2429Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2430{
     2431  assert(0);
     2432}
     2433
     2434/** Parse I_PCM information.
     2435* \param pcCU pointer to CU
     2436* \param uiAbsPartIdx CU index
     2437* \param uiDepth CU depth
     2438* \returns Void
     2439*
     2440* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
     2441*/
     2442Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2443{
     2444  assert(0);
     2445}
     2446
     2447Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2448{
     2449  assert(0);
     2450}
     2451
     2452Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2453{
     2454  assert(0);
     2455}
     2456
     2457Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
     2458{
     2459  assert(0);
     2460}
     2461
     2462Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
     2463{
     2464  assert(0);
     2465}
     2466
     2467Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
     2468{
     2469  assert(0);
     2470}
     2471
     2472Void TDecCavlc::parseCrossComponentPrediction( class TComTU& /*rTu*/, ComponentID /*compID*/ )
     2473{
     2474  assert(0);
     2475}
     2476
     2477Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2478{
     2479  Int qp;
     2480  Int  iDQp;
     2481
     2482#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2483  READ_SVLC(iDQp, "delta_qp");
     2484#else
     2485  xReadSvlc( iDQp );
     2486#endif
     2487
     2488#if REPN_FORMAT_IN_VPS
     2489  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
     2490#else
     2491  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
     2492#endif
     2493  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
     2494
     2495  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
     2496  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
     2497
     2498  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
     2499}
     2500
     2501Void TDecCavlc::parseChromaQpAdjustment( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     2502{
     2503  assert(0);
     2504}
     2505
     2506Void TDecCavlc::parseCoeffNxN( TComTU &/*rTu*/, ComponentID /*compID*/ )
     2507{
     2508  assert(0);
     2509}
     2510
     2511Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
     2512{
     2513  assert(0);
     2514}
     2515
     2516Void TDecCavlc::parseQtCbf( TComTU &/*rTu*/, const ComponentID /*compID*/, const Bool /*lowestLevel*/ )
     2517{
     2518  assert(0);
     2519}
     2520
     2521Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
     2522{
     2523  assert(0);
     2524}
     2525
     2526Void TDecCavlc::parseTransformSkipFlags (TComTU &/*rTu*/, ComponentID /*component*/)
     2527{
     2528  assert(0);
     2529}
     2530
     2531Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
     2532{
     2533  assert(0);
     2534}
     2535
     2536Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
     2537{
     2538  assert(0);
     2539}
     2540
     2541// ====================================================================================================================
     2542// Protected member functions
     2543// ====================================================================================================================
     2544
     2545/** parse explicit wp tables
     2546* \param TComSlice* pcSlice
     2547* \returns Void
     2548*/
     2549Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
     2550{
     2551        WPScalingParam *wp;
     2552        TComSPS        *sps          = pcSlice->getSPS();
     2553  const ChromaFormat    chFmt        = sps->getChromaFormatIdc();
     2554  const Int             numValidComp = Int(getNumberValidComponents(chFmt));
     2555  const Bool            bChroma      = (chFmt!=CHROMA_400);
     2556  const SliceType       eSliceType   = pcSlice->getSliceType();
     2557  const Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
     2558        UInt            uiLog2WeightDenomLuma=0, uiLog2WeightDenomChroma=0;
     2559        UInt            uiTotalSignalledWeightFlags = 0;
     2560
     2561  Int iDeltaDenom;
     2562  // decode delta_luma_log2_weight_denom :
     2563  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     2564  assert( uiLog2WeightDenomLuma <= 7 );
     2565  if( bChroma )
     2566  {
     2567    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
     2568    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
     2569    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
     2570    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
     2571  }
     2572
     2573  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
     2574  {
     2575    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     2576    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2577    {
     2578      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     2579
     2580      wp[COMPONENT_Y].uiLog2WeightDenom = uiLog2WeightDenomLuma;
     2581      for(Int j=1; j<numValidComp; j++)
     2582      {
     2583        wp[j].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     2584      }
     2585
     2586      UInt  uiCode;
     2587      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
     2588      wp[COMPONENT_Y].bPresentFlag = ( uiCode == 1 );
     2589      uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
     2590    }
     2591    if ( bChroma )
     2592    {
     2593      UInt  uiCode;
     2594      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2595      {
     2596        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     2597        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
     2598        for(Int j=1; j<numValidComp; j++)
     2599        {
     2600          wp[j].bPresentFlag = ( uiCode == 1 );
     2601        }
     2602        uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag;
     2603      }
     2604    }
     2605    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2606    {
     2607      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     2608      if ( wp[COMPONENT_Y].bPresentFlag )
     2609      {
     2610        Int iDeltaWeight;
     2611        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
     2612        assert( iDeltaWeight >= -128 );
     2613        assert( iDeltaWeight <=  127 );
     2614        wp[COMPONENT_Y].iWeight = (iDeltaWeight + (1<<wp[COMPONENT_Y].uiLog2WeightDenom));
     2615        READ_SVLC( wp[COMPONENT_Y].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
     2616        Int range=sps->getUseHighPrecisionPredictionWeighting() ? (1<<g_bitDepth[CHANNEL_TYPE_LUMA])/2 : 128;
     2617        assert( wp[0].iOffset >= -range );
     2618        assert( wp[0].iOffset <   range );
     2619      }
     2620      else
     2621      {
     2622        wp[COMPONENT_Y].iWeight = (1 << wp[COMPONENT_Y].uiLog2WeightDenom);
     2623        wp[COMPONENT_Y].iOffset = 0;
     2624      }
     2625      if ( bChroma )
     2626      {
     2627        if ( wp[COMPONENT_Cb].bPresentFlag )
     2628        {
     2629          Int range=sps->getUseHighPrecisionPredictionWeighting() ? (1<<g_bitDepth[CHANNEL_TYPE_CHROMA])/2 : 128;
     2630          for ( Int j=1 ; j<numValidComp ; j++ )
     2631          {
     2632            Int iDeltaWeight;
     2633            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
     2634            assert( iDeltaWeight >= -128 );
     2635            assert( iDeltaWeight <=  127 );
     2636            wp[j].iWeight = (iDeltaWeight + (1<<wp[j].uiLog2WeightDenom));
     2637
     2638            Int iDeltaChroma;
     2639            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
     2640            assert( iDeltaChroma >= -4*range);
     2641            assert( iDeltaChroma <   4*range);
     2642            Int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     2643            wp[j].iOffset = Clip3(-range, range-1, (iDeltaChroma + pred) );
     2644          }
     2645        }
     2646        else
     2647        {
     2648          for ( Int j=1 ; j<numValidComp ; j++ )
     2649          {
     2650            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
     2651            wp[j].iOffset = 0;
     2652          }
     2653        }
     2654      }
     2655    }
     2656
     2657    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     2658    {
     2659      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     2660
     2661      wp[0].bPresentFlag = false;
     2662      wp[1].bPresentFlag = false;
     2663      wp[2].bPresentFlag = false;
     2664    }
     2665  }
     2666  assert(uiTotalSignalledWeightFlags<=24);
     2667}
     2668
     2669/** decode quantization matrix
     2670* \param scalingList quantization matrix information
     2671*/
     2672Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
     2673{
     2674  UInt  code, sizeId, listId;
     2675  Bool scalingListPredModeFlag;
     2676  //for each size
     2677  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     2678  {
     2679    for(listId = 0; listId <  SCALING_LIST_NUM; listId++)
     2680    {
     2681      if ((sizeId==SCALING_LIST_32x32) && (listId%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) != 0))
     2682      {
     2683        Int *src = scalingList->getScalingListAddress(sizeId, listId);
     2684        const Int size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
     2685        const Int *srcNextSmallerSize = scalingList->getScalingListAddress(sizeId-1, listId);
     2686        for(Int i=0; i<size; i++)
     2687        {
     2688          src[i] = srcNextSmallerSize[i];
     2689        }
     2690        scalingList->setScalingListDC(sizeId,listId,(sizeId > SCALING_LIST_8x8) ? scalingList->getScalingListDC(sizeId-1, listId) : src[0]);
     2691      }
     2692      else
     2693      {
     2694        READ_FLAG( code, "scaling_list_pred_mode_flag");
     2695        scalingListPredModeFlag = (code) ? true : false;
     2696        if(!scalingListPredModeFlag) //Copy Mode
     2697        {
     2698          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
     2699
     2700          if (sizeId==SCALING_LIST_32x32)
     2701            code*=(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES); // Adjust the decoded code for this size, to cope with the missing 32x32 chroma entries.
     2702
     2703          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
     2704          if( sizeId > SCALING_LIST_8x8 )
     2705          {
     2706            scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
     2707          }
     2708          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
     2709
     2710        }
     2711        else //DPCM Mode
     2712        {
     2713          xDecodeScalingList(scalingList, sizeId, listId);
     2714        }
     2715      }
     2716    }
     2717  }
     2718
     2719  return;
     2720}
     2721/** decode DPCM
     2722* \param scalingList  quantization matrix information
     2723* \param sizeId size index
     2724* \param listId list index
     2725*/
     2726Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
     2727{
     2728  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
     2729  Int data;
     2730  Int scalingListDcCoefMinus8 = 0;
     2731  Int nextCoef = SCALING_LIST_START_VALUE;
     2732  UInt* scan  = g_scanOrder[SCAN_UNGROUPED][SCAN_DIAG][sizeId==0 ? 2 : 3][sizeId==0 ? 2 : 3];
     2733  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
     2734
     2735  if( sizeId > SCALING_LIST_8x8 )
     2736  {
     2737    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
     2738    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
     2739    nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2740  }
     2741
     2742  for(i = 0; i < coefNum; i++)
     2743  {
     2744    READ_SVLC( data, "scaling_list_delta_coef");
     2745    nextCoef = (nextCoef + data + 256 ) % 256;
     2746    dst[scan[i]] = nextCoef;
     2747  }
     2748}
     2749
     2750Bool TDecCavlc::xMoreRbspData()
     2751{
     2752  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
     2753
     2754  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
     2755  if (bitsLeft > 8)
     2756  {
     2757    return true;
     2758  }
     2759
     2760  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
     2761  Int cnt = bitsLeft;
     2762
     2763  // remove trailing bits equal to zero
     2764  while ((cnt>0) && ((lastByte & 1) == 0))
     2765  {
     2766    lastByte >>= 1;
     2767    cnt--;
     2768  }
     2769  // remove bit equal to one
     2770  cnt--;
     2771
     2772  // we should not have a negative number of bits
     2773  assert (cnt>=0);
     2774
     2775  // we have more data, if cnt is not zero
     2776  return (cnt>0);
     2777}
     2778
     2779Void TDecCavlc::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
     2780{
     2781  assert(0);
    13852782}
    13862783
     
    16383035#if !MULTIPLE_PTL_SUPPORT
    16393036  vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
    1640 #endif 
     3037#endif
    16413038#if LIST_OF_PTL
    16423039  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
     
    16453042#endif
    16463043  {
    1647     READ_FLAG( uiCode, "vps_profile_present_flag[i]" );
    1648     vps->setProfilePresentFlag(idx, uiCode ? true : false);
     3044    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
    16493045    if( !vps->getProfilePresentFlag(idx) )
    16503046    {
     
    17153111  if( vps->getNumLayerSets() > 1 )
    17163112  {
    1717     READ_UVLC( uiCode, "num_add_olss" );                  vps->setNumAddOutputLayerSets( uiCode );
     3113    READ_UVLC( uiCode, "num_add_olss" );            vps->setNumAddOutputLayerSets( uiCode );
    17183114    READ_CODE( 2, uiCode, "default_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
    17193115  }
     
    18303226#endif
    18313227      {
    1832         READ_CODE( numBitsForPtlIdx, uiCode, "profile_level_tier_idx[i]" );
     3228        READ_CODE( numBitsForPtlIdx, uiCode, "profile_tier_level_idx[i]" );
    18333229        vps->setProfileLevelTierIdx(i, j, uiCode );
     3230
    18343231#if MULTIPLE_PTL_SUPPORT
    18353232        //For conformance checking
     
    18623259      numBits++;
    18633260    }
    1864     READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
     3261    READ_CODE( numBits, uiCode, "profile_tier_level_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
    18653262#endif
    18663263#if P0300_ALT_OUTPUT_LAYER_FLAG
     
    21673564  }
    21683565#endif
     3566
    21693567#if VPS_FIX_TO_MATCH_SPEC
    2170   for (i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++)
    2171 #else
    2172   for (i = 1; i < vps->getMaxLayers(); i++)
     3568  for( i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++ )
     3569#else
     3570  for(i = 1; i < vps->getMaxLayers(); i++)
    21733571#endif
    21743572  {
    21753573#if VPS_FIX_TO_MATCH_SPEC
    2176     for (j = vps->getBaseLayerInternalFlag() ? 0 : 1; j < i; j++)
    2177 #else
    2178     for (j = 0; j < i; j++)
     3574    for( j = vps->getBaseLayerInternalFlag() ? 0 : 1; j < i; j++ )
     3575#else
     3576    for(j = 0; j < i; j++)
    21793577#endif
    21803578    {
     
    30534451}
    30544452
    3055 #endif //SVC_EXTENSION
    3056 
    3057 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
    3058 {
    3059   UInt  uiCode;
    3060   Int   iCode;
    3061 
    3062 #if ENC_DEC_TRACE
    3063   xTraceSliceHeader(rpcSlice);
    3064 #endif
    3065   TComPPS* pps = NULL;
    3066   TComSPS* sps = NULL;
    3067 
    3068   UInt firstSliceSegmentInPic;
    3069   READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
    3070   if( rpcSlice->getRapPicFlag())
    3071   {
    3072     READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
    3073 #if SETTING_NO_OUT_PIC_PRIOR
    3074     rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
    3075 #else
    3076     rpcSlice->setNoOutputPicPrior( false );
    3077 #endif
    3078   }
    3079   READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
    3080   pps = parameterSetManager->getPrefetchedPPS(uiCode);
    3081   //!KS: need to add error handling code here, if PPS is not available
    3082   assert(pps!=0);
    3083   sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
    3084   //!KS: need to add error handling code here, if SPS is not available
    3085   assert(sps!=0);
    3086   rpcSlice->setSPS(sps);
    3087   rpcSlice->setPPS(pps);
    3088 
    3089 #if R0227_REP_FORMAT_CONSTRAINT //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
    3090   TComVPS* vps = NULL;
    3091   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
    3092   UInt layerIdx = vps->getLayerIdInVps(rpcSlice->getLayerId());
    3093 #if R0279_REP_FORMAT_INBL
    3094   if ( vps->getVpsExtensionFlag() == 1 && (rpcSlice->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
    3095   {
    3096     assert( sps->getPicWidthInLumaSamples()  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
    3097     assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
    3098     assert( sps->getChromaFormatIdc()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
    3099     assert( sps->getBitDepthY()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
    3100     assert( sps->getBitDepthC()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
    3101 #else
    3102   if ( rpcSlice->getLayerId() == 0 && vps->getVpsExtensionFlag() == 1 )
    3103   {
    3104     assert( sps->getPicWidthInLumaSamples()  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicWidthVpsInLumaSamples() );
    3105     assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicHeightVpsInLumaSamples() );
    3106     assert( sps->getChromaFormatIdc()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getChromaFormatVpsIdc() );
    3107     assert( sps->getBitDepthY()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsLuma() );
    3108     assert( sps->getBitDepthC()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsChroma() );
    3109 #endif
    3110   }
    3111   else if ( vps->getVpsExtensionFlag() == 1 )
    3112   {
    3113     assert(vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
    3114     assert(vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
    3115     assert(vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
    3116     assert(vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
    3117     assert(vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
    3118   }
    3119 #endif
    3120 
    3121   if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
    3122   {
    3123     READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
    3124   }
    3125   else
    3126   {
    3127     rpcSlice->setDependentSliceSegmentFlag(false);
    3128   }
    3129 #if REPN_FORMAT_IN_VPS
    3130   Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
    3131 #else
    3132   Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
    3133 #endif
    3134   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
    3135   UInt sliceSegmentAddress = 0;
    3136   Int bitsSliceSegmentAddress = 0;
    3137   while(numCTUs>(1<<bitsSliceSegmentAddress))
    3138   {
    3139     bitsSliceSegmentAddress++;
    3140   }
    3141 
    3142   if(!firstSliceSegmentInPic)
    3143   {
    3144     READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
    3145   }
    3146   //set uiCode to equal slice start address (or dependent slice start address)
    3147   Int startCuAddress = maxParts*sliceSegmentAddress;
    3148   rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
    3149   rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
    3150 
    3151   if (rpcSlice->getDependentSliceSegmentFlag())
    3152   {
    3153     rpcSlice->setNextSlice          ( false );
    3154     rpcSlice->setNextSliceSegment ( true  );
    3155   }
    3156   else
    3157   {
    3158     rpcSlice->setNextSlice          ( true  );
    3159     rpcSlice->setNextSliceSegment ( false );
    3160 
    3161     rpcSlice->setSliceCurStartCUAddr(startCuAddress);
    3162     rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
    3163   }
    3164 
    3165 #if Q0142_POC_LSB_NOT_PRESENT
    3166 #if SHM_FIX7
    3167   Int iPOClsb = 0;
    3168 #endif
    3169 #endif
    3170 
    3171   if(!rpcSlice->getDependentSliceSegmentFlag())
    3172   {
    3173 #if SVC_EXTENSION
    3174 #if POC_RESET_FLAG
    3175     Int iBits = 0;
    3176     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
    3177     {
    3178       READ_FLAG(uiCode, "poc_reset_flag");      rpcSlice->setPocResetFlag( uiCode ? true : false );
    3179       iBits++;
    3180     }
    3181     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
    3182     {
    3183 #if DISCARDABLE_PIC_RPS
    3184       READ_FLAG(uiCode, "discardable_flag"); rpcSlice->setDiscardableFlag( uiCode ? true : false );
    3185 #else
    3186       READ_FLAG(uiCode, "discardable_flag"); // ignored
    3187 #endif
    3188       iBits++;
    3189     }
    3190 #if O0149_CROSS_LAYER_BLA_FLAG
    3191     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
    3192     {
    3193       READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
    3194       iBits++;
    3195     }
    3196 #endif
    3197     for (; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
    3198     {
    3199       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
    3200     }
    3201 #else
    3202 #if CROSS_LAYER_BLA_FLAG_FIX
    3203     Int iBits = 0;
    3204     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
    3205 #else
    3206     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
    3207 #endif
    3208     {
    3209       READ_FLAG(uiCode, "discardable_flag"); // ignored
    3210 #if NON_REF_NAL_TYPE_DISCARDABLE
    3211       rpcSlice->setDiscardableFlag( uiCode ? true : false );
    3212       if (uiCode)
    3213       {
    3214         assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
    3215           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
    3216           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
    3217           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
    3218           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
    3219       }
    3220 #endif
    3221 #if CROSS_LAYER_BLA_FLAG_FIX
    3222       iBits++;
    3223 #endif
    3224     }
    3225 #if CROSS_LAYER_BLA_FLAG_FIX
    3226     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
    3227     {
    3228       READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
    3229       iBits++;
    3230     }
    3231     for ( ; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
    3232 #else
    3233     for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
    3234 #endif
    3235     {
    3236       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
    3237     }
    3238 #endif
    3239 #else //SVC_EXTENSION
    3240     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
    3241     {
    3242       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
    3243     }
    3244 #endif //SVC_EXTENSION
    3245 
    3246     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
    3247     if( pps->getOutputFlagPresentFlag() )
    3248     {
    3249       READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
    3250     }
    3251     else
    3252     {
    3253       rpcSlice->setPicOutputFlag( true );
    3254     }
    3255     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
    3256     assert (sps->getChromaFormatIdc() == 1 );
    3257     // if( separate_colour_plane_flag  ==  1 )
    3258     //   colour_plane_id                                      u(2)
    3259 
    3260     if( rpcSlice->getIdrPicFlag() )
    3261     {
    3262       rpcSlice->setPOC(0);
    3263       TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
    3264       rps->setNumberOfNegativePictures(0);
    3265       rps->setNumberOfPositivePictures(0);
    3266       rps->setNumberOfLongtermPictures(0);
    3267       rps->setNumberOfPictures(0);
    3268       rpcSlice->setRPS(rps);
    3269     }
    3270 #if N0065_LAYER_POC_ALIGNMENT
    3271 #if !Q0142_POC_LSB_NOT_PRESENT
    3272 #if SHM_FIX7
    3273     Int iPOClsb = 0;
    3274 #endif
    3275 #endif
    3276 #if O0062_POC_LSB_NOT_PRESENT_FLAG
    3277     if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
    3278 #else
    3279     if( rpcSlice->getLayerId() > 0 || !rpcSlice->getIdrPicFlag() )
    3280 #endif
    3281 #else
    3282     else
    3283 #endif
    3284     {
    3285       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
    3286 #if POC_RESET_IDC_DECODER
    3287       rpcSlice->setPicOrderCntLsb( uiCode );
    3288 #endif
    3289 #if SHM_FIX7
    3290       iPOClsb = uiCode;
    3291 #else
    3292       Int iPOClsb = uiCode;
    3293 #endif
    3294       Int iPrevPOC = rpcSlice->getPrevTid0POC();
    3295       Int iMaxPOClsb = 1<< sps->getBitsForPOC();
    3296       Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
    3297       Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
    3298       Int iPOCmsb;
    3299       if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
    3300       {
    3301         iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
    3302       }
    3303       else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
    3304       {
    3305         iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
    3306       }
    3307       else
    3308       {
    3309         iPOCmsb = iPrevPOCmsb;
    3310       }
    3311       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    3312         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    3313         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    3314       {
    3315         // For BLA picture types, POCmsb is set to 0.
    3316         iPOCmsb = 0;
    3317       }
    3318       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
    3319 
    3320 #if N0065_LAYER_POC_ALIGNMENT
    3321 #if SHM_FIX7
    3322     }
    3323 #endif
    3324 #if POC_RESET_IDC_DECODER
    3325   else
    3326   {
    3327     rpcSlice->setPicOrderCntLsb( 0 );
    3328   }
    3329 #endif
    3330   if( !rpcSlice->getIdrPicFlag() )
    3331   {
    3332 #endif
    3333     TComReferencePictureSet* rps;
    3334     rps = rpcSlice->getLocalRPS();
    3335     rpcSlice->setRPS(rps);
    3336     READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
    3337     if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
    3338     {
    3339       parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
    3340     }
    3341     else // use reference to short-term reference picture set in PPS
    3342     {
    3343       Int numBits = 0;
    3344       while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
    3345       {
    3346         numBits++;
    3347       }
    3348       if (numBits > 0)
    3349       {
    3350         READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
    3351       }
    3352       else
    3353       {
    3354         uiCode = 0;       
    3355       }
    3356       *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
    3357     }
    3358     if(sps->getLongTermRefsPresent())
    3359     {
    3360       Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
    3361       UInt numOfLtrp = 0;
    3362       UInt numLtrpInSPS = 0;
    3363       if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
    3364       {
    3365         READ_UVLC( uiCode, "num_long_term_sps");
    3366         numLtrpInSPS = uiCode;
    3367         numOfLtrp += numLtrpInSPS;
    3368         rps->setNumberOfLongtermPictures(numOfLtrp);
    3369       }
    3370       Int bitsForLtrpInSPS = 0;
    3371       while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
    3372       {
    3373         bitsForLtrpInSPS++;
    3374       }
    3375       READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
    3376       numOfLtrp += uiCode;
    3377       rps->setNumberOfLongtermPictures(numOfLtrp);
    3378       Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
    3379       Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
    3380       for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
    3381       {
    3382         Int pocLsbLt;
    3383         if (k < numLtrpInSPS)
    3384         {
    3385           uiCode = 0;
    3386           if (bitsForLtrpInSPS > 0)
    3387           {
    3388             READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
    3389           }
    3390           Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
    3391 
    3392           pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
    3393           rps->setUsed(j,usedByCurrFromSPS);
    3394         }
    3395         else
    3396         {
    3397           READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
    3398           READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
    3399         }
    3400         READ_FLAG(uiCode,"delta_poc_msb_present_flag");
    3401         Bool mSBPresentFlag = uiCode ? true : false;
    3402         if(mSBPresentFlag)
    3403         {
    3404           READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
    3405           Bool deltaFlag = false;
    3406           //            First LTRP                               || First LTRP from SH
    3407           if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
    3408           {
    3409             deltaFlag = true;
    3410           }
    3411           if(deltaFlag)
    3412           {
    3413             deltaPocMSBCycleLT = uiCode;
    3414           }
    3415           else
    3416           {
    3417             deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
    3418           }
    3419 
    3420           Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
    3421             - iPOClsb + pocLsbLt;
    3422           rps->setPOC     (j, pocLTCurr);
    3423           rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
    3424           rps->setCheckLTMSBPresent(j,true);
    3425         }
    3426         else
    3427         {
    3428           rps->setPOC     (j, pocLsbLt);
    3429           rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
    3430           rps->setCheckLTMSBPresent(j,false);
    3431 
    3432           // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
    3433           if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
    3434           {
    3435             deltaPocMSBCycleLT = 0;
    3436           }
    3437         }
    3438         prevDeltaMSB = deltaPocMSBCycleLT;
    3439       }
    3440       offset += rps->getNumberOfLongtermPictures();
    3441       rps->setNumberOfPictures(offset);
    3442     }
    3443 #if DPB_CONSTRAINTS
    3444     if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
    3445     {
    3446 #if Q0078_ADD_LAYER_SETS
    3447       for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
    3448 #else
    3449       for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
    3450 #endif
    3451       {
    3452         Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
    3453         Int chkAssert=0;
    3454         for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
    3455         {
    3456 #if R0235_SMALLEST_LAYER_ID
    3457           if(vps->getNecessaryLayerFlag(ii, kk) && rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
    3458 #else
    3459           if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
    3460 #endif
    3461           {
    3462             chkAssert=1;
    3463           }
    3464         }
    3465         if(chkAssert)
    3466         {
    3467           // There may be something wrong here (layer id assumed to be layer idx?)
    3468           assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
    3469           assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
    3470           assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
    3471         }
    3472       }
    3473 
    3474 
    3475     }
    3476     if(rpcSlice->getLayerId() == 0)
    3477     {
    3478       assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
    3479       assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
    3480       assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
    3481     }
    3482 #endif
    3483     if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    3484       || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    3485       || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    3486     {
    3487       // In the case of BLA picture types, rps data is read from slice header but ignored
    3488       rps = rpcSlice->getLocalRPS();
    3489       rps->setNumberOfNegativePictures(0);
    3490       rps->setNumberOfPositivePictures(0);
    3491       rps->setNumberOfLongtermPictures(0);
    3492       rps->setNumberOfPictures(0);
    3493       rpcSlice->setRPS(rps);
    3494     }
    3495     if (rpcSlice->getSPS()->getTMVPFlagsPresent())
    3496     {
    3497 #if R0226_SLICE_TMVP
    3498       READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
    3499 #else
    3500       READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
    3501 #endif
    3502       rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
    3503     }
    3504     else
    3505     {
    3506       rpcSlice->setEnableTMVPFlag(false);
    3507     }
    3508 #if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
    3509   }
    3510 #endif
    3511   }
    3512 
    3513 #if SVC_EXTENSION
    3514   rpcSlice->setActiveNumILRRefIdx(0);
    3515   if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
    3516   {
    3517     READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
    3518     rpcSlice->setInterLayerPredEnabledFlag(uiCode);
    3519     if( rpcSlice->getInterLayerPredEnabledFlag())
    3520     {
    3521       if(rpcSlice->getNumILRRefIdx() > 1)
    3522       {
    3523         Int numBits = 1;
    3524         while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
    3525         {
    3526           numBits++;
    3527         }
    3528         if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
    3529         {
    3530           READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
    3531           rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
    3532         }
    3533         else
    3534         {
    3535 #if P0079_DERIVE_NUMACTIVE_REF_PICS
    3536           for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ )
    3537           {
    3538 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    3539             if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    3540               (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    3541 #else
    3542             if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
    3543               (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    3544 #endif
    3545             {         
    3546               rpcSlice->setActiveNumILRRefIdx(1);
    3547               break;
    3548             }
    3549           }
    3550 #else
    3551           rpcSlice->setActiveNumILRRefIdx(1);
    3552 #endif
    3553         }
    3554 
    3555         if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
    3556         {
    3557           for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    3558           {
    3559             rpcSlice->setInterLayerPredLayerIdc(i,i);
    3560           }
    3561         }
    3562         else
    3563         {
    3564           for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    3565           {
    3566             READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
    3567             rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
    3568           }
    3569         }
    3570       }
    3571       else
    3572       {
    3573 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
    3574 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    3575         if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    3576           (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
    3577 #else
    3578         if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
    3579           (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
    3580 #endif
    3581         {
    3582 #endif
    3583           rpcSlice->setActiveNumILRRefIdx(1);
    3584           rpcSlice->setInterLayerPredLayerIdc(0,0);
    3585 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
    3586         }
    3587 #endif
    3588       }
    3589     }
    3590   }
    3591   else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
    3592   {
    3593     rpcSlice->setInterLayerPredEnabledFlag(true);
    3594 
    3595 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
    3596     Int   numRefLayerPics = 0;
    3597     Int   i = 0;
    3598     Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
    3599     for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ )
    3600     {
    3601 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    3602       if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    3603         (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    3604 #else
    3605       if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
    3606         (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    3607 #endif
    3608       {         
    3609         refLayerPicIdc[ numRefLayerPics++ ] = i;
    3610       }
    3611     }
    3612     rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
    3613     for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    3614     {
    3615       rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
    3616     }     
    3617 #else
    3618     rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
    3619     for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    3620     {
    3621       rpcSlice->setInterLayerPredLayerIdc(i,i);
    3622     }
    3623 #endif
    3624   }
     4453Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
     4454{
     4455  UInt uiCode;
     4456  // more syntax elements to be parsed here
     4457
     4458  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
     4459  // Vertical MV component restriction is not used in SHVC CTC
     4460  assert( uiCode == 0 );
     4461
     4462#if !MOVE_SCALED_OFFSET_TO_PPS
     4463  if( pcSPS->getLayerId() > 0 )
     4464  {
     4465    Int iCode;
     4466    READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
     4467    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
     4468    {
     4469      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
     4470#if O0098_SCALED_REF_LAYER_ID
     4471      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
     4472#endif
     4473      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     4474      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     4475      READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     4476      READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
    36254477#if P0312_VERT_PHASE_ADJ
    3626     for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    3627     {
    3628       UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
    3629 #if !MOVE_SCALED_OFFSET_TO_PPS
    3630       if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
    3631 #else
    3632       if( rpcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
    3633 #endif
    3634       {
    3635         READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
    3636       }
    3637   }
    3638 #endif
    3639 #endif //SVC_EXTENSION
    3640 
    3641   if(sps->getUseSAO())
    3642   {
    3643     READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
    3644 #if AUXILIARY_PICTURES
    3645     ChromaFormat format;
    3646 #if REPN_FORMAT_IN_VPS
    3647 #if O0096_REP_FORMAT_INDEX
    3648     if( sps->getLayerId() == 0 )
    3649     {
    3650       format = sps->getChromaFormatIdc();
    3651     }
    3652     else
    3653     {
    3654       format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx( rpcSlice->getVPS()->getLayerIdInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
    3655 #if Q0195_REP_FORMAT_CLEANUP
    3656       assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
    3657 #endif
    3658     }
    3659 #else
    3660     if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
    3661     {
    3662       format = sps->getChromaFormatIdc();
    3663     }
    3664     else
    3665     {
    3666       format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx( rpcSlice->getVPS()->getLayerIdInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
    3667     }
    3668 #endif
    3669 #else
    3670     format = sps->getChromaFormatIdc();
    3671 #endif
    3672     if (format != CHROMA_400)
    3673     {
    3674 #endif
    3675       READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
    3676 #if AUXILIARY_PICTURES
    3677     }
    3678     else
    3679     {
    3680       rpcSlice->setSaoEnabledFlagChroma(false);
    3681     }
    3682 #endif
    3683   }
    3684 
    3685   if (rpcSlice->getIdrPicFlag())
    3686   {
    3687     rpcSlice->setEnableTMVPFlag(false);
    3688   }
    3689   if (!rpcSlice->isIntra())
    3690   {
    3691 
    3692     READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
    3693     if (uiCode)
    3694     {
    3695       READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
    3696       if (rpcSlice->isInterB())
    3697       {
    3698         READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
    3699       }
    3700       else
    3701       {
    3702         rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    3703       }
    3704     }
    3705     else
    3706     {
    3707       rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
    3708       if (rpcSlice->isInterB())
    3709       {
    3710         rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
    3711       }
    3712       else
    3713       {
    3714         rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
    3715       }
    3716     }
    3717   }
    3718   // }
    3719   TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
    3720   if(!rpcSlice->isIntra())
    3721   {
    3722     if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    3723     {
    3724       refPicListModification->setRefPicListModificationFlagL0( 0 );
    3725     }
    3726     else
    3727     {
    3728       READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
    3729     }
    3730 
    3731     if(refPicListModification->getRefPicListModificationFlagL0())
    3732     {
    3733       uiCode = 0;
    3734       Int i = 0;
    3735       Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
    3736       if ( numRpsCurrTempList0 > 1 )
    3737       {
    3738         Int length = 1;
    3739         numRpsCurrTempList0 --;
    3740         while ( numRpsCurrTempList0 >>= 1)
    3741         {
    3742           length ++;
    3743         }
    3744         for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    3745         {
    3746           READ_CODE( length, uiCode, "list_entry_l0" );
    3747           refPicListModification->setRefPicSetIdxL0(i, uiCode );
    3748         }
    3749       }
    3750       else
    3751       {
    3752         for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    3753         {
    3754           refPicListModification->setRefPicSetIdxL0(i, 0 );
    3755         }
    3756       }
    3757     }
    3758   }
    3759   else
    3760   {
    3761     refPicListModification->setRefPicListModificationFlagL0(0);
    3762   }
    3763   if(rpcSlice->isInterB())
    3764   {
    3765     if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    3766     {
    3767       refPicListModification->setRefPicListModificationFlagL1( 0 );
    3768     }
    3769     else
    3770     {
    3771       READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
    3772     }
    3773     if(refPicListModification->getRefPicListModificationFlagL1())
    3774     {
    3775       uiCode = 0;
    3776       Int i = 0;
    3777       Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
    3778       if ( numRpsCurrTempList1 > 1 )
    3779       {
    3780         Int length = 1;
    3781         numRpsCurrTempList1 --;
    3782         while ( numRpsCurrTempList1 >>= 1)
    3783         {
    3784           length ++;
    3785         }
    3786         for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    3787         {
    3788           READ_CODE( length, uiCode, "list_entry_l1" );
    3789           refPicListModification->setRefPicSetIdxL1(i, uiCode );
    3790         }
    3791       }
    3792       else
    3793       {
    3794         for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    3795         {
    3796           refPicListModification->setRefPicSetIdxL1(i, 0 );
    3797         }
    3798       }
    3799     }
    3800   }
    3801   else
    3802   {
    3803     refPicListModification->setRefPicListModificationFlagL1(0);
    3804   }
    3805   if (rpcSlice->isInterB())
    3806   {
    3807     READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
    3808   }
    3809 
    3810   rpcSlice->setCabacInitFlag( false ); // default
    3811   if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
    3812   {
    3813     READ_FLAG(uiCode, "cabac_init_flag");
    3814     rpcSlice->setCabacInitFlag( uiCode ? true : false );
    3815   }
    3816 
    3817   if ( rpcSlice->getEnableTMVPFlag() )
    3818   {
    3819 #if SVC_EXTENSION && REF_IDX_MFM
    3820     // set motion mapping flag
    3821     rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
    3822 #endif
    3823     if ( rpcSlice->getSliceType() == B_SLICE )
    3824     {
    3825       READ_FLAG( uiCode, "collocated_from_l0_flag" );
    3826       rpcSlice->setColFromL0Flag(uiCode);
    3827     }
    3828     else
    3829     {
    3830       rpcSlice->setColFromL0Flag( 1 );
    3831     }
    3832 
    3833     if ( rpcSlice->getSliceType() != I_SLICE &&
    3834       ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
    3835       (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
    3836     {
    3837       READ_UVLC( uiCode, "collocated_ref_idx" );
    3838       rpcSlice->setColRefIdx(uiCode);
    3839     }
    3840     else
    3841     {
    3842       rpcSlice->setColRefIdx(0);
    3843     }
    3844   }
    3845   if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
    3846   {
    3847     xParsePredWeightTable(rpcSlice);
    3848     rpcSlice->initWpScaling();
    3849   }
    3850   if (!rpcSlice->isIntra())
    3851   {
    3852     READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
    3853     rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
    3854   }
    3855 
    3856   READ_SVLC( iCode, "slice_qp_delta" );
    3857   rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
    3858 
    3859 #if REPN_FORMAT_IN_VPS
    3860 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    3861   g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
    3862   g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
    3863 #endif
    3864   assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
    3865 #else
    3866   assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
    3867 #endif
    3868   assert( rpcSlice->getSliceQp() <=  51 );
    3869 
    3870   if (rpcSlice->getPPS()->getSliceChromaQpFlag())
    3871   {
    3872     READ_SVLC( iCode, "slice_qp_delta_cb" );
    3873     rpcSlice->setSliceQpDeltaCb( iCode );
    3874     assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
    3875     assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
    3876     assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
    3877     assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
    3878 
    3879     READ_SVLC( iCode, "slice_qp_delta_cr" );
    3880     rpcSlice->setSliceQpDeltaCr( iCode );
    3881     assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
    3882     assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
    3883     assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
    3884     assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
    3885   }
    3886 
    3887   if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    3888   {
    3889     if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
    3890     {
    3891       READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
    3892     }
    3893     else
    3894     {
    3895       rpcSlice->setDeblockingFilterOverrideFlag(0);
    3896     }
    3897     if(rpcSlice->getDeblockingFilterOverrideFlag())
    3898     {
    3899       READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
    3900       if(!rpcSlice->getDeblockingFilterDisable())
    3901       {
    3902         READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
    3903         assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
    3904           rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
    3905         READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
    3906         assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
    3907           rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
    3908       }
    3909     }
    3910     else
    3911     {
    3912       rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
    3913       rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
    3914       rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
    3915     }
    3916   }
    3917   else
    3918   {
    3919     rpcSlice->setDeblockingFilterDisable       ( false );
    3920     rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
    3921     rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
    3922   }
    3923 
    3924   Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
    3925   Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
    3926 
    3927   if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
    3928   {
    3929     READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
    3930   }
    3931   else
    3932   {
    3933     uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
    3934   }
    3935   rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
    3936 
    3937 }
    3938 
    3939 UInt *entryPointOffset          = NULL;
    3940 UInt numEntryPointOffsets, offsetLenMinus1;
    3941 if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    3942 {
    3943   READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
    3944   if (numEntryPointOffsets>0)
    3945   {
    3946     READ_UVLC(offsetLenMinus1, "offset_len_minus1");
    3947   }
    3948   entryPointOffset = new UInt[numEntryPointOffsets];
    3949   for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    3950   {
    3951     READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
    3952     entryPointOffset[ idx ] = uiCode + 1;
    3953   }
    3954 }
    3955 else
    3956 {
    3957   rpcSlice->setNumEntryPointOffsets ( 0 );
    3958 }
    3959 
    3960 #if POC_RESET_IDC_SIGNALLING
    3961 Int sliceHeaderExtensionLength = 0;
    3962 if(pps->getSliceHeaderExtensionPresentFlag())
    3963 {
    3964   READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
    3965 }
    3966 else
    3967 {
    3968   sliceHeaderExtensionLength = 0;
    3969 #if INFERENCE_POC_MSB_VAL_PRESENT
    3970   rpcSlice->setPocMsbValPresentFlag( false );
    3971 #endif
    3972 }
    3973 UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
    3974 if( sliceHeaderExtensionLength > 0 )
    3975 {
    3976   if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
    3977   {
    3978     READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
    3979 #if POC_RESET_RESTRICTIONS
    3980     /* The value of poc_reset_idc shall not be equal to 1 or 2 for a RASL picture, a RADL picture,
    3981        a sub-layer non-reference picture, or a picture that has TemporalId greater than 0,
    3982        or a picture that has discardable_flag equal to 1. */
    3983     if( rpcSlice->getPocResetIdc() == 1 || rpcSlice->getPocResetIdc() == 2 )
    3984     {
    3985       assert( !rpcSlice->isRASL() );
    3986       assert( !rpcSlice->isRADL() );
    3987       assert( !rpcSlice->isSLNR() );
    3988       assert( rpcSlice->getTLayer() == 0 );
    3989       assert( rpcSlice->getDiscardableFlag() == 0 );
    3990     }
    3991 
    3992     // The value of poc_reset_idc of a CRA or BLA picture shall be less than 3.
    3993     if( rpcSlice->getPocResetIdc() == 3)
    3994     {
    3995       assert( ! ( rpcSlice->isCRA() || rpcSlice->isBLA() ) );
    3996     }
    3997 #endif
    3998   }
    3999   else
    4000   {
    4001     rpcSlice->setPocResetIdc( 0 );
    4002   }
    4003 #if Q0142_POC_LSB_NOT_PRESENT
    4004   if ( vps->getPocLsbNotPresentFlag(layerIdx) && iPOClsb > 0 )
    4005   {
    4006     assert( rpcSlice->getPocResetIdc() != 2 );
    4007   }
    4008 #endif
    4009   if( rpcSlice->getPocResetIdc() > 0 )
    4010   {
    4011     READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
    4012   }
    4013   else
    4014   {
    4015 
    4016     rpcSlice->setPocResetPeriodId( 0 );
    4017   }
    4018 
    4019   if (rpcSlice->getPocResetIdc() == 3)
    4020   {
    4021     READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
    4022     READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
    4023 #if Q0142_POC_LSB_NOT_PRESENT
    4024     if ( vps->getPocLsbNotPresentFlag(layerIdx) && rpcSlice->getFullPocResetFlag() )
    4025     {
    4026       assert( rpcSlice->getPocLsbVal() == 0 );
    4027     }
    4028 #endif
    4029   }
    4030 
    4031   // Derive the value of PocMsbValRequiredFlag
    4032 #if P0297_VPS_POC_LSB_ALIGNED_FLAG
    4033   rpcSlice->setPocMsbValRequiredFlag( (rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag())
    4034                                       && (!rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() ||
    4035                                          (rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() && rpcSlice->getVPS()->getNumDirectRefLayers(rpcSlice->getLayerId()) == 0))
    4036                                     );
    4037 #else
    4038   rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag() );
    4039 #endif
    4040 
    4041 #if P0297_VPS_POC_LSB_ALIGNED_FLAG
    4042   if (!rpcSlice->getPocMsbValRequiredFlag() && rpcSlice->getVPS()->getVpsPocLsbAlignedFlag())
    4043 #else
    4044   if (!rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */)
    4045 #endif
    4046   {
    4047 #if P0297_VPS_POC_LSB_ALIGNED_FLAG
    4048     READ_FLAG(uiCode, "poc_msb_cycle_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
    4049 #else
    4050     READ_FLAG(uiCode, "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
    4051 #endif
    4052   }
    4053   else
    4054   {
    4055 #if POC_MSB_VAL_PRESENT_FLAG_SEM
    4056     if( sliceHeaderExtensionLength == 0 )
    4057     {
    4058       rpcSlice->setPocMsbValPresentFlag( false );
    4059     }
    4060     else if( rpcSlice->getPocMsbValRequiredFlag() )
    4061 #else
    4062     if( rpcSlice->getPocMsbValRequiredFlag() )
    4063 #endif
    4064     {
    4065       rpcSlice->setPocMsbValPresentFlag( true );
    4066     }
    4067     else
    4068     {
    4069       rpcSlice->setPocMsbValPresentFlag( false );
    4070     }
    4071   }
    4072 
    4073 #if !POC_RESET_IDC_DECODER
    4074   Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
    4075 #endif
    4076   if( rpcSlice->getPocMsbValPresentFlag() )
    4077   {
    4078 #if P0297_VPS_POC_LSB_ALIGNED_FLAG
    4079     READ_UVLC( uiCode,    "poc_msb_cycle_val");             rpcSlice->setPocMsbVal( uiCode );
    4080 #else
    4081     READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
    4082 #endif
    4083 
    4084 #if !POC_RESET_IDC_DECODER
    4085     // Update POC of the slice based on this MSB val
    4086     Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
    4087     rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
    4088   }
    4089   else
    4090   {
    4091     rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
    4092 #endif
    4093   }
    4094 
    4095   // Read remaining bits in the slice header extension.
    4096   UInt endBits = m_pcBitstream->getNumBitsRead();
    4097   Int counter = (endBits - startBits) % 8;
    4098   if( counter )
    4099   {
    4100     counter = 8 - counter;
    4101   }
    4102 
    4103   while( counter )
    4104   {
    4105 #if Q0146_SSH_EXT_DATA_BIT
    4106     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
    4107 #else
    4108     READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
    4109 #endif
    4110     counter--;
    4111   }
    4112 }
    4113 #else
    4114 if(pps->getSliceHeaderExtensionPresentFlag())
    4115 {
    4116   READ_UVLC(uiCode,"slice_header_extension_length");
    4117   for(Int i=0; i<uiCode; i++)
    4118   {
    4119     UInt ignore;
    4120     READ_CODE(8,ignore,"slice_header_extension_data_byte");
    4121   }
    4122 }
    4123 #endif
    4124 m_pcBitstream->readByteAlignment();
    4125 
    4126 if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    4127 {
    4128   Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
    4129 
    4130   // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
    4131   for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    4132   {
    4133     if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
    4134     {
    4135       endOfSliceHeaderLocation++;
    4136     }
    4137   }
    4138 
    4139   Int  curEntryPointOffset     = 0;
    4140   Int  prevEntryPointOffset    = 0;
    4141   for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    4142   {
    4143     curEntryPointOffset += entryPointOffset[ idx ];
    4144 
    4145     Int emulationPreventionByteCount = 0;
    4146     for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    4147     {
    4148       if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
    4149         m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
    4150       {
    4151         emulationPreventionByteCount++;
    4152       }
    4153     }
    4154 
    4155     entryPointOffset[ idx ] -= emulationPreventionByteCount;
    4156     prevEntryPointOffset = curEntryPointOffset;
    4157   }
    4158 
    4159   if ( pps->getTilesEnabledFlag() )
    4160   {
    4161     rpcSlice->setTileLocationCount( numEntryPointOffsets );
    4162 
    4163     UInt prevPos = 0;
    4164     for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    4165     {
    4166       rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
    4167       prevPos += entryPointOffset[ idx ];
    4168     }
    4169   }
    4170   else if ( pps->getEntropyCodingSyncEnabledFlag() )
    4171   {
    4172     Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
    4173     rpcSlice->allocSubstreamSizes(numSubstreams);
    4174     UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
    4175     for (Int idx=0; idx<numSubstreams-1; idx++)
    4176     {
    4177       if ( idx < numEntryPointOffsets )
    4178       {
    4179         pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    4180       }
    4181       else
    4182       {
    4183         pSubstreamSizes[ idx ] = 0;
    4184       }
    4185     }
    4186   }
    4187 
    4188   if (entryPointOffset)
    4189   {
    4190     delete [] entryPointOffset;
    4191   }
    4192 }
    4193 
    4194 return;
    4195 }
    4196 
    4197 Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
    4198 {
    4199   UInt uiCode;
    4200   if(profilePresentFlag)
    4201   {
    4202     parseProfileTier(rpcPTL->getGeneralPTL());
    4203   }
    4204   READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
    4205 
    4206   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
    4207   {
    4208 #if MULTIPLE_PTL_SUPPORT
    4209     READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
    4210 #else
    4211     if(profilePresentFlag)
    4212     {
    4213       READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
    4214     }
    4215 #endif
    4216     READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
    4217   }
    4218 
    4219   if (maxNumSubLayersMinus1 > 0)
    4220   {
    4221     for (Int i = maxNumSubLayersMinus1; i < 8; i++)
    4222     {
    4223       READ_CODE(2, uiCode, "reserved_zero_2bits");
    4224       assert(uiCode == 0);
    4225     }
    4226   }
    4227 
    4228   for(Int i = 0; i < maxNumSubLayersMinus1; i++)
    4229   {
    4230 #if MULTIPLE_PTL_SUPPORT
    4231     if( rpcPTL->getSubLayerProfilePresentFlag(i) )
    4232 #else
    4233     if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
    4234 #endif
    4235     {
    4236       parseProfileTier(rpcPTL->getSubLayerPTL(i));
    4237     }
    4238     if(rpcPTL->getSubLayerLevelPresentFlag(i))
    4239     {
    4240       READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
    4241     }
    4242   }
    4243 }
    4244 
    4245 Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
    4246 {
    4247   UInt uiCode;
    4248   READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
    4249   READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
    4250   READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
    4251   for(Int j = 0; j < 32; j++)
    4252   {
    4253     READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
    4254   }
    4255   READ_FLAG(uiCode, "general_progressive_source_flag");
    4256   ptl->setProgressiveSourceFlag(uiCode ? true : false);
    4257 
    4258   READ_FLAG(uiCode, "general_interlaced_source_flag");
    4259   ptl->setInterlacedSourceFlag(uiCode ? true : false);
    4260 
    4261   READ_FLAG(uiCode, "general_non_packed_constraint_flag");
    4262   ptl->setNonPackedConstraintFlag(uiCode ? true : false);
    4263 
    4264   READ_FLAG(uiCode, "general_frame_only_constraint_flag");
    4265   ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
    4266 
    4267 #if MULTIPLE_PTL_SUPPORT
    4268   if( ptl->getProfileIdc() == 4 || ptl->getProfileCompatibilityFlag(4) ||
    4269       ptl->getProfileIdc() == 5 || ptl->getProfileCompatibilityFlag(5) ||
    4270       ptl->getProfileIdc() == 6 || ptl->getProfileCompatibilityFlag(6) ||
    4271       ptl->getProfileIdc() == 7 || ptl->getProfileCompatibilityFlag(7)    )
    4272   {
    4273     READ_FLAG(    uiCode, "general_max_12bit_constraint_flag" ); assert (uiCode == 1);
    4274     READ_FLAG(    uiCode, "general_max_10bit_constraint_flag" ); assert (uiCode == 1);
    4275     READ_FLAG(    uiCode, "general_max_8bit_constraint_flag"  ); ptl->setProfileIdc  ((uiCode) ? Profile::SCALABLEMAIN : Profile::SCALABLEMAIN10);
    4276     READ_FLAG(    uiCode, "general_max_422chroma_constraint_flag"  ); assert (uiCode == 1);
    4277     READ_FLAG(    uiCode, "general_max_420chroma_constraint_flag"  ); assert (uiCode == 1);
    4278     READ_FLAG(    uiCode, "general_max_monochrome_constraint_flag" ); assert (uiCode == 0);
    4279     READ_FLAG(    uiCode, "general_intra_constraint_flag"); assert (uiCode == 0);
    4280     READ_FLAG(    uiCode, "general_one_picture_only_constraint_flag"); assert (uiCode == 0);
    4281     READ_FLAG(    uiCode, "general_lower_bit_rate_constraint_flag"); assert (uiCode == 1);
    4282     READ_CODE(32, uiCode, "general_reserved_zero_34bits");  READ_CODE(2, uiCode, "general_reserved_zero_34bits");
    4283   }
    4284   else
    4285   {
    4286     READ_CODE(32,  uiCode, "general_reserved_zero_43bits");  READ_CODE(11,  uiCode, "general_reserved_zero_43bits");
    4287   }
    4288 
    4289   if( ( ptl->getProfileIdc() >= 1 && ptl->getProfileIdc() <= 5 ) ||
    4290       ptl->getProfileCompatibilityFlag(1) || ptl->getProfileCompatibilityFlag(2) ||
    4291       ptl->getProfileCompatibilityFlag(3) || ptl->getProfileCompatibilityFlag(4) ||
    4292       ptl->getProfileCompatibilityFlag(5)                                           )
    4293   {
    4294     READ_FLAG(uiCode, "general_inbld_flag");
    4295   }
    4296   else
    4297   {
    4298     READ_FLAG(uiCode, "general_reserved_zero_bit");
    4299   }
    4300 #else
    4301   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
    4302   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
    4303   READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
    4304 #endif
    4305 }
    4306 
    4307 Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
    4308 {
    4309   ruiBit = false;
    4310   Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
    4311   if(iBitsLeft <= 8)
    4312   {
    4313     UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
    4314     if (uiPeekValue == (1<<(iBitsLeft-1)))
    4315     {
    4316       ruiBit = true;
    4317     }
    4318   }
    4319 }
    4320 
    4321 Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4322 {
    4323   assert(0);
    4324 }
    4325 
    4326 Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4327 {
    4328   assert(0);
    4329 }
    4330 
    4331 Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
    4332 {
    4333   assert(0);
    4334 }
    4335 
    4336 Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4337 {
    4338   assert(0);
    4339 }
    4340 
    4341 Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4342 {
    4343   assert(0);
    4344 }
    4345 
    4346 Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4347 {
    4348   assert(0);
    4349 }
    4350 
    4351 /** Parse I_PCM information.
    4352 * \param pcCU pointer to CU
    4353 * \param uiAbsPartIdx CU index
    4354 * \param uiDepth CU depth
    4355 * \returns Void
    4356 *
    4357 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
    4358 */
    4359 Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4360 {
    4361   assert(0);
    4362 }
    4363 
    4364 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4365 {
    4366   assert(0);
    4367 }
    4368 
    4369 Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    4370 {
    4371   assert(0);
    4372 }
    4373 
    4374 Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
    4375 {
    4376   assert(0);
    4377 }
    4378 
    4379 Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
    4380 {
    4381   assert(0);
    4382 }
    4383 
    4384 Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
    4385 {
    4386   assert(0);
    4387 }
    4388 
    4389 Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    4390 {
    4391   Int qp;
    4392   Int  iDQp;
    4393 
    4394   xReadSvlc( iDQp );
    4395 
    4396 #if REPN_FORMAT_IN_VPS
    4397   Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
    4398 #else
    4399   Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    4400 #endif
    4401   qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
    4402 
    4403   UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
    4404   UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
    4405 
    4406   pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
    4407 }
    4408 
    4409 Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
    4410 {
    4411   assert(0);
    4412 }
    4413 
    4414 Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
    4415 {
    4416   assert(0);
    4417 }
    4418 
    4419 Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
    4420 {
    4421   assert(0);
    4422 }
    4423 
    4424 Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
    4425 {
    4426   assert(0);
    4427 }
    4428 
    4429 Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
    4430 {
    4431   assert(0);
    4432 }
    4433 
    4434 Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
    4435 {
    4436   assert(0);
    4437 }
    4438 
    4439 Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
    4440 {
    4441   assert(0);
    4442 }
    4443 
    4444 // ====================================================================================================================
    4445 // Protected member functions
    4446 // ====================================================================================================================
    4447 
    4448 /** parse explicit wp tables
    4449 * \param TComSlice* pcSlice
    4450 * \returns Void
    4451 */
    4452 Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
    4453 {
    4454   wpScalingParam  *wp;
    4455   Bool            bChroma     = true; // color always present in HEVC ?
    4456   SliceType       eSliceType  = pcSlice->getSliceType();
    4457   Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
    4458 #if SVC_EXTENSION
    4459   UInt            uiLog2WeightDenomLuma = 0, uiLog2WeightDenomChroma = 0;
    4460 #else
    4461   UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
    4462 #endif
    4463   UInt            uiTotalSignalledWeightFlags = 0;
    4464 
    4465   Int iDeltaDenom;
    4466 #if AUXILIARY_PICTURES
    4467   if (pcSlice->getChromaFormatIdc() == CHROMA_400)
    4468   {
    4469     bChroma = false;
    4470   }
    4471 #endif
    4472   // decode delta_luma_log2_weight_denom :
    4473   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
    4474   assert( uiLog2WeightDenomLuma <= 7 );
    4475   if( bChroma )
    4476   {
    4477     READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
    4478     assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
    4479     assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
    4480     uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
    4481   }
    4482 
    4483   for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
    4484   {
    4485     RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    4486     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    4487     {
    4488       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    4489 
    4490       wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
    4491 #if AUXILIARY_PICTURES
    4492       if (!bChroma)
    4493       {
    4494         wp[1].uiLog2WeightDenom = 0;
    4495         wp[2].uiLog2WeightDenom = 0;
    4496       }
    4497       else
    4498       {
    4499 #endif
    4500         wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    4501         wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    4502 #if AUXILIARY_PICTURES
    4503       }
    4504 #endif
    4505 
    4506       UInt  uiCode;
    4507       READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
    4508       wp[0].bPresentFlag = ( uiCode == 1 );
    4509       uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
    4510     }
    4511     if ( bChroma )
    4512     {
    4513       UInt  uiCode;
    4514       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    4515       {
    4516         pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    4517         READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
    4518         wp[1].bPresentFlag = ( uiCode == 1 );
    4519         wp[2].bPresentFlag = ( uiCode == 1 );
    4520         uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
    4521       }
    4522     }
    4523     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    4524     {
    4525       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    4526       if ( wp[0].bPresentFlag )
    4527       {
    4528         Int iDeltaWeight;
    4529         READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
    4530         assert( iDeltaWeight >= -128 );
    4531         assert( iDeltaWeight <=  127 );
    4532         wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
    4533         READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
    4534         assert( wp[0].iOffset >= -128 );
    4535         assert( wp[0].iOffset <=  127 );
    4536       }
    4537       else
    4538       {
    4539         wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
    4540         wp[0].iOffset = 0;
    4541       }
    4542       if ( bChroma )
    4543       {
    4544         if ( wp[1].bPresentFlag )
    4545         {
    4546           for ( Int j=1 ; j<3 ; j++ )
    4547           {
    4548             Int iDeltaWeight;
    4549             READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
    4550             assert( iDeltaWeight >= -128 );
    4551             assert( iDeltaWeight <=  127 );
    4552             wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
    4553 
    4554             Int iDeltaChroma;
    4555             READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
    4556             assert( iDeltaChroma >= -512 );
    4557             assert( iDeltaChroma <=  511 );
    4558             Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
    4559             wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
    4560           }
    4561         }
    4562         else
    4563         {
    4564           for ( Int j=1 ; j<3 ; j++ )
    4565           {
    4566             wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
    4567             wp[j].iOffset = 0;
    4568           }
    4569         }
    4570       }
    4571     }
    4572 
    4573     for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
    4574     {
    4575       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    4576 
    4577       wp[0].bPresentFlag = false;
    4578       wp[1].bPresentFlag = false;
    4579       wp[2].bPresentFlag = false;
    4580     }
    4581   }
    4582   assert(uiTotalSignalledWeightFlags<=24);
    4583 }
    4584 
    4585 /** decode quantization matrix
    4586 * \param scalingList quantization matrix information
    4587 */
    4588 Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
    4589 {
    4590   UInt  code, sizeId, listId;
    4591   Bool scalingListPredModeFlag;
    4592   //for each size
    4593   for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    4594   {
    4595     for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
    4596     {
    4597       READ_FLAG( code, "scaling_list_pred_mode_flag");
    4598       scalingListPredModeFlag = (code) ? true : false;
    4599       if(!scalingListPredModeFlag) //Copy Mode
    4600       {
    4601         READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
    4602         scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
    4603         if( sizeId > SCALING_LIST_8x8 )
    4604         {
    4605           scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
    4606         }
    4607         scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
    4608 
    4609       }
    4610       else //DPCM Mode
    4611       {
    4612         xDecodeScalingList(scalingList, sizeId, listId);
    4613       }
    4614     }
    4615   }
    4616 
    4617   return;
    4618 }
    4619 /** decode DPCM
    4620 * \param scalingList  quantization matrix information
    4621 * \param sizeId size index
    4622 * \param listId list index
    4623 */
    4624 Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
    4625 {
    4626   Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    4627   Int data;
    4628   Int scalingListDcCoefMinus8 = 0;
    4629   Int nextCoef = SCALING_LIST_START_VALUE;
    4630   UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
    4631   Int *dst = scalingList->getScalingListAddress(sizeId, listId);
    4632 
    4633   if( sizeId > SCALING_LIST_8x8 )
    4634   {
    4635     READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
    4636     scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
    4637     nextCoef = scalingList->getScalingListDC(sizeId,listId);
    4638   }
    4639 
    4640   for(i = 0; i < coefNum; i++)
    4641   {
    4642     READ_SVLC( data, "scaling_list_delta_coef");
    4643     nextCoef = (nextCoef + data + 256 ) % 256;
    4644     dst[scan[i]] = nextCoef;
    4645   }
    4646 }
    4647 
    4648 Bool TDecCavlc::xMoreRbspData()
    4649 {
    4650   Int bitsLeft = m_pcBitstream->getNumBitsLeft();
    4651 
    4652   // if there are more than 8 bits, it cannot be rbsp_trailing_bits
    4653   if (bitsLeft > 8)
    4654   {
    4655     return true;
    4656   }
    4657 
    4658   UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
    4659   Int cnt = bitsLeft;
    4660 
    4661   // remove trailing bits equal to zero
    4662   while ((cnt>0) && ((lastByte & 1) == 0))
    4663   {
    4664     lastByte >>= 1;
    4665     cnt--;
    4666   }
    4667   // remove bit equal to one
    4668   cnt--;
    4669 
    4670   // we should not have a negative number of bits
    4671   assert (cnt>=0);
    4672 
    4673   // we have more data, if cnt is not zero
    4674   return (cnt>0);
    4675 }
     4478      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);   
     4479#endif
     4480    }
     4481  }
     4482#endif
     4483}
     4484#endif
    46764485
    46774486#if Q0048_CGS_3D_ASYMLUT
     
    49624771              if( vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams() > 1 )
    49634772              {
    4964 #endif
    4965 #if VPS_FIX_TO_MATCH_SPEC
    49664773                Int numBits = 1;
    49674774                while ((1 << numBits) < (vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams()))
     
    49704777                }
    49714778                READ_CODE(numBits, uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
    4972 #else
    4973                 READ_UVLC(uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
    4974 #endif
    4975 #if VPS_FIX_TO_MATCH_SPEC
    49764779              }
     4780#else
     4781              READ_UVLC(uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
    49774782#endif
    49784783              READ_UVLC(uiCode, "bsp_comb_sched_idx[h][i][t][j][k]");    vps->setBspSchedIdx(h, i, t, j, k, uiCode);
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.h

    r894 r1029  
    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-2014, ITU/ISO/IEC
     
    6262  TDecCavlc();
    6363  virtual ~TDecCavlc();
    64  
     64
    6565protected:
    66   void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Int idx);
    67  
     66
     67  Void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Int idx);
     68
    6869public:
    6970
     
    7273  Void  setBitstream        ( TComInputBitstream* p )   { m_pcBitstream = p; }
    7374  Void  parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize );
    74   Void  parseQtCbf          ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth );
     75  Void  parseQtCbf          ( class TComTU &rTu, const ComponentID compID, const Bool lowestLevel );
    7576  Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
    7677  Void  parseVPS            ( TComVPS* pcVPS );
     78#if !SVC_EXTENSION
     79  Void  parseSPS            ( TComSPS* pcSPS );
     80  Void  parsePPS            ( TComPPS* pcPPS );
     81#endif
     82  Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
     83  Void  parseSEI            ( SEIMessages& );
     84  Void  parsePTL            ( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 );
     85  Void  parseProfileTier    (ProfileTierLevel *ptl);
     86  Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
     87  Void  parseSliceHeader    ( TComSlice* pcSlice, ParameterSetManagerDecoder *parameterSetManager);
     88  Void  parseTerminatingBit ( UInt& ruiBit );
     89  Void  parseRemainingBytes ( Bool noTrailingBytesExpected );
     90
     91  Void parseMVPIdx          ( Int& riMVPIdx );
     92
     93  Void parseSkipFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     94  Void parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     95  Void parseMergeFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
     96  Void parseMergeIndex      ( TComDataCU* pcCU, UInt& ruiMergeIndex );
     97  Void parseSplitFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     98  Void parsePartSize        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     99  Void parsePredMode        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     100
     101  Void parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     102  Void parseIntraDirChroma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     103
     104  Void parseInterDir        ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
     105  Void parseRefFrmIdx       ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList );
     106  Void parseMvd             ( TComDataCU* pcCU, UInt uiAbsPartAddr,UInt uiPartIdx,    UInt uiDepth, RefPicList eRefList );
     107
     108  Void parseCrossComponentPrediction( class TComTU &rTu, ComponentID compID );
     109
     110  Void parseDeltaQP         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     111  Void parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth);
     112
     113  Void parseCoeffNxN        ( class TComTU &rTu, ComponentID compID );
     114
     115  Void parseTransformSkipFlags ( class TComTU &rTu, ComponentID component );
     116
     117  Void parseIPCMInfo        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
     118
     119  Void xParsePredWeightTable ( TComSlice* pcSlice );
     120  Void  parseScalingList     ( TComScalingList* scalingList );
     121  Void xDecodeScalingList    ( TComScalingList *scalingList, UInt sizeId, UInt listId);
     122
     123  Void  parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID );
     124
     125protected:
     126  Bool  xMoreRbspData();
     127
    77128#if SVC_EXTENSION
     129public:
    78130  Void  parseVPSExtension   ( TComVPS* pcVPS );
    79131  Void  defaultVPSExtension ( TComVPS* pcVPS );
     
    95147#endif
    96148  Void  parseSPSExtension    ( TComSPS* pcSPS );
    97 #else //SVC_EXTENSION
    98   Void  parseSPS            ( TComSPS* pcSPS );
    99 #endif //SVC_EXTENSION
    100   Void  parsePPS            ( TComPPS* pcPPS
    101149#if Q0048_CGS_3D_ASYMLUT
    102     , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
     150  Void  parsePPS            ( TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID );
     151#else
     152  Void  parsePPS            ( TComPPS* pcPPS );
    103153#endif
    104     );
    105   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
    106   Void  parseSEI            ( SEIMessages& );
    107   Void  parsePTL            ( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 );
    108   Void  parseProfileTier    (ProfileTierLevel *ptl);
    109   Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
    110   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager);
    111   Void  parseTerminatingBit ( UInt& ruiBit );
    112  
    113   Void  parseMVPIdx         ( Int& riMVPIdx );
    114  
    115   Void  parseSkipFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    116   Void  parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    117   Void parseMergeFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
    118   Void parseMergeIndex      ( TComDataCU* pcCU, UInt& ruiMergeIndex );
    119   Void parseSplitFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    120   Void parsePartSize        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    121   Void parsePredMode        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    122  
    123   Void parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    124  
    125   Void parseIntraDirChroma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    126  
    127   Void parseInterDir        ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
    128   Void parseRefFrmIdx       ( TComDataCU* pcCU, Int& riRefFrmIdx,  RefPicList eRefList );
    129   Void parseMvd             ( TComDataCU* pcCU, UInt uiAbsPartAddr,UInt uiPartIdx,    UInt uiDepth, RefPicList eRefList );
    130  
    131   Void parseDeltaQP         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    132   Void parseCoeffNxN        ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType );
    133   Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType);
    134154
    135   Void parseIPCMInfo        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
    136 
    137   Void updateContextTables  ( SliceType /*eSliceType*/, Int /*iQp*/ ) { return; }
    138 
    139   Void xParsePredWeightTable ( TComSlice* pcSlice );
    140   Void  parseScalingList               ( TComScalingList* scalingList );
    141   Void xDecodeScalingList    ( TComScalingList *scalingList, UInt sizeId, UInt listId);
    142155protected:
    143   Bool  xMoreRbspData();
    144 
    145156#if Q0048_CGS_3D_ASYMLUT
    146157  Void xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
     
    154165#endif
    155166#endif
     167#endif //SVC_EXTENSION
     168
    156169};
    157170
     
    159172
    160173#endif // !defined(AFX_TDECCAVLC_H__9732DD64_59B0_4A41_B29E_1A5B18821EAD__INCLUDED_)
    161 
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.cpp

    r713 r1029  
    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-2014, ITU/ISO/IEC
     
    3737
    3838#include "TDecCu.h"
     39#include "TLibCommon/TComTU.h"
    3940#if SVC_EXTENSION
    4041#include "TDecTop.h"
     
    9596 \param    uiMaxHeight   largest CU height
    9697 */
    97 Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight )
     98Void TDecCu::create( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC )
    9899{
    99100  m_uiMaxDepth = uiMaxDepth+1;
    100  
     101
    101102  m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
    102103  m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
    103104  m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
    104  
     105
    105106  UInt uiNumPartitions;
    106107  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
     
    109110    UInt uiWidth  = uiMaxWidth  >> ui;
    110111    UInt uiHeight = uiMaxHeight >> ui;
    111    
    112     m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
    113     m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
    114     m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
    115   }
    116  
     112
     113    m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
     114    m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
     115    m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( chromaFormatIDC, uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
     116  }
     117
    117118  m_bDecodeDQP = false;
     119  m_IsChromaQpAdjCoded = false;
    118120
    119121  // initialize partition order.
     
    121123  initZscanToRaster(m_uiMaxDepth, 1, 0, piTmp);
    122124  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
    123  
     125
    124126  // initialize conversion matrix from partition index to pel
    125127  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
     
    134136    m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
    135137  }
    136  
     138
    137139  delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
    138140  delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
     
    147149 \param    ruiIsLast   last data?
    148150 */
    149 Void TDecCu::decodeCU( TComDataCU* pcCU, UInt& ruiIsLast )
    150 {
    151   if ( pcCU->getSlice()->getPPS()->getUseDQP() )
     151Void TDecCu::decodeCtu( TComDataCU* pCtu, Bool& isLastCtuOfSliceSegment )
     152{
     153  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
    152154  {
    153155    setdQPFlag(true);
    154156  }
    155157
     158  if ( pCtu->getSlice()->getUseChromaQpAdj() )
     159  {
     160    setIsChromaQpAdjCoded(true);
     161  }
     162
     163#if SVC_EXTENSION
     164  pCtu->setLayerId(m_layerId);
     165#endif
     166
    156167  // start from the top level CU
    157 #if SVC_EXTENSION
    158   pcCU->setLayerId(m_layerId);
    159 #endif
    160   xDecodeCU( pcCU, 0, 0, ruiIsLast);
     168  xDecodeCU( pCtu, 0, 0, isLastCtuOfSliceSegment);
    161169}
    162170
    163171/** \param    pcCU        pointer of CU data
    164172 */
    165 Void TDecCu::decompressCU( TComDataCU* pcCU )
    166 {
    167   xDecompressCU( pcCU, 0,  0 );
     173Void TDecCu::decompressCtu( TComDataCU* pCtu )
     174{
     175  xDecompressCU( pCtu, 0,  0 );
    168176}
    169177
     
    174182/**decode end-of-slice flag
    175183 * \param pcCU
    176  * \param uiAbsPartIdx 
    177  * \param uiDepth 
     184 * \param uiAbsPartIdx
     185 * \param uiDepth
    178186 * \returns Bool
    179187 */
    180 Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth)
    181 {
    182   UInt uiIsLast;
    183   TComPic* pcPic = pcCU->getPic();
    184   TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
    185   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
    186 #if REPN_FORMAT_IN_VPS
    187   UInt uiWidth  = pcSlice->getPicWidthInLumaSamples();
    188   UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
    189 #else
    190   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    191   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
    192 #endif
    193   UInt uiGranularityWidth = g_uiMaxCUWidth;
    194   UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    195   UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    196 
    197   if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
    198     &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
    199   {
    200     m_pcEntropyDecoder->decodeTerminatingBit( uiIsLast );
     188Bool TDecCu::xDecodeSliceEnd( TComDataCU* pcCU, UInt uiAbsPartIdx )
     189{
     190  UInt uiIsLastCtuOfSliceSegment;
     191
     192  if (pcCU->isLastSubCUOfCtu(uiAbsPartIdx))
     193  {
     194    m_pcEntropyDecoder->decodeTerminatingBit( uiIsLastCtuOfSliceSegment );
    201195  }
    202196  else
    203197  {
    204     uiIsLast=0;
    205   }
    206  
    207   if(uiIsLast)
    208   {
    209     if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice())
    210     {
    211       pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    212     }
    213     else
    214     {
    215       pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    216       pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
    217     }
    218   }
    219 
    220   return uiIsLast>0;
     198    uiIsLastCtuOfSliceSegment=0;
     199  }
     200
     201  return uiIsLastCtuOfSliceSegment>0;
    221202}
    222203
    223204/** decode CU block recursively
    224205 * \param pcCU
    225  * \param uiAbsPartIdx 
    226  * \param uiDepth 
     206 * \param uiAbsPartIdx
     207 * \param uiDepth
    227208 * \returns Void
    228209 */
    229210
    230 Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
     211Void TDecCu::xDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
    231212{
    232213  TComPic* pcPic = pcCU->getPic();
    233   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
     214  UInt uiCurNumParts    = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
    234215  UInt uiQNumParts      = uiCurNumParts>>2;
    235  
     216
    236217  Bool bBoundary = false;
    237218  UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
     
    239220  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    240221  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    241  
     222
    242223  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    243   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
    244224#if REPN_FORMAT_IN_VPS
    245   if((!bStartInCU) && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()          ) )
     225  if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) )
    246226#else
    247   if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     227  if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    248228#endif
    249229  {
     
    254234    bBoundary = true;
    255235  }
    256  
     236
    257237  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
    258238  {
     
    264244    }
    265245
     246    if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
     247    {
     248      setIsChromaQpAdjCoded(true);
     249    }
     250
    266251    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
    267252    {
    268253      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
    269254      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
    270      
    271       Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
    272       if ( bSubInSlice )
    273       {
     255
    274256#if REPN_FORMAT_IN_VPS
    275         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples()          ) )
     257      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
    276258#else
    277         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
    278 #endif
    279         {
    280           xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
    281         }
    282         else
    283         {
    284           pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
    285         }
    286       }
    287      
     259      if ( !isLastCtuOfSliceSegment && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
     260#endif
     261      {
     262        xDecodeCU( pcCU, uiIdx, uiDepth+1, isLastCtuOfSliceSegment );
     263      }
     264      else
     265      {
     266        pcCU->setOutsideCUPart( uiIdx, uiDepth+1 );
     267      }
     268
    288269      uiIdx += uiQNumParts;
    289270    }
     
    292273      if ( getdQPFlag() )
    293274      {
    294         UInt uiQPSrcPartIdx;
    295         if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
    296         {
    297           uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
    298         }
    299         else
    300         {
    301           uiQPSrcPartIdx = uiAbsPartIdx;
    302         }
     275        UInt uiQPSrcPartIdx = uiAbsPartIdx;
    303276        pcCU->setQPSubParts( pcCU->getRefQP( uiQPSrcPartIdx ), uiAbsPartIdx, uiDepth ); // set QP to default QP
    304277      }
     
    306279    return;
    307280  }
    308  
     281
    309282  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
    310283  {
     
    313286  }
    314287
     288  if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj() )
     289  {
     290    setIsChromaQpAdjCoded(true);
     291  }
     292
    315293  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    316294  {
    317295    m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
    318296  }
    319  
     297
    320298  // decode CU mode and the partition size
    321299  if( !pcCU->getSlice()->isIntra())
     
    360338    TComMv cTmpMv( 0, 0 );
    361339    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    362     {       
     340    {
    363341      if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
    364342      {
     
    369347      }
    370348    }
    371     xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
     349    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
    372350    return;
    373351  }
     
    382360    if(pcCU->getIPCMFlag(uiAbsPartIdx))
    383361    {
    384       xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
     362      xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
    385363      return;
    386364    }
    387365  }
    388366
    389   UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
    390   UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
    391  
    392367  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
    393368  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
     
    395370  // Coefficient decoding
    396371  Bool bCodeDQP = getdQPFlag();
    397   m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, uiCurrWidth, uiCurrHeight, bCodeDQP );
     372  Bool isChromaQpAdjCoded = getIsChromaQpAdjCoded();
     373  m_pcEntropyDecoder->decodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, isChromaQpAdjCoded );
     374  setIsChromaQpAdjCoded( isChromaQpAdjCoded );
    398375  setdQPFlag( bCodeDQP );
    399   xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
    400 }
    401 
    402 Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& ruiIsLast)
     376  xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, isLastCtuOfSliceSegment );
     377}
     378
     379Void TDecCu::xFinishDecodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment)
    403380{
    404381  if(  pcCU->getSlice()->getPPS()->getUseDQP())
     
    407384  }
    408385
    409   ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
    410 }
    411 
    412 Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
    413 {
    414   TComPic* pcPic = pcCU->getPic();
    415  
     386  if (pcCU->getSlice()->getUseChromaQpAdj() && !getIsChromaQpAdjCoded())
     387  {
     388    pcCU->setChromaQpAdjSubParts( pcCU->getCodedChromaQpAdj(), uiAbsPartIdx, uiDepth ); // set QP
     389  }
     390
     391  isLastCtuOfSliceSegment = xDecodeSliceEnd( pcCU, uiAbsPartIdx );
     392}
     393
     394Void TDecCu::xDecompressCU( TComDataCU* pCtu, UInt uiAbsPartIdx,  UInt uiDepth )
     395{
     396  TComPic* pcPic = pCtu->getPic();
     397
    416398  Bool bBoundary = false;
    417   UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
     399  UInt uiLPelX   = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    418400  UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
    419   UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
     401  UInt uiTPelY   = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    420402  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    421  
    422   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
    423   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    424   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
     403
     404  TComSlice * pcSlice = pCtu->getPic()->getSlice(pCtu->getPic()->getCurrSliceIdx());
     405
    425406#if REPN_FORMAT_IN_VPS
    426   if(bStartInCU||( uiRPelX >= pcSlice->getPicWidthInLumaSamples()           ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples()           ) )
     407  if( ( uiRPelX >= pcSlice->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples() ) )
     408
    427409#else
    428   if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     410  if( ( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    429411#endif
    430412  {
    431413    bBoundary = true;
    432414  }
    433  
    434   if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
     415
     416  if( ( ( uiDepth < pCtu->getDepth( uiAbsPartIdx ) ) && ( uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary )
    435417  {
    436418    UInt uiNextDepth = uiDepth + 1;
    437     UInt uiQNumParts = pcCU->getTotalNumPart() >> (uiNextDepth<<1);
     419    UInt uiQNumParts = pCtu->getTotalNumPart() >> (uiNextDepth<<1);
    438420    UInt uiIdx = uiAbsPartIdx;
    439421    for ( UInt uiPartIdx = 0; uiPartIdx < 4; uiPartIdx++ )
    440422    {
    441       uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
    442       uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
    443      
    444       Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
     423      uiLPelX = pCtu->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
     424      uiTPelY = pCtu->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
     425
    445426#if REPN_FORMAT_IN_VPS
    446       if(binSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()          ) )
     427      if( ( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) )
    447428#else
    448       if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    449 #endif
    450       {
    451         xDecompressCU(pcCU, uiIdx, uiNextDepth );
    452       }
    453      
     429      if( ( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     430#endif
     431      {
     432        xDecompressCU(pCtu, uiIdx, uiNextDepth );
     433      }
     434
    454435      uiIdx += uiQNumParts;
    455436    }
    456437    return;
    457438  }
    458  
     439
    459440  // Residual reconstruction
    460441  m_ppcYuvResi[uiDepth]->clear();
    461  
    462   m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
    463  
     442
     443  m_ppcCU[uiDepth]->copySubCU( pCtu, uiAbsPartIdx, uiDepth );
     444
    464445  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
    465446  {
     
    474455      break;
    475456  }
     457
     458#ifdef DEBUG_STRING
     459  const PredMode predMode=m_ppcCU[uiDepth]->getPredictionMode(0);
     460  if (DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode))
     461  {
     462    PartSize eSize=m_ppcCU[uiDepth]->getPartitionSize(0);
     463    std::ostream &ss(std::cout);
     464
     465    ss <<"###: " << (predMode==MODE_INTRA?"Intra   ":"Inter   ") << partSizeToString[eSize] << " CU at " << m_ppcCU[uiDepth]->getCUPelX() << ", " << m_ppcCU[uiDepth]->getCUPelY() << " width=" << UInt(m_ppcCU[uiDepth]->getWidth(0)) << std::endl;
     466  }
     467#endif
     468
    476469  if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
    477470  {
    478471    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
    479472  }
    480  
     473
    481474  xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
    482475}
     
    484477Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
    485478{
    486  
     479
    487480  // inter prediction
    488481  m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
    489  
     482
     483#ifdef DEBUG_STRING
     484  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTER);
     485  if (DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-pred: ", *(m_ppcYuvReco[uiDepth]));
     486#endif
     487
    490488  // inter recon
    491   xDecodeInterTexture( pcCU, 0, uiDepth );
    492  
     489  xDecodeInterTexture( pcCU, uiDepth );
     490
     491#ifdef DEBUG_STRING
     492  if (DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-resi: ", *(m_ppcYuvResi[uiDepth]));
     493#endif
     494
    493495  // clip for only non-zero cbp case
    494   if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
     496  if  ( pcCU->getQtRootCbf( 0) )
    495497  {
    496498    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
     
    500502    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
    501503  }
    502 }
     504#ifdef DEBUG_STRING
     505  if (DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) printBlockToStream(std::cout, "###inter-reco: ", *(m_ppcYuvReco[uiDepth]));
     506#endif
     507
     508}
     509
    503510
    504511Void
    505 TDecCu::xIntraRecLumaBlk( TComDataCU* pcCU,
    506                          UInt        uiTrDepth,
    507                          UInt        uiAbsPartIdx,
    508                          TComYuv*    pcRecoYuv,
    509                          TComYuv*    pcPredYuv,
    510                          TComYuv*    pcResiYuv )
    511 {
    512   UInt    uiWidth           = pcCU     ->getWidth   ( 0 ) >> uiTrDepth;
    513   UInt    uiHeight          = pcCU     ->getHeight  ( 0 ) >> uiTrDepth;
    514   UInt    uiStride          = pcRecoYuv->getStride  ();
    515   Pel*    piReco            = pcRecoYuv->getLumaAddr( uiAbsPartIdx );
    516   Pel*    piPred            = pcPredYuv->getLumaAddr( uiAbsPartIdx );
    517   Pel*    piResi            = pcResiYuv->getLumaAddr( uiAbsPartIdx );
    518  
    519   UInt    uiNumCoeffInc     = ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 );
    520   TCoeff* pcCoeff           = pcCU->getCoeffY() + ( uiNumCoeffInc * uiAbsPartIdx );
    521  
    522   UInt    uiLumaPredMode    = pcCU->getLumaIntraDir     ( uiAbsPartIdx );
    523  
    524   UInt    uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    525   Pel*    piRecIPred        = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder );
    526   UInt    uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride  ();
    527   Bool    useTransformSkip  = pcCU->getTransformSkip(uiAbsPartIdx, TEXT_LUMA);
     512TDecCu::xIntraRecBlk(       TComYuv*    pcRecoYuv,
     513                            TComYuv*    pcPredYuv,
     514                            TComYuv*    pcResiYuv,
     515                      const ComponentID compID,
     516                            TComTU     &rTu)
     517{
     518  if (!rTu.ProcessComponentSection(compID)) return;
     519  const Bool       bIsLuma = isLuma(compID);
     520
     521
     522  TComDataCU *pcCU = rTu.getCU();
     523  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
     524
     525  const TComRectangle &tuRect  =rTu.getRect(compID);
     526  const UInt uiWidth           = tuRect.width;
     527  const UInt uiHeight          = tuRect.height;
     528  const UInt uiStride          = pcRecoYuv->getStride (compID);
     529        Pel* piPred            = pcPredYuv->getAddr( compID, uiAbsPartIdx );
     530  const ChromaFormat chFmt     = rTu.GetChromaFormat();
     531
     532  if (uiWidth != uiHeight)
     533  {
     534    //------------------------------------------------
     535
     536    //split at current level if dividing into square sub-TUs
     537
     538    TComTURecurse subTURecurse(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
     539
     540    //recurse further
     541    do
     542    {
     543      xIntraRecBlk(pcRecoYuv, pcPredYuv, pcResiYuv, compID, subTURecurse);
     544    }
     545    while (subTURecurse.nextSection(rTu));
     546
     547    //------------------------------------------------
     548
     549    return;
     550  }
     551
     552  const UInt uiChPredMode  = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
     553  const UInt uiChCodedMode = (uiChPredMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, chFmt)) : uiChPredMode;
     554  const UInt uiChFinalMode = ((chFmt == CHROMA_422)       && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiChCodedMode] : uiChCodedMode;
     555
    528556  //===== init availability pattern =====
    529557  Bool  bAboveAvail = false;
    530558  Bool  bLeftAvail  = false;
    531   pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx );
    532   pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth,
    533                                      m_pcPrediction->getPredicBuf       (),
    534                                      m_pcPrediction->getPredicBufWidth  (),
    535                                      m_pcPrediction->getPredicBufHeight (),
    536                                      bAboveAvail, bLeftAvail );
    537  
     559
     560  const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getDisableIntraReferenceSmoothing());
     561
     562#ifdef DEBUG_STRING
     563  std::ostream &ss(std::cout);
     564#endif
     565
     566  DEBUG_STRING_NEW(sTemp)
     567  m_pcPrediction->initAdiPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
     568
     569
    538570  //===== get prediction signal =====
    539   m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
    540  
    541   if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
    542   {
     571
     572  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
     573
     574#ifdef DEBUG_STRING
     575  ss << sTemp;
     576#endif
     577
    543578  //===== inverse transform =====
    544 #if REPN_FORMAT_IN_VPS
    545   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     579  Pel*      piResi            = pcResiYuv->getAddr( compID, uiAbsPartIdx );
     580  TCoeff*   pcCoeff           = pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID);//( uiNumCoeffInc * uiAbsPartIdx );
     581
     582  const QpParam cQP(*pcCU, compID);
     583
     584
     585  DEBUG_STRING_NEW(sDebug);
     586#ifdef DEBUG_STRING
     587  const Int debugPredModeMask=DebugStringGetPredModeMask(MODE_INTRA);
     588  std::string *psDebug=(DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) ? &sDebug : 0;
     589#endif
     590
     591  if (pcCU->getCbf(uiAbsPartIdx, compID, rTu.GetTransformDepthRel()) != 0)
     592  {
     593    m_pcTrQuant->invTransformNxN( rTu, compID, piResi, uiStride, pcCoeff, cQP DEBUG_STRING_PASS_INTO(psDebug) );
     594  }
     595  else
     596  {
     597    for (UInt y = 0; y < uiHeight; y++)
     598      for (UInt x = 0; x < uiWidth; x++)
     599      {
     600        piResi[(y * uiStride) + x] = 0;
     601      }
     602  }
     603
     604#ifdef DEBUG_STRING
     605  if (psDebug)
     606    ss << (*psDebug);
     607#endif
     608
     609  //===== reconstruction =====
     610  const UInt uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getStride(compID);
     611
     612  const Bool useCrossComponentPrediction = isChroma(compID) && (pcCU->getCrossComponentPredictionAlpha(uiAbsPartIdx, compID) != 0);
     613  const Pel* pResiLuma  = pcResiYuv->getAddr( COMPONENT_Y, uiAbsPartIdx );
     614  const Int  strideLuma = pcResiYuv->getStride( COMPONENT_Y );
     615
     616        Pel* pPred      = piPred;
     617        Pel* pResi      = piResi;
     618        Pel* pReco      = pcRecoYuv->getAddr( compID, uiAbsPartIdx );
     619        Pel* pRecIPred  = pcCU->getPic()->getPicYuvRec()->getAddr( compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
     620
     621
     622#ifdef DEBUG_STRING
     623  const Bool bDebugPred=((DebugOptionList::DebugString_Pred.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     624  const Bool bDebugResi=((DebugOptionList::DebugString_Resi.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     625  const Bool bDebugReco=((DebugOptionList::DebugString_Reco.getInt()&debugPredModeMask) && DEBUG_STRING_CHANNEL_CONDITION(compID));
     626  if (bDebugPred || bDebugResi || bDebugReco)
     627    ss << "###: " << "CompID: " << compID << " pred mode (ch/fin): " << uiChPredMode << "/" << uiChFinalMode << " absPartIdx: " << rTu.GetAbsPartIdxTU() << std::endl;
     628#endif
     629
     630#if O0043_BEST_EFFORT_DECODING
     631  const Int bitDepthDelta = g_bitDepthInStream[toChannelType(compID)] - g_bitDepth[toChannelType(compID)];
     632#endif
     633  const Int clipbd = g_bitDepth[toChannelType(compID)];
     634
     635  if( useCrossComponentPrediction )
     636  {
     637    TComTrQuant::crossComponentPrediction( rTu, compID, pResiLuma, piResi, piResi, uiWidth, uiHeight, strideLuma, uiStride, uiStride, true );
     638  }
     639
     640  for( UInt uiY = 0; uiY < uiHeight; uiY++ )
     641  {
     642#ifdef DEBUG_STRING
     643    if (bDebugPred || bDebugResi || bDebugReco) ss << "###: ";
     644
     645    if (bDebugPred)
     646    {
     647      ss << " - pred: ";
     648      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     649      {
     650        ss << pPred[ uiX ] << ", ";
     651      }
     652    }
     653    if (bDebugResi) ss << " - resi: ";
     654#endif
     655
     656    for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     657    {
     658#ifdef DEBUG_STRING
     659      if (bDebugResi)
     660        ss << pResi[ uiX ] << ", ";
     661#endif
     662#if O0043_BEST_EFFORT_DECODING
     663      pReco    [ uiX ] = ClipBD( rightShiftEvenRounding<Pel>(pPred[ uiX ] + pResi[ uiX ], bitDepthDelta), clipbd );
    546664#else
    547   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
    548 #endif
    549 
    550   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
    551     assert(scalingListType < SCALING_LIST_NUM);
    552   m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
    553 
    554  
    555   //===== reconstruction =====
    556   Pel* pPred      = piPred;
    557   Pel* pResi      = piResi;
    558   Pel* pReco      = piReco;
    559   Pel* pRecIPred  = piRecIPred;
    560   for( UInt uiY = 0; uiY < uiHeight; uiY++ )
    561   {
    562     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
    563     {
    564       pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
     665      pReco    [ uiX ] = ClipBD( pPred[ uiX ] + pResi[ uiX ], clipbd );
     666#endif
    565667      pRecIPred[ uiX ] = pReco[ uiX ];
    566668    }
     669#ifdef DEBUG_STRING
     670    if (bDebugReco)
     671    {
     672      ss << " - reco: ";
     673      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     674      {
     675        ss << pReco[ uiX ] << ", ";
     676      }
     677    }
     678
     679    if (bDebugPred || bDebugResi || bDebugReco)
     680      ss << "\n";
     681#endif
    567682    pPred     += uiStride;
    568683    pResi     += uiStride;
     
    570685    pRecIPred += uiRecIPredStride;
    571686  }
    572   }
    573   else
    574   {
    575     //===== reconstruction =====
    576     Pel* pPred      = piPred;
    577     Pel* pReco      = piReco;
    578     Pel* pRecIPred  = piRecIPred;
    579     for ( Int y = 0; y < uiHeight; y++ )
    580     {
    581       for ( Int x = 0; x < uiWidth; x++ )
    582       {
    583         pReco    [ x ] = pPred[ x ];
    584         pRecIPred[ x ] = pReco[ x ];
    585       }
    586       pPred     += uiStride;
    587       pReco     += uiStride;
    588       pRecIPred += uiRecIPredStride;
    589     }
    590   }
    591 }
    592 
    593 
    594 Void
    595 TDecCu::xIntraRecChromaBlk( TComDataCU* pcCU,
    596                            UInt        uiTrDepth,
    597                            UInt        uiAbsPartIdx,
    598                            TComYuv*    pcRecoYuv,
    599                            TComYuv*    pcPredYuv,
    600                            TComYuv*    pcResiYuv,
    601                            UInt        uiChromaId )
    602 {
    603   UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
    604   UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2;
    605 
    606   if( uiLog2TrSize == 2 )
    607   {
    608     assert( uiTrDepth > 0 );
    609     uiTrDepth--;
    610     UInt uiQPDiv = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth( 0 ) + uiTrDepth ) << 1 );
    611     Bool bFirstQ = ( ( uiAbsPartIdx % uiQPDiv ) == 0 );
    612     if( !bFirstQ )
    613     {
    614       return;
    615     }
    616   }
    617  
    618   TextType  eText             = ( uiChromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U );
    619   UInt      uiWidth           = pcCU     ->getWidth   ( 0 ) >> ( uiTrDepth + 1 );
    620   UInt      uiHeight          = pcCU     ->getHeight  ( 0 ) >> ( uiTrDepth + 1 );
    621   UInt      uiStride          = pcRecoYuv->getCStride ();
    622   Pel*      piReco            = ( uiChromaId > 0 ? pcRecoYuv->getCrAddr( uiAbsPartIdx ) : pcRecoYuv->getCbAddr( uiAbsPartIdx ) );
    623   Pel*      piPred            = ( uiChromaId > 0 ? pcPredYuv->getCrAddr( uiAbsPartIdx ) : pcPredYuv->getCbAddr( uiAbsPartIdx ) );
    624   Pel*      piResi            = ( uiChromaId > 0 ? pcResiYuv->getCrAddr( uiAbsPartIdx ) : pcResiYuv->getCbAddr( uiAbsPartIdx ) );
    625  
    626   UInt      uiNumCoeffInc     = ( ( pcCU->getSlice()->getSPS()->getMaxCUWidth() * pcCU->getSlice()->getSPS()->getMaxCUHeight() ) >> ( pcCU->getSlice()->getSPS()->getMaxCUDepth() << 1 ) ) >> 2;
    627   TCoeff*   pcCoeff           = ( uiChromaId > 0 ? pcCU->getCoeffCr() : pcCU->getCoeffCb() ) + ( uiNumCoeffInc * uiAbsPartIdx );
    628  
    629   UInt      uiChromaPredMode  = pcCU->getChromaIntraDir( 0 );
    630  
    631   UInt      uiZOrder          = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    632   Pel*      piRecIPred        = ( uiChromaId > 0 ? pcCU->getPic()->getPicYuvRec()->getCrAddr( pcCU->getAddr(), uiZOrder ) : pcCU->getPic()->getPicYuvRec()->getCbAddr( pcCU->getAddr(), uiZOrder ) );
    633   UInt      uiRecIPredStride  = pcCU->getPic()->getPicYuvRec()->getCStride();
    634   Bool      useTransformSkipChroma = pcCU->getTransformSkip(uiAbsPartIdx,eText);
    635   //===== init availability pattern =====
    636   Bool  bAboveAvail = false;
    637   Bool  bLeftAvail  = false;
    638   pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
    639 
    640   pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
    641                                            m_pcPrediction->getPredicBuf       (),
    642                                            m_pcPrediction->getPredicBufWidth  (),
    643                                            m_pcPrediction->getPredicBufHeight (),
    644                                            bAboveAvail, bLeftAvail );
    645   Int* pPatChroma   = ( uiChromaId > 0 ? pcCU->getPattern()->getAdiCrBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) : pcCU->getPattern()->getAdiCbBuf( uiWidth, uiHeight, m_pcPrediction->getPredicBuf() ) );
    646  
    647   //===== get prediction signal =====
    648   if( uiChromaPredMode == DM_CHROMA_IDX )
    649   {
    650     uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
    651   }
    652   m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 
    653 
    654   if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
    655   {
    656   //===== inverse transform =====
    657   Int curChromaQpOffset;
    658   if(eText == TEXT_CHROMA_U)
    659   {
    660     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
    661   }
    662   else
    663   {
    664     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    665   }
    666 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    667   // Bug-fix
    668 #if REPN_FORMAT_IN_VPS
    669   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    670 #else
    671   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    672 #endif
    673 #else
    674   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    675 #endif
    676 
    677   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
    678     assert(scalingListType < SCALING_LIST_NUM);
    679   m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
    680 
    681   //===== reconstruction =====
    682   Pel* pPred      = piPred;
    683   Pel* pResi      = piResi;
    684   Pel* pReco      = piReco;
    685   Pel* pRecIPred  = piRecIPred;
    686   for( UInt uiY = 0; uiY < uiHeight; uiY++ )
    687   {
    688     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
    689     {
    690       pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
    691       pRecIPred[ uiX ] = pReco[ uiX ];
    692     }
    693     pPred     += uiStride;
    694     pResi     += uiStride;
    695     pReco     += uiStride;
    696     pRecIPred += uiRecIPredStride;
    697   }
    698   }
    699   else
    700   {
    701     //===== reconstruction =====
    702     Pel* pPred      = piPred;
    703     Pel* pReco      = piReco;
    704     Pel* pRecIPred  = piRecIPred;
    705     for ( Int y = 0; y < uiHeight; y++ )
    706     {
    707       for ( Int x = 0; x < uiWidth; x++ )
    708       {
    709         pReco    [ x ] = pPred[ x ];
    710         pRecIPred[ x ] = pReco[ x ];
    711       }
    712       pPred     += uiStride;
    713       pReco     += uiStride;
    714       pRecIPred += uiRecIPredStride;
    715     }   
    716   }
    717687}
    718688
     
    721691TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
    722692{
    723   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
    724   UInt  uiNumPart     = pcCU->getNumPartitions();
    725   UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
    726  
    727693  if (pcCU->getIPCMFlag(0))
    728694  {
     
    730696    return;
    731697  }
    732 
    733   for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
    734   {
    735     xIntraLumaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
    736   } 
    737 
    738   for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
    739   {
    740     xIntraChromaRecQT( pcCU, uiInitTrDepth, uiPU * uiNumQParts, m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth] );
    741   }
    742 
    743 }
    744 
    745 /** Function for deriving recontructed PU/CU Luma sample with QTree structure
    746  * \param pcCU pointer of current CU
    747  * \param uiTrDepth current tranform split depth
    748  * \param uiAbsPartIdx  part index
    749  * \param pcRecoYuv pointer to reconstructed sample arrays
    750  * \param pcPredYuv pointer to prediction sample arrays
    751  * \param pcResiYuv pointer to residue sample arrays
    752  *
    753  \ This function dervies recontructed PU/CU Luma sample with recursive QTree structure
    754  */
    755 Void
    756 TDecCu::xIntraLumaRecQT( TComDataCU* pcCU,
    757                      UInt        uiTrDepth,
    758                      UInt        uiAbsPartIdx,
    759                      TComYuv*    pcRecoYuv,
    760                      TComYuv*    pcPredYuv,
    761                      TComYuv*    pcResiYuv )
    762 {
    763   UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
    764   UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
    765   if( uiTrMode == uiTrDepth )
    766   {
    767     xIntraRecLumaBlk  ( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv );
    768   }
    769   else
    770   {
    771     UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
    772     for( UInt uiPart = 0; uiPart < 4; uiPart++ )
    773     {
    774       xIntraLumaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
    775     }
    776   }
    777 }
     698  const UInt numChType = pcCU->getPic()->getChromaFormat()!=CHROMA_400 ? 2 : 1;
     699  for (UInt chType=CHANNEL_TYPE_LUMA; chType<numChType; chType++)
     700  {
     701    const ChannelType chanType=ChannelType(chType);
     702    const Bool NxNPUHas4Parts = ::isChroma(chanType) ? enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) : true;
     703    const UInt uiInitTrDepth = ( pcCU->getPartitionSize(0) != SIZE_2Nx2N && NxNPUHas4Parts ? 1 : 0 );
     704
     705    TComTURecurse tuRecurseCU(pcCU, 0);
     706    TComTURecurse tuRecurseWithPU(tuRecurseCU, false, (uiInitTrDepth==0)?TComTU::DONT_SPLIT : TComTU::QUAD_SPLIT);
     707
     708    do
     709    {
     710      xIntraRecQT( m_ppcYuvReco[uiDepth], m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], chanType, tuRecurseWithPU );
     711    } while (tuRecurseWithPU.nextSection(tuRecurseCU));
     712  }
     713}
     714
     715
    778716
    779717/** Function for deriving recontructed PU/CU chroma samples with QTree structure
     
    784722 * \param pcPredYuv pointer to prediction sample arrays
    785723 * \param pcResiYuv pointer to residue sample arrays
    786  * 
     724 *
    787725 \ This function dervies recontructed PU/CU chroma samples with QTree recursive structure
    788726 */
     727
    789728Void
    790 TDecCu::xIntraChromaRecQT( TComDataCU* pcCU,
    791                      UInt        uiTrDepth,
    792                      UInt        uiAbsPartIdx,
    793                      TComYuv*    pcRecoYuv,
    794                      TComYuv*    pcPredYuv,
    795                      TComYuv*    pcResiYuv )
    796 {
    797   UInt uiFullDepth  = pcCU->getDepth(0) + uiTrDepth;
     729TDecCu::xIntraRecQT(TComYuv*    pcRecoYuv,
     730                    TComYuv*    pcPredYuv,
     731                    TComYuv*    pcResiYuv,
     732                    const ChannelType chType,
     733                    TComTU     &rTu)
     734{
     735  UInt uiTrDepth    = rTu.GetTransformDepthRel();
     736  TComDataCU *pcCU  = rTu.getCU();
     737  UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
    798738  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
    799739  if( uiTrMode == uiTrDepth )
    800740  {
    801     xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 0 );
    802     xIntraRecChromaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcRecoYuv, pcPredYuv, pcResiYuv, 1 );
     741    if (isLuma(chType))
     742      xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, COMPONENT_Y,  rTu );
     743    else
     744    {
     745      const UInt numValidComp=getNumberValidComponents(rTu.GetChromaFormat());
     746      for(UInt compID=COMPONENT_Cb; compID<numValidComp; compID++)
     747      {
     748        xIntraRecBlk( pcRecoYuv, pcPredYuv, pcResiYuv, ComponentID(compID), rTu );
     749      }
     750    }
    803751  }
    804752  else
    805753  {
    806     UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
    807     for( UInt uiPart = 0; uiPart < 4; uiPart++ )
    808     {
    809       xIntraChromaRecQT( pcCU, uiTrDepth + 1, uiAbsPartIdx + uiPart * uiNumQPart, pcRecoYuv, pcPredYuv, pcResiYuv );
    810     }
     754    TComTURecurse tuRecurseChild(rTu, false);
     755    do
     756    {
     757      xIntraRecQT( pcRecoYuv, pcPredYuv, pcResiYuv, chType, tuRecurseChild );
     758    } while (tuRecurseChild.nextSection(rTu));
    811759  }
    812760}
     
    814762Void TDecCu::xCopyToPic( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth )
    815763{
    816   UInt uiCUAddr = pcCU->getAddr();
    817  
    818   m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCUAddr, uiZorderIdx );
    819  
     764  UInt uiCtuRsAddr = pcCU->getCtuRsAddr();
     765
     766  m_ppcYuvReco[uiDepth]->copyToPicYuv  ( pcPic->getPicYuvRec (), uiCtuRsAddr, uiZorderIdx );
     767
    820768  return;
    821769}
    822770
    823 Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    824 {
    825   UInt    uiWidth    = pcCU->getWidth ( uiAbsPartIdx );
    826   UInt    uiHeight   = pcCU->getHeight( uiAbsPartIdx );
    827   TCoeff* piCoeff;
    828  
    829   Pel*    pResi;
    830   UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
    831  
    832   // Y
    833   piCoeff = pcCU->getCoeffY();
    834   pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
    835 
    836 #if REPN_FORMAT_IN_VPS
    837   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
    838 #else
    839   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
    840 #endif
    841 
    842   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
    843  
    844   // Cb and Cr
    845   Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
    846 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    847   // Bug-fix
    848 #if REPN_FORMAT_IN_VPS
    849   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    850 #else
    851   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    852 #endif
    853 #else
    854   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    855 #endif
    856 
    857   uiWidth  >>= 1;
    858   uiHeight >>= 1;
    859   piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
    860   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
    861 
    862   curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    863 #if O0194_DIFFERENT_BITDEPTH_EL_BL
    864   // Bug-fix
    865 #if REPN_FORMAT_IN_VPS
    866   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
    867 #else
    868   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    869 #endif
    870 #else
    871   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
    872 #endif
    873 
    874   piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
    875   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
     771Void TDecCu::xDecodeInterTexture ( TComDataCU* pcCU, UInt uiDepth )
     772{
     773
     774  TComTURecurse tuRecur(pcCU, 0, uiDepth);
     775
     776  for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
     777  {
     778    const ComponentID compID=ComponentID(ch);
     779    DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[compID])
     780
     781    m_pcTrQuant->invRecurTransformNxN ( compID, m_ppcYuvResi[uiDepth], tuRecur );
     782  }
     783
     784  DEBUG_STRING_OUTPUT(std::cout, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
    876785}
    877786
     
    887796 * \returns Void
    888797 */
    889 Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText)
    890 {
    891   UInt uiX, uiY;
    892   Pel* piPicReco;
    893   UInt uiPicStride;
    894   UInt uiPcmLeftShiftBit;
    895 
    896   if( ttText == TEXT_LUMA )
    897   {
    898     uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
    899     piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    900     uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    901   }
    902   else
    903   {
    904     uiPicStride = pcCU->getPic()->getPicYuvRec()->getCStride();
    905 
    906     if( ttText == TEXT_CHROMA_U )
    907     {
    908       piPicReco = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    909     }
    910     else
    911     {
    912       piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
    913     }
    914     uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    915   }
    916 
    917   for( uiY = 0; uiY < uiHeight; uiY++ )
    918   {
    919     for( uiX = 0; uiX < uiWidth; uiX++ )
     798Void TDecCu::xDecodePCMTexture( TComDataCU* pcCU, const UInt uiPartIdx, const Pel *piPCM, Pel* piReco, const UInt uiStride, const UInt uiWidth, const UInt uiHeight, const ComponentID compID)
     799{
     800        Pel* piPicReco         = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiPartIdx);
     801  const UInt uiPicStride       = pcCU->getPic()->getPicYuvRec()->getStride(compID);
     802  const UInt uiPcmLeftShiftBit = g_bitDepth[toChannelType(compID)] - pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
     803
     804  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
     805  {
     806    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
    920807    {
    921808      piReco[uiX] = (piPCM[uiX] << uiPcmLeftShiftBit);
     
    935822Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
    936823{
    937   // Luma
    938   UInt uiWidth  = (g_uiMaxCUWidth >> uiDepth);
    939   UInt uiHeight = (g_uiMaxCUHeight >> uiDepth);
    940 
    941   Pel* piPcmY = pcCU->getPCMSampleY();
    942   Pel* piRecoY = m_ppcYuvReco[uiDepth]->getLumaAddr(0, uiWidth);
    943 
    944   UInt uiStride = m_ppcYuvResi[uiDepth]->getStride();
    945 
    946   xDecodePCMTexture( pcCU, 0, piPcmY, piRecoY, uiStride, uiWidth, uiHeight, TEXT_LUMA);
    947 
    948   // Cb and Cr
    949   UInt uiCWidth  = (uiWidth>>1);
    950   UInt uiCHeight = (uiHeight>>1);
    951 
    952   Pel* piPcmCb = pcCU->getPCMSampleCb();
    953   Pel* piPcmCr = pcCU->getPCMSampleCr();
    954   Pel* pRecoCb = m_ppcYuvReco[uiDepth]->getCbAddr();
    955   Pel* pRecoCr = m_ppcYuvReco[uiDepth]->getCrAddr();
    956 
    957   UInt uiCStride = m_ppcYuvReco[uiDepth]->getCStride();
    958 
    959   xDecodePCMTexture( pcCU, 0, piPcmCb, pRecoCb, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_U);
    960   xDecodePCMTexture( pcCU, 0, piPcmCr, pRecoCr, uiCStride, uiCWidth, uiCHeight, TEXT_CHROMA_V);
    961 }
    962 
    963 /** Function for filling the PCM buffer of a CU using its reconstructed sample array
     824  for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
     825  {
     826    const ComponentID compID = ComponentID(ch);
     827    const UInt width  = (g_uiMaxCUWidth >>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleX(compID)));
     828    const UInt height = (g_uiMaxCUHeight>>(uiDepth+m_ppcYuvResi[uiDepth]->getComponentScaleY(compID)));
     829    const UInt stride = m_ppcYuvResi[uiDepth]->getStride(compID);
     830    Pel * pPCMChannel = pcCU->getPCMSample(compID);
     831    Pel * pRecChannel = m_ppcYuvReco[uiDepth]->getAddr(compID);
     832    xDecodePCMTexture( pcCU, 0, pPCMChannel, pRecChannel, stride, width, height, compID );
     833  }
     834}
     835
     836/** Function for filling the PCM buffer of a CU using its reconstructed sample array
    964837 * \param pcCU pointer to current CU
    965838 * \param uiDepth CU Depth
     
    968841Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
    969842{
    970   // Luma
    971   UInt width  = (g_uiMaxCUWidth >> depth);
    972   UInt height = (g_uiMaxCUHeight >> depth);
    973 
    974   Pel* pPcmY = pCU->getPCMSampleY();
    975   Pel* pRecoY = m_ppcYuvReco[depth]->getLumaAddr(0, width);
    976 
    977   UInt stride = m_ppcYuvReco[depth]->getStride();
    978 
    979   for(Int y = 0; y < height; y++ )
    980   {
    981     for(Int x = 0; x < width; x++ )
    982     {
    983       pPcmY[x] = pRecoY[x];
    984     }
    985     pPcmY += width;
    986     pRecoY += stride;
    987   }
    988 
    989   // Cb and Cr
    990   UInt widthC  = (width>>1);
    991   UInt heightC = (height>>1);
    992 
    993   Pel* pPcmCb = pCU->getPCMSampleCb();
    994   Pel* pPcmCr = pCU->getPCMSampleCr();
    995   Pel* pRecoCb = m_ppcYuvReco[depth]->getCbAddr();
    996   Pel* pRecoCr = m_ppcYuvReco[depth]->getCrAddr();
    997 
    998   UInt strideC = m_ppcYuvReco[depth]->getCStride();
    999 
    1000   for(Int y = 0; y < heightC; y++ )
    1001   {
    1002     for(Int x = 0; x < widthC; x++ )
    1003     {
    1004       pPcmCb[x] = pRecoCb[x];
    1005       pPcmCr[x] = pRecoCr[x];
    1006     }
    1007     pPcmCr += widthC;
    1008     pPcmCb += widthC;
    1009     pRecoCb += strideC;
    1010     pRecoCr += strideC;
    1011   }
    1012 
     843  const ChromaFormat format = pCU->getPic()->getChromaFormat();
     844  const UInt numValidComp=getNumberValidComponents(format);
     845
     846  for (UInt componentIndex = 0; componentIndex < numValidComp; componentIndex++)
     847  {
     848    const ComponentID component = ComponentID(componentIndex);
     849
     850    const UInt width  = g_uiMaxCUWidth  >> (depth + getComponentScaleX(component, format));
     851    const UInt height = g_uiMaxCUHeight >> (depth + getComponentScaleY(component, format));
     852
     853    Pel *source      = m_ppcYuvReco[depth]->getAddr(component, 0, width);
     854    Pel *destination = pCU->getPCMSample(component);
     855
     856    const UInt sourceStride = m_ppcYuvReco[depth]->getStride(component);
     857
     858    for (Int line = 0; line < height; line++)
     859    {
     860      for (Int column = 0; column < width; column++)
     861      {
     862        destination[column] = source[column];
     863      }
     864
     865      source      += sourceStride;
     866      destination += width;
     867    }
     868  }
    1013869}
    1014870
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.h

    r595 r1029  
    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-2014, ITU/ISO/IEC
     
    6565  TComYuv**           m_ppcYuvReco;       ///< array of prediction & reconstruction buffer
    6666  TComDataCU**        m_ppcCU;            ///< CU data array
    67  
     67
    6868  // access channel
    6969  TComTrQuant*        m_pcTrQuant;
     
    7272
    7373  Bool                m_bDecodeDQP;
     74  Bool                m_IsChromaQpAdjCoded;
     75
    7476#if SVC_EXTENSION
    7577  TDecTop**           m_ppcTDecTop;
     
    8082  TDecCu();
    8183  virtual ~TDecCu();
    82  
     84
    8385  /// initialize access channels
    8486#if SVC_EXTENSION
     
    8991 
    9092  /// create internal buffers
    91   Void  create                  ( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight );
    92  
     93  Void  create                  ( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormatIDC );
     94
    9395  /// destroy internal buffers
    9496  Void  destroy                 ();
    95  
    96   /// decode CU information
    97   Void  decodeCU                ( TComDataCU* pcCU, UInt& ruiIsLast );
    98  
    99   /// reconstruct CU information
    100   Void  decompressCU            ( TComDataCU* pcCU );
    101   
     97
     98  /// decode Ctu information
     99  Void  decodeCtu               ( TComDataCU* pCtu, Bool &isLastCtuOfSliceSegment );
     100
     101  /// reconstruct Ctu information
     102  Void  decompressCtu           ( TComDataCU* pCtu );
     103 
    102104#if SVC_EXTENSION
    103105  TDecTop*   getLayerDec        ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }
    104106#endif
    105107protected:
    106  
    107   Void xDecodeCU                ( TComDataCU* pcCU,                       UInt uiAbsPartIdx, UInt uiDepth, UInt &ruiIsLast);
    108   Void xFinishDecodeCU          ( TComDataCU* pcCU,                       UInt uiAbsPartIdx, UInt uiDepth, UInt &ruiIsLast);
    109   Bool xDecodeSliceEnd          ( TComDataCU* pcCU,                       UInt uiAbsPartIdx, UInt uiDepth);
    110   Void xDecompressCU            ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    111  
     108
     109  Void xDecodeCU                ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment);
     110  Void xFinishDecodeCU          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool &isLastCtuOfSliceSegment);
     111  Bool xDecodeSliceEnd          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     112  Void xDecompressCU            ( TComDataCU* pCtu, UInt uiAbsPartIdx, UInt uiDepth );
     113
    112114  Void xReconInter              ( TComDataCU* pcCU, UInt uiDepth );
    113  
    114   Void  xReconIntraQT           ( TComDataCU* pcCU, UInt uiDepth );
    115   Void  xIntraRecLumaBlk        ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv );
    116   Void  xIntraRecChromaBlk      ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, UInt uiChromaId );
    117  
    118   Void  xReconPCM               ( TComDataCU* pcCU, UInt uiDepth );
    119115
    120   Void xDecodeInterTexture      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    121   Void xDecodePCMTexture        ( TComDataCU* pcCU, UInt uiPartIdx, Pel *piPCM, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType ttText);
    122  
     116  Void xReconIntraQT            ( TComDataCU* pcCU, UInt uiDepth );
     117  Void xIntraRecBlk             ( TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, const ComponentID component, TComTU &rTu );
     118  Void xIntraRecQT              ( TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, const ChannelType chType, TComTU &rTu );
     119
     120  Void xReconPCM                ( TComDataCU* pcCU, UInt uiDepth );
     121
     122  Void xDecodeInterTexture      ( TComDataCU* pcCU, UInt uiDepth );
     123  Void xDecodePCMTexture        ( TComDataCU* pcCU, const UInt uiPartIdx, const Pel *piPCM, Pel* piReco, const UInt uiStride, const UInt uiWidth, const UInt uiHeight, const ComponentID compID);
     124
    123125  Void xCopyToPic               ( TComDataCU* pcCU, TComPic* pcPic, UInt uiZorderIdx, UInt uiDepth );
    124 
    125   Void  xIntraLumaRecQT         ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv );
    126   Void  xIntraChromaRecQT       ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv );
    127126
    128127  Bool getdQPFlag               ()                        { return m_bDecodeDQP;        }
    129128  Void setdQPFlag               ( Bool b )                { m_bDecodeDQP = b;           }
     129  Bool getIsChromaQpAdjCoded    ()                        { return m_IsChromaQpAdjCoded;        }
     130  Void setIsChromaQpAdjCoded    ( Bool b )                { m_IsChromaQpAdjCoded = b;           }
     131
    130132  Void xFillPCMBuffer           (TComDataCU* pCU, UInt depth);
    131133};
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.cpp

    r595 r1029  
    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-2014, ITU/ISO/IEC
     
    3737
    3838#include "TDecEntropy.h"
     39#include "TLibCommon/TComTU.h"
     40
     41#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     42#include "../TLibCommon/Debug.h"
     43static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0;
     44static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
     45Bool g_bFinalEncode=true;
     46#endif
    3947
    4048//! \ingroup TLibDecoder
     
    5361}
    5462
     63
    5564Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    5665{
    5766  m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
    5867}
     68
    5969
    6070/** decode merge flag
    6171 * \param pcSubCU
    62  * \param uiAbsPartIdx 
     72 * \param uiAbsPartIdx
    6373 * \param uiDepth
    64  * \param uiPUIdx 
     74 * \param uiPUIdx
    6575 * \returns Void
    6676 */
    6777Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
    68 { 
     78{
    6979  // at least one merge candidate exists
    7080  m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx );
     
    7383/** decode merge index
    7484 * \param pcCU
    75  * \param uiPartIdx 
    76  * \param uiAbsPartIdx 
     85 * \param uiPartIdx
     86 * \param uiAbsPartIdx
    7787 * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours
    7888 * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours
     
    107117  {
    108118    decodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx, uiDepth );
    109     decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
     119    if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
     120    {
     121      decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth );
     122      if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
     123      {
     124        UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
     125        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset,   uiDepth+1 );
     126        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 );
     127        decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 );
     128      }
     129    }
    110130  }
    111131  else                                                                // if it is Inter mode, encode motion vector and reference index
     
    115135}
    116136
    117 /** Parse I_PCM information. 
     137/** Parse I_PCM information.
    118138 * \param pcCU  pointer to CUpointer to CU
    119139 * \param uiAbsPartIdx CU index
     
    129149    return;
    130150  }
    131  
     151
    132152  m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth );
    133153}
     
    141161{
    142162  m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth );
    143 }
     163#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     164  if (bDebugPredEnabled)
     165  {
     166    UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
     167    if (cdir==36) cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
     168    printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
     169  }
     170#endif
     171}
     172
    144173
    145174/** decode motion information for every PU block.
    146175 * \param pcCU
    147  * \param uiAbsPartIdx 
     176 * \param uiAbsPartIdx
    148177 * \param uiDepth
    149178 * \param pcSubCU
     
    174203    {
    175204      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
     205#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     206      if (bDebugPredEnabled)
     207      {
     208        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
     209        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
     210      }
     211#endif
     212
    176213      UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
    177       if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
     214      if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 )
    178215      {
    179216        pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
     
    190227        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
    191228      }
     229
    192230      pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
    193231
    194232      TComMv cTmpMv( 0, 0 );
    195233      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    196       {       
     234      {
    197235        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
    198236        {
     
    201239          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
    202240          pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx );
     241
    203242        }
    204243      }
     
    208247      decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx );
    209248      for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    210       {       
     249      {
    211250        if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )
    212251        {
     
    214253          decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
    215254          decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
     255#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     256          if (bDebugPredEnabled)
     257          {
     258            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
     259            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
     260            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
     261            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
     262            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
     263          }
     264#endif
    216265        }
    217266      }
    218267    }
     268
    219269    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
    220270    {
     
    229279/** decode inter direction for a PU block
    230280 * \param pcCU
    231  * \param uiAbsPartIdx 
     281 * \param uiAbsPartIdx
    232282 * \param uiDepth
    233  * \param uiPartIdx 
     283 * \param uiPartIdx
    234284 * \returns Void
    235285 */
     
    274324/** decode motion vector difference for a PU block
    275325 * \param pcCU
    276  * \param uiAbsPartIdx 
     326 * \param uiAbsPartIdx
    277327 * \param uiDepth
    278328 * \param uiPartIdx
    279  * \param eRefList 
     329 * \param eRefList
    280330 * \returns Void
    281331 */
     
    319369}
    320370
    321 Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int quadtreeTULog2MinSizeInCU)
    322 {
     371Void TDecEntropy::xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU )
     372{
     373  TComDataCU *pcCU=rTu.getCU();
     374  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
     375  const UInt uiDepth=rTu.GetTransformDepthTotal();
     376  const UInt uiTrDepth = rTu.GetTransformDepthRel();
     377
    323378  UInt uiSubdiv;
    324   const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
    325 
    326   if(uiTrIdx==0)
    327   {
    328     m_bakAbsPartIdxCU = uiAbsPartIdx;
    329   }
    330   if( uiLog2TrafoSize == 2 )
    331   {
    332     UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    333     if( ( uiAbsPartIdx % partNum ) == 0 )
    334     {
    335       m_uiBakAbsPartIdx   = uiAbsPartIdx;
    336       m_uiBakChromaOffset = offsetChroma;
    337     }
    338   }
    339   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
     379  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
     380  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
     381
     382  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
     383#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     384  if (bDebugRQT)
     385  {
     386    printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
     387        rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber());
     388    fflush(stdout);
     389  }
     390#endif
     391
     392  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
    340393  {
    341394    uiSubdiv = 1;
    342395  }
    343   else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
    344   {
    345     uiSubdiv = (uiLog2TrafoSize > quadtreeTULog2MinSizeInCU);
     396  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
     397  {
     398    uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU);
    346399  }
    347400  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     
    362415    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    363416  }
    364  
    365   const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx );
    366   {
     417
     418  for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++)
     419  {
     420    const ComponentID compID=ComponentID(chan);
     421    const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID);
     422
    367423    const Bool bFirstCbfOfCU = uiTrDepth == 0;
     424
    368425    if( bFirstCbfOfCU )
    369426    {
    370       pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
    371       pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
    372     }
    373     if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
    374     {
    375       if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) )
    376       {
    377         m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth );
    378       }
    379       if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) )
    380       {
    381         m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth );
    382       }
    383     }
    384     else
    385     {
    386       pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth );
    387       pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth );
    388     }
    389   }
    390  
     427      pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj);
     428    }
     429    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
     430    {
     431      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) )
     432      {
     433        m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) );
     434      }
     435    }
     436  }
     437
    391438  if( uiSubdiv )
    392439  {
    393     UInt size;
    394     width  >>= 1;
    395     height >>= 1;
    396     size = width*height;
    397     uiTrIdx++;
    398     ++uiDepth;
    399     const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
    400     const UInt uiStartAbsPartIdx = uiAbsPartIdx;
    401     UInt uiYCbf = 0;
    402     UInt uiUCbf = 0;
    403     UInt uiVCbf = 0;
    404    
    405     for( Int i = 0; i < 4; i++ )
    406     {
    407       xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, quadtreeTULog2MinSizeInCU );
    408       uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
    409       uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
    410       uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
    411       uiAbsPartIdx += uiQPartNum;
    412       offsetLuma += size;  offsetChroma += (size>>2);
    413     }
    414    
    415     for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
    416     {
    417       pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
    418       pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
    419       pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
     440    const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1);
     441    UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0};
     442
     443    TComTURecurse tuRecurseChild(rTu, true);
     444
     445    do
     446    {
     447      xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU );
     448      UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU();
     449      for(UInt ch=0; ch<numValidComponent; ch++)
     450      {
     451        uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch),  uiTrDepth+1 );
     452      }
     453
     454    } while (tuRecurseChild.nextSection(rTu) );
     455
     456    for(UInt ch=0; ch<numValidComponent; ch++)
     457    {
     458      UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx;
     459      const UChar flag = uiYUVCbf[ch] << uiTrDepth;
     460
     461      for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
     462      {
     463        pBase[ui] |= flag;
     464      }
    420465    }
    421466  }
     
    424469    assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) );
    425470    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth );
    426    
     471
    427472    {
    428473      DTRACE_CABAC_VL( g_nSymbolCounter++ );
     
    435480      DTRACE_CABAC_T( "\n" );
    436481    }
    437    
    438     pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
    439     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
    440     {
    441       pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
     482
     483    pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth );
     484
     485    if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) ))
     486    {
     487      pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth );
    442488    }
    443489    else
    444490    {
    445       m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
     491      m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true );
    446492    }
    447493
    448494
    449495    // transform_unit begin
    450     UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
    451     UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
    452     UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
    453     if( uiLog2TrafoSize == 2 )
    454     {
    455       UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    456       if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
    457       {
    458         cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
    459         cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
    460       }
    461     }
    462     if ( cbfY || cbfU || cbfV )
    463     {
    464       // dQP: only for LCU
     496    UInt cbf[MAX_NUM_COMPONENT]={0,0,0};
     497    Bool validCbf       = false;
     498    Bool validChromaCbf = false;
     499    const UInt uiTrIdx = rTu.GetTransformDepthRel();
     500
     501    for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++)
     502    {
     503      const ComponentID compID = ComponentID(ch);
     504
     505      cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx );
     506
     507      if (cbf[compID] != 0)
     508      {
     509        validCbf = true;
     510        if (isChroma(compID)) validChromaCbf = true;
     511      }
     512    }
     513
     514    if ( validCbf )
     515    {
     516
     517      // dQP: only for CTU
    465518      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
    466519      {
    467520        if ( bCodeDQP )
    468521        {
    469           decodeQP( pcCU, m_bakAbsPartIdxCU);
     522          const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU();
     523          decodeQP( pcCU, uiAbsPartIdxCU);
    470524          bCodeDQP = false;
    471525        }
    472526      }
    473     }
    474     if( cbfY )
    475     {
    476       Int trWidth = width;
    477       Int trHeight = height;
    478       m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
    479     }
    480     if( uiLog2TrafoSize > 2 )
    481     {
    482       Int trWidth = width >> 1;
    483       Int trHeight = height >> 1;
    484       if( cbfU )
    485       {
    486         m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
    487       }
    488       if( cbfV )
    489       {
    490         m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
    491       }
    492     }
    493     else
    494     {
    495       UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    496       if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
    497       {
    498         Int trWidth = width;
    499         Int trHeight = height;
    500         if( cbfU )
     527
     528      if ( pcCU->getSlice()->getUseChromaQpAdj() )
     529      {
     530        if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
    501531        {
    502           m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
     532          decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
     533          isChromaQpAdjCoded = false;
    503534        }
    504         if( cbfV )
     535      }
     536
     537      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
     538
     539      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
     540      {
     541        const ComponentID compID=ComponentID(ch);
     542
     543        if( rTu.ProcessComponentSection(compID) )
    505544        {
    506           m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     545#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     546          if (bDebugRQT) printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
     547#endif
     548
     549          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
     550          {
     551            //code two sub-TUs
     552            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
     553
     554            do
     555            {
     556              const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1));
     557
     558              if (subTUCBF != 0)
     559              {
     560#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     561                if (bDebugRQT) printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
     562#endif
     563                m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID );
     564              }
     565            }
     566            while (subTUIterator.nextSection(rTu));
     567          }
     568          else
     569          {
     570            if(isChroma(compID) && (cbf[COMPONENT_Y] != 0))
     571            {
     572              m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID );
     573            }
     574
     575            if(cbf[compID] != 0)
     576            {
     577              m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID );
     578            }
     579          }
    507580        }
    508581      }
     
    517590  {
    518591    m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
     592  }
     593}
     594
     595Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx )
     596{
     597  if ( pcCU->getSlice()->getUseChromaQpAdj() )
     598  {
     599    m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) );
    519600  }
    520601}
     
    523604/** decode coefficients
    524605 * \param pcCU
    525  * \param uiAbsPartIdx 
     606 * \param uiAbsPartIdx
    526607 * \param uiDepth
    527608 * \param uiWidth
    528  * \param uiHeight 
     609 * \param uiHeight
    529610 * \returns Void
    530611 */
    531 Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
    532 {
    533   UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    534   UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
    535   UInt uiChromaOffset = uiLumaOffset>>2;
    536  
     612Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded )
     613{
    537614  if( pcCU->isIntra(uiAbsPartIdx) )
    538615  {
     
    547624    if ( !uiQtRootCbf )
    548625    {
    549       pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
     626      static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
     627      pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth );
    550628      pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
    551629      return;
    552630    }
    553    
    554   }
     631
     632  }
     633
     634  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
     635
     636#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     637  if (bDebugRQT)
     638    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
     639#endif
     640
     641  Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
    555642 
    556   Int getQuadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
    557  
    558   xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, getQuadtreeTULog2MinSizeInCU );
     643  xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU );
    559644}
    560645
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecEntropy.h

    r713 r1029  
    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-2014, ITU/ISO/IEC
     
    4545#include "TLibCommon/TComPrediction.h"
    4646#include "TLibCommon/TComSampleAdaptiveOffset.h"
     47#include "TLibCommon/TComRectangle.h"
    4748
    4849class TDecSbac;
     
    6869  virtual Void  setBitstream          ( TComInputBitstream* p )  = 0;
    6970
    70   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
    71 #if SVC_EXTENSION && !SPS_DPB_PARAMS
    72   virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )           = 0;
     71  virtual Void  parseVPS                  ( TComVPS* pcVPS )     = 0;
     72  virtual Void  parseSPS                  ( TComSPS* pcSPS )     = 0;
     73#if Q0048_CGS_3D_ASYMLUT
     74  virtual Void  parsePPS                  ( TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID )     = 0;
    7375#else
    74   virtual Void  parseSPS                  ( TComSPS* pcSPS )                                      = 0;
     76  virtual Void  parsePPS                  ( TComPPS* pcPPS )     = 0;
    7577#endif
    76   virtual Void  parsePPS                  ( TComPPS* pcPPS
    77 #if Q0048_CGS_3D_ASYMLUT
    78     , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
    79 #endif
    80     )                                      = 0;
    8178
    82   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)       = 0;
     79  virtual Void parseSliceHeader          ( TComSlice* pcSlice, ParameterSetManagerDecoder *parameterSetManager)       = 0;
    8380
    84   virtual Void  parseTerminatingBit       ( UInt& ruilsLast )                                     = 0;
    85  
     81  virtual Void parseTerminatingBit       ( UInt& ruilsLast )                                     = 0;
     82  virtual Void parseRemainingBytes( Bool noTrailingBytesExpected ) = 0;
     83
    8684  virtual Void parseMVPIdx        ( Int& riMVPIdx ) = 0;
    87  
     85
    8886public:
    8987  virtual Void parseSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
     
    9492  virtual Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    9593  virtual Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    96  
     94
    9795  virtual Void parseIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    98  
    9996  virtual Void parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    100  
     97
    10198  virtual Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) = 0;
    10299  virtual Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) = 0;
    103100  virtual Void parseMvd           ( TComDataCU* pcCU, UInt uiAbsPartAddr, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) = 0;
    104  
     101
     102  virtual Void parseCrossComponentPrediction ( class TComTU &rTu, ComponentID compID ) = 0;
     103
    105104  virtual Void parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) = 0;
    106   virtual Void parseQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) = 0;
     105  virtual Void parseQtCbf         ( TComTU &rTu, const ComponentID compID, const Bool lowestLevel ) = 0;
    107106  virtual Void parseQtRootCbf     ( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) = 0;
    108  
     107
    109108  virtual Void parseDeltaQP       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    110  
     109  virtual Void parseChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
     110
    111111  virtual Void parseIPCMInfo     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth) = 0;
    112112
    113   virtual Void parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    114   virtual Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) = 0;
    115   virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0;
    116  
     113  virtual Void parseCoeffNxN( class TComTU &rTu, ComponentID compID  ) = 0;
     114
     115  virtual Void parseTransformSkipFlags ( class TComTU &rTu, ComponentID component ) = 0;
     116
     117  virtual Void parseExplicitRdpcmMode ( TComTU &rTu, ComponentID compID ) = 0;
     118
    117119  virtual ~TDecEntropyIf() {}
    118120};
     
    124126  TDecEntropyIf*  m_pcEntropyDecoderIf;
    125127  TComPrediction* m_pcPrediction;
    126   UInt    m_uiBakAbsPartIdx;
    127   UInt    m_uiBakChromaOffset;
    128   UInt    m_bakAbsPartIdxCU;
    129  
     128  //UInt    m_uiBakAbsPartIdx;
     129  //UInt    m_uiBakChromaOffset;
     130  //UInt    m_bakAbsPartIdxCU;
     131
    130132public:
    131133  Void init (TComPrediction* p) {m_pcPrediction = p;}
     
    135137  Void decodeMvdPU        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList );
    136138  Void decodeMVPIdxPU     ( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList );
    137  
     139
    138140  Void    setEntropyDecoder           ( TDecEntropyIf* p );
    139141  Void    setBitstream                ( TComInputBitstream* p ) { m_pcEntropyDecoderIf->setBitstream(p);                    }
    140142  Void    resetEntropy                ( TComSlice* p)           { m_pcEntropyDecoderIf->resetEntropy(p);                    }
     143
    141144  Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
    142 #if SVC_EXTENSION && !SPS_DPB_PARAMS
    143   Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )    { m_pcEntropyDecoderIf->parseSPS(pcSPS, parameterSetManager);                    }
    144 #else
    145   Void    decodeSPS                   ( TComSPS* pcSPS     )    { m_pcEntropyDecoderIf->parseSPS(pcSPS);                    }
    146 #endif
     145  Void    decodeSPS                   ( TComSPS* pcSPS ) { m_pcEntropyDecoderIf->parseSPS(pcSPS); }
    147146
    148147#if Q0048_CGS_3D_ASYMLUT
    149148  Void    decodePPS                   ( TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT, Int nLayerID )    { m_pcEntropyDecoderIf->parsePPS(pcPPS, pc3DAsymLUT , nLayerID );                     }
    150149#else
    151   Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS ); }
     150  Void    decodePPS                   ( TComPPS* pcPPS ) { m_pcEntropyDecoderIf->parsePPS(pcPPS); }
    152151#endif
    153   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager);         }
     152  Void    decodeSliceHeader           ( TComSlice* pcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(pcSlice, parameterSetManager);         }
    154153
    155154  Void    decodeTerminatingBit        ( UInt& ruiIsLast )       { m_pcEntropyDecoderIf->parseTerminatingBit(ruiIsLast);     }
    156  
     155  Void    decodeRemainingBytes( Bool noTrailingBytesExpected ) { m_pcEntropyDecoderIf->parseRemainingBytes(noTrailingBytesExpected); }
     156
    157157  TDecEntropyIf* getEntropyDecoder() { return m_pcEntropyDecoderIf; }
    158  
     158
    159159public:
    160160  Void decodeSplitFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     
    165165  Void decodePredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    166166  Void decodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    167  
     167
    168168  Void decodeIPCMInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    169169
    170170  Void decodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU );
    171  
     171
    172172  Void decodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    173173  Void decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    174  
     174
    175175  Void decodeQP                ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    176  
    177   Void updateContextTables    ( SliceType eSliceType, Int iQp ) { m_pcEntropyDecoderIf->updateContextTables( eSliceType, iQp ); }
    178  
    179  
     176  Void decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx );
     177
    180178private:
    181   Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int getQuadtreeTULog2MinSizeInCU );
     179
     180  Void xDecodeTransform        ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU );
    182181
    183182public:
    184   Void decodeCoeff             ( TComDataCU* pcCU                 , UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP );
    185  
     183
     184  Void decodeCoeff             ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded );
     185
    186186};// END CLASS DEFINITION TDecEntropy
    187187
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp

    r930 r1029  
    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-2014, ITU/ISO/IEC
     
    4545#if SVC_EXTENSION
    4646#include "TDecTop.h"
    47 #endif
     47#if CONFORMANCE_BITSTREAM_MODE
    4848#include <algorithm>
     49#endif
     50#endif
     51
    4952#include <time.h>
    5053
     
    5760}
    5861#endif
     62
    5963//! \ingroup TLibDecoder
    6064//! \{
    61 static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
     65static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
    6266#if Q0074_COLOUR_REMAPPING_SEI
    6367static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 );
     
    7175{
    7276  m_dDecTime = 0;
    73   m_pcSbacDecoders = NULL;
    74   m_pcBinCABACs = NULL;
    7577}
    7678
    7779TDecGop::~TDecGop()
    7880{
    79  
     81
    8082}
    8183
     
    8890Void TDecGop::create()
    8991{
    90  
     92
    9193}
    9294#endif
     
    9597{
    9698}
    97 #if SVC_EXTENSION
    98 Void TDecGop::init(TDecTop**               ppcDecTop,
    99                    TDecEntropy*            pcEntropyDecoder,
    100 #else
    101 Void TDecGop::init( TDecEntropy*            pcEntropyDecoder,
    102 #endif
    103                    TDecSbac*               pcSbacDecoder,
     99
     100#if SVC_EXTENSION
     101Void TDecGop::init( TDecTop**               ppcDecTop,
     102                   TDecEntropy*             pcEntropyDecoder,
     103#else
     104Void TDecGop::init( TDecEntropy*            pcEntropyDecoder,
     105#endif
     106                   TDecSbac*               pcSbacDecoder,
    104107                   TDecBinCABAC*           pcBinCABAC,
    105                    TDecCavlc*              pcCavlcDecoder, 
    106                    TDecSlice*              pcSliceDecoder, 
     108                   TDecCavlc*              pcCavlcDecoder,
     109                   TDecSlice*              pcSliceDecoder,
    107110                   TComLoopFilter*         pcLoopFilter,
    108111                   TComSampleAdaptiveOffset* pcSAO
     
    129132// ====================================================================================================================
    130133
    131 Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic)
    132 {
    133   TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
     134Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic)
     135{
     136  TComSlice*  pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
    134137  // Table of extracted substreams.
    135138  // These must be deallocated AND their internal fifos, too.
     
    137140
    138141  //-- For time output for each slice
    139   long iBeforeTime = clock();
     142  clock_t iBeforeTime = clock();
    140143  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
    141144  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
    142145
    143   UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumEntryPointOffsets()+1 : pcSlice->getPPS()->getNumSubstreams();
     146  const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1;
     147//  const UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumberOfSubstreamSizes()+1 : pcSlice->getPPS()->getNumSubstreams();
    144148
    145149  // init each couple {EntropyDecoder, Substream}
    146   UInt *puiSubstreamSizes = pcSlice->getSubstreamSizes();
    147150  ppcSubstreams    = new TComInputBitstream*[uiNumSubstreams];
    148   m_pcSbacDecoders = new TDecSbac[uiNumSubstreams];
    149   m_pcBinCABACs    = new TDecBinCABAC[uiNumSubstreams];
    150151  for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ )
    151152  {
    152     m_pcSbacDecoders[ui].init(&m_pcBinCABACs[ui]);
    153     ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? puiSubstreamSizes[ui] : pcBitstream->getNumBitsLeft());
    154   }
    155 
    156   for ( UInt ui = 0 ; ui+1 < uiNumSubstreams; ui++ )
    157   {
    158     m_pcEntropyDecoder->setEntropyDecoder ( &m_pcSbacDecoders[uiNumSubstreams - 1 - ui] );
    159     m_pcEntropyDecoder->setBitstream      (  ppcSubstreams   [uiNumSubstreams - 1 - ui] );
    160     m_pcEntropyDecoder->resetEntropy      (pcSlice);
    161   }
    162 
    163   m_pcEntropyDecoder->setEntropyDecoder ( m_pcSbacDecoder  );
    164   m_pcEntropyDecoder->setBitstream      ( ppcSubstreams[0] );
    165   m_pcEntropyDecoder->resetEntropy      (pcSlice);
    166   m_pcSbacDecoders[0].load(m_pcSbacDecoder);
    167   m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
    168   m_pcEntropyDecoder->setBitstream(  ppcSubstreams[uiNumSubstreams-1] );
     153    ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft());
     154  }
     155
     156  m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder);
    169157  // deallocate all created substreams, including internal buffers.
    170158  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
     
    174162  }
    175163  delete[] ppcSubstreams;
    176   delete[] m_pcSbacDecoders; m_pcSbacDecoders = NULL;
    177   delete[] m_pcBinCABACs; m_pcBinCABACs = NULL;
    178164
    179165  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
    180166}
    181167
    182 Void TDecGop::filterPicture(TComPic*& rpcPic)
    183 {
    184   TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
     168Void TDecGop::filterPicture(TComPic* pcPic)
     169{
     170  TComSlice*  pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
    185171
    186172  //-- For time output for each slice
    187   long iBeforeTime = clock();
     173  clock_t iBeforeTime = clock();
    188174
    189175  // deblocking filter
    190176  Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
    191177  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
    192   m_pcLoopFilter->loopFilterPic( rpcPic );
     178  m_pcLoopFilter->loopFilterPic( pcPic );
     179
    193180  if( pcSlice->getSPS()->getUseSAO() )
    194181  {
    195     m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam());
    196     m_pcSAO->SAOProcess(rpcPic);
    197     m_pcSAO->PCMLFDisableProcess(rpcPic);
    198   }
    199   rpcPic->compressMotion();
     182    m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam());
     183    m_pcSAO->SAOProcess(pcPic);
     184    m_pcSAO->PCMLFDisableProcess(pcPic);
     185  }
     186
     187  pcPic->compressMotion();
    200188  Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
    201189  if (!pcSlice->isReferenced()) c += 32;
     
    203191  //-- For time output for each slice
    204192#if SVC_EXTENSION
    205   printf("\nPOC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP%3d ) ", pcSlice->getPOC(),
    206                                                     rpcPic->getLayerId(),
     193  printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP%3d ) ", pcSlice->getPOC(),
     194                                                    pcPic->getLayerId(),
    207195                                                    pcSlice->getTLayer(),
    208196                                                    c,
     
    210198                                                    pcSlice->getSliceQp() );
    211199#else
    212   printf("\nPOC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
    213                                                     pcSlice->getTLayer(),
    214                                                     c,
    215                                                     pcSlice->getSliceQp() );
     200  printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
     201                                                  pcSlice->getTLayer(),
     202                                                  c,
     203                                                  pcSlice->getSliceQp() );
     204
    216205#endif
    217206  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
     
    254243  if (m_decodedPictureHashSEIEnabled)
    255244  {
    256     SEIMessages pictureHashes = getSeisByType(rpcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
     245    SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
    257246    const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
    258247    if (pictureHashes.size() > 1)
     
    260249      printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
    261250    }
    262     calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash);
     251    calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash);
    263252  }
    264253#if CONFORMANCE_BITSTREAM_MODE
    265   if( this->getLayerDec(rpcPic->getLayerId())->getConfModeFlag() )
     254  if( this->getLayerDec(pcPic->getLayerId())->getConfModeFlag() )
    266255  {
    267256    // Add this reconstructed picture to the parallel buffer.
    268     std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(rpcPic->getLayerId()))->getConfListPic();
    269     thisLayerBuffer->push_back(*rpcPic);
     257    std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerId()))->getConfListPic();
     258    thisLayerBuffer->push_back(*pcPic);
    270259    std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction );
    271260  }
     
    274263  if (m_colourRemapSEIEnabled)
    275264  {
    276     SEIMessages colourRemappingInfo = getSeisByType(rpcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
     265    SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
    277266    const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
    278267    if (colourRemappingInfo.size() > 1)
     
    280269      printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
    281270    }
    282     applyColourRemapping(*rpcPic->getPicYuvRec(), seiColourRemappingInfo
    283 #if SVC_EXTENSION
    284      , rpcPic->getLayerId()
     271    applyColourRemapping(*pcPic->getPicYuvRec(), seiColourRemappingInfo
     272#if SVC_EXTENSION
     273     , pcPic->getLayerId()
    285274#endif
    286275     );
     
    288277#endif
    289278
    290 #if SETTING_PIC_OUTPUT_MARK
    291   rpcPic->setOutputMark(rpcPic->getSlice(0)->getPicOutputFlag() ? true : false);
    292 #else
    293   rpcPic->setOutputMark(true);
    294 #endif
    295   rpcPic->setReconMark(true);
     279  printf("\n");
     280
     281  pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false);
     282  pcPic->setReconMark(true);
    296283}
    297284
     
    307294 *            unk         - no SEI message was available for comparison
    308295 */
    309 static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
     296static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
    310297{
    311298  /* calculate MD5sum for entire reconstructed picture */
    312   UChar recon_digest[3][16];
     299  TComDigest recon_digest;
    313300  Int numChar=0;
    314301  const Char* hashType = "\0";
     
    318305    switch (pictureHashSEI->method)
    319306    {
    320     case SEIDecodedPictureHash::MD5:
    321       {
    322         hashType = "MD5";
    323         calcMD5(pic, recon_digest);
    324         numChar = 16;
    325         break;
    326       }
    327     case SEIDecodedPictureHash::CRC:
    328       {
    329         hashType = "CRC";
    330         calcCRC(pic, recon_digest);
    331         numChar = 2;
    332         break;
    333       }
    334     case SEIDecodedPictureHash::CHECKSUM:
    335       {
    336         hashType = "Checksum";
    337         calcChecksum(pic, recon_digest);
    338         numChar = 4;
    339         break;
    340       }
    341     default:
    342       {
    343         assert (!"unknown hash type");
    344       }
     307      case SEIDecodedPictureHash::MD5:
     308        {
     309          hashType = "MD5";
     310          numChar = calcMD5(pic, recon_digest);
     311          break;
     312        }
     313      case SEIDecodedPictureHash::CRC:
     314        {
     315          hashType = "CRC";
     316          numChar = calcCRC(pic, recon_digest);
     317          break;
     318        }
     319      case SEIDecodedPictureHash::CHECKSUM:
     320        {
     321          hashType = "Checksum";
     322          numChar = calcChecksum(pic, recon_digest);
     323          break;
     324        }
     325      default:
     326        {
     327          assert (!"unknown hash type");
     328          break;
     329        }
    345330    }
    346331  }
     
    353338  {
    354339    ok = "(OK)";
    355     for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
    356     {
    357       for (UInt i = 0; i < numChar; i++)
    358       {
    359         if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
    360         {
    361           ok = "(***ERROR***)";
    362           mismatch = true;
    363         }
    364       }
    365     }
    366   }
    367 
    368   printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok);
     340    if (recon_digest != pictureHashSEI->m_digest)
     341    {
     342      ok = "(***ERROR***)";
     343      mismatch = true;
     344    }
     345  }
     346
     347  printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar).c_str(), ok);
    369348
    370349  if (mismatch)
    371350  {
    372351    g_md5_mismatch = true;
    373     printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
     352    printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->m_digest, numChar).c_str());
    374353  }
    375354}
     
    433412}
    434413
    435 static void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
     414static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
    436415
    437416  if( !storeCriSEI.size() )
     
    447426  if( !storeCriSEI[layerId].m_colourRemapCancelFlag )
    448427  {
    449     Int iHeight  = pic.getHeight();
    450     Int iWidth   = pic.getWidth();
    451     Int iStride  = pic.getStride();
    452     Int iCStride = pic.getCStride();
     428    Int iHeight  = pic.getHeight(COMPONENT_Y);
     429    Int iWidth   = pic.getWidth(COMPONENT_Y);
     430    Int iStride  = pic.getStride(COMPONENT_Y);
     431    Int iCStride = pic.getStride(COMPONENT_Cb);
    453432
    454433    Pel *YUVIn[3], *YUVOut[3];
    455     YUVIn[0] = pic.getLumaAddr();
    456     YUVIn[1] = pic.getCbAddr();
    457     YUVIn[2] = pic.getCrAddr();
     434    YUVIn[0] = pic.getAddr(COMPONENT_Y);
     435    YUVIn[1] = pic.getAddr(COMPONENT_Cb);
     436    YUVIn[2] = pic.getAddr(COMPONENT_Cr);
    458437   
    459438    TComPicYuv picColourRemapped;
    460439#if SVC_EXTENSION
    461 #if AUXILIARY_PICTURES
    462     picColourRemapped.create( pic.getWidth(), pic.getHeight(), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
    463 #else
    464     picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
    465 #endif
    466 #else
    467     picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     440    picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
     441#else
     442    picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    468443#endif
    469     YUVOut[0] = picColourRemapped.getLumaAddr();
    470     YUVOut[1] = picColourRemapped.getCbAddr();
    471     YUVOut[2] = picColourRemapped.getCrAddr();
    472 
    473 #if SVC_EXTENSION
    474     Int bitDepthY = g_bitDepthYLayer[layerId];
    475     Int bitDepthC = g_bitDepthCLayer[layerId];
    476 
    477     assert( g_bitDepthY == bitDepthY );
    478     assert( g_bitDepthC == bitDepthC );
    479 #else
    480     Int bitDepthY = g_bitDepthY;
    481     Int bitDepthC = g_bitDepthC;
     444    YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y);
     445    YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb);
     446    YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr);
     447
     448#if SVC_EXTENSION
     449    Int bitDepthY = g_bitDepthLayer[CHANNEL_TYPE_LUMA][layerId];
     450    Int bitDepthC = g_bitDepthLayer[CHANNEL_TYPE_CHROMA][layerId];
     451
     452    assert( g_bitDepth[CHANNEL_TYPE_LUMA] == bitDepthY );
     453    assert( g_bitDepth[CHANNEL_TYPE_CHROMA] == bitDepthC );
     454#else
     455    Int bitDepthY = g_bitDepth[CHANNEL_TYPE_LUMA];
     456    Int bitDepthC = g_bitDepth[CHANNEL_TYPE_CHROMA];
    482457#endif
    483458
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.h

    r930 r1029  
    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-2014, ITU/ISO/IEC
     
    6868private:
    6969  TComList<TComPic*>    m_cListPic;         //  Dynamic buffer
    70  
     70
    7171  //  Access channel
    7272  TDecEntropy*          m_pcEntropyDecoder;
    7373  TDecSbac*             m_pcSbacDecoder;
    7474  TDecBinCABAC*         m_pcBinCABAC;
    75   TDecSbac*             m_pcSbacDecoders; // independant CABAC decoders
    76   TDecBinCABAC*         m_pcBinCABACs;
    7775  TDecCavlc*            m_pcCavlcDecoder;
    7876  TDecSlice*            m_pcSliceDecoder;
    7977  TComLoopFilter*       m_pcLoopFilter;
    80  
     78
    8179  TComSampleAdaptiveOffset*     m_pcSAO;
    8280  Double                m_dDecTime;
     
    10199                 TDecSbac*               pcSbacDecoder,
    102100                 TDecBinCABAC*           pcBinCABAC,
    103                  TDecCavlc*              pcCavlcDecoder, 
    104                  TDecSlice*              pcSliceDecoder, 
     101                 TDecCavlc*              pcCavlcDecoder,
     102                 TDecSlice*              pcSliceDecoder,
    105103                 TComLoopFilter*         pcLoopFilter,
    106104                 TComSampleAdaptiveOffset* pcSAO
     
    112110#endif
    113111  Void  destroy ();
    114   Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic );
    115   Void  filterPicture  (TComPic*& rpcPic );
     112  Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic );
     113  Void  filterPicture  (TComPic* pcPic );
    116114
    117115  Void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.cpp

    r644 r1029  
    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-2014, ITU/ISO/IEC
     
    3737
    3838#include "TDecSbac.h"
     39#include "TLibCommon/TComTU.h"
     40
     41#if RExt__DECODER_DEBUG_BIT_STATISTICS
     42#include "TLibCommon/TComCodingStatistics.h"
     43//
     44#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a) , a
     45#else
     46#define RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(a)
     47#endif
    3948
    4049//! \ingroup TLibDecoder
    4150//! \{
     51
     52#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     53#include "../TLibCommon/Debug.h"
     54#endif
     55
    4256
    4357//////////////////////////////////////////////////////////////////////
     
    4559//////////////////////////////////////////////////////////////////////
    4660
    47 TDecSbac::TDecSbac() 
     61TDecSbac::TDecSbac()
    4862// new structure here
    49 : m_pcBitstream               ( 0 )
    50 , m_pcTDecBinIf               ( NULL )
    51 , m_numContextModels          ( 0 )
    52 , m_cCUSplitFlagSCModel       ( 1,             1,               NUM_SPLIT_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels )
    53 , m_cCUSkipFlagSCModel        ( 1,             1,               NUM_SKIP_FLAG_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    54 , m_cCUMergeFlagExtSCModel    ( 1,             1,               NUM_MERGE_FLAG_EXT_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
    55 , m_cCUMergeIdxExtSCModel     ( 1,             1,               NUM_MERGE_IDX_EXT_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
    56 , m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    57 , m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    58 , m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
    59 , m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    60 , m_cCUDeltaQpSCModel         ( 1,             1,               NUM_DELTA_QP_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    61 , m_cCUInterDirSCModel        ( 1,             1,               NUM_INTER_DIR_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    62 , m_cCURefPicSCModel          ( 1,             1,               NUM_REF_NO_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    63 , m_cCUMvdSCModel             ( 1,             1,               NUM_MV_RES_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    64 , m_cCUQtCbfSCModel           ( 1,             2,               NUM_QT_CBF_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    65 , m_cCUTransSubdivFlagSCModel ( 1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    66 , m_cCUQtRootCbfSCModel       ( 1,             1,               NUM_QT_ROOT_CBF_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    67 , m_cCUSigCoeffGroupSCModel   ( 1,             2,               NUM_SIG_CG_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    68 , m_cCUSigSCModel             ( 1,             1,               NUM_SIG_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    69 , m_cCuCtxLastX               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
    70 , m_cCuCtxLastY               ( 1,             2,               NUM_CTX_LAST_FLAG_XY          , m_contextModels + m_numContextModels, m_numContextModels)
    71 , m_cCUOneSCModel             ( 1,             1,               NUM_ONE_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    72 , m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    73 , m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    74 , m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    75 , m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
    76 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
    77 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
     63: m_pcBitstream                              ( 0 )
     64, m_pcTDecBinIf                              ( NULL )
     65, m_numContextModels                         ( 0 )
     66, m_cCUSplitFlagSCModel                      ( 1,             1,                      NUM_SPLIT_FLAG_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
     67, m_cCUSkipFlagSCModel                       ( 1,             1,                      NUM_SKIP_FLAG_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     68, m_cCUMergeFlagExtSCModel                   ( 1,             1,                      NUM_MERGE_FLAG_EXT_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
     69, m_cCUMergeIdxExtSCModel                    ( 1,             1,                      NUM_MERGE_IDX_EXT_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
     70, m_cCUPartSizeSCModel                       ( 1,             1,                      NUM_PART_SIZE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     71, m_cCUPredModeSCModel                       ( 1,             1,                      NUM_PRED_MODE_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     72, m_cCUIntraPredSCModel                      ( 1,             1,                      NUM_ADI_CTX                          , m_contextModels + m_numContextModels, m_numContextModels)
     73, m_cCUChromaPredSCModel                     ( 1,             1,                      NUM_CHROMA_PRED_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     74, m_cCUDeltaQpSCModel                        ( 1,             1,                      NUM_DELTA_QP_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     75, m_cCUInterDirSCModel                       ( 1,             1,                      NUM_INTER_DIR_CTX                    , m_contextModels + m_numContextModels, m_numContextModels)
     76, m_cCURefPicSCModel                         ( 1,             1,                      NUM_REF_NO_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
     77, m_cCUMvdSCModel                            ( 1,             1,                      NUM_MV_RES_CTX                       , m_contextModels + m_numContextModels, m_numContextModels)
     78, m_cCUQtCbfSCModel                          ( 1,             NUM_QT_CBF_CTX_SETS,    NUM_QT_CBF_CTX_PER_SET               , m_contextModels + m_numContextModels, m_numContextModels)
     79, m_cCUTransSubdivFlagSCModel                ( 1,             1,                      NUM_TRANS_SUBDIV_FLAG_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
     80, m_cCUQtRootCbfSCModel                      ( 1,             1,                      NUM_QT_ROOT_CBF_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     81, m_cCUSigCoeffGroupSCModel                  ( 1,             2,                      NUM_SIG_CG_FLAG_CTX                  , m_contextModels + m_numContextModels, m_numContextModels)
     82, m_cCUSigSCModel                            ( 1,             1,                      NUM_SIG_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     83, m_cCuCtxLastX                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
     84, m_cCuCtxLastY                              ( 1,             NUM_CTX_LAST_FLAG_SETS, NUM_CTX_LAST_FLAG_XY                 , m_contextModels + m_numContextModels, m_numContextModels)
     85, m_cCUOneSCModel                            ( 1,             1,                      NUM_ONE_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     86, m_cCUAbsSCModel                            ( 1,             1,                      NUM_ABS_FLAG_CTX                     , m_contextModels + m_numContextModels, m_numContextModels)
     87, m_cMVPIdxSCModel                           ( 1,             1,                      NUM_MVP_IDX_CTX                      , m_contextModels + m_numContextModels, m_numContextModels)
     88, m_cSaoMergeSCModel                         ( 1,             1,                      NUM_SAO_MERGE_FLAG_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
     89, m_cSaoTypeIdxSCModel                       ( 1,             1,                      NUM_SAO_TYPE_IDX_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
     90, m_cTransformSkipSCModel                    ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_TRANSFORMSKIP_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     91, m_CUTransquantBypassFlagSCModel            ( 1,             1,                      NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
     92, m_explicitRdpcmFlagSCModel                 ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_FLAG_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     93, m_explicitRdpcmDirSCModel                  ( 1,             MAX_NUM_CHANNEL_TYPE,   NUM_EXPLICIT_RDPCM_DIR_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     94, m_cCrossComponentPredictionSCModel         ( 1,             1,                      NUM_CROSS_COMPONENT_PREDICTION_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
     95, m_ChromaQpAdjFlagSCModel                   ( 1,             1,                      NUM_CHROMA_QP_ADJ_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     96, m_ChromaQpAdjIdcSCModel                    ( 1,             1,                      NUM_CHROMA_QP_ADJ_IDC_CTX            , m_contextModels + m_numContextModels, m_numContextModels)
    7897{
    7998  assert( m_numContextModels <= MAX_NUM_CTX_MOD );
     
    98117    {
    99118    case P_SLICE:           // change initialization table to B_SLICE initialization
    100       sliceType = B_SLICE; 
     119      sliceType = B_SLICE;
    101120      break;
    102121    case B_SLICE:           // change initialization table to P_SLICE initialization
    103       sliceType = P_SLICE; 
     122      sliceType = P_SLICE;
    104123      break;
    105124    default     :           // should not occur
    106125      assert(0);
    107     }
    108   }
    109 
    110   m_cCUSplitFlagSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
    111   m_cCUSkipFlagSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
    112   m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
    113   m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
    114   m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
    115   m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
    116   m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
    117   m_cCUChromaPredSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
    118   m_cCUInterDirSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_INTER_DIR );
    119   m_cCUMvdSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MVD );
    120   m_cCURefPicSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_REF_PIC );
    121   m_cCUDeltaQpSCModel.initBuffer         ( sliceType, qp, (UChar*)INIT_DQP );
    122   m_cCUQtCbfSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_QT_CBF );
    123   m_cCUQtRootCbfSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
    124   m_cCUSigCoeffGroupSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
    125   m_cCUSigSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
    126   m_cCuCtxLastX.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
    127   m_cCuCtxLastY.initBuffer               ( sliceType, qp, (UChar*)INIT_LAST );
    128   m_cCUOneSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
    129   m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
    130   m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
    131   m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
    132   m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
    133 
    134   m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    135   m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
    136   m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
    137   m_uiLastDQpNonZero  = 0;
    138  
    139   // new structure
    140   m_uiLastQp          = qp;
    141  
     126      break;
     127    }
     128  }
     129
     130  m_cCUSplitFlagSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_SPLIT_FLAG );
     131  m_cCUSkipFlagSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SKIP_FLAG );
     132  m_cCUMergeFlagExtSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
     133  m_cCUMergeIdxExtSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
     134  m_cCUPartSizeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PART_SIZE );
     135  m_cCUPredModeSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_PRED_MODE );
     136  m_cCUIntraPredSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
     137  m_cCUChromaPredSCModel.initBuffer               ( sliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE );
     138  m_cCUInterDirSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_INTER_DIR );
     139  m_cCUMvdSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_MVD );
     140  m_cCURefPicSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_REF_PIC );
     141  m_cCUDeltaQpSCModel.initBuffer                  ( sliceType, qp, (UChar*)INIT_DQP );
     142  m_cCUQtCbfSCModel.initBuffer                    ( sliceType, qp, (UChar*)INIT_QT_CBF );
     143  m_cCUQtRootCbfSCModel.initBuffer                ( sliceType, qp, (UChar*)INIT_QT_ROOT_CBF );
     144  m_cCUSigCoeffGroupSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_SIG_CG_FLAG );
     145  m_cCUSigSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_SIG_FLAG );
     146  m_cCuCtxLastX.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
     147  m_cCuCtxLastY.initBuffer                        ( sliceType, qp, (UChar*)INIT_LAST );
     148  m_cCUOneSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ONE_FLAG );
     149  m_cCUAbsSCModel.initBuffer                      ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
     150  m_cMVPIdxSCModel.initBuffer                     ( sliceType, qp, (UChar*)INIT_MVP_IDX );
     151  m_cSaoMergeSCModel.initBuffer                   ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
     152  m_cSaoTypeIdxSCModel.initBuffer                 ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     153  m_cCUTransSubdivFlagSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     154  m_cTransformSkipSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
     155  m_CUTransquantBypassFlagSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
     156  m_explicitRdpcmFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_FLAG);
     157  m_explicitRdpcmDirSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_EXPLICIT_RDPCM_DIR);
     158  m_cCrossComponentPredictionSCModel.initBuffer   ( sliceType, qp, (UChar*)INIT_CROSS_COMPONENT_PREDICTION );
     159  m_ChromaQpAdjFlagSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_FLAG );
     160  m_ChromaQpAdjIdcSCModel.initBuffer              ( sliceType, qp, (UChar*)INIT_CHROMA_QP_ADJ_IDC );
     161
     162  for (UInt statisticIndex = 0; statisticIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS ; statisticIndex++)
     163  {
     164    m_golombRiceAdaptationStatistics[statisticIndex] = 0;
     165  }
     166
    142167  m_pcTDecBinIf->start();
    143168}
    144169
    145 /** The function does the following: Read out terminate bit. Flush CABAC. Byte-align for next tile.
    146  *  Intialize CABAC states. Start CABAC.
    147  */
    148 Void TDecSbac::updateContextTables( SliceType eSliceType, Int iQp )
    149 {
    150   UInt uiBit;
    151   m_pcTDecBinIf->decodeBinTrm(uiBit);
    152   assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
    153   m_pcTDecBinIf->finish(); 
    154   m_pcBitstream->readOutTrailingBits();
    155   m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
    156   m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
    157   m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
    158   m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
    159   m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    160   m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    161   m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
    162   m_cCUChromaPredSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE );
    163   m_cCUInterDirSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_INTER_DIR );
    164   m_cCUMvdSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_MVD );
    165   m_cCURefPicSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_REF_PIC );
    166   m_cCUDeltaQpSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_DQP );
    167   m_cCUQtCbfSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_QT_CBF );
    168   m_cCUQtRootCbfSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF );
    169   m_cCUSigCoeffGroupSCModel.initBuffer   ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG );
    170   m_cCUSigSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG );
    171   m_cCuCtxLastX.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
    172   m_cCuCtxLastY.initBuffer               ( eSliceType, iQp, (UChar*)INIT_LAST );
    173   m_cCUOneSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG );
    174   m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
    175   m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
    176   m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
    177   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
    178   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
    179   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
    180   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
    181   m_pcTDecBinIf->start();
    182 }
    183 
    184170Void TDecSbac::parseTerminatingBit( UInt& ruiBit )
    185171{
    186172  m_pcTDecBinIf->decodeBinTrm( ruiBit );
    187   if ( ruiBit )
     173  if ( ruiBit == 1 )
    188174  {
    189175    m_pcTDecBinIf->finish();
    190   }
    191 }
    192 
    193 
     176
     177#if RExt__DECODER_DEBUG_BIT_STATISTICS
     178    TComCodingStatistics::IncrementStatisticEP(STATS__TRAILING_BITS, m_pcBitstream->readOutTrailingBits(),0);
     179#else
     180    m_pcBitstream->readOutTrailingBits();
     181#endif
     182  }
     183}
     184
     185Void TDecSbac::parseRemainingBytes( Bool noTrailingBytesExpected )
     186{
     187  if (noTrailingBytesExpected)
     188  {
     189    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
     190    assert (numberOfRemainingSubstreamBytes == 0);
     191  }
     192  else
     193  {
     194    while (m_pcBitstream->getNumBitsLeft())
     195    {
     196      UInt trailingNullByte=m_pcBitstream->readByte();
     197      if (trailingNullByte!=0)
     198      {
     199        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
     200        assert(trailingNullByte==0);
     201      }
     202    }
     203  }
     204}
     205
     206#if RExt__DECODER_DEBUG_BIT_STATISTICS
     207Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat )
     208#else
    194209Void TDecSbac::xReadUnaryMaxSymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol )
     210#endif
    195211{
    196212  if (uiMaxSymbol == 0)
     
    199215    return;
    200216  }
    201  
    202   m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
    203  
     217
     218  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     219
    204220  if( ruiSymbol == 0 || uiMaxSymbol == 1 )
    205221  {
    206222    return;
    207223  }
    208  
     224
    209225  UInt uiSymbol = 0;
    210226  UInt uiCont;
    211  
     227
    212228  do
    213229  {
    214     m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
     230    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    215231    uiSymbol++;
    216232  }
    217233  while( uiCont && ( uiSymbol < uiMaxSymbol - 1 ) );
    218  
     234
    219235  if( uiCont && ( uiSymbol == uiMaxSymbol - 1 ) )
    220236  {
    221237    uiSymbol++;
    222238  }
    223  
     239
    224240  ruiSymbol = uiSymbol;
    225241}
    226242
     243#if RExt__DECODER_DEBUG_BIT_STATISTICS
     244Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat )
     245#else
    227246Void TDecSbac::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
     247#endif
    228248{
    229249  UInt uiSymbol = 0;
    230250  UInt uiBit = 1;
    231  
     251
    232252  while( uiBit )
    233253  {
    234     m_pcTDecBinIf->decodeBinEP( uiBit );
     254    m_pcTDecBinIf->decodeBinEP( uiBit RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    235255    uiSymbol += uiBit << uiCount++;
    236256  }
    237  
     257
    238258  if ( --uiCount )
    239259  {
    240260    UInt bins;
    241     m_pcTDecBinIf->decodeBinsEP( bins, uiCount );
     261    m_pcTDecBinIf->decodeBinsEP( bins, uiCount RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
    242262    uiSymbol += bins;
    243263  }
    244  
     264
    245265  ruiSymbol = uiSymbol;
    246266}
    247267
     268#if RExt__DECODER_DEBUG_BIT_STATISTICS
     269Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat )
     270#else
    248271Void TDecSbac::xReadUnarySymbol( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset )
    249 {
    250   m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] );
    251  
     272#endif
     273{
     274  m_pcTDecBinIf->decodeBin( ruiSymbol, pcSCModel[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
     275
    252276  if( !ruiSymbol )
    253277  {
    254278    return;
    255279  }
    256  
     280
    257281  UInt uiSymbol = 0;
    258282  UInt uiCont;
    259  
     283
    260284  do
    261285  {
    262     m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] );
     286    m_pcTDecBinIf->decodeBin( uiCont, pcSCModel[ iOffset ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    263287    uiSymbol++;
    264288  }
    265289  while( uiCont );
    266  
     290
    267291  ruiSymbol = uiSymbol;
    268292}
     
    274298 * \returns Void
    275299 */
    276 Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam )
    277 {
    278 
     300#if RExt__DECODER_DEBUG_BIT_STATISTICS
     301Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const class TComCodingStatisticsClassType &whichStat )
     302#else
     303Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType )
     304#endif
     305{
    279306  UInt prefix   = 0;
    280307  UInt codeWord = 0;
    281   do
    282   {
    283     prefix++;
    284     m_pcTDecBinIf->decodeBinEP( codeWord );
    285   }
    286   while( codeWord);
     308
     309  if (useLimitedPrefixLength)
     310  {
     311    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])) + COEF_REMAIN_BIN_REDUCTION;
     312
     313    do
     314    {
     315      prefix++;
     316      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     317    }
     318    while((codeWord != 0) && (prefix < longestPossiblePrefix));
     319  }
     320  else
     321  {
     322    do
     323    {
     324      prefix++;
     325      m_pcTDecBinIf->decodeBinEP( codeWord RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat) );
     326    }
     327    while( codeWord);
     328  }
     329
    287330  codeWord  = 1 - codeWord;
    288331  prefix -= codeWord;
    289332  codeWord=0;
     333
    290334  if (prefix < COEF_REMAIN_BIN_REDUCTION )
    291335  {
    292     m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
     336    m_pcTDecBinIf->decodeBinsEP(codeWord,rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    293337    rSymbol = (prefix<<rParam) + codeWord;
    294338  }
     339  else if (useLimitedPrefixLength)
     340  {
     341    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType]));
     342
     343    const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
     344    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (g_maxTrDynamicRange[channelType] - rParam) : prefixLength;
     345
     346    m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
     347
     348    rSymbol = codeWord + ((((1 << prefixLength) - 1) + COEF_REMAIN_BIN_REDUCTION) << rParam);
     349  }
    295350  else
    296351  {
    297     m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
     352    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
    298353    rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
    299354  }
    300355}
    301356
    302 /** Parse I_PCM information.
     357
     358/** Parse I_PCM information.
    303359 * \param pcCU
    304  * \param uiAbsPartIdx 
     360 * \param uiAbsPartIdx
    305361 * \param uiDepth
    306362 * \returns Void
    307363 *
    308  * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
     364 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
    309365 */
    310366Void TDecSbac::parseIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     
    312368  UInt uiSymbol;
    313369
    314     m_pcTDecBinIf->decodeBinTrm(uiSymbol);
    315 
    316     if (uiSymbol)
    317     {
     370  m_pcTDecBinIf->decodeBinTrm(uiSymbol);
     371
     372  if (uiSymbol == 1)
     373  {
    318374    Bool bIpcmFlag = true;
    319375
     
    323379    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
    324380
    325     UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    326     UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
    327     UInt uiChromaOffset = uiLumaOffset>>2;
    328 
    329     Pel* piPCMSample;
    330     UInt uiWidth;
    331     UInt uiHeight;
    332     UInt uiSampleBits;
    333     UInt uiX, uiY;
    334 
    335     piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
    336     uiWidth = pcCU->getWidth(uiAbsPartIdx);
    337     uiHeight = pcCU->getHeight(uiAbsPartIdx);
    338     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    339 
    340     for(uiY = 0; uiY < uiHeight; uiY++)
    341     {
    342       for(uiX = 0; uiX < uiWidth; uiX++)
    343       {
    344         UInt uiSample;
    345         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    346         piPCMSample[uiX] = uiSample;
    347       }
    348       piPCMSample += uiWidth;
    349     }
    350 
    351     piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
    352     uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    353     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    354     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    355 #if AUXILIARY_PICTURES
    356     ChromaFormat format = pcCU->getSlice()->getChromaFormatIdc();
    357     UInt uiGrayVal = 1 << (uiSampleBits - 1);
    358 #endif
    359 
    360     for(uiY = 0; uiY < uiHeight; uiY++)
    361     {
    362       for(uiX = 0; uiX < uiWidth; uiX++)
    363       {
    364         UInt uiSample;
    365 #if AUXILIARY_PICTURES
    366         if (format == CHROMA_400)
     381    const UInt minCoeffSizeY = pcCU->getPic()->getMinCUWidth() * pcCU->getPic()->getMinCUHeight();
     382    const UInt offsetY       = minCoeffSizeY * uiAbsPartIdx;
     383    for (UInt ch=0; ch < pcCU->getPic()->getNumberValidComponents(); ch++)
     384    {
     385      const ComponentID compID = ComponentID(ch);
     386      const UInt offset = offsetY >> (pcCU->getPic()->getComponentScaleX(compID) + pcCU->getPic()->getComponentScaleY(compID));
     387      Pel * pPCMSample  = pcCU->getPCMSample(compID) + offset;
     388      const UInt width  = pcCU->getWidth (uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleX(compID);
     389      const UInt height = pcCU->getHeight(uiAbsPartIdx) >> pcCU->getPic()->getComponentScaleY(compID);
     390      const UInt sampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepth(toChannelType(compID));
     391      for (UInt y=0; y<height; y++)
     392      {
     393        for (UInt x=0; x<width; x++)
    367394        {
    368           uiSample = uiGrayVal;
     395          UInt sample;
     396          m_pcTDecBinIf->xReadPCMCode(sampleBits, sample);
     397          pPCMSample[x] = sample;
    369398        }
    370         else
    371 #endif
    372         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    373         piPCMSample[uiX] = uiSample;
    374       }
    375       piPCMSample += uiWidth;
    376     }
    377 
    378     piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
    379     uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    380     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    381     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    382 
    383     for(uiY = 0; uiY < uiHeight; uiY++)
    384     {
    385       for(uiX = 0; uiX < uiWidth; uiX++)
    386       {
    387         UInt uiSample;
    388 #if AUXILIARY_PICTURES
    389         if (format == CHROMA_400)
    390         {
    391           uiSample = uiGrayVal;
    392         }
    393         else
    394 #endif
    395         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
    396         piPCMSample[uiX] = uiSample;
    397       }
    398       piPCMSample += uiWidth;
     399        pPCMSample += width;
     400      }
    399401    }
    400402
     
    406408{
    407409  UInt uiSymbol;
    408   m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) );
     410  m_pcTDecBinIf->decodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__TQ_BYPASS_FLAG) );
    409411  pcCU->setCUTransquantBypassSubParts(uiSymbol ? true : false, uiAbsPartIdx, uiDepth);
    410412}
     
    412414/** parse skip flag
    413415 * \param pcCU
    414  * \param uiAbsPartIdx 
     416 * \param uiAbsPartIdx
    415417 * \param uiDepth
    416418 * \returns Void
     
    422424    return;
    423425  }
    424  
     426
    425427  UInt uiSymbol = 0;
    426428  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
    427   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
     429  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SKIP_FLAG) );
    428430  DTRACE_CABAC_VL( g_nSymbolCounter++ );
    429431  DTRACE_CABAC_T( "\tSkipFlag" );
     
    433435  DTRACE_CABAC_V( uiSymbol );
    434436  DTRACE_CABAC_T( "\n");
    435  
     437
    436438  if( uiSymbol )
    437439  {
     
    444446}
    445447
     448
    446449/** parse merge flag
    447450 * \param pcCU
    448  * \param uiAbsPartIdx 
     451 * \param uiAbsPartIdx
    449452 * \param uiDepth
    450453 * \param uiPUIdx
     
    454457{
    455458  UInt uiSymbol;
    456   m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) );
     459  m_pcTDecBinIf->decodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_FLAG) );
    457460  pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth );
    458461
     
    461464  DTRACE_CABAC_V( uiSymbol );
    462465  DTRACE_CABAC_T( "\tAddress: " );
    463   DTRACE_CABAC_V( pcCU->getAddr() );
     466  DTRACE_CABAC_V( pcCU->getCtuRsAddr() );
    464467  DTRACE_CABAC_T( "\tuiAbsPartIdx: " );
    465468  DTRACE_CABAC_V( uiAbsPartIdx );
     
    478481      if ( uiUnaryIdx==0 )
    479482      {
    480         m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) );
     483        m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
    481484      }
    482485      else
    483486      {
    484         m_pcTDecBinIf->decodeBinEP( uiSymbol );
     487        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MERGE_INDEX) );
    485488      }
    486489      if( uiSymbol == 0 )
     
    502505{
    503506  UInt uiSymbol;
    504   xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1);
     507  xReadUnaryMaxSymbol(uiSymbol, m_cMVPIdxSCModel.get(0), 1, AMVP_MAX_NUM_CANDS-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVP_IDX) );
    505508  riMVPIdx = uiSymbol;
    506509}
     
    513516    return;
    514517  }
    515  
     518#if RExt__DECODER_DEBUG_BIT_STATISTICS
     519  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__SPLIT_FLAG, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2);
     520#endif
     521
    516522  UInt uiSymbol;
    517   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) );
     523  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUSplitFlagSCModel.get( 0, 0, pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    518524  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    519525  DTRACE_CABAC_T( "\tSplitFlag\n" )
    520526  pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx );
    521  
     527
    522528  return;
    523529}
     
    525531/** parse partition size
    526532 * \param pcCU
    527  * \param uiAbsPartIdx 
     533 * \param uiAbsPartIdx
    528534 * \param uiDepth
    529535 * \returns Void
     
    534540  PartSize eMode;
    535541
     542#if RExt__DECODER_DEBUG_BIT_STATISTICS
     543  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__PART_SIZE, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2);
     544#endif
     545
    536546  if ( pcCU->isIntra( uiAbsPartIdx ) )
    537547  {
     
    539549    if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    540550    {
    541       m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) );
     551      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    542552    }
    543553    eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN;
    544     UInt uiTrLevel = 0;   
     554    UInt uiTrLevel = 0;
    545555    UInt uiWidthInBit  = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2;
    546556    UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2;
     
    558568  {
    559569    UInt uiMaxNumBits = 2;
     570
    560571    if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( (g_uiMaxCUWidth>>uiDepth) == 8 && (g_uiMaxCUHeight>>uiDepth) == 8 ) )
    561572    {
    562573      uiMaxNumBits ++;
    563574    }
     575
    564576    for ( UInt ui = 0; ui < uiMaxNumBits; ui++ )
    565577    {
    566       m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) );
     578      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, ui) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    567579      if ( uiSymbol )
    568580      {
     
    576588      if (eMode == SIZE_2NxN)
    577589      {
    578         m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
     590        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
    579591        if (uiSymbol == 0)
    580592        {
    581           m_pcTDecBinIf->decodeBinEP(uiSymbol);
     593          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    582594          eMode = (uiSymbol == 0? SIZE_2NxnU : SIZE_2NxnD);
    583595        }
     
    585597      else if (eMode == SIZE_Nx2N)
    586598      {
    587         m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
     599        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    588600        if (uiSymbol == 0)
    589601        {
    590           m_pcTDecBinIf->decodeBinEP(uiSymbol);
     602          m_pcTDecBinIf->decodeBinEP(uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    591603          eMode = (uiSymbol == 0? SIZE_nLx2N : SIZE_nRx2N);
    592604        }
     
    598610}
    599611
     612
    600613/** parse prediction mode
    601614 * \param pcCU
    602  * \param uiAbsPartIdx 
     615 * \param uiAbsPartIdx
    603616 * \param uiDepth
    604617 * \returns Void
     
    611624    return;
    612625  }
    613  
     626
    614627  UInt uiSymbol;
    615628  Int  iPredMode = MODE_INTER;
    616   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) );
     629  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUPredModeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__PRED_MODE) );
    617630  iPredMode += uiSymbol;
    618631  pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth );
    619632}
    620633
     634
    621635Void TDecSbac::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt absPartIdx, UInt depth )
    622636{
    623637  PartSize mode = pcCU->getPartitionSize( absPartIdx );
    624638  UInt partNum = mode==SIZE_NxN?4:1;
    625   UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
     639  UInt partOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2;
    626640  UInt mpmPred[4],symbol;
    627   Int j,intraPredMode;   
     641  Int j,intraPredMode;
    628642  if (mode==SIZE_NxN)
    629643  {
    630644    depth++;
    631645  }
     646#if RExt__DECODER_DEBUG_BIT_STATISTICS
     647  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[g_uiMaxCUWidth>>depth]+2, CHANNEL_TYPE_LUMA);
     648#endif
    632649  for (j=0;j<partNum;j++)
    633650  {
    634     m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) );
     651    m_pcTDecBinIf->decodeBin( symbol, m_cCUIntraPredSCModel.get( 0, 0, 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    635652    mpmPred[j] = symbol;
    636653  }
    637654  for (j=0;j<partNum;j++)
    638655  {
    639     Int preds[3] = {-1, -1, -1};
    640     Int predNum = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds); 
     656    Int preds[NUM_MOST_PROBABLE_MODES] = {-1, -1, -1};
     657    Int predNum = pcCU->getIntraDirPredictor(absPartIdx+partOffset*j, preds, COMPONENT_Y);
    641658    if (mpmPred[j])
    642659    {
    643       m_pcTDecBinIf->decodeBinEP( symbol );
     660      m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    644661      if (symbol)
    645662      {
    646         m_pcTDecBinIf->decodeBinEP( symbol );
     663        m_pcTDecBinIf->decodeBinEP( symbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    647664        symbol++;
    648665      }
     
    651668    else
    652669    {
    653       m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
     670      m_pcTDecBinIf->decodeBinsEP( symbol, 5 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    654671      intraPredMode = symbol;
    655        
     672
    656673      //postponed sorting of MPMs (only in remaining branch)
     674      assert(predNum>=3); // It is currently always 3!
    657675      if (preds[0] > preds[1])
    658       { 
    659         std::swap(preds[0], preds[1]); 
     676      {
     677        std::swap(preds[0], preds[1]);
    660678      }
    661679      if (preds[0] > preds[2])
     
    672690      }
    673691    }
    674     pcCU->setLumaIntraDirSubParts( (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
    675   }
    676 }
     692    pcCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, (UChar)intraPredMode, absPartIdx+partOffset*j, depth );
     693  }
     694}
     695
    677696
    678697Void TDecSbac::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    679698{
    680699  UInt uiSymbol;
    681 
    682 #if AUXILIARY_PICTURES
    683   if ( pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 )
    684   {
    685     uiSymbol = DC_IDX;
     700#if RExt__DECODER_DEBUG_BIT_STATISTICS
     701  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__INTRA_DIR_ANG, g_aucConvertToBit[g_uiMaxCUWidth>>uiDepth]+2, CHANNEL_TYPE_CHROMA);
     702#endif
     703
     704  m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     705  if( uiSymbol == 0 )
     706  {
     707    uiSymbol = DM_CHROMA_IDX;
    686708  }
    687709  else
    688710  {
    689 #endif
    690   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
    691 
    692   if( uiSymbol == 0 )
    693   {
    694     uiSymbol = DM_CHROMA_IDX;
    695   }
    696   else
    697   {
    698     {
    699       UInt uiIPredMode;
    700       m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 );
    701       UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
    702       pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
    703       uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
    704     }
    705   }
    706 #if AUXILIARY_PICTURES
    707   }
    708 #endif
    709   pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
    710   return;
    711 }
     711    UInt uiIPredMode;
     712    m_pcTDecBinIf->decodeBinsEP( uiIPredMode, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     713    UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ];
     714    pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir );
     715    uiSymbol = uiAllowedChromaDir[ uiIPredMode ];
     716  }
     717
     718  pcCU->setIntraDirSubParts( CHANNEL_TYPE_CHROMA, uiSymbol, uiAbsPartIdx, uiDepth );
     719}
     720
    712721
    713722Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
     
    716725  const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
    717726  ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
     727
    718728  uiSymbol = 0;
    719729  if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
    720730  {
    721     m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
     731    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
    722732  }
    723733
     
    728738  else
    729739  {
    730     m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) );
     740    m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + 4 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__INTER_DIR) );
    731741    assert(uiSymbol == 0 || uiSymbol == 1);
    732742  }
     
    740750{
    741751  UInt uiSymbol;
    742   {
    743     ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
    744     m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
    745 
    746     if( uiSymbol )
    747     {
    748       UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
    749       pCtx++;
    750       UInt ui;
    751       for( ui = 0; ui < uiRefNum; ++ui )
    752       {
    753         if( ui == 0 )
    754         {
    755           m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
    756         }
    757         else
    758         {
    759           m_pcTDecBinIf->decodeBinEP( uiSymbol );
    760         }
    761         if( uiSymbol == 0 )
    762         {
    763           break;
    764         }
    765       }
    766       uiSymbol = ui + 1;
    767     }
    768     riRefFrmIdx = uiSymbol;
    769   }
     752
     753  ContextModel *pCtx = m_cCURefPicSCModel.get( 0 );
     754  m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     755
     756  if( uiSymbol )
     757  {
     758    UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
     759    pCtx++;
     760    UInt ui;
     761    for( ui = 0; ui < uiRefNum; ++ui )
     762    {
     763      if( ui == 0 )
     764      {
     765        m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     766      }
     767      else
     768      {
     769        m_pcTDecBinIf->decodeBinEP( uiSymbol RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__REF_FRM_IDX) );
     770      }
     771      if( uiSymbol == 0 )
     772      {
     773        break;
     774      }
     775    }
     776    uiSymbol = ui + 1;
     777  }
     778  riRefFrmIdx = uiSymbol;
    770779
    771780  return;
     
    788797  else
    789798  {
    790     m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx );
    791     m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx );
     799    m_pcTDecBinIf->decodeBin( uiHorAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
     800    m_pcTDecBinIf->decodeBin( uiVerAbs, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    792801
    793802    const Bool bHorAbsGr0 = uiHorAbs != 0;
     
    797806    if( bHorAbsGr0 )
    798807    {
    799       m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
     808      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    800809      uiHorAbs += uiSymbol;
    801810    }
     
    803812    if( bVerAbsGr0 )
    804813    {
    805       m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx );
     814      m_pcTDecBinIf->decodeBin( uiSymbol, *pCtx RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD) );
    806815      uiVerAbs += uiSymbol;
    807816    }
     
    811820      if( 2 == uiHorAbs )
    812821      {
    813         xReadEpExGolomb( uiSymbol, 1 );
     822        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    814823        uiHorAbs += uiSymbol;
    815824      }
    816825
    817       m_pcTDecBinIf->decodeBinEP( uiHorSign );
     826      m_pcTDecBinIf->decodeBinEP( uiHorSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    818827    }
    819828
     
    822831      if( 2 == uiVerAbs )
    823832      {
    824         xReadEpExGolomb( uiSymbol, 1 );
     833        xReadEpExGolomb( uiSymbol, 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    825834        uiVerAbs += uiSymbol;
    826835      }
    827836
    828       m_pcTDecBinIf->decodeBinEP( uiVerSign );
     837      m_pcTDecBinIf->decodeBinEP( uiVerSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__MVD_EP) );
    829838    }
    830839
     
    836845}
    837846
     847Void TDecSbac::parseCrossComponentPrediction( TComTU &rTu, ComponentID compID )
     848{
     849  TComDataCU *pcCU = rTu.getCU();
     850
     851  if( isLuma(compID) || !pcCU->getSlice()->getPPS()->getUseCrossComponentPrediction() ) return;
     852
     853  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
     854
     855  if (!pcCU->isIntra(uiAbsPartIdx) || (pcCU->getIntraDir( CHANNEL_TYPE_CHROMA, uiAbsPartIdx ) == DM_CHROMA_IDX))
     856  {
     857    Char alpha  = 0;
     858    UInt symbol = 0;
     859
     860    DTRACE_CABAC_VL( g_nSymbolCounter++ )
     861    DTRACE_CABAC_T("\tparseCrossComponentPrediction()")
     862    DTRACE_CABAC_T( "\tAddr=" )
     863    DTRACE_CABAC_V( compID )
     864    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     865    DTRACE_CABAC_V( uiAbsPartIdx )
     866#if RExt__DECODER_DEBUG_BIT_STATISTICS
     867    TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, (g_aucConvertToBit[rTu.getRect(compID).width] + 2), compID);
     868#endif
     869    ContextModel *pCtx = m_cCrossComponentPredictionSCModel.get(0, 0) + ((compID == COMPONENT_Cr) ? (NUM_CROSS_COMPONENT_PREDICTION_CTX >> 1) : 0);
     870    m_pcTDecBinIf->decodeBin( symbol, pCtx[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     871
     872    if(symbol != 0)
     873    {
     874      // Cross-component prediction alpha is non-zero.
     875      UInt sign = 0;
     876      m_pcTDecBinIf->decodeBin( symbol, pCtx[1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     877
     878      if (symbol != 0)
     879      {
     880        // alpha is 2 (symbol=1), 4(symbol=2) or 8(symbol=3).
     881        // Read up to two more bits
     882        xReadUnaryMaxSymbol( symbol, (pCtx + 2), 1, 2 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     883        symbol += 1;
     884      }
     885      m_pcTDecBinIf->decodeBin( sign, pCtx[4] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     886
     887      alpha = (sign != 0) ? -(1 << symbol) : (1 << symbol);
     888    }
     889    DTRACE_CABAC_T( "\tAlpha=" )
     890    DTRACE_CABAC_V( alpha )
     891    DTRACE_CABAC_T( "\n" )
     892
     893    pcCU->setCrossComponentPredictionAlphaPartRange( alpha, compID, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts( compID ) );
     894  }
     895}
    838896
    839897Void TDecSbac::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
    840898{
    841   m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize ) );
     899  m_pcTDecBinIf->decodeBin( ruiSubdivFlag, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiLog2TransformBlockSize )
     900      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, 5-uiLog2TransformBlockSize))
     901                          );
    842902  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    843903  DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" )
     
    853913  UInt uiSymbol;
    854914  const UInt uiCtx = 0;
    855   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) );
     915  m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__QT_ROOT_CBF) );
    856916  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    857917  DTRACE_CABAC_T( "\tparseQtRootCbf()" )
     
    863923  DTRACE_CABAC_V( uiAbsPartIdx )
    864924  DTRACE_CABAC_T( "\n" )
    865  
     925
    866926  uiQtRootCbf = uiSymbol;
    867927}
     
    872932  UInt uiDQp;
    873933  Int  iDQp;
    874  
     934
    875935  UInt uiSymbol;
    876936
    877   xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX);
     937  xReadUnaryMaxSymbol (uiDQp,  &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP) );
    878938
    879939  if( uiDQp >= CU_DQP_TU_CMAX)
    880940  {
    881     xReadEpExGolomb( uiSymbol, CU_DQP_EG_k );
     941    xReadEpExGolomb( uiSymbol, CU_DQP_EG_k RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
    882942    uiDQp+=uiSymbol;
    883943  }
     
    889949    Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
    890950#else
    891     Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    892 #endif
    893     m_pcTDecBinIf->decodeBinEP(uiSign);
     951    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
     952#endif
     953    m_pcTDecBinIf->decodeBinEP(uiSign RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__DELTA_QP_EP));
    894954    iDQp = uiDQp;
    895955    if(uiSign)
     
    899959    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
    900960  }
    901   else 
     961  else
    902962  {
    903963    qp = pcCU->getRefQP(uiAbsPartIdx);
    904964  }
    905   pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth); 
     965
     966  pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);
    906967  pcCU->setCodedQP(qp);
    907968}
    908969
    909 Void TDecSbac::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
    910 {
    911   UInt uiSymbol;
    912   const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
    913 #if AUXILIARY_PICTURES
    914   if (pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 && (eType == TEXT_CHROMA_U || eType == TEXT_CHROMA_V))
    915   {
    916     uiSymbol = 0;
     970/** parse chroma qp adjustment, converting to the internal table representation.
     971 * \returns Void
     972 */
     973Void TDecSbac::parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth )
     974{
     975  UInt symbol;
     976#if RExt__DECODER_DEBUG_BIT_STATISTICS
     977  const TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, g_aucConvertToBit[g_uiMaxCUWidth>>depth]+2, CHANNEL_TYPE_CHROMA);
     978#endif
     979
     980  Int tableSize = cu->getSlice()->getPPS()->getChromaQpAdjTableSize();
     981
     982  /* cu_chroma_qp_adjustment_flag */
     983  m_pcTDecBinIf->decodeBin( symbol, m_ChromaQpAdjFlagSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     984
     985  if (symbol && tableSize > 1) {
     986    /* cu_chroma_qp_adjustment_idc */
     987    xReadUnaryMaxSymbol( symbol,  &m_ChromaQpAdjIdcSCModel.get( 0, 0, 0 ), 0, tableSize - 1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     988    symbol++;
     989  }
     990  /* NB, symbol = 0 if outer flag is not set,
     991   *              1 if outer flag is set and there is no inner flag
     992   *              1+ otherwise */
     993  cu->setChromaQpAdjSubParts( symbol, absPartIdx, depth );
     994  cu->setCodedChromaQpAdj(symbol);
     995}
     996
     997Void TDecSbac::parseQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
     998{
     999  TComDataCU* pcCU = rTu.getCU();
     1000
     1001  const UInt absPartIdx       = rTu.GetAbsPartIdxTU(compID);
     1002  const UInt TUDepth          = rTu.GetTransformDepthRel();
     1003  const UInt uiCtx            = pcCU->getCtxQtCbf( rTu, toChannelType(compID) );
     1004  const UInt contextSet       = toChannelType(compID);
     1005
     1006  const UInt width            = rTu.getRect(compID).width;
     1007  const UInt height           = rTu.getRect(compID).height;
     1008  const Bool canQuadSplit     = (width >= (MIN_TU_SIZE * 2)) && (height >= (MIN_TU_SIZE * 2));
     1009  const UInt coveredPartIdxes = rTu.GetAbsPartIdxNumParts(compID);
     1010
     1011  //             Since the CBF for chroma is coded at the highest level possible, if sub-TUs are
     1012  //             to be coded for a 4x8 chroma TU, their CBFs must be coded at the highest 4x8 level
     1013  //             (i.e. where luma TUs are 8x8 rather than 4x4)
     1014  //    ___ ___
     1015  //   |   |   | <- 4 x (8x8 luma + 4x8 4:2:2 chroma)
     1016  //   |___|___|    each quadrant has its own chroma CBF
     1017  //   |   |   | _ _ _ _
     1018  //   |___|___|        |
     1019  //   <--16--->        V
     1020  //                   _ _
     1021  //                  |_|_| <- 4 x 4x4 luma + 1 x 4x8 4:2:2 chroma
     1022  //                  |_|_|    no chroma CBF is coded - instead the parent CBF is inherited
     1023  //                  <-8->    if sub-TUs are present, their CBFs had to be coded at the parent level
     1024
     1025  const UInt lowestTUDepth = TUDepth + ((!lowestLevel && !canQuadSplit) ? 1 : 0); //unsplittable TUs inherit their parent's CBF
     1026        UInt lowestTUCBF   = 0;
     1027
     1028  if ((width != height) && (lowestLevel || !canQuadSplit)) //if sub-TUs are present
     1029  {
     1030    const UInt subTUDepth        = lowestTUDepth + 1;
     1031    const UInt partIdxesPerSubTU = rTu.GetAbsPartIdxNumParts(compID) >> 1;
     1032
     1033    UInt combinedSubTUCBF = 0;
     1034
     1035    for (UInt subTU = 0; subTU < 2; subTU++)
     1036    {
     1037      UInt uiCbf = MAX_UINT;
     1038      m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
     1039
     1040      const UInt subTUAbsPartIdx = absPartIdx + (subTU * partIdxesPerSubTU);
     1041      pcCU->setCbfPartRange((uiCbf << subTUDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
     1042      combinedSubTUCBF |= uiCbf;
     1043
     1044      DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1045      DTRACE_CABAC_T( "\tparseQtCbf()" )
     1046      DTRACE_CABAC_T( "\tsub-TU=" )
     1047      DTRACE_CABAC_V( subTU )
     1048      DTRACE_CABAC_T( "\tsymbol=" )
     1049      DTRACE_CABAC_V( uiCbf )
     1050      DTRACE_CABAC_T( "\tctx=" )
     1051      DTRACE_CABAC_V( uiCtx )
     1052      DTRACE_CABAC_T( "\tetype=" )
     1053      DTRACE_CABAC_V( compID )
     1054      DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1055      DTRACE_CABAC_V( subTUAbsPartIdx )
     1056      DTRACE_CABAC_T( "\n" )
     1057    }
     1058
     1059    //propagate the sub-TU CBF up to the lowest TU level
     1060    if (combinedSubTUCBF != 0)
     1061    {
     1062      pcCU->bitwiseOrCbfPartRange((combinedSubTUCBF << lowestTUDepth), compID, absPartIdx, coveredPartIdxes);
     1063      lowestTUCBF = combinedSubTUCBF;
     1064    }
    9171065  }
    9181066  else
    9191067  {
    920 #endif
    921   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
    922 #if AUXILIARY_PICTURES
    923   }
    924 #endif
    925  
    926   DTRACE_CABAC_VL( g_nSymbolCounter++ )
    927   DTRACE_CABAC_T( "\tparseQtCbf()" )
    928   DTRACE_CABAC_T( "\tsymbol=" )
    929   DTRACE_CABAC_V( uiSymbol )
    930   DTRACE_CABAC_T( "\tctx=" )
    931   DTRACE_CABAC_V( uiCtx )
    932   DTRACE_CABAC_T( "\tetype=" )
    933   DTRACE_CABAC_V( eType )
    934   DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
    935   DTRACE_CABAC_V( uiAbsPartIdx )
    936   DTRACE_CABAC_T( "\n" )
    937  
    938   pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth );
    939 }
    940 
    941 void TDecSbac::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
    942 {
     1068    UInt uiCbf = MAX_UINT;
     1069    m_pcTDecBinIf->decodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, contextSet, uiCtx) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__QT_CBF, g_aucConvertToBit[rTu.getRect(compID).width]+2, compID)));
     1070
     1071    pcCU->setCbfSubParts((uiCbf << lowestTUDepth), compID, absPartIdx, rTu.GetTransformDepthTotalAdj(compID));
     1072
     1073    DTRACE_CABAC_VL( g_nSymbolCounter++ )
     1074    DTRACE_CABAC_T( "\tparseQtCbf()" )
     1075    DTRACE_CABAC_T( "\tsymbol=" )
     1076    DTRACE_CABAC_V( uiCbf )
     1077    DTRACE_CABAC_T( "\tctx=" )
     1078    DTRACE_CABAC_V( uiCtx )
     1079    DTRACE_CABAC_T( "\tetype=" )
     1080    DTRACE_CABAC_V( compID )
     1081    DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
     1082    DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
     1083    DTRACE_CABAC_T( "\n" )
     1084
     1085    lowestTUCBF = uiCbf;
     1086  }
     1087
     1088  //propagate the lowest level CBF up to the current level
     1089  if (lowestTUCBF != 0)
     1090  {
     1091    for (UInt depth = TUDepth; depth < lowestTUDepth; depth++)
     1092    {
     1093      pcCU->bitwiseOrCbfPartRange((lowestTUCBF << depth), compID, absPartIdx, coveredPartIdxes);
     1094    }
     1095  }
     1096}
     1097
     1098
     1099Void TDecSbac::parseTransformSkipFlags (TComTU &rTu, ComponentID component)
     1100{
     1101  TComDataCU* pcCU=rTu.getCU();
     1102  UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(component);
     1103
    9431104  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
    9441105  {
    9451106    return;
    9461107  }
    947   if(width != 4 || height != 4)
     1108
     1109  if (!TUCompRectHasAssociatedTransformSkipFlag(rTu.getRect(component), pcCU->getSlice()->getPPS()->getTransformSkipLog2MaxSize()))
    9481110  {
    9491111    return;
    9501112  }
    951  
     1113
    9521114  UInt useTransformSkip;
    953   m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
    954   if(eTType!= TEXT_LUMA)
    955   {
    956     const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
    957     if(uiLog2TrafoSize == 2)
    958     {
    959       uiDepth --;
    960     }
    961   }
     1115
     1116  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, toChannelType(component), 0 )
     1117      RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(TComCodingStatisticsClassType(STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, component))
     1118                          );
     1119
    9621120  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    9631121  DTRACE_CABAC_T("\tparseTransformSkip()");
     
    9651123  DTRACE_CABAC_V( useTransformSkip )
    9661124  DTRACE_CABAC_T( "\tAddr=" )
    967   DTRACE_CABAC_V( pcCU->getAddr() )
     1125  DTRACE_CABAC_V( pcCU->getCtuRsAddr() )
    9681126  DTRACE_CABAC_T( "\tetype=" )
    969   DTRACE_CABAC_V( eTType )
     1127  DTRACE_CABAC_V( component )
    9701128  DTRACE_CABAC_T( "\tuiAbsPartIdx=" )
    971   DTRACE_CABAC_V( uiAbsPartIdx )
     1129  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU() )
    9721130  DTRACE_CABAC_T( "\n" )
    9731131
    974   pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
    975 }
     1132  pcCU->setTransformSkipPartRange( useTransformSkip, component, uiAbsPartIdx, rTu.GetAbsPartIdxNumParts(component));
     1133}
     1134
    9761135
    9771136/** Parse (X,Y) position of the last significant coefficient
     
    9851144 * This method decodes the X and Y component within a block of the last significant coefficient.
    9861145 */
    987 Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx )
     1146Void TDecSbac::parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx )
    9881147{
    9891148  UInt uiLast;
    990   ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType );
    991   ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType );
     1149
     1150  ContextModel *pCtxX = m_cCuCtxLastX.get( 0, toChannelType(component) );
     1151  ContextModel *pCtxY = m_cCuCtxLastY.get( 0, toChannelType(component) );
     1152
     1153#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1154  TComCodingStatisticsClassType ctype(STATS__CABAC_BITS__LAST_SIG_X_Y, g_aucConvertToBit[width]+2, component);
     1155#endif
     1156
     1157
     1158  if ( uiScanIdx == SCAN_VER )
     1159  {
     1160    swap( width, height );
     1161  }
    9921162
    9931163  Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY;
    994   blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
    995   blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
    996   shiftX= eTType ? g_aucConvertToBit[ width  ] :((g_aucConvertToBit[ width  ]+3)>>2);
    997   shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
     1164  getLastSignificantContextParameters(component, width, height, blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY);
     1165
     1166  //------------------
     1167
    9981168  // posX
     1169
    9991170  for( uiPosLastX = 0; uiPosLastX < g_uiGroupIdx[ width - 1 ]; uiPosLastX++ )
    10001171  {
    1001     m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) );
     1172    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxX + blkSizeOffsetX + (uiPosLastX >>shiftX) ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1173
    10021174    if( !uiLast )
    10031175    {
     
    10071179
    10081180  // posY
     1181
    10091182  for( uiPosLastY = 0; uiPosLastY < g_uiGroupIdx[ height - 1 ]; uiPosLastY++ )
    10101183  {
    1011     m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) );
     1184    m_pcTDecBinIf->decodeBin( uiLast, *( pCtxY + blkSizeOffsetY + (uiPosLastY >>shiftY)) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
     1185
    10121186    if( !uiLast )
    10131187    {
     
    10151189    }
    10161190  }
     1191
     1192  // EP-coded part
     1193
    10171194  if ( uiPosLastX > 3 )
    10181195  {
     
    10211198    for ( Int i = uiCount - 1; i >= 0; i-- )
    10221199    {
    1023       m_pcTDecBinIf->decodeBinEP( uiLast );
     1200      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    10241201      uiTemp += uiLast << i;
    10251202    }
     
    10321209    for ( Int i = uiCount - 1; i >= 0; i-- )
    10331210    {
    1034       m_pcTDecBinIf->decodeBinEP( uiLast );
     1211      m_pcTDecBinIf->decodeBinEP( uiLast RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype) );
    10351212      uiTemp += uiLast << i;
    10361213    }
    10371214    uiPosLastY = g_uiMinInGroup[ uiPosLastY ] + uiTemp;
    10381215  }
    1039  
     1216
    10401217  if( uiScanIdx == SCAN_VER )
    10411218  {
     
    10441221}
    10451222
    1046 Void TDecSbac::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
    1047 {
     1223Void TDecSbac::parseCoeffNxN(  TComTU &rTu, ComponentID compID )
     1224{
     1225  TComDataCU* pcCU=rTu.getCU();
     1226  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(compID);
     1227  const TComRectangle &rRect=rTu.getRect(compID);
     1228  const UInt uiWidth=rRect.width;
     1229  const UInt uiHeight=rRect.height;
     1230  TCoeff* pcCoef=(pcCU->getCoeff(compID)+rTu.getCoefficientOffset(compID));
     1231
    10481232  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    10491233  DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" )
    1050   DTRACE_CABAC_V( eTType )
     1234  DTRACE_CABAC_V( compID )
    10511235  DTRACE_CABAC_T( "\twidth=" )
    10521236  DTRACE_CABAC_V( uiWidth )
     
    10541238  DTRACE_CABAC_V( uiHeight )
    10551239  DTRACE_CABAC_T( "\tdepth=" )
    1056   DTRACE_CABAC_V( uiDepth )
     1240//  DTRACE_CABAC_V( rTu.GetTransformDepthTotalAdj(compID) )
     1241  DTRACE_CABAC_V( rTu.GetTransformDepthTotal() )
    10571242  DTRACE_CABAC_T( "\tabspartidx=" )
    1058   DTRACE_CABAC_V( uiAbsPartIdx )
     1243//  DTRACE_CABAC_V( uiAbsPartIdx )
     1244  DTRACE_CABAC_V( rTu.GetAbsPartIdxTU(compID) )
    10591245  DTRACE_CABAC_T( "\ttoCU-X=" )
    10601246  DTRACE_CABAC_V( pcCU->getCUPelX() )
     
    10621248  DTRACE_CABAC_V( pcCU->getCUPelY() )
    10631249  DTRACE_CABAC_T( "\tCU-addr=" )
    1064   DTRACE_CABAC_V(  pcCU->getAddr() )
     1250  DTRACE_CABAC_V(  pcCU->getCtuRsAddr() )
    10651251  DTRACE_CABAC_T( "\tinCU-X=" )
    1066   DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1252//  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1253  DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
    10671254  DTRACE_CABAC_T( "\tinCU-Y=" )
    1068   DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1255// DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] )
     1256  DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[rTu.GetAbsPartIdxTU(compID)] ] )
    10691257  DTRACE_CABAC_T( "\tpredmode=" )
    10701258  DTRACE_CABAC_V(  pcCU->getPredictionMode( uiAbsPartIdx ) )
    10711259  DTRACE_CABAC_T( "\n" )
    1072  
     1260
     1261  //--------------------------------------------------------------------------------------------------
     1262
    10731263  if( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() )
    10741264  {
    1075     uiWidth  = pcCU->getSlice()->getSPS()->getMaxTrSize();
    1076     uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
    1077   }
     1265    std::cerr << "ERROR: parseCoeffNxN was passed a TU with dimensions larger than the maximum allowed size" << std::endl;
     1266    assert(false);
     1267    exit(1);
     1268  }
     1269
     1270  //--------------------------------------------------------------------------------------------------
     1271
     1272  //set parameters
     1273
     1274  const ChannelType  chType            = toChannelType(compID);
     1275  const UInt         uiLog2BlockWidth  = g_aucConvertToBit[ uiWidth  ] + 2;
     1276  const UInt         uiLog2BlockHeight = g_aucConvertToBit[ uiHeight ] + 2;
     1277  const UInt         uiMaxNumCoeff     = uiWidth * uiHeight;
     1278  const UInt         uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
     1279
     1280  const ChannelType  channelType       = toChannelType(compID);
     1281  const Bool         extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision();
     1282
     1283  const Bool         alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass();
     1284
     1285#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1286  TComCodingStatisticsClassType ctype_group(STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, uiLog2BlockWidth, compID);
     1287  TComCodingStatisticsClassType ctype_map(STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, uiLog2BlockWidth, compID);
     1288  TComCodingStatisticsClassType ctype_gt1(STATS__CABAC_BITS__GT1_FLAG, uiLog2BlockWidth, compID);
     1289  TComCodingStatisticsClassType ctype_gt2(STATS__CABAC_BITS__GT2_FLAG, uiLog2BlockWidth, compID);
     1290#endif
     1291
     1292  Bool beValid;
     1293  if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
     1294  {
     1295    beValid = false;
     1296    if((!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx))
     1297      parseExplicitRdpcmMode(rTu, compID);
     1298  }
     1299  else
     1300  {
     1301    beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
     1302  }
     1303
     1304  UInt absSum = 0;
     1305
     1306  //--------------------------------------------------------------------------------------------------
     1307
    10781308  if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
    10791309  {
    1080     parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
    1081   }
    1082 
    1083   eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA );
    1084  
    1085   //----- parse significance map -----
    1086   const UInt  uiLog2BlockSize   = g_aucConvertToBit[ uiWidth ] + 2;
    1087   const UInt  uiMaxNumCoeff     = uiWidth * uiHeight;
    1088   const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
    1089   UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
    1090  
     1310    parseTransformSkipFlags(rTu, compID);
     1311    //  This TU has coefficients and is transform skipped. Check whether is inter coded and if yes decode the explicit RDPCM mode
     1312    if(pcCU->getTransformSkip(uiAbsPartIdx, compID) && (!pcCU->isIntra(uiAbsPartIdx)) && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
     1313    {
     1314      parseExplicitRdpcmMode(rTu, compID);
     1315      if(pcCU->getExplicitRdpcmMode(compID, uiAbsPartIdx) != RDPCM_OFF)
     1316      {
     1317        //  Sign data hiding is avoided for horizontal and vertical RDPCM modes
     1318        beValid = false;
     1319      }
     1320    }
     1321  }
     1322
     1323  Int uiIntraMode = -1;
     1324  const Bool       bIsLuma = isLuma(compID);
     1325  Int isIntra = pcCU->isIntra(uiAbsPartIdx) ? 1 : 0;
     1326  if ( isIntra && pcCU->isRDPCMEnabled(uiAbsPartIdx) )
     1327  {
     1328    uiIntraMode = pcCU->getIntraDir( toChannelType(compID), uiAbsPartIdx );
     1329    uiIntraMode = (uiIntraMode==DM_CHROMA_IDX && !bIsLuma) ? pcCU->getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, rTu.GetChromaFormat())) : uiIntraMode;
     1330    uiIntraMode = ((rTu.GetChromaFormat() == CHROMA_422) && !bIsLuma) ? g_chroma422IntraAngleMappingTable[uiIntraMode] : uiIntraMode;
     1331
     1332    Bool transformSkip = pcCU->getTransformSkip( uiAbsPartIdx,compID);
     1333    Bool rdpcm_lossy = ( transformSkip /*&& isIntra*/ && ( (uiIntraMode == HOR_IDX) || (uiIntraMode == VER_IDX) ) );
     1334    if ( rdpcm_lossy )
     1335    {
     1336      beValid = false;
     1337    }
     1338  }
     1339
     1340  //--------------------------------------------------------------------------------------------------
     1341
     1342  const Bool  bUseGolombRiceParameterAdaptation = pcCU->getSlice()->getSPS()->getUseGolombRiceParameterAdaptation();
     1343        UInt &currentGolombRiceStatistic        = m_golombRiceAdaptationStatistics[rTu.getGolombRiceStatisticsIndex(compID)];
     1344
     1345  //select scans
     1346  TUEntropyCodingParameters codingParameters;
     1347  getTUEntropyCodingParameters(codingParameters, rTu, compID);
     1348
    10911349  //===== decode last significant =====
    10921350  UInt uiPosLastX, uiPosLastY;
    1093   parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, eTType, uiScanIdx );
    1094   UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockSize);
     1351  parseLastSignificantXY( uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, codingParameters.scanType );
     1352  UInt uiBlkPosLast      = uiPosLastX + (uiPosLastY<<uiLog2BlockWidth);
    10951353  pcCoef[ uiBlkPosLast ] = 1;
    10961354
    10971355  //===== decode significance flags =====
    10981356  UInt uiScanPosLast;
    1099   const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
    11001357  for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
    11011358  {
    1102     UInt uiBlkPos = scan[ uiScanPosLast ];
     1359    UInt uiBlkPos = codingParameters.scan[ uiScanPosLast ];
    11031360    if( uiBlkPosLast == uiBlkPos )
    11041361    {
     
    11071364  }
    11081365
    1109   ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType );
    1110   ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA;
    1111 
    1112   const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
    1113   UInt c1 = 1;
    1114   UInt uiGoRiceParam           = 0;
    1115 
    1116   Bool beValid;
    1117   if (pcCU->getCUTransquantBypass(uiAbsPartIdx))
    1118   {
    1119     beValid = false;
    1120   }
    1121   else
    1122   {
    1123     beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0;
    1124   }
    1125   UInt absSum = 0;
     1366  ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, isChroma(chType) );
     1367  ContextModel * const baseCtx = m_cCUSigSCModel.get( 0, 0 ) + getSignificanceMapContextOffset(compID);
     1368
     1369  const Int  iLastScanSet  = uiScanPosLast >> MLS_CG_SIZE;
     1370  UInt c1                  = 1;
     1371  UInt uiGoRiceParam       = 0;
     1372
    11261373
    11271374  UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
    1128   ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
    1129   const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
    1130   const UInt * scanCG;
    1131   {
    1132     scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];   
    1133     if( uiLog2BlockSize == 3 )
    1134     {
    1135       scanCG = g_sigLastScan8x8[ uiScanIdx ];
    1136     }
    1137     else if( uiLog2BlockSize == 5 )
    1138     {
    1139       scanCG = g_sigLastScanCG32x32;
    1140     }
    1141   }
     1375  memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );
     1376
    11421377  Int  iScanPosSig             = (Int) uiScanPosLast;
    11431378  for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
    11441379  {
    1145     Int  iSubPos     = iSubSet << LOG2_SCAN_SET_SIZE;
    1146     uiGoRiceParam    = 0;
     1380    Int  iSubPos   = iSubSet << MLS_CG_SIZE;
     1381    uiGoRiceParam  = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
     1382    Bool updateGolombRiceStatistics = bUseGolombRiceParameterAdaptation; //leave the statistics at 0 when not using the adaptation system
    11471383    Int numNonZero = 0;
    1148    
    1149     Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE;
    1150 
    1151     Int pos[SCAN_SET_SIZE];
     1384
     1385    Int lastNZPosInCG  = -1;
     1386    Int firstNZPosInCG = 1 << MLS_CG_SIZE;
     1387
     1388    Bool escapeDataPresentInGroup = false;
     1389
     1390    Int pos[1 << MLS_CG_SIZE];
     1391
    11521392    if( iScanPosSig == (Int) uiScanPosLast )
    11531393    {
     
    11601400
    11611401    // decode significant_coeffgroup_flag
    1162     Int iCGBlkPos = scanCG[ iSubSet ];
    1163     Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
    1164     Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
     1402    Int iCGBlkPos = codingParameters.scanCG[ iSubSet ];
     1403    Int iCGPosY   = iCGBlkPos / codingParameters.widthInGroups;
     1404    Int iCGPosX   = iCGBlkPos - (iCGPosY * codingParameters.widthInGroups);
     1405
    11651406    if( iSubSet == iLastScanSet || iSubSet == 0)
    11661407    {
     
    11701411    {
    11711412      UInt uiSigCoeffGroup;
    1172       UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
    1173       m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
     1413      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups );
     1414      m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_group) );
    11741415      uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
    11751416    }
    11761417
    11771418    // decode significant_coeff_flag
    1178     Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
    1179     UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig;
     1419    const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, iCGPosX, iCGPosY, codingParameters.widthInGroups, codingParameters.heightInGroups);
     1420
     1421    UInt uiBlkPos, uiSig, uiCtxSig;
    11801422    for( ; iScanPosSig >= iSubPos; iScanPosSig-- )
    11811423    {
    1182       uiBlkPos  = scan[ iScanPosSig ];
    1183       uiPosY    = uiBlkPos >> uiLog2BlockSize;
    1184       uiPosX    = uiBlkPos - ( uiPosY << uiLog2BlockSize );
     1424      uiBlkPos  = codingParameters.scan[ iScanPosSig ];
    11851425      uiSig     = 0;
    1186      
     1426
    11871427      if( uiSigCoeffGroupFlag[ iCGBlkPos ] )
    11881428      {
    11891429        if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
    11901430        {
    1191           uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
    1192           m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
     1431          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, codingParameters, iScanPosSig, uiLog2BlockWidth, uiLog2BlockHeight, chType );
     1432          m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_map) );
    11931433        }
    11941434        else
     
    12091449      }
    12101450    }
    1211    
    1212     if( numNonZero )
     1451
     1452    if( numNonZero > 0 )
    12131453    {
    12141454      Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
     1455
    12151456      absSum = 0;
    1216       UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
     1457
     1458      const UInt uiCtxSet = getContextSetIndex(compID, iSubSet, (c1 == 0));
     1459      c1 = 1;
    12171460      UInt uiBin;
    1218       if( c1 == 0 )
    1219       {
    1220         uiCtxSet++;
    1221       }
    1222       c1 = 1;
    1223       ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
    1224       Int absCoeff[SCAN_SET_SIZE];
    1225 
    1226       for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;   
     1461
     1462      ContextModel *baseCtxMod = m_cCUOneSCModel.get( 0, 0 ) + (NUM_ONE_FLAG_CTX_PER_SET * uiCtxSet);
     1463
     1464      Int absCoeff[1 << MLS_CG_SIZE];
     1465
     1466      for ( Int i = 0; i < numNonZero; i++) absCoeff[i] = 1;
    12271467      Int numC1Flag = min(numNonZero, C1FLAG_NUMBER);
    12281468      Int firstC2FlagIdx = -1;
     
    12301470      for( Int idx = 0; idx < numC1Flag; idx++ )
    12311471      {
    1232         m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] );
     1472        m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[c1] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt1) );
    12331473        if( uiBin == 1 )
    12341474        {
     
    12381478            firstC2FlagIdx = idx;
    12391479          }
     1480          else //if a greater-than-one has been encountered already this group
     1481          {
     1482            escapeDataPresentInGroup = true;
     1483          }
    12401484        }
    12411485        else if( (c1 < 3) && (c1 > 0) )
     
    12451489        absCoeff[ idx ] = uiBin + 1;
    12461490      }
    1247      
     1491
    12481492      if (c1 == 0)
    12491493      {
    1250         baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
     1494        baseCtxMod = m_cCUAbsSCModel.get( 0, 0 ) + (NUM_ABS_FLAG_CTX_PER_SET * uiCtxSet);
    12511495        if ( firstC2FlagIdx != -1)
    12521496        {
    1253           m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] );
     1497          m_pcTDecBinIf->decodeBin( uiBin, baseCtxMod[0] RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_gt2) );
    12541498          absCoeff[ firstC2FlagIdx ] = uiBin + 2;
     1499          if (uiBin != 0)
     1500          {
     1501            escapeDataPresentInGroup = true;
     1502          }
    12551503        }
     1504      }
     1505
     1506      escapeDataPresentInGroup = escapeDataPresentInGroup || (numNonZero > C1FLAG_NUMBER);
     1507
     1508      const Bool alignGroup = escapeDataPresentInGroup && alignCABACBeforeBypass;
     1509
     1510#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1511      TComCodingStatisticsClassType ctype_signs((alignGroup ? STATS__CABAC_BITS__ALIGNED_SIGN_BIT    : STATS__CABAC_BITS__SIGN_BIT   ), uiLog2BlockWidth, compID);
     1512      TComCodingStatisticsClassType ctype_escs ((alignGroup ? STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS : STATS__CABAC_BITS__ESCAPE_BITS), uiLog2BlockWidth, compID);
     1513#endif
     1514
     1515      if (alignGroup)
     1516      {
     1517        m_pcTDecBinIf->align();
    12561518      }
    12571519
     
    12591521      if ( signHidden && beValid )
    12601522      {
    1261         m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 );
     1523        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero-1 RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
    12621524        coeffSigns <<= 32 - (numNonZero-1);
    12631525      }
    12641526      else
    12651527      {
    1266         m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero );
     1528        m_pcTDecBinIf->decodeBinsEP( coeffSigns, numNonZero RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_signs) );
    12671529        coeffSigns <<= 32 - numNonZero;
    12681530      }
    1269      
    1270       Int iFirstCoeff2 = 1;   
    1271       if (c1 == 0 || numNonZero > C1FLAG_NUMBER)
     1531
     1532      Int iFirstCoeff2 = 1;
     1533      if (escapeDataPresentInGroup)
    12721534      {
    12731535        for( Int idx = 0; idx < numNonZero; idx++ )
     
    12781540          {
    12791541            UInt uiLevel;
    1280             xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam );
     1542            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, channelType RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
     1543
    12811544            absCoeff[ idx ] = uiLevel + baseLevel;
    1282             if(absCoeff[idx]>3*(1<<uiGoRiceParam))
     1545
     1546            if (absCoeff[idx] > (3 << uiGoRiceParam))
    12831547            {
    1284               uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4);
     1548              uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
     1549            }
     1550
     1551            if (updateGolombRiceStatistics)
     1552            {
     1553              const UInt initialGolombRiceParameter = currentGolombRiceStatistic / RExt__GOLOMB_RICE_INCREMENT_DIVISOR;
     1554
     1555              if (uiLevel >= (3 << initialGolombRiceParameter))
     1556              {
     1557                currentGolombRiceStatistic++;
     1558              }
     1559              else if (((uiLevel * 2) < (1 << initialGolombRiceParameter)) && (currentGolombRiceStatistic > 0))
     1560              {
     1561                currentGolombRiceStatistic--;
     1562              }
     1563
     1564              updateGolombRiceStatistics = false;
    12851565            }
    12861566          }
    12871567
    1288           if(absCoeff[ idx ] >= 2) 
     1568          if(absCoeff[ idx ] >= 2)
    12891569          {
    12901570            iFirstCoeff2 = 0;
     
    13031583        {
    13041584          // Infer sign of 1st element.
    1305           if (absSum&0x1)
    1306           {
    1307             pcCoef[ blkPos ] = -pcCoef[ blkPos ];
    1308           }
     1585          if (absSum&0x1) pcCoef[ blkPos ] = -pcCoef[ blkPos ];
    13091586        }
    13101587        else
     
    13171594    }
    13181595  }
    1319  
     1596
     1597#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     1598  printSBACCoeffData(uiPosLastX, uiPosLastY, uiWidth, uiHeight, compID, uiAbsPartIdx, codingParameters.scanType, pcCoef);
     1599#endif
     1600
    13201601  return;
    13211602}
    1322 
    13231603
    13241604Void TDecSbac::parseSaoMaxUvlc ( UInt& val, UInt maxSymbol )
     
    13321612  UInt code;
    13331613  Int  i;
    1334   m_pcTDecBinIf->decodeBinEP( code );
     1614  m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    13351615  if ( code == 0 )
    13361616  {
     
    13421622  while (1)
    13431623  {
    1344     m_pcTDecBinIf->decodeBinEP( code );
     1624    m_pcTDecBinIf->decodeBinEP( code RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    13451625    if ( code == 0 )
    13461626    {
     
    13481628    }
    13491629    i++;
    1350     if (i == maxSymbol) 
     1630    if (i == maxSymbol)
    13511631    {
    13521632      break;
     
    13561636  val = i;
    13571637}
     1638
    13581639Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
    13591640{
    1360   m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
    1361 }
     1641  m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
     1642}
     1643
    13621644Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
    13631645{
    13641646  UInt uiCode;
    1365   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
     1647  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    13661648  ruiVal = (Int)uiCode;
    13671649}
     1650
    13681651Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
    13691652{
    13701653  UInt uiCode;
    1371   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    1372   if (uiCode == 0) 
     1654  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
     1655  if (uiCode == 0)
    13731656  {
    13741657    ruiVal = 0;
     
    13761659  else
    13771660  {
    1378     m_pcTDecBinIf->decodeBinEP( uiCode );
     1661    m_pcTDecBinIf->decodeBinEP( uiCode RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    13791662    if (uiCode == 0)
    13801663    {
     
    13901673Void TDecSbac::parseSaoSign(UInt& val)
    13911674{
    1392   m_pcTDecBinIf->decodeBinEP ( val );
     1675  m_pcTDecBinIf->decodeBinEP ( val RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(STATS__CABAC_BITS__SAO) );
    13931676}
    13941677
     
    14211704  if(isLeftMerge || isAboveMerge) //merge mode
    14221705  {
    1423     saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
    1424     saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
     1706    for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
     1707    {
     1708      saoBlkParam[componentIndex].modeIdc = (sliceEnabled[componentIndex]) ? SAO_MODE_MERGE : SAO_MODE_OFF;
     1709      saoBlkParam[componentIndex].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
     1710    }
    14251711  }
    14261712  else //new or off mode
    1427   {   
    1428     for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    1429     {
     1713  {
     1714    for(Int compId=COMPONENT_Y; compId < MAX_NUM_COMPONENT; compId++)
     1715    {
     1716      const ComponentID compIdx=ComponentID(compId);
     1717      const ComponentID firstCompOfChType = getFirstComponentOfChannel(toChannelType(compIdx));
    14301718      SAOOffset& ctbParam = saoBlkParam[compIdx];
    14311719
     
    14381726
    14391727      //type
    1440       if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1728      if(compIdx == firstCompOfChType)
    14411729      {
    14421730        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
     
    14621750      else //Cr, follow Cb SAO type
    14631751      {
    1464         ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
    1465         ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     1752        ctbParam.modeIdc = saoBlkParam[COMPONENT_Cb].modeIdc;
     1753        ctbParam.typeIdc = saoBlkParam[COMPONENT_Cb].typeIdc;
    14661754      }
    14671755
    14681756      if(ctbParam.modeIdc == SAO_MODE_NEW)
    14691757      {
     1758#if O0043_BEST_EFFORT_DECODING
     1759        Int bitDepthOrig = g_bitDepthInStream[toChannelType(compIdx)];
     1760        Int forceBitDepthAdjust = bitDepthOrig - g_bitDepth[toChannelType(compIdx)];
     1761#endif
    14701762        Int offset[4];
    14711763        for(Int i=0; i< 4; i++)
     
    14741766          parseSaoMaxUvlc(uiSymbol,  saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
    14751767#else
     1768#if O0043_BEST_EFFORT_DECODING
     1769          Int saoMaxOffsetQVal = (1<<(min(bitDepthOrig, MAX_SAO_TRUNCATED_BITDEPTH)-5))-1;
     1770          parseSaoMaxUvlc(uiSymbol, saoMaxOffsetQVal); //sao_offset_abs
     1771#else
    14761772          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     1773#endif
    14771774#endif
    14781775          offset[i] = (Int)uiSymbol;
     
    14881785              if(uiSymbol)
    14891786              {
     1787#if O0043_BEST_EFFORT_DECODING
     1788                offset[i] >>= forceBitDepthAdjust;
     1789#endif
    14901790                offset[i] = -offset[i];
    14911791              }
     
    14941794          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
    14951795          ctbParam.typeAuxInfo = uiSymbol;
    1496        
     1796
    14971797          for(Int i=0; i<4; i++)
    14981798          {
    14991799            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
    1500           }     
    1501        
     1800          }
     1801
    15021802        }
    15031803        else //EO
     
    15051805          ctbParam.typeAuxInfo = 0;
    15061806
    1507           if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1807          if(firstCompOfChType == compIdx)
    15081808          {
    15091809            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
     
    15121812          else
    15131813          {
    1514             ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     1814            ctbParam.typeIdc = saoBlkParam[firstCompOfChType].typeIdc;
    15151815          }
    15161816          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
     
    15301830 \param pSrc Contexts to be copied.
    15311831 */
    1532 Void TDecSbac::xCopyContextsFrom( TDecSbac* pSrc )
     1832Void TDecSbac::xCopyContextsFrom( const TDecSbac* pSrc )
    15331833{
    15341834  memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0]));
    1535 }
    1536 
    1537 Void TDecSbac::xCopyFrom( TDecSbac* pSrc )
     1835  memcpy(m_golombRiceAdaptationStatistics, pSrc->m_golombRiceAdaptationStatistics, (sizeof(UInt) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS));
     1836}
     1837
     1838Void TDecSbac::xCopyFrom( const TDecSbac* pSrc )
    15381839{
    15391840  m_pcTDecBinIf->copyState( pSrc->m_pcTDecBinIf );
    1540 
    1541   m_uiLastQp           = pSrc->m_uiLastQp;
    15421841  xCopyContextsFrom( pSrc );
    1543 
    1544 }
    1545 
    1546 Void TDecSbac::load ( TDecSbac* pScr )
    1547 {
    1548   xCopyFrom(pScr);
    1549 }
    1550 
    1551 Void TDecSbac::loadContexts ( TDecSbac* pScr )
    1552 {
    1553   xCopyContextsFrom(pScr);
    1554 }
     1842}
     1843
     1844Void TDecSbac::load ( const TDecSbac* pSrc )
     1845{
     1846  xCopyFrom(pSrc);
     1847}
     1848
     1849Void TDecSbac::loadContexts ( const TDecSbac* pSrc )
     1850{
     1851  xCopyContextsFrom(pSrc);
     1852}
     1853
     1854/** Performs CABAC decoding of the explicit RDPCM mode
     1855 * \param rTu current TU data structure
     1856 * \param compID component identifier
     1857 */
     1858Void TDecSbac::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
     1859{
     1860  TComDataCU* cu = rTu.getCU();
     1861  const UInt absPartIdx=rTu.GetAbsPartIdxTU(compID);
     1862  const TComRectangle &rect = rTu.getRect(compID);
     1863  const UInt tuHeight = g_aucConvertToBit[rect.height];
     1864  const UInt tuWidth  = g_aucConvertToBit[rect.width];
     1865  UInt code = 0;
     1866
     1867  assert(tuHeight == tuWidth);
     1868
     1869#if RExt__DECODER_DEBUG_BIT_STATISTICS
     1870  const TComCodingStatisticsClassType ctype(STATS__EXPLICIT_RDPCM_BITS, g_aucConvertToBit[g_uiMaxCUWidth>>rTu.GetTransformDepthTotal()]+2);
     1871#endif
     1872
     1873  m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmFlagSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     1874
     1875  if(code == 0)
     1876  {
     1877    cu->setExplicitRdpcmModePartRange( RDPCM_OFF, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     1878  }
     1879  else
     1880  {
     1881    m_pcTDecBinIf->decodeBin(code, m_explicitRdpcmDirSCModel.get (0, toChannelType(compID), 0) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype));
     1882    if(code == 0)
     1883    {
     1884      cu->setExplicitRdpcmModePartRange( RDPCM_HOR, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     1885    }
     1886    else
     1887    {
     1888      cu->setExplicitRdpcmModePartRange( RDPCM_VER, compID, absPartIdx, rTu.GetAbsPartIdxNumParts(compID));
     1889    }
     1890  }
     1891}
     1892
     1893
    15551894//! \}
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h

    r713 r1029  
    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-2014, ITU/ISO/IEC
     
    5858// ====================================================================================================================
    5959
     60class SEImessages;
     61
    6062/// SBAC decoder class
    6163class TDecSbac : public TDecEntropyIf
     
    6466  TDecSbac();
    6567  virtual ~TDecSbac();
    66  
     68
    6769  Void  init                      ( TDecBinIf* p )    { m_pcTDecBinIf = p; }
    6870  Void  uninit                    (              )    { m_pcTDecBinIf = 0; }
    69  
    70   Void load                          ( TDecSbac* pScr );
    71   Void loadContexts                  ( TDecSbac* pScr );
    72   Void xCopyFrom           ( TDecSbac* pSrc );
    73   Void xCopyContextsFrom       ( TDecSbac* pSrc );
     71
     72  Void load                       ( const TDecSbac* pSrc );
     73  Void loadContexts               ( const TDecSbac* pSrc );
     74  Void xCopyFrom                  ( const TDecSbac* pSrc );
     75  Void xCopyContextsFrom          ( const TDecSbac* pSrc );
    7476
    7577  Void  resetEntropy (TComSlice* pSlice );
    7678  Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
    7779  Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
    78 #if SVC_EXTENSION && !SPS_DPB_PARAMS
    79   Void  parseSPS                  ( TComSPS* /*pcSPS*/, ParameterSetManagerDecoder * /*parameterSetManager*/ ) {}
    80 #else
    8180  Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
    82 #endif
    8381  Void  parsePPS                  ( TComPPS* /*pcPPS*/
    8482#if Q0048_CGS_3D_ASYMLUT
     
    8785    ) {}
    8886
    89   Void  parseSliceHeader          ( TComSlice*& /*rpcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/) {}
     87  Void  parseSliceHeader          ( TComSlice* /*pcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/) {}
    9088  Void  parseTerminatingBit       ( UInt& ruiBit );
     89  Void  parseRemainingBytes       ( Bool noTrailingBytesExpected);
    9190  Void  parseMVPIdx               ( Int& riMVPIdx          );
    9291  Void  parseSaoMaxUvlc           ( UInt& val, UInt maxSymbol );
    93   Void  parseSaoMerge         ( UInt&  ruiVal   );
     92  Void  parseSaoMerge             ( UInt&  ruiVal   );
    9493  Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
    9594  Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
    9695
    9796#if SVC_EXTENSION
    98   Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail );
     97  Void parseSAOBlkParam           (SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail );
    9998#else
    100   Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail);
     99  Void parseSAOBlkParam           (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail);
    101100#endif
    102   Void parseSaoSign(UInt& val);
     101  Void parseSaoSign               (UInt& val);
     102
    103103private:
     104#if RExt__DECODER_DEBUG_BIT_STATISTICS
     105  Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, const class TComCodingStatisticsClassType &whichStat );
     106  Void  xReadUnaryMaxSymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat );
     107  Void  xReadEpExGolomb     ( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat );
     108  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const class TComCodingStatisticsClassType &whichStat );
     109#else
    104110  Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset );
    105111  Void  xReadUnaryMaxSymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol );
    106112  Void  xReadEpExGolomb     ( UInt& ruiSymbol, UInt uiCount );
    107   Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam );
     113  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType );
     114#endif
    108115private:
    109116  TComInputBitstream* m_pcBitstream;
    110117  TDecBinIf*        m_pcTDecBinIf;
    111  
     118
    112119public:
    113  
     120
    114121  Void parseSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    115122  Void parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
     
    119126  Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    120127  Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    121  
     128
    122129  Void parseIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    123  
    124130  Void parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    125  
     131
    126132  Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
    127133  Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList );
    128134  Void parseMvd           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList );
    129  
     135
     136  Void parseCrossComponentPrediction ( class TComTU &rTu, ComponentID compID );
     137
    130138  Void parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize );
    131   Void parseQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth );
     139  Void parseQtCbf         ( TComTU &rTu, const ComponentID compID, const Bool lowestLevel );
    132140  Void parseQtRootCbf     ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
    133  
     141
    134142  Void parseDeltaQP       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    135  
     143  Void parseChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, UInt depth );
     144
    136145  Void parseIPCMInfo      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
    137146
    138   Void parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, TextType eTType, UInt uiScanIdx );
    139   Void parseCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType );
    140   Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType);
    141 
    142   Void updateContextTables( SliceType eSliceType, Int iQp );
     147  Void parseLastSignificantXY( UInt& uiPosLastX, UInt& uiPosLastY, Int width, Int height, ComponentID component, UInt uiScanIdx );
     148  Void parseCoeffNxN      ( class TComTU &rTu, ComponentID compID  );
     149  Void parseTransformSkipFlags ( class TComTU &rTu, ComponentID component );
    143150
    144151  Void  parseScalingList ( TComScalingList* /*scalingList*/ ) {}
    145152
     153  Void  parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID );
     154
    146155private:
    147   UInt m_uiLastDQpNonZero;
    148   UInt m_uiLastQp;
    149  
    150156  ContextModel         m_contextModels[MAX_NUM_CTX_MOD];
    151157  Int                  m_numContextModels;
     
    165171  ContextModel3DBuffer m_cCUTransSubdivFlagSCModel;
    166172  ContextModel3DBuffer m_cCUQtRootCbfSCModel;
    167  
     173
    168174  ContextModel3DBuffer m_cCUSigCoeffGroupSCModel;
    169175  ContextModel3DBuffer m_cCUSigSCModel;
     
    172178  ContextModel3DBuffer m_cCUOneSCModel;
    173179  ContextModel3DBuffer m_cCUAbsSCModel;
    174  
     180
    175181  ContextModel3DBuffer m_cMVPIdxSCModel;
    176  
     182
    177183  ContextModel3DBuffer m_cSaoMergeSCModel;
    178184  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
    179185  ContextModel3DBuffer m_cTransformSkipSCModel;
    180186  ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
     187  ContextModel3DBuffer m_explicitRdpcmFlagSCModel;
     188  ContextModel3DBuffer m_explicitRdpcmDirSCModel;
     189  ContextModel3DBuffer m_cCrossComponentPredictionSCModel;
     190
     191  ContextModel3DBuffer m_ChromaQpAdjFlagSCModel;
     192  ContextModel3DBuffer m_ChromaQpAdjIdcSCModel;
     193
     194  UInt m_golombRiceAdaptationStatistics[RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS];
    181195};
    182196
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecSlice.cpp

    r880 r1029  
    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-2014, ITU/ISO/IEC
     
    5353TDecSlice::TDecSlice()
    5454{
    55   m_pcBufferSbacDecoders = NULL;
    56   m_pcBufferBinCABACs    = NULL;
    57   m_pcBufferLowLatSbacDecoders = NULL;
    58   m_pcBufferLowLatBinCABACs    = NULL;
    5955}
    6056
    6157TDecSlice::~TDecSlice()
    6258{
    63   for (std::vector<TDecSbac*>::iterator i = CTXMem.begin(); i != CTXMem.end(); i++)
    64   {
    65     delete (*i);
    66   }
    67   CTXMem.clear();
    68 }
    69 
    70 Void TDecSlice::initCtxMem(  UInt i )               
    71 {   
    72   for (std::vector<TDecSbac*>::iterator j = CTXMem.begin(); j != CTXMem.end(); j++)
    73   {
    74     delete (*j);
    75   }
    76   CTXMem.clear();
    77   CTXMem.resize(i);
    7859}
    7960
     
    8465Void TDecSlice::destroy()
    8566{
    86   if ( m_pcBufferSbacDecoders )
    87   {
    88     delete[] m_pcBufferSbacDecoders;
    89     m_pcBufferSbacDecoders = NULL;
    90   }
    91   if ( m_pcBufferBinCABACs )
    92   {
    93     delete[] m_pcBufferBinCABACs;
    94     m_pcBufferBinCABACs = NULL;
    95   }
    96   if ( m_pcBufferLowLatSbacDecoders )
    97   {
    98     delete[] m_pcBufferLowLatSbacDecoders;
    99     m_pcBufferLowLatSbacDecoders = NULL;
    100   }
    101   if ( m_pcBufferLowLatBinCABACs )
    102   {
    103     delete[] m_pcBufferLowLatBinCABACs;
    104     m_pcBufferLowLatBinCABACs = NULL;
    105   }
    10667}
    10768
     
    12182#endif
    12283
    123 Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders)
    124 {
    125   TComDataCU* pcCU;
    126   UInt        uiIsLast = 0;
    127   Int   iStartCUEncOrder = max(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU(), rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr()/rpcPic->getNumPartInCU());
    128   Int   iStartCUAddr = rpcPic->getPicSym()->getCUOrderMap(iStartCUEncOrder);
    129 
    130   // decoder don't need prediction & residual frame buffer
    131   rpcPic->setPicYuvPred( 0 );
    132   rpcPic->setPicYuvResi( 0 );
    133  
     84Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic* pcPic, TDecSbac* pcSbacDecoder)
     85{
     86  TComSlice* pcSlice                 = pcPic->getSlice(pcPic->getCurrSliceIdx());
     87
     88  const Int  startCtuTsAddr          = pcSlice->getSliceSegmentCurStartCtuTsAddr();
     89  const Int  startCtuRsAddr          = pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTsAddr);
     90  const UInt numCtusInFrame          = pcPic->getNumberOfCtusInFrame();
     91
     92  const UInt frameWidthInCtus        = pcPic->getPicSym()->getFrameWidthInCtus();
     93  const Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
     94  const Bool wavefrontsEnabled       = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
     95
     96  m_pcEntropyDecoder->setEntropyDecoder ( pcSbacDecoder  );
     97  m_pcEntropyDecoder->setBitstream      ( ppcSubstreams[0] );
     98  m_pcEntropyDecoder->resetEntropy      (pcSlice);
     99
     100  // decoder doesn't need prediction & residual frame buffer
     101  pcPic->setPicYuvPred( 0 );
     102  pcPic->setPicYuvResi( 0 );
     103
    134104#if ENC_DEC_TRACE
    135105  g_bJustDoIt = g_bEncDecTraceEnable;
     
    137107  DTRACE_CABAC_VL( g_nSymbolCounter++ );
    138108  DTRACE_CABAC_T( "\tPOC: " );
    139   DTRACE_CABAC_V( rpcPic->getPOC() );
     109  DTRACE_CABAC_V( pcPic->getPOC() );
    140110  DTRACE_CABAC_T( "\n" );
    141111
     
    144114#endif
    145115
    146   UInt uiTilesAcross   = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
    147   TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
    148 #if !WPP_FIX
    149   Int  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    150 #endif
    151 
    152   // delete decoders if already allocated in previous slice
    153   if (m_pcBufferSbacDecoders)
    154   {
    155     delete [] m_pcBufferSbacDecoders;
    156   }
    157   if (m_pcBufferBinCABACs)
    158   {
    159     delete [] m_pcBufferBinCABACs;
    160   }
    161   // allocate new decoders based on tile numbaer
    162   m_pcBufferSbacDecoders = new TDecSbac    [uiTilesAcross]; 
    163   m_pcBufferBinCABACs    = new TDecBinCABAC[uiTilesAcross];
    164   for (UInt ui = 0; ui < uiTilesAcross; ui++)
    165   {
    166     m_pcBufferSbacDecoders[ui].init(&m_pcBufferBinCABACs[ui]);
    167   }
    168   //save init. state
    169   for (UInt ui = 0; ui < uiTilesAcross; ui++)
    170   {
    171     m_pcBufferSbacDecoders[ui].load(pcSbacDecoder);
    172   }
    173 
    174   // free memory if already allocated in previous call
    175   if (m_pcBufferLowLatSbacDecoders)
    176   {
    177     delete [] m_pcBufferLowLatSbacDecoders;
    178   }
    179   if (m_pcBufferLowLatBinCABACs)
    180   {
    181     delete [] m_pcBufferLowLatBinCABACs;
    182   }
    183   m_pcBufferLowLatSbacDecoders = new TDecSbac    [uiTilesAcross]; 
    184   m_pcBufferLowLatBinCABACs    = new TDecBinCABAC[uiTilesAcross];
    185   for (UInt ui = 0; ui < uiTilesAcross; ui++)
    186   {
    187     m_pcBufferLowLatSbacDecoders[ui].init(&m_pcBufferLowLatBinCABACs[ui]);
    188   }
    189   //save init. state
    190   for (UInt ui = 0; ui < uiTilesAcross; ui++)
    191   {
    192     m_pcBufferLowLatSbacDecoders[ui].load(pcSbacDecoder);
    193   }
    194 
    195   UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    196   //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
    197 
    198 #if WPP_FIX
    199   UInt uiTileCol;
    200   UInt uiTileLCUX;
    201   const Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
    202   const UInt startTileIdx=rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr);
    203   TComTile *pCurrentTile=rpcPic->getPicSym()->getTComTile(startTileIdx);
    204   UInt uiTileStartLCU = pCurrentTile->getFirstCUAddr(); // Code tidy
    205 
    206   // The first LCU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForLCUAddr may be higher.
     116  // The first CTU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForCtuAddr may be higher.
    207117  // This calculates the common offset for all substreams in this slice.
    208   const UInt subStreamOffset=rpcPic->getSubstreamForLCUAddr(iStartCUAddr, true, pcSlice);
    209 #else
    210   UInt uiCol=0, uiLin=0, uiSubStrm=0;
    211 
    212   UInt uiTileCol;
    213   UInt uiTileStartLCU;
    214   UInt uiTileLCUX;
    215   Int iNumSubstreamsPerTile = 1; // if independent.
    216   Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
    217   uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
    218 #endif
    219   if( depSliceSegmentsEnabled )
    220   {
    221 #if WPP_FIX
    222     if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) && iStartCUAddr != uiTileStartLCU)  // Code tidy // Is this a dependent slice segment and not the start of a tile?
    223 #else
    224     if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) &&
    225        iStartCUAddr != rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr())
    226 #endif
    227     {
    228       if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    229       {
    230 #if WPP_FIX
    231         uiTileCol = startTileIdx % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // Code tidy
    232 #else
    233         uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
    234 #endif
    235         m_pcBufferSbacDecoders[uiTileCol].loadContexts( CTXMem[1]  );//2.LCU
    236 #if WPP_FIX
    237         if ( pCurrentTile->getTileWidth() < 2)
     118  const UInt subStreamOffset=pcPic->getSubstreamForCtuAddr(startCtuRsAddr, true, pcSlice);
     119
     120
     121  if (depSliceSegmentsEnabled)
     122  {
     123    // modify initial contexts with previous slice segment if this is a dependent slice.
     124    const UInt startTileIdx=pcPic->getPicSym()->getTileIdxMap(startCtuRsAddr);
     125    const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(startTileIdx);
     126    const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
     127
     128    if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
     129    {
     130      if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
     131      {
     132        pcSbacDecoder->loadContexts(&m_lastSliceSegmentEndContextState);
     133      }
     134    }
     135  }
     136
     137  // for every CTU in the slice segment...
     138
     139  Bool isLastCtuOfSliceSegment = false;
     140  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
     141  {
     142    const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
     143    const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
     144    const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
     145    const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
     146    const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
     147    const UInt ctuXPosInCtus  = ctuRsAddr % frameWidthInCtus;
     148    const UInt ctuYPosInCtus  = ctuRsAddr / frameWidthInCtus;
     149    const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset;
     150    TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
     151    pCtu->initCtu( pcPic, ctuRsAddr );
     152
     153    m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
     154
     155    // set up CABAC contexts' state for this CTU
     156    if (ctuRsAddr == firstCtuRsAddrOfTile)
     157    {
     158      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
     159      {
     160        m_pcEntropyDecoder->resetEntropy(pcSlice);
     161      }
     162    }
     163    else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
     164    {
     165      // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
     166      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
     167      {
     168        m_pcEntropyDecoder->resetEntropy(pcSlice);
     169      }
     170      TComDataCU *pCtuUp = pCtu->getCtuAbove();
     171      if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus)  )
     172      {
     173        TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
     174        if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
    238175        {
    239           CTXMem[0]->loadContexts(pcSbacDecoder); // If tile width is less than 2, need to ensure CTX states get initialised to un-adapted CABAC. Set here, to load a few lines later (!)
     176          // Top-right is available, so use it.
     177          pcSbacDecoder->loadContexts( &m_entropyCodingSyncContextState );
    240178        }
    241 #else
    242         if ( (iStartCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
    243         {
    244           uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
    245           uiCol     = iStartCUAddr % uiWidthInLCUs;
    246           if(uiCol==uiTileLCUX)
    247           {
    248             CTXMem[0]->loadContexts(pcSbacDecoder);
    249           }
    250         }
    251 #endif
    252       }
    253       pcSbacDecoder->loadContexts(CTXMem[0] ); //end of depSlice-1
    254 #if WPP_FIX
    255       pcSbacDecoders[0].loadContexts(pcSbacDecoder); // The first substream used for the slice will always be 0. (The original code was equivalent)
    256 #else
    257       pcSbacDecoders[uiSubStrm].loadContexts(pcSbacDecoder);
    258 #endif
    259     }
    260     else
    261     {
    262       if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    263       {
    264         CTXMem[1]->loadContexts(pcSbacDecoder);
    265       }
    266       CTXMem[0]->loadContexts(pcSbacDecoder);
    267     }
    268   }
    269   for( Int iCUAddr = iStartCUAddr; !uiIsLast && iCUAddr < rpcPic->getNumCUsInFrame(); iCUAddr = rpcPic->getPicSym()->xCalculateNxtCUAddr(iCUAddr) )
    270   {
    271     pcCU = rpcPic->getCU( iCUAddr );
    272     pcCU->initCU( rpcPic, iCUAddr );
    273     uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    274     uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr();
    275     uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
    276 #if WPP_FIX
    277     UInt uiCol     = iCUAddr % uiWidthInLCUs;
    278     UInt uiSubStrm=rpcPic->getSubstreamForLCUAddr(iCUAddr, true, pcSlice)-subStreamOffset;
    279 #else
    280     uiCol     = iCUAddr % uiWidthInLCUs;
    281     // The 'line' is now relative to the 1st line in the slice, not the 1st line in the picture.
    282     uiLin     = (iCUAddr/uiWidthInLCUs)-(iStartCUAddr/uiWidthInLCUs);
    283 #endif
    284     // inherit from TR if necessary, select substream to use.
    285     if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( depSliceSegmentsEnabled  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ))
    286     {
    287 #if !WPP_FIX
    288       // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
    289       iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    290       uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(iCUAddr)*iNumSubstreamsPerTile
    291                   + uiLin%iNumSubstreamsPerTile;
    292 #endif
    293       m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
    294       // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
    295       if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()))
    296       {
    297         // We'll sync if the TR is available.
    298         TComDataCU *pcCUUp = pcCU->getCUAbove();
    299         UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
    300         TComDataCU *pcCUTR = NULL;
    301         if ( pcCUUp && ((iCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
    302         {
    303           pcCUTR = rpcPic->getCU( iCUAddr - uiWidthInCU + 1 );
    304         }
    305         UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
    306 
    307         if ( (true/*bEnforceSliceRestriction*/ &&
    308              ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
    309              ((pcCUTR->getSCUAddr()+uiMaxParts-1) < pcSlice->getSliceCurStartCUAddr()) ||
    310              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)))
    311              ))
    312            )
    313         {
    314           // TR not available.
    315         }
    316         else
    317         {
    318           // TR is available, we use it.
    319           pcSbacDecoders[uiSubStrm].loadContexts( &m_pcBufferSbacDecoders[uiTileCol] );
    320         }
    321       }
    322       pcSbacDecoder->load(&pcSbacDecoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to pcSbacDecoders)
    323     }
    324 #if !WPP_FIX
    325     else if ( pcSlice->getPPS()->getNumSubstreams() <= 1 )
    326     {
    327       // Set variables to appropriate values to avoid later code change.
    328       iNumSubstreamsPerTile = 1;
    329     }
    330 #endif
    331 
    332     if ( (iCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr()) && // 1st in tile.
    333          (iCUAddr!=0) && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())
    334          && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr())/rpcPic->getNumPartInCU())
    335          ) // !1st in frame && !1st in slice
    336     {
    337       if (pcSlice->getPPS()->getNumSubstreams() > 1)
    338       {
    339         // We're crossing into another tile, tiles are independent.
    340         // When tiles are independent, we have "substreams per tile".  Each substream has already been terminated, and we no longer
    341         // have to perform it here.
    342         // For TILES_DECODER, there can be a header at the start of the 1st substream in a tile.  These are read when the substreams
    343         // are extracted, not here.
    344       }
    345       else
    346       {
    347         SliceType sliceType  = pcSlice->getSliceType();
    348         if (pcSlice->getCabacInitFlag())
    349         {
    350           switch (sliceType)
    351           {
    352           case P_SLICE:           // change initialization table to B_SLICE intialization
    353             sliceType = B_SLICE;
    354             break;
    355           case B_SLICE:           // change initialization table to P_SLICE intialization
    356             sliceType = P_SLICE;
    357             break;
    358           default     :           // should not occur
    359             assert(0);
    360           }
    361         }
    362         m_pcEntropyDecoder->updateContextTables( sliceType, pcSlice->getSliceQp() );
    363       }
    364      
     179      }
    365180    }
    366181
     
    371186    if ( pcSlice->getSPS()->getUseSAO() )
    372187    {
    373       SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[iCUAddr];
    374       if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
    375       {
    376         Bool sliceEnabled[NUM_SAO_COMPONENTS];
    377         sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
    378         sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
    379 
     188      SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
     189      Bool bIsSAOSliceEnabled = false;
     190      Bool sliceEnabled[MAX_NUM_COMPONENT];
     191      for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
     192      {
     193        ComponentID compId=ComponentID(comp);
     194        sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
     195        if (sliceEnabled[compId]) bIsSAOSliceEnabled=true;
     196        saoblkParam[compId].modeIdc = SAO_MODE_OFF;
     197      }
     198      if (bIsSAOSliceEnabled)
     199      {
    380200        Bool leftMergeAvail = false;
    381201        Bool aboveMergeAvail= false;
    382202
    383203        //merge left condition
    384         Int rx = (iCUAddr % uiWidthInLCUs);
     204        Int rx = (ctuRsAddr % frameWidthInCtus);
    385205        if(rx > 0)
    386206        {
    387           leftMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-1);
     207          leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
    388208        }
    389209        //merge up condition
    390         Int ry = (iCUAddr / uiWidthInLCUs);
     210        Int ry = (ctuRsAddr / frameWidthInCtus);
    391211        if(ry > 0)
    392212        {
    393           aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs);
     213          aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
    394214        }
    395215#if SVC_EXTENSION
     
    397217#else
    398218        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
    399 #endif
    400       }
    401       else
    402       {
    403         saoblkParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
    404         saoblkParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
    405         saoblkParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
    406       }
    407     }
    408 
    409     m_pcCuDecoder->decodeCU     ( pcCU, uiIsLast );
    410     m_pcCuDecoder->decompressCU ( pcCU );
    411    
     219#endif     
     220      }
     221    }
     222
     223    m_pcCuDecoder->decodeCtu     ( pCtu, isLastCtuOfSliceSegment );
     224    m_pcCuDecoder->decompressCtu ( pCtu );
     225
    412226#if ENC_DEC_TRACE
    413227    g_bJustDoIt = g_bEncDecTraceDisable;
    414228#endif
    415     pcSbacDecoders[uiSubStrm].load(pcSbacDecoder);
    416 
    417     if ( uiCol == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getRightEdgePosInCU()
    418         && pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()
    419         && !uiIsLast )
    420     {
    421       // Parse end_of_substream_one_bit for WPP case
     229
     230    //Store probabilities of second CTU in line into buffer
     231    if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
     232    {
     233      m_entropyCodingSyncContextState.loadContexts( pcSbacDecoder );
     234    }
     235
     236    // Should the sub-stream/stream be terminated after this CTU?
     237    // (end of slice-segment, end of tile, end of wavefront-CTU-row)
     238    if (isLastCtuOfSliceSegment ||
     239         (  ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
     240          ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
     241         )
     242       )
     243    {
    422244      UInt binVal;
    423245      pcSbacDecoder->parseTerminatingBit( binVal );
    424246      assert( binVal );
    425     }
    426 
    427     //Store probabilities of second LCU in line into buffer
    428     if ( (uiCol == uiTileLCUX+1)&& (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) )
    429     {
    430       m_pcBufferSbacDecoders[uiTileCol].loadContexts( &pcSbacDecoders[uiSubStrm] );
    431     }
    432     if( uiIsLast && depSliceSegmentsEnabled )
    433     {
    434       if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    435        {
    436          CTXMem[1]->loadContexts( &m_pcBufferSbacDecoders[uiTileCol] );//ctx 2.LCU
    437        }
    438       CTXMem[0]->loadContexts( pcSbacDecoder );//ctx end of dep.slice
    439       return;
    440     }
    441   }
     247#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
     248      pcSbacDecoder->parseRemainingBytes(!isLastCtuOfSliceSegment);
     249#endif
     250
     251      if (isLastCtuOfSliceSegment)
     252      {
     253        if(!pcSlice->getDependentSliceSegmentFlag())
     254        {
     255          pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 );
     256        }
     257        pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 );
     258        break;
     259      }
     260    }
     261  }
     262
     263  assert(isLastCtuOfSliceSegment == true);
     264
     265
     266  if( depSliceSegmentsEnabled )
     267  {
     268    m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
     269  }
     270
    442271}
    443272
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecSlice.h

    r834 r1029  
    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-2014, ITU/ISO/IEC
     
    6666  TDecCu*         m_pcCuDecoder;
    6767
    68   TDecSbac*       m_pcBufferSbacDecoders;   ///< line to store temporary contexts, one per column of tiles.
    69   TDecBinCABAC*   m_pcBufferBinCABACs;
    70   TDecSbac*       m_pcBufferLowLatSbacDecoders;   ///< dependent tiles: line to store temporary contexts, one per column of tiles.
    71   TDecBinCABAC*   m_pcBufferLowLatBinCABACs;
    72   std::vector<TDecSbac*> CTXMem;
     68  TDecSbac        m_lastSliceSegmentEndContextState;    ///< context storage for state at the end of the previous slice-segment (used for dependent slices only).
     69  TDecSbac        m_entropyCodingSyncContextState;      ///< context storate for state of contexts at the wavefront/WPP/entropy-coding-sync second CTU of tile-row
     70
    7371#if SVC_EXTENSION
    7472  UInt*           m_saoMaxOffsetQVal;
    7573#endif
    76  
     74
    7775public:
    7876  TDecSlice();
     
    8684  Void  create            ();
    8785  Void  destroy           ();
    88  
    89   Void  decompressSlice   ( TComInputBitstream** ppcSubstreams,   TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders );
    90   Void      initCtxMem(  UInt i );
    91   Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
    92   Int       getCtxMemSize( )                   { return (Int)CTXMem.size(); }
     86
     87  Void  decompressSlice   ( TComInputBitstream** ppcSubstreams,   TComPic* pcPic, TDecSbac* pcSbacDecoder );
    9388};
    9489
     
    114109#else
    115110  ParameterSetMap<TComVPS> m_vpsBuffer;
    116   ParameterSetMap<TComSPS> m_spsBuffer; 
     111  ParameterSetMap<TComSPS> m_spsBuffer;
    117112  ParameterSetMap<TComPPS> m_ppsBuffer;
    118113#endif
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp

    r1015 r1029  
    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-2014, ITU/ISO/IEC
     
    3838#include "NALread.h"
    3939#include "TDecTop.h"
     40#if RExt__DECODER_DEBUG_BIT_STATISTICS
     41#include "TLibCommon/TComCodingStatistics.h"
     42#endif
    4043
    4144#if SVC_EXTENSION
     
    6467
    6568TDecTop::TDecTop()
     69  : m_pDecodedSEIOutputStream(NULL)
    6670{
    6771  m_pcPic = 0;
    6872  m_iMaxRefPicNum = 0;
    6973#if ENC_DEC_TRACE
    70   g_hTrace = fopen( "TraceDec.txt", "wb" );
     74  if (g_hTrace == NULL)
     75  {
     76    g_hTrace = fopen( "TraceDec.txt", "wb" );
     77  }
    7178  g_bJustDoIt = g_bEncDecTraceDisable;
    7279  g_nSymbolCounter = 0;
     
    7481  m_associatedIRAPType = NAL_UNIT_INVALID;
    7582  m_pocCRA = 0;
    76   m_pocRandomAccess = MAX_INT;         
     83  m_pocRandomAccess = MAX_INT;
    7784#if !SVC_EXTENSION
    7885  m_prevPOC                = MAX_INT;
     
    94101  m_prevSliceSkipped = false;
    95102  m_skippedPOC = 0;
    96 #if SETTING_NO_OUT_PIC_PRIOR
    97103  m_bFirstSliceInBitstream  = true;
    98104  m_lastPOCNoOutputPriorPics = -1;
    99105  m_craNoRaslOutputFlag = false;
    100106  m_isNoOutputPriorPics = false;
    101 #endif
    102107#if Q0177_EOS_CHECKS
    103108  m_isLastNALWasEos = false;
     
    141146{
    142147#if ENC_DEC_TRACE
    143   fclose( g_hTrace );
     148  if (g_hTrace != stdout)
     149  {
     150    fclose( g_hTrace );
     151  }
    144152#endif
    145153#if Q0048_CGS_3D_ASYMLUT
     
    167175{
    168176  m_cGopDecoder.destroy();
    169  
     177
    170178  delete m_apcSlicePilot;
    171179  m_apcSlicePilot = NULL;
    172  
     180
    173181  m_cSliceDecoder.destroy();
    174182#if SVC_EXTENSION
     
    201209}
    202210
    203 #if SVC_EXTENSION
    204 #if !REPN_FORMAT_IN_VPS
    205 Void TDecTop::xInitILRP(TComSPS *pcSPS)
    206 #else
    207 Void TDecTop::xInitILRP(TComSlice *slice)
    208 #endif
    209 {
    210 #if REPN_FORMAT_IN_VPS
    211   TComSPS* pcSPS = slice->getSPS();
    212   Int bitDepthY   = slice->getBitDepthY();
    213   Int bitDepthC   = slice->getBitDepthC();
    214   Int picWidth    = slice->getPicWidthInLumaSamples();
    215   Int picHeight   = slice->getPicHeightInLumaSamples();
    216 #endif
    217   if(m_layerId>0)
    218   {
    219 #if REPN_FORMAT_IN_VPS
    220     g_bitDepthY     = bitDepthY;
    221     g_bitDepthC     = bitDepthC;
    222 #else
    223     g_bitDepthY     = pcSPS->getBitDepthY();
    224     g_bitDepthC     = pcSPS->getBitDepthC();
    225 #endif
    226     g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
    227     g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
    228     g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
    229     g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
    230 
    231     Int  numReorderPics[MAX_TLAYER];
    232 #if R0156_CONF_WINDOW_IN_REP_FORMAT
    233     Window &conformanceWindow = slice->getConformanceWindow();
    234 #else
    235     Window &conformanceWindow = pcSPS->getConformanceWindow();
    236 #endif
    237     Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
    238 
    239     for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
    240     {
    241 #if USE_DPB_SIZE_TABLE
    242       if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
    243       {
    244         assert( this->getLayerId() == 0 );
    245         numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
    246       }
    247       else
    248       {
    249         TComVPS *vps = slice->getVPS();
    250         // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
    251         numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
    252       }
    253 #else
    254       numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
    255 #endif
    256     }
    257 
    258     if (m_cIlpPic[0] == NULL)
    259     {
    260       for (Int j=0; j < m_numDirectRefLayers; j++)
    261       {
    262 
    263         m_cIlpPic[j] = new  TComPic;
    264 
    265 #if AUXILIARY_PICTURES
    266 #if REPN_FORMAT_IN_VPS
    267         m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
    268 #else
    269         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
    270 #endif
    271 #else
    272 #if REPN_FORMAT_IN_VPS
    273         m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
    274 #else
    275         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
    276 #endif
    277 #endif
    278         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
    279         {
    280           m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
    281         }
    282       }
    283     }
    284   }
    285 }
    286 #endif
    287 
    288211Void TDecTop::deletePicBuffer ( )
    289212{
    290213  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
    291214  Int iSize = Int( m_cListPic.size() );
    292  
     215
    293216  for (Int i = 0; i < iSize; i++ )
    294217  {
     
    304227#else
    305228    pcPic->destroy();
    306    
     229
    307230    delete pcPic;
    308231    pcPic = NULL;
    309232#endif
    310233  }
    311  
     234
    312235  m_cSAO.destroy();
    313  
     236
    314237  m_cLoopFilter.        destroy();
    315238 
     
    330253  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
    331254
    332   for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
     255  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
    333256  {
    334257#if USE_DPB_SIZE_TABLE
     
    420343#if O0194_DIFFERENT_BITDEPTH_EL_BL
    421344        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
    422         Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
     345        Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
    423346
    424347#if REF_IDX_MFM
    425         if( pcPicYuvRecBase->getWidth() == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight() == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
     348        if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight(COMPONENT_Y) == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
    426349        {
    427350          rpcPic->setEqualPictureSizeAndOffsetFlag( i, true );
     
    480403    }
    481404
    482 #if AUXILIARY_PICTURES
    483405#if REPN_FORMAT_IN_VPS
    484406    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     
    488410                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    489411#endif
    490 #else
    491 #if REPN_FORMAT_IN_VPS
    492     rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    493                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    494 #else
    495     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    496                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    497 #endif
    498 #endif
    499412
    500413#else //SVC_EXTENSION
    501     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     414    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    502415                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
    503416#endif //SVC_EXTENSION
    504417   
    505418    m_cListPic.pushBack( rpcPic );
    506    
     419
    507420    return;
    508421  }
    509  
     422
    510423  Bool bBufferIsAvailable = false;
    511424  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
     
    531444    }
    532445  }
    533  
     446
    534447  if ( !bBufferIsAvailable )
    535448  {
     
    542455
    543456#if SVC_EXTENSION
    544 #if AUXILIARY_PICTURES
    545457#if REPN_FORMAT_IN_VPS
    546458  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     
    550462                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    551463#endif
    552 #else
    553 #if REPN_FORMAT_IN_VPS
    554   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    555                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    556 
    557 #else
    558   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    559                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
    560 #endif
    561 #endif
    562464#else  //SVC_EXTENSION
    563   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     465  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    564466                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
    565467#endif //SVC_EXTENSION
     
    573475    return;
    574476  }
    575  
    576   TComPic*&   pcPic         = m_pcPic;
     477
     478  TComPic*   pcPic         = m_pcPic;
    577479
    578480  // Execute Deblock + Cleanup
     481
    579482  m_cGopDecoder.filterPicture(pcPic);
    580483
     
    588491  TComSlice::sortPicList( m_cListPic ); // sorting for application output
    589492  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
    590   rpcListPic          = &m_cListPic; 
    591   m_cCuDecoder.destroy();       
     493  rpcListPic          = &m_cListPic;
     494  m_cCuDecoder.destroy();
    592495  m_bFirstSliceInPicture  = true;
    593496
     
    595498}
    596499
    597 #if SETTING_NO_OUT_PIC_PRIOR
    598 Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
     500Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
    599501{
    600   if (!rpcListPic || !m_isNoOutputPriorPics) return;
    601 
    602   TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
    603 
    604   while (iterPic != rpcListPic->end())
    605   {
    606     TComPic*& pcPicTmp = *(iterPic++);
     502  if (!pcListPic || !m_isNoOutputPriorPics) return;
     503
     504  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
     505
     506  while (iterPic != pcListPic->end())
     507  {
     508    TComPic* pcPicTmp = *(iterPic++);
    607509    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
    608510    {
     
    611513  }
    612514}
    613 #endif
    614 
    615 #if EARLY_REF_PIC_MARKING
    616 Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
    617 {
    618   UInt currTid = m_pcPic->getTLayer();
    619   UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
    620   UInt latestDecLayerId = m_layerId;
    621   UInt numTargetDecLayers = 0;
    622   Int targetDecLayerIdList[MAX_LAYERS];
    623   UInt latestDecIdx = 0;
    624   TComSlice* pcSlice = m_pcPic->getSlice(0);
    625 
    626   if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
    627   {
    628     return;
    629   }
    630 
    631   // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
    632   if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
    633           pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
    634           pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
    635           pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
    636           pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
    637           pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
    638           pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
    639           pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
    640   {
    641     return;
    642   }
    643 
    644   if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
    645   {
    646     return;
    647   }
    648 
    649   for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
    650   {
    651     if ( latestDecLayerId == (*it) )
    652     {
    653       latestDecIdx = numTargetDecLayers;
    654     }
    655     targetDecLayerIdList[numTargetDecLayers++] = (*it);
    656   }
    657 
    658   Int remainingInterLayerReferencesFlag = 0;
    659 #if O0225_MAX_TID_FOR_REF_LAYERS
    660   for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
    661   {
    662     Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
    663     if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
    664     {
    665 #else
    666   if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
    667   {
    668     for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
    669     {
    670 #endif
    671       for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
    672       {
    673         if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
    674         {
    675           remainingInterLayerReferencesFlag = 1;
    676         }
    677       }
    678     }
    679   }
    680 
    681   if ( remainingInterLayerReferencesFlag == 0 )
    682   {
    683     pcSlice->setReferenced(false);
    684   }
    685 }
    686 #endif
    687 
    688 Void TDecTop::xCreateLostPicture(Int iLostPoc)
     515
     516Void TDecTop::xCreateLostPicture(Int iLostPoc)
    689517{
    690518  printf("\ninserting lost poc : %d\n",iLostPoc);
     
    731559  }
    732560  cFillPic->setCurrSliceIdx(0);
    733   for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++)
    734   {
    735     cFillPic->getCU(i)->initCU(cFillPic,i);
     561  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
     562  {
     563    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
    736564  }
    737565  cFillPic->getSlice(0)->setReferenced(true);
     
    749577{
    750578  m_parameterSetManagerDecoder.applyPrefetchedPS();
    751  
     579
    752580  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
    753581  assert (pps != 0);
     
    872700
    873701#if O0194_DIFFERENT_BITDEPTH_EL_BL
    874       g_bitDepthYLayer[0] = repFormat->getBitDepthVpsLuma();
    875       g_bitDepthCLayer[0] = repFormat->getBitDepthVpsChroma();
     702      g_bitDepthLayer[CHANNEL_TYPE_LUMA][0] = repFormat->getBitDepthVpsLuma();
     703      g_bitDepthLayer[CHANNEL_TYPE_CHROMA][0] = repFormat->getBitDepthVpsChroma();
    876704#endif
    877705    }
     
    934762#endif
    935763    }
    936    
     764
    937765#if P0182_VPS_VUI_PS_FLAG
    938766    UInt layerIdx = activeVPS->getLayerIdInVps( m_layerId );
     
    948776      assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
    949777      assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
    950       assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepthY() );
    951       assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepthC() );
     778      assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepth(CHANNEL_TYPE_LUMA) );
     779      assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) );
    952780      assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
    953781      assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
     
    959787#endif
    960788
    961   if( pps->getDependentSliceSegmentsEnabledFlag() )
    962   {
    963     Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
    964 
    965     if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
    966     {
    967       m_cSliceDecoder.initCtxMem(NumCtx);
    968       for ( UInt st = 0; st < NumCtx; st++ )
    969       {
    970         TDecSbac* ctx = NULL;
    971         ctx = new TDecSbac;
    972         ctx->init( &m_cBinCABAC );
    973         m_cSliceDecoder.setCtxMem( ctx, st );
    974       }
    975     }
    976   }
     789#if R0227_REP_FORMAT_CONSTRAINT //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
     790  UInt layerIdx = activeVPS->getLayerIdInVps(m_apcSlicePilot->getLayerId());
     791
     792  if ( activeVPS->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
     793  {
     794    assert( sps->getPicWidthInLumaSamples()        <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
     795    assert( sps->getPicHeightInLumaSamples()       <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
     796    assert( sps->getChromaFormatIdc()              <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
     797    assert( sps->getBitDepth(CHANNEL_TYPE_LUMA)    <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
     798    assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA)  <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
     799  }
     800  else if ( activeVPS->getVpsExtensionFlag() == 1 )
     801  {
     802    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
     803    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
     804    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
     805    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
     806    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
     807  }
     808#endif
    977809
    978810  m_apcSlicePilot->setPPS(pps);
    979811  m_apcSlicePilot->setSPS(sps);
    980812  pps->setSPS(sps);
     813  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : ((pps->getNumTileRowsMinus1() + 1)*(pps->getNumTileColumnsMinus1() + 1)));
     814  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
     815  pps->setMinCuChromaQpAdjSize( sps->getMaxCUWidth() >> ( pps->getMaxCuChromaQpAdjDepth()) );
     816
     817  for (UInt channel = 0; channel < MAX_NUM_CHANNEL_TYPE; channel++)
     818  {
    981819#if REPN_FORMAT_IN_VPS
    982   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
    983 #else
    984   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
    985 #endif
    986   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
    987 
    988 #if REPN_FORMAT_IN_VPS
    989   g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
    990   g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
    991 #else
    992   g_bitDepthY     = sps->getBitDepthY();
    993   g_bitDepthC     = sps->getBitDepthC();
    994 #endif
     820    g_bitDepth[channel] = isLuma(ChannelType(channel)) ? m_apcSlicePilot->getBitDepthY() : m_apcSlicePilot->getBitDepthC();
     821#else
     822    g_bitDepth[channel] = sps->getBitDepth(ChannelType(channel));
     823#endif
     824
     825    if (sps->getUseExtendedPrecision()) g_maxTrDynamicRange[channel] = std::max<Int>(15, (g_bitDepth[channel] + 6));
     826    else                                g_maxTrDynamicRange[channel] = 15;
     827  }
    995828  g_uiMaxCUWidth  = sps->getMaxCUWidth();
    996829  g_uiMaxCUHeight = sps->getMaxCUHeight();
    997830  g_uiMaxCUDepth  = sps->getMaxCUDepth();
    998   g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
     831  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() + (Int)getMaxCUDepthOffset(sps->getChromaFormatIdc(), sps->getQuadtreeTULog2MinSize()));
    999832
    1000833  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
     
    1010843  m_cSAO.destroy();
    1011844#if REPN_FORMAT_IN_VPS
    1012 #if AUXILIARY_PICTURES
    1013   m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
    1014 #else
    1015   m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
    1016 #endif
    1017 #else
    1018   m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
     845  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), pps->getSaoOffsetBitShift(CHANNEL_TYPE_LUMA), pps->getSaoOffsetBitShift(CHANNEL_TYPE_CHROMA) );
     846#else
     847  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), pps->getSaoOffsetBitShift(CHANNEL_TYPE_LUMA), pps->getSaoOffsetBitShift(CHANNEL_TYPE_CHROMA) );
    1019848#endif
    1020849  m_cLoopFilter.create( sps->getMaxCUDepth() );
     
    1031860#endif
    1032861{
    1033   TComPic*&   pcPic         = m_pcPic;
    1034862#if SVC_EXTENSION
    1035863  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
     
    1046874      assert(layerIdx > m_apcSlicePilot->getVPS()->getVpsNumLayerSetsMinus1());
    1047875    }
    1048   }
    1049 #else
    1050   checkValueOfTargetOutputLayerSetIdx(m_apcSlicePilot->getVPS());
     876  } 
     877#else
     878  checkValueOfTargetOutputLayerSetIdx( m_apcSlicePilot->getVPS());
    1051879#endif
    1052880#endif
     
    1062890  if (m_bFirstSliceInPicture)
    1063891  {
    1064     m_uiSliceIdx     = 0;
     892    m_uiSliceIdx = 0;
    1065893  }
    1066894  else
    1067895  {
    1068     m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
     896    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
    1069897  }
    1070898  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
     
    1080908                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
    1081909  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
    1082  
    1083910  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
    1084911  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
     912
     913#if ENC_DEC_TRACE
     914  const UInt64 originalSymbolCount = g_nSymbolCounter;
     915#endif
    1085916
    1086917#if SVC_EXTENSION
     
    1093924
    1094925  // set POC for dependent slices in skipped pictures
    1095   if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
     926  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
    1096927  {
    1097928    m_apcSlicePilot->setPOC(m_skippedPOC);
     
    1101932  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
    1102933
    1103 #if SETTING_NO_OUT_PIC_PRIOR
    1104934  //For inference of NoOutputOfPriorPicsFlag
    1105935  if (m_apcSlicePilot->getRapPicFlag())
     
    1147977    }
    1148978  }
    1149 #endif
    1150 
    1151 #if FIX_POC_CRA_NORASL_OUTPUT
     979
    1152980  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
    1153981  {
     
    1155983    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
    1156984  }
    1157 #endif
    1158985
    1159986  // Skip pictures due to random access
     
    11921019    }
    11931020#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
    1194     else if (m_lastPicHasEos)
     1021    else if( m_lastPicHasEos )
    11951022    {
    11961023      setNoClrasOutputFlag(true);
     
    15711398#endif
    15721399#if POC_RESET_IDC_DECODER
    1573   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
    1574 #else
    1575   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
     1400  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
     1401#else
     1402  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
    15761403#endif
    15771404  {
     
    16111438
    16121439  // actual decoding starts here
    1613     xActivateParameterSets();
     1440  xActivateParameterSets();
    16141441
    16151442#if REPN_FORMAT_IN_VPS
     
    16191446  xInitILRP(m_apcSlicePilot);
    16201447#endif
    1621   if (m_apcSlicePilot->isNextSlice())
     1448  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
    16221449  {
    16231450    m_prevPOC = m_apcSlicePilot->getPOC();
     
    16261453  }
    16271454  m_bFirstSliceInSequence = false;
    1628 #if SETTING_NO_OUT_PIC_PRIOR 
    16291455  m_bFirstSliceInBitstream  = false;
    1630 #endif
    16311456#if POC_RESET_FLAG
    16321457  // This operation would do the following:
     
    17341559#else //SVC_EXTENSION
    17351560  //we should only get a different poc for a new picture (with CTU address==0)
    1736   if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
     1561  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0)) 
    17371562  {
    17381563    printf ("Warning, the first slice of a picture might have been lost!\n");
    17391564  }
     1565
    17401566  // exit when a new picture is found
    1741   if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
     1567  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
    17421568  {
    17431569    if (m_prevPOC >= m_pocRandomAccess)
    17441570    {
    17451571      m_prevPOC = m_apcSlicePilot->getPOC();
     1572#if ENC_DEC_TRACE
     1573      //rewind the trace counter since we didn't actually decode the slice
     1574      g_nSymbolCounter = originalSymbolCount;
     1575#endif
    17461576      return true;
    17471577    }
     
    17521582  xActivateParameterSets();
    17531583
    1754   if (m_apcSlicePilot->isNextSlice())
     1584  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
    17551585  {
    17561586    m_prevPOC = m_apcSlicePilot->getPOC();
    17571587  }
    17581588  m_bFirstSliceInSequence = false;
     1589  m_bFirstSliceInBitstream  = false;
    17591590#endif //SVC_EXTENSION
    17601591  //detect lost reference picture and insert copy of earlier frame.
     
    17791610      if( pFile->good() )
    17801611      {
    1781         Bool is16bit  = g_bitDepthYLayer[0] > 8 || g_bitDepthCLayer[0] > 8;
    1782         UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth();
    1783         UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
     1612        Bool is16bit  = g_bitDepthLayer[CHANNEL_TYPE_LUMA][0] > 8 || g_bitDepthLayer[CHANNEL_TYPE_CHROMA][0] > 8;
     1613        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth(COMPONENT_Y);
     1614        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(COMPONENT_Y);
    17841615
    17851616        Int len = uiWidth * (is16bit ? 2 : 1);
     
    17951626
    17961627        // read Y component
    1797         Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
    1798         UInt uiStride = pBLPic->getPicYuvRec()->getStride();
     1628        Pel* pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Y);
     1629        UInt uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Y);
    17991630        for( Int i = 0; i < uiHeight; i++ )
    18001631        {
     
    18241655
    18251656        // read Cb component
    1826         pPel = pBLPic->getPicYuvRec()->getCbAddr();
    1827         uiStride = pBLPic->getPicYuvRec()->getCStride();
     1657        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cb);
     1658        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cb);
    18281659        for( Int i = 0; i < uiHeight; i++ )
    18291660        {
     
    18491680
    18501681        // read Cr component
    1851         pPel = pBLPic->getPicYuvRec()->getCrAddr();
    1852         uiStride = pBLPic->getPicYuvRec()->getCStride();
     1682        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cr);
     1683        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cr);
    18531684        for( Int i = 0; i < uiHeight; i++ )
    18541685        {
     
    18931724#endif
    18941725    // Buffer initialize for prediction.
    1895     m_cPrediction.initTempBuff();
     1726    m_cPrediction.initTempBuff(m_apcSlicePilot->getSPS()->getChromaFormatIdc());
    18961727#if ALIGNED_BUMPING
    18971728    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
     
    19001731#endif
    19011732    //  Get a new picture buffer
    1902     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
     1733    xGetNewPicBuffer (m_apcSlicePilot, m_pcPic);
    19031734
    19041735#if POC_RESET_IDC_DECODER
    1905     pcPic->setCurrAuFlag( true );
     1736    m_pcPic->setCurrAuFlag( true );
    19061737#if POC_RESET_RESTRICTIONS
    1907     if( pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
     1738    if( m_pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
    19081739    {
    19091740      // IDR picture with nuh_layer_id > 0 present
     
    19281759      m_checkPocRestrictionsForCurrAu = true;
    19291760      m_pocResetIdcOrCurrAu = m_apcSlicePilot->getPocResetIdc();
    1930       if( pcPic->getLayerId() == 0 )
     1761      if( m_pcPic->getLayerId() == 0 )
    19311762      {
    19321763        // Base layer picture is present
     
    20091840      if (seiTMVPConstrainsList.size() > 0)
    20101841      {
    2011         assert ( pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
     1842        assert ( m_pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
    20121843        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
    20131844        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
     
    20181849          {
    20191850            TComPic *refPic = *iterRefPic;
    2020             if( ( refPic->getLayerId() == pcPic->getLayerId() ) && refPic->getReconMark() )
     1851            if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() )
    20211852            {
    20221853              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
     
    20381869
    20391870    // transfer any SEI messages that have been received to the picture
    2040     pcPic->setSEIs(m_SEIs);
     1871    m_pcPic->setSEIs(m_SEIs);
    20411872    m_SEIs.clear();
    20421873
    20431874    // Recursive structure
    2044     m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
     1875    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getChromaFormatIdc() );
    20451876#if SVC_EXTENSION
    20461877    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
     
    20581889    {
    20591890      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
    2060       SEIMessages &picSEI = pcPic->getSEIs();
     1891      SEIMessages &picSEI = m_pcPic->getSEIs();
    20611892      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
    20621893      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
     
    20641895    }
    20651896  }
    2066  
     1897
    20671898  //  Set picture slice pointer
    20681899  TComSlice*  pcSlice = m_apcSlicePilot;
    2069   Bool bNextSlice     = pcSlice->isNextSlice();
    2070 
    2071   UInt i;
    2072   pcPic->getPicSym()->initTiles(pcSlice->getPPS());
    2073 
    2074   //generate the Coding Order Map and Inverse Coding Order Map
    2075   UInt uiEncCUAddr;
    2076   for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
    2077   {
    2078     pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
    2079     pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
    2080   }
    2081   pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
    2082   pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
    2083 
    2084   //convert the start and end CU addresses of the slice and dependent slice into encoding order
    2085   pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
    2086   pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
    2087   if(pcSlice->isNextSlice())
    2088   {
    2089     pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
    2090     pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
    2091   }
    2092 
    2093   if (m_bFirstSliceInPicture)
    2094   {
    2095     if(pcPic->getNumAllocatedSlice() != 1)
    2096     {
    2097       pcPic->clearSliceBuffer();
     1900
     1901  m_pcPic->getPicSym()->initTiles(pcSlice->getPPS());
     1902  m_pcPic->getPicSym()->initCtuTsRsAddrMaps();
     1903
     1904  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
     1905  // Now, having set up the maps, convert them to the correct form.
     1906  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
     1907  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
     1908  if(!pcSlice->getDependentSliceSegmentFlag())
     1909  {
     1910    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
     1911    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
     1912  }
     1913
     1914  if (m_bFirstSliceInPicture)
     1915  {
     1916    if(m_pcPic->getNumAllocatedSlice() != 1)
     1917    {
     1918      m_pcPic->clearSliceBuffer();
    20981919    }
    20991920  }
    21001921  else
    21011922  {
    2102     pcPic->allocateNewSlice();
    2103   }
    2104   assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
    2105   m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
    2106   pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
    2107 
    2108   pcPic->setTLayer(nalu.m_temporalId);
     1923    m_pcPic->allocateNewSlice();
     1924  }
     1925  assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
     1926  m_apcSlicePilot = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
     1927  m_pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
     1928
     1929  m_pcPic->setTLayer(nalu.m_temporalId);
    21091930
    21101931#if SVC_EXTENSION
    2111   pcPic->setLayerId(nalu.m_layerId);
     1932  m_pcPic->setLayerId(nalu.m_layerId);
    21121933  pcSlice->setLayerId(nalu.m_layerId);
    2113   pcSlice->setPic(pcPic);
    2114 #endif
    2115 
    2116   if (bNextSlice)
     1934  pcSlice->setPic(m_pcPic);
     1935#endif
     1936
     1937  if (!pcSlice->getDependentSliceSegmentFlag())
    21171938  {
    21181939    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
     
    21311952      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
    21321953#endif
    2133       for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
     1954      for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
    21341955      {
    21351956        UInt refLayerIdc = i;
     
    21922013#if REF_REGION_OFFSET
    21932014        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
    2194         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
    2195         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
    2196 #else
    2197         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
    2198         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
     2015        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y) - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
     2016        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y) - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
     2017#else
     2018        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y);
     2019        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y);
    21992020#if Q0200_CONFORMANCE_BL_SIZE
    22002021        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
     
    22042025#endif
    22052026#endif
    2206         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
    2207         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
     2027        Int widthEL   = m_pcPic->getPicYuvRec()->getWidth(COMPONENT_Y)  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     2028        Int heightEL  = m_pcPic->getPicYuvRec()->getHeight(COMPONENT_Y) - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
    22082029
    22092030#if RESAMPLING_FIX
     
    22562077#endif
    22572078#if SVC_EXTENSION
    2258         if( pcPic->isSpatialEnhLayer(refLayerIdc) )
     2079        if( m_pcPic->isSpatialEnhLayer(refLayerIdc) )
    22592080        {
    22602081          // check for the sample prediction picture type
     
    22622083          {
    22632084#if O0215_PHASE_ALIGNMENT_REMOVAL
    2264             m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec());
     2085            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec());
    22652086#else
    22662087#if O0215_PHASE_ALIGNMENT
    22672088#if O0194_JOINT_US_BITSHIFT
    22682089#if Q0048_CGS_3D_ASYMLUT
    2269             m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
    2270 #else
    2271             m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
     2090            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
     2091#else
     2092            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
    22722093#endif
    22732094#else
    22742095#if Q0048_CGS_3D_ASYMLUT
    22752096#if MOVE_SCALED_OFFSET_TO_PPS
    2276           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    2277 #else
    2278           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    2279 #endif
    2280 #else
    2281           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     2097          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     2098#else
     2099          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     2100#endif
     2101#else
     2102          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
    22822103#endif
    22832104#endif
     
    22862107#if Q0048_CGS_3D_ASYMLUT
    22872108#if REF_REGION_OFFSET
    2288           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
    2289 #else
    2290           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
    2291 #endif
    2292 #else
    2293           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     2109          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL, altRL );
     2110#else
     2111          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL );
     2112#endif
     2113#else
     2114          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL );
    22942115#endif
    22952116#else
    22962117#if Q0048_CGS_3D_ASYMLUT
    2297             m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
    2298 #else
    2299             m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     2118            m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL );
     2119#else
     2120            m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL );
    23002121#endif
    23012122#endif
     
    23062127        else
    23072128        {
    2308           pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
    2309         }
    2310         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
     2129          m_pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
     2130        }
     2131        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
    23112132#endif //SVC_EXTENSION
    23122133      }
     
    23152136    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    23162137    {
    2317       for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     2138      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
    23182139      {
    23192140        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     
    23472168#endif
    23482169
    2349         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
     2170        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
    23502171      }
    23512172
     
    24462267            bLowDelay = false;
    24472268          }
    2448         }       
    2449       }
    2450 
    2451       pcSlice->setCheckLDC(bLowDelay);           
     2269        }
     2270      }
     2271
     2272      pcSlice->setCheckLDC(bLowDelay);
    24522273    }
    24532274
     
    24562277  }
    24572278
    2458   pcPic->setCurrSliceIdx(m_uiSliceIdx);
     2279  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
    24592280  if(pcSlice->getSPS()->getScalingListFlag())
    24602281  {
     
    24762297      pcSlice->setDefaultScalingList();
    24772298    }
    2478     m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
     2299    m_cTrQuant.setScalingListDec(pcSlice->getScalingList(), pcSlice->getSPS()->getChromaFormatIdc());
    24792300    m_cTrQuant.setUseScalingList(true);
    24802301  }
    24812302  else
    24822303  {
    2483     m_cTrQuant.setFlatScalingList();
     2304    m_cTrQuant.setFlatScalingList(pcSlice->getSPS()->getChromaFormatIdc());
    24842305    m_cTrQuant.setUseScalingList(false);
    24852306  }
    24862307
    24872308  //  Decode a picture
    2488   m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
     2309  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, m_pcPic);
    24892310
    24902311#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     
    25042325{
    25052326  TComVPS* vps = new TComVPS();
    2506  
     2327
    25072328  m_cEntropyDecoder.decodeVPS( vps );
    25082329  m_parameterSetManagerDecoder.storePrefetchedVPS(vps);
     
    25162337{
    25172338  TComSPS* sps = new TComSPS();
     2339#if O0043_BEST_EFFORT_DECODING
     2340  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
     2341#endif
    25182342  sps->setLayerId(m_layerId);
    25192343#if SPS_DPB_PARAMS
     
    25542378{
    25552379  TComSPS* sps = new TComSPS();
     2380#if O0043_BEST_EFFORT_DECODING
     2381  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
     2382#endif
    25562383  m_cEntropyDecoder.decodeSPS( sps );
    25572384  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
     
    25762403    }
    25772404#if LAYERS_NOT_PRESENT_SEI
    2578     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
    2579 #else
    2580     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     2405    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
     2406#else
     2407    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
    25812408#endif
    25822409  }
     
    25842411  {
    25852412#if LAYERS_NOT_PRESENT_SEI
    2586     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
    2587 #else
    2588     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     2413    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
     2414#else
     2415    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
    25892416#endif
    25902417    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     
    26222449  {
    26232450#if LAYERS_NOT_PRESENT_SEI
    2624     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
    2625 #else
    2626     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     2451    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
     2452#else
     2453    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
     2454
    26272455#endif
    26282456  }
     
    26302458  {
    26312459#if LAYERS_NOT_PRESENT_SEI
    2632     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
    2633 #else
    2634     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     2460    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
     2461#else
     2462    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
    26352463#endif
    26362464    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     
    26732501#endif
    26742502      xDecodeVPS();
     2503#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2504      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
     2505#endif
    26752506#if Q0177_EOS_CHECKS
    26762507      m_isLastNALWasEos = false;
     
    26992530#endif
    27002531      return false;
    2701      
     2532
    27022533    case NAL_UNIT_SPS:
    27032534      xDecodeSPS();
     2535#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2536      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
     2537#endif
    27042538      return false;
    27052539
     
    27102544#endif
    27112545        );
     2546#if RExt__DECODER_DEBUG_BIT_STATISTICS
     2547      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
     2548#endif
    27122549      return false;
    2713      
     2550
    27142551    case NAL_UNIT_PREFIX_SEI:
    27152552    case NAL_UNIT_SUFFIX_SEI:
     
    27592596#endif
    27602597      break;
    2761      
     2598
    27622599    case NAL_UNIT_EOS:
    27632600#if Q0177_EOS_CHECKS
     
    27802617      m_pocRandomAccess = MAX_INT;
    27812618      m_prevPOC = MAX_INT;
    2782       m_bFirstSliceInPicture = true;
    2783       m_bFirstSliceInSequence = true;
    27842619      m_prevSliceSkipped = false;
    27852620      m_skippedPOC = 0;
    27862621      return false;
    2787      
     2622
    27882623    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
    27892624      // TODO: process AU delimiter
    27902625      return false;
    2791      
     2626
    27922627    case NAL_UNIT_EOB:
    27932628#if P0130_EOB
     
    27992634#endif
    28002635      return false;
    2801      
     2636
    28022637    case NAL_UNIT_FILLER_DATA:
    28032638#if Q0177_EOS_CHECKS
     
    28052640#endif
    28062641      return false;
    2807      
     2642
    28082643    case NAL_UNIT_RESERVED_VCL_N10:
    28092644    case NAL_UNIT_RESERVED_VCL_R11:
     
    28122647    case NAL_UNIT_RESERVED_VCL_N14:
    28132648    case NAL_UNIT_RESERVED_VCL_R15:
    2814      
     2649
    28152650    case NAL_UNIT_RESERVED_IRAP_VCL22:
    28162651    case NAL_UNIT_RESERVED_IRAP_VCL23:
    2817      
     2652
    28182653    case NAL_UNIT_RESERVED_VCL24:
    28192654    case NAL_UNIT_RESERVED_VCL25:
     
    28242659    case NAL_UNIT_RESERVED_VCL30:
    28252660    case NAL_UNIT_RESERVED_VCL31:
    2826      
     2661
    28272662    case NAL_UNIT_RESERVED_NVCL41:
    28282663    case NAL_UNIT_RESERVED_NVCL42:
     
    28512686    default:
    28522687      assert (0);
     2688      break;
    28532689  }
    28542690
     
    28642700Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
    28652701{
    2866   if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
     2702  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) &&
    28672703       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
    28682704  {
     
    28822718 * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped.
    28832719 * If the random access point is IDR all pictures after the random access point are decoded.
    2884  * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC 
    2885  * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random 
     2720 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
     2721 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
    28862722 * access point there is no guarantee that the decoder will not crash.
    28872723 */
    28882724Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
    28892725{
    2890   if (iSkipFrame) 
     2726  if (iSkipFrame)
    28912727  {
    28922728    iSkipFrame--;   // decrement the counter
     
    29072743      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
    29082744    }
    2909     else 
     2745    else
    29102746    {
    29112747      static Bool warningMessage = false;
     
    29252761  }
    29262762  // if we reach here, then the picture is not skipped.
    2927   return false; 
     2763  return false;
    29282764}
    29292765
    29302766#if SVC_EXTENSION
     2767#if !REPN_FORMAT_IN_VPS
     2768Void TDecTop::xInitILRP(TComSPS *pcSPS)
     2769#else
     2770Void TDecTop::xInitILRP(TComSlice *slice)
     2771#endif
     2772{
     2773#if REPN_FORMAT_IN_VPS
     2774  TComSPS* pcSPS = slice->getSPS();
     2775  Int bitDepthY   = slice->getBitDepthY();
     2776  Int bitDepthC   = slice->getBitDepthC();
     2777  Int picWidth    = slice->getPicWidthInLumaSamples();
     2778  Int picHeight   = slice->getPicHeightInLumaSamples();
     2779#endif
     2780  if(m_layerId>0)
     2781  {
     2782#if REPN_FORMAT_IN_VPS
     2783    g_bitDepth[CHANNEL_TYPE_LUMA]     = bitDepthY;
     2784    g_bitDepth[CHANNEL_TYPE_CHROMA]   = bitDepthC;
     2785#else
     2786    g_bitDepth[CHANNEL_TYPE_LUMA]     = pcSPS->getBitDepthY();
     2787    g_bitDepth[CHANNEL_TYPE_CHROMA]   = pcSPS->getBitDepthC();
     2788#endif
     2789    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
     2790    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
     2791    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
     2792    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
     2793
     2794    Int  numReorderPics[MAX_TLAYER];
     2795#if R0156_CONF_WINDOW_IN_REP_FORMAT
     2796    Window &conformanceWindow = slice->getConformanceWindow();
     2797#else
     2798    Window &conformanceWindow = pcSPS->getConformanceWindow();
     2799#endif
     2800    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
     2801
     2802    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
     2803    {
     2804#if USE_DPB_SIZE_TABLE
     2805      if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
     2806      {
     2807        assert( this->getLayerId() == 0 );
     2808        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
     2809      }
     2810      else
     2811      {
     2812        TComVPS *vps = slice->getVPS();
     2813        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
     2814        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
     2815      }
     2816#else
     2817      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
     2818#endif
     2819    }
     2820
     2821    if (m_cIlpPic[0] == NULL)
     2822    {
     2823      for (Int j=0; j < m_numDirectRefLayers; j++)
     2824      {
     2825
     2826        m_cIlpPic[j] = new  TComPic;
     2827
     2828#if AUXILIARY_PICTURES
     2829#if REPN_FORMAT_IN_VPS
     2830        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
     2831#else
     2832        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
     2833#endif
     2834#else
     2835#if REPN_FORMAT_IN_VPS
     2836        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
     2837#else
     2838        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
     2839#endif
     2840#endif
     2841        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
     2842        {
     2843          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
     2844        }
     2845      }
     2846    }
     2847  }
     2848}
     2849
    29312850#if VPS_EXTN_DIRECT_REF_LAYERS
    29322851TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
     
    29932912  }
    29942913}
    2995 
     2914#endif
     2915
     2916#if EARLY_REF_PIC_MARKING
     2917Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
     2918{
     2919  UInt currTid = m_pcPic->getTLayer();
     2920  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
     2921  UInt latestDecLayerId = m_layerId;
     2922  UInt numTargetDecLayers = 0;
     2923  Int targetDecLayerIdList[MAX_LAYERS];
     2924  UInt latestDecIdx = 0;
     2925  TComSlice* pcSlice = m_pcPic->getSlice(0);
     2926
     2927  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
     2928  {
     2929    return;
     2930  }
     2931
     2932  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
     2933  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
     2934          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
     2935          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
     2936          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
     2937          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
     2938          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
     2939          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
     2940          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
     2941  {
     2942    return;
     2943  }
     2944
     2945  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
     2946  {
     2947    return;
     2948  }
     2949
     2950  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
     2951  {
     2952    if ( latestDecLayerId == (*it) )
     2953    {
     2954      latestDecIdx = numTargetDecLayers;
     2955    }
     2956    targetDecLayerIdList[numTargetDecLayers++] = (*it);
     2957  }
     2958
     2959  Int remainingInterLayerReferencesFlag = 0;
     2960#if O0225_MAX_TID_FOR_REF_LAYERS
     2961  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
     2962  {
     2963    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
     2964    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
     2965    {
     2966#else
     2967  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
     2968  {
     2969    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
     2970    {
     2971#endif
     2972      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
     2973      {
     2974        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
     2975        {
     2976          remainingInterLayerReferencesFlag = 1;
     2977        }
     2978      }
     2979    }
     2980  }
     2981
     2982  if ( remainingInterLayerReferencesFlag == 0 )
     2983  {
     2984    pcSlice->setReferenced(false);
     2985  }
     2986}
    29962987#endif
    29972988
     
    30773068    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
    30783069#endif
     3070   
    30793071#if !R0235_SMALLEST_LAYER_ID
    30803072    Bool layerSetMatchFlag = true;
     
    32793271{
    32803272  UInt smallestLayerId;
    3281   Int  targetOlsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx();
     3273  Int  targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx();
    32823274  assert( targetOlsIdx >= 0 );
    32833275
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h

    r1005 r1029  
    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-2014, ITU/ISO/IEC
     
    6969private:
    7070  Int                     m_iMaxRefPicNum;
    71  
     71
    7272  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
    7373  Int                     m_pocCRA;            ///< POC number of the latest CRA picture
     
    7575
    7676  TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
    77   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
     77  ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets
    7878  TComSlice*              m_apcSlicePilot;
    7979
     
    111111  Bool                    m_prevSliceSkipped;
    112112  Int                     m_skippedPOC;
    113 #if SETTING_NO_OUT_PIC_PRIOR 
    114113  Bool                    m_bFirstSliceInBitstream;
    115114  Int                     m_lastPOCNoOutputPriorPics;
    116115  Bool                    m_isNoOutputPriorPics;
    117116  Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
    118 #endif
     117#if O0043_BEST_EFFORT_DECODING
     118  UInt                    m_forceDecodeBitDepth;
     119#endif
     120  std::ostream           *m_pDecodedSEIOutputStream;
     121
     122#if SVC_EXTENSION
    119123#if Q0177_EOS_CHECKS
    120124  Bool                    m_isLastNALWasEos;
     
    123127  Bool                    m_lastPicHasEos;
    124128#endif
    125 #if SVC_EXTENSION
    126129  static UInt             m_prevPOC;        // POC of the previous slice
    127130  static UInt             m_uiPrevLayerId;  // LayerId of the previous slice
     
    199202  TDecTop();
    200203  virtual ~TDecTop();
    201  
     204
    202205  Void  create  ();
    203206  Void  destroy ();
    204207
    205   void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
     208  Void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
    206209#if Q0074_COLOUR_REMAPPING_SEI
    207210  void setColourRemappingInfoSEIEnabled(Bool enabled)  { m_cGopDecoder.setColourRemappingInfoSEIEnabled(enabled); }
     
    221224
    222225
    223   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
    224 #if SETTING_NO_OUT_PIC_PRIOR 
    225   Void  checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic);
    226   Bool  getNoOutputPriorPicsFlag ()         { return m_isNoOutputPriorPics; }
     226  Void  executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
     227  Void  checkNoOutputPriorPics (TComList<TComPic*>* rpcListPic);
     228
     229  Bool  getNoOutputPriorPicsFlag () { return m_isNoOutputPriorPics; }
    227230  Void  setNoOutputPriorPicsFlag (Bool val) { m_isNoOutputPriorPics = val; }
    228 #endif
     231  Void  setFirstSliceInPicture (bool val)  { m_bFirstSliceInPicture = val; }
     232  Bool  getFirstSliceInSequence ()         { return m_bFirstSliceInSequence; }
     233  Void  setFirstSliceInSequence (bool val) { m_bFirstSliceInSequence = val; }
     234#if O0043_BEST_EFFORT_DECODING
     235  Void  setForceDecodeBitDepth(UInt bitDepth) { m_forceDecodeBitDepth = bitDepth; }
     236#endif
     237  Void  setDecodedSEIMessageOutputStream(std::ostream *pOpStream) { m_pDecodedSEIOutputStream = pOpStream; }
    229238
    230239#if SVC_EXTENSION
     
    314323  std::vector<TComPic>* getConfListPic() {return &m_confListPic; }
    315324  // std::string const getDecodedYuvLayerFileName(Int layerId) { return m_decodedYuvLayerFileName[layerId]; }
     325  Bool const getConfModeFlag() { return m_confModeFlag; }
     326  Void setConfModeFlag(Bool x) { m_confModeFlag = x; }
    316327#endif
    317328#endif //SVC_EXTENSION
     
    354365  Void resetPocRestrictionCheckParameters();
    355366#endif
    356   public:
    357 #if CONFORMANCE_BITSTREAM_MODE
    358   Bool const getConfModeFlag() { return m_confModeFlag; }
    359   Void setConfModeFlag(Bool x) { m_confModeFlag = x; }
    360 #endif
    361367#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
    362368  Void xCheckLayerReset();
     
    367373
    368374
    369 
    370375//! \}
    371376
Note: See TracChangeset for help on using the changeset viewer.