source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp @ 1263

Last change on this file since 1263 was 1259, checked in by seregin, 9 years ago

port rev 4256

  • Property svn:eol-style set to native
File size: 86.7 KB
RevLine 
[313]1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
[1259]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[313]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
[1029]34/**
[313]35 \file     SEIread.cpp
[1029]36 \brief    reading funtionality for SEI messages
[313]37 */
38
39#include "TLibCommon/CommonDef.h"
40#include "TLibCommon/TComBitStream.h"
41#include "TLibCommon/SEI.h"
42#include "TLibCommon/TComSlice.h"
43#include "SyntaxElementParser.h"
44#include "SEIread.h"
[1029]45#include "TLibCommon/TComPicYuv.h"
46#include <iomanip>
[313]47
[1029]48
[313]49//! \ingroup TLibDecoder
50//! \{
51
[1029]52
[313]53#if ENC_DEC_TRACE
54Void  xTraceSEIHeader()
55{
56  fprintf( g_hTrace, "=========== SEI message ===========\n");
57}
58
59Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
60{
[1029]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);
[1246]68  if (pOS)
69  {
70    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
71  }
[1029]72}
73
74Void SEIReader::sei_read_uvlc(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
75{
76  READ_UVLC(ruiCode, pSymbolName);
[1246]77  if (pOS)
78  {
79    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
80  }
[1029]81}
82
83Void SEIReader::sei_read_svlc(std::ostream *pOS, Int& ruiCode, const Char *pSymbolName)
84{
85  READ_SVLC(ruiCode, pSymbolName);
[1246]86  if (pOS)
87  {
88    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << ruiCode << "\n";
89  }
[1029]90}
91
92Void SEIReader::sei_read_flag(std::ostream *pOS, UInt& ruiCode, const Char *pSymbolName)
93{
94  READ_FLAG(ruiCode, pSymbolName);
[1246]95  if (pOS)
96  {
97    (*pOS) << "  " << std::setw(55) << pSymbolName << ": " << (ruiCode?1:0) << "\n";
98  }
[1029]99}
100
101static inline Void output_sei_message_header(SEI &sei, std::ostream *pDecodedMessageOutputStream, UInt payloadSize)
102{
103  if (pDecodedMessageOutputStream)
[313]104  {
[1029]105    std::string seiMessageHdr(SEI::getSEIMessageString(sei.payloadType())); seiMessageHdr+=" SEI message";
106    (*pDecodedMessageOutputStream) << std::setfill('-') << std::setw(seiMessageHdr.size()) << "-" << std::setfill(' ') << "\n" << seiMessageHdr << "\n";
[313]107  }
108}
109
[1029]110#undef READ_CODE
111#undef READ_SVLC
112#undef READ_UVLC
113#undef READ_FLAG
114
115
[313]116/**
117 * unmarshal a single SEI message from bitstream bs
118 */
[588]119#if LAYERS_NOT_PRESENT_SEI
[1235]120Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[313]121#else
[1235]122Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[313]123#endif
124{
125  setBitstream(bs);
126
127  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
128  do
129  {
[588]130#if LAYERS_NOT_PRESENT_SEI
[1029]131    xReadSEImessage(seis, nalUnitType, vps, sps, pDecodedMessageOutputStream);
[313]132#else
[1029]133    xReadSEImessage(seis, nalUnitType, sps, pDecodedMessageOutputStream);
[313]134#endif
135    /* SEI messages are an integer number of bytes, something has failed
136    * in the parsing if bitstream not byte-aligned */
137    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
[1246]138  }
139  while (m_pcBitstream->getNumBitsLeft() > 8);
[313]140
141  UInt rbspTrailingBits;
[1029]142  sei_read_code(NULL, 8, rbspTrailingBits, "rbsp_trailing_bits");
[313]143  assert(rbspTrailingBits == 0x80);
144}
145
[644]146#if O0164_MULTI_LAYER_HRD
[588]147#if LAYERS_NOT_PRESENT_SEI
[1235]148Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei)
[644]149#else
[1235]150Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream, const SEIScalableNesting *nestingSei)
[644]151#endif
152#else
153#if LAYERS_NOT_PRESENT_SEI
[1235]154Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[313]155#else
[1235]156Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[313]157#endif
[644]158#endif
[313]159{
160#if ENC_DEC_TRACE
161  xTraceSEIHeader();
162#endif
163  Int payloadType = 0;
164  UInt val = 0;
165
166  do
167  {
[1029]168    sei_read_code(NULL, 8, val, "payload_type");
[313]169    payloadType += val;
170  } while (val==0xFF);
171
172  UInt payloadSize = 0;
173  do
174  {
[1029]175    sei_read_code(NULL, 8, val, "payload_size");
[313]176    payloadSize += val;
177  } while (val==0xFF);
178
179#if ENC_DEC_TRACE
180  xTraceSEIMessageType((SEI::PayloadType)payloadType);
181#endif
182
183  /* extract the payload for this single SEI message.
184   * This allows greater safety in erroneous parsing of an SEI message
185   * from affecting subsequent messages.
186   * After parsing the payload, bs needs to be restored as the primary
187   * bitstream.
188   */
189  TComInputBitstream *bs = getBitstream();
190  setBitstream(bs->extractSubstream(payloadSize * 8));
191
192  SEI *sei = NULL;
193
194  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
195  {
196    switch (payloadType)
197    {
198    case SEI::USER_DATA_UNREGISTERED:
199      sei = new SEIuserDataUnregistered;
[1029]200      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]201      break;
202    case SEI::ACTIVE_PARAMETER_SETS:
[1029]203      sei = new SEIActiveParameterSets;
204      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize, pDecodedMessageOutputStream);
205      break;
[313]206    case SEI::DECODING_UNIT_INFO:
207      if (!sps)
208      {
209        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
210      }
211      else
212      {
[1029]213        sei = new SEIDecodingUnitInfo;
[1185]214#if SVC_EXTENSION
[1029]215        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
216#else       
217        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
[894]218#endif
[313]219      }
[1029]220      break;
[313]221    case SEI::BUFFERING_PERIOD:
222      if (!sps)
223      {
224        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
225      }
226      else
227      {
228        sei = new SEIBufferingPeriod;
[1185]229#if SVC_EXTENSION
[1029]230        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
[894]231#else
[1029]232        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
[894]233#endif
[313]234      }
235      break;
236    case SEI::PICTURE_TIMING:
237      if (!sps)
238      {
239        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
240      }
241      else
242      {
243        sei = new SEIPictureTiming;
[1185]244#if SVC_EXTENSION
[1029]245        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, nestingSei, bspNestingSei, vps, pDecodedMessageOutputStream);
[894]246#else
[1029]247        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, pDecodedMessageOutputStream);
[894]248#endif
[313]249      }
250      break;
251    case SEI::RECOVERY_POINT:
252      sei = new SEIRecoveryPoint;
[1029]253      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]254      break;
255    case SEI::FRAME_PACKING:
256      sei = new SEIFramePacking;
[1029]257      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]258      break;
[1029]259    case SEI::SEGM_RECT_FRAME_PACKING:
260      sei = new SEISegmentedRectFramePacking;
261      xParseSEISegmentedRectFramePacking((SEISegmentedRectFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
262      break;
[313]263    case SEI::DISPLAY_ORIENTATION:
264      sei = new SEIDisplayOrientation;
[1029]265      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]266      break;
267    case SEI::TEMPORAL_LEVEL0_INDEX:
268      sei = new SEITemporalLevel0Index;
[1029]269      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]270      break;
271    case SEI::REGION_REFRESH_INFO:
272      sei = new SEIGradualDecodingRefreshInfo;
[1029]273      xParseSEIRegionRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]274      break;
[1029]275    case SEI::NO_DISPLAY:
276      sei = new SEINoDisplay;
277      xParseSEINoDisplay((SEINoDisplay&) *sei, payloadSize, pDecodedMessageOutputStream);
278      break;
[313]279    case SEI::TONE_MAPPING_INFO:
280      sei = new SEIToneMappingInfo;
[1029]281      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]282      break;
[595]283    case SEI::SOP_DESCRIPTION:
284      sei = new SEISOPDescription;
[1029]285      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize, pDecodedMessageOutputStream);
[595]286      break;
287    case SEI::SCALABLE_NESTING:
288      sei = new SEIScalableNesting;
[588]289#if LAYERS_NOT_PRESENT_SEI
[1029]290      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps, pDecodedMessageOutputStream);
[595]291#else
[1029]292      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps, pDecodedMessageOutputStream);
[595]293#endif
[644]294      break;
[1029]295    case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
296      sei = new SEITempMotionConstrainedTileSets;
297      xParseSEITempMotionConstraintsTileSets((SEITempMotionConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
298      break;
299    case SEI::TIME_CODE:
300      sei = new SEITimeCode;
301      xParseSEITimeCode((SEITimeCode&) *sei, payloadSize, pDecodedMessageOutputStream);
302      break;
303    case SEI::CHROMA_SAMPLING_FILTER_HINT:
304      sei = new SEIChromaSamplingFilterHint;
305      xParseSEIChromaSamplingFilterHint((SEIChromaSamplingFilterHint&) *sei, payloadSize/*, sps*/, pDecodedMessageOutputStream);
306      //}
307      break;
308    case SEI::KNEE_FUNCTION_INFO:
309      sei = new SEIKneeFunctionInfo;
310      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
311      break;
312    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
313      sei = new SEIMasteringDisplayColourVolume;
314      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
315      break;
316#if Q0074_COLOUR_REMAPPING_SEI
317    case SEI::COLOUR_REMAPPING_INFO:
318      sei = new SEIColourRemappingInfo;
319      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
320      break;
321#endif
[595]322#if SVC_EXTENSION
323#if LAYERS_NOT_PRESENT_SEI
[588]324    case SEI::LAYERS_NOT_PRESENT:
[313]325      if (!vps)
326      {
[588]327        printf ("Warning: Found Layers not present SEI message, but no active VPS is available. Ignoring.");
[313]328      }
329      else
330      {
[588]331        sei = new SEILayersNotPresent;
[1029]332        xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps, pDecodedMessageOutputStream);
[313]333      }
334      break;
335#endif
[442]336#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
337    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
338      sei = new SEIInterLayerConstrainedTileSets;
[1029]339      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
[442]340      break;
341#endif
[588]342#if SUB_BITSTREAM_PROPERTY_SEI
343   case SEI::SUB_BITSTREAM_PROPERTY:
344     sei = new SEISubBitstreamProperty;
[1029]345     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, vps, pDecodedMessageOutputStream);
[588]346     break;
347#endif
[644]348#if O0164_MULTI_LAYER_HRD
349   case SEI::BSP_NESTING:
350     sei = new SEIBspNesting;
351#if LAYERS_NOT_PRESENT_SEI
[1029]352     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei, pDecodedMessageOutputStream);
[644]353#else
[1029]354     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei, pDecodedMessageOutputStream);
[644]355#endif
356     break;
357   case SEI::BSP_INITIAL_ARRIVAL_TIME:
358     sei = new SEIBspInitialArrivalTime;
[1029]359     xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei, pDecodedMessageOutputStream);
[644]360     break;
361#endif
[815]362#if Q0189_TMVP_CONSTRAINTS
363   case SEI::TMVP_CONSTRAINTS:
364     sei =  new SEITMVPConstrains;
[1029]365     xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize, pDecodedMessageOutputStream);
[815]366     break;
367#endif
368#if Q0247_FRAME_FIELD_INFO
369   case SEI::FRAME_FIELD_INFO:
370     sei =  new SEIFrameFieldInfo;
[1029]371     xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
[815]372     break;
373#endif
[1037]374#if P0123_ALPHA_CHANNEL_SEI
375   case SEI::ALPHA_CHANNEL_INFO:
376     sei = new SEIAlphaChannelInfo;
377     xParseSEIAlphaChannelInfo((SEIAlphaChannelInfo &) *sei, payloadSize, pDecodedMessageOutputStream);
378     break;
379#endif
[912]380#if Q0096_OVERLAY_SEI
381   case SEI::OVERLAY_INFO:
382     sei = new SEIOverlayInfo;
[1029]383     xParseSEIOverlayInfo((SEIOverlayInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
[912]384     break;
385#endif
[595]386#endif //SVC_EXTENSION
[1037]387   default:
388     for (UInt i = 0; i < payloadSize; i++)
389     {
390       UInt seiByte;
391       sei_read_code (NULL, 8, seiByte, "unknown prefix SEI payload byte");
392     }
393     printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
394     if (pDecodedMessageOutputStream)
395     {
396       (*pDecodedMessageOutputStream) << "Unknown prefix SEI message (payloadType = " << payloadType << ") was found!\n";
397     }
398     break;
[313]399    }
400  }
401  else
402  {
403    switch (payloadType)
404    {
405      case SEI::USER_DATA_UNREGISTERED:
406        sei = new SEIuserDataUnregistered;
[1029]407        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]408        break;
409      case SEI::DECODED_PICTURE_HASH:
410        sei = new SEIDecodedPictureHash;
[1029]411        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize, pDecodedMessageOutputStream);
[313]412        break;
413      default:
414        for (UInt i = 0; i < payloadSize; i++)
415        {
416          UInt seiByte;
[1029]417          sei_read_code( NULL, 8, seiByte, "unknown suffix SEI payload byte");
[313]418        }
419        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
[1029]420        if (pDecodedMessageOutputStream)
421        {
422          (*pDecodedMessageOutputStream) << "Unknown suffix SEI message (payloadType = " << payloadType << ") was found!\n";
423        }
424        break;
[313]425    }
426  }
[1029]427
[313]428  if (sei != NULL)
429  {
430    seis.push_back(sei);
431  }
432
433  /* By definition the underlying bitstream terminates in a byte-aligned manner.
434   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
435   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
436   * 3. Extract the remainingreserved_payload_extension_data bits.
437   *
438   * If there are fewer than 9 bits available, extract them.
439   */
440  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
441  if (payloadBitsRemaining) /* more_data_in_payload() */
442  {
443    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
444    {
445      UInt reservedPayloadExtensionData;
[1029]446      sei_read_code ( pDecodedMessageOutputStream, 1, reservedPayloadExtensionData, "reserved_payload_extension_data");
[313]447    }
448
449    /* 2 */
450    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
451    Int finalPayloadBits = 0;
452    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
453    {
454      continue;
455    }
456
457    /* 3 */
458    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
459    {
460      UInt reservedPayloadExtensionData;
[1029]461      sei_read_flag ( 0, reservedPayloadExtensionData, "reserved_payload_extension_data");
[313]462    }
463
464    UInt dummy;
[1029]465    sei_read_flag( 0, dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
[313]466    while (payloadBitsRemaining)
467    {
[1029]468      sei_read_flag( 0, dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
[313]469    }
470  }
471
472  /* restore primary bitstream for sei_message */
[442]473  getBitstream()->deleteFifo();
[313]474  delete getBitstream();
475  setBitstream(bs);
476}
477
478/**
479 * parse bitstream bs and unpack a user_data_unregistered SEI message
480 * of payloasSize bytes into sei.
481 */
[1029]482
483Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]484{
[1029]485  assert(payloadSize >= ISO_IEC_11578_LEN);
[313]486  UInt val;
[1029]487  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
[313]488
[1029]489  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
[313]490  {
[1029]491    sei_read_code( pDecodedMessageOutputStream, 8, val, "uuid_iso_iec_11578");
[313]492    sei.uuid_iso_iec_11578[i] = val;
493  }
494
[1029]495  sei.userDataLength = payloadSize - ISO_IEC_11578_LEN;
[313]496  if (!sei.userDataLength)
497  {
498    sei.userData = 0;
499    return;
500  }
501
502  sei.userData = new UChar[sei.userDataLength];
503  for (UInt i = 0; i < sei.userDataLength; i++)
504  {
[1246]505    sei_read_code( NULL, 8, val, "user_data_payload_byte" );
[313]506    sei.userData[i] = val;
507  }
[1246]508  if (pDecodedMessageOutputStream)
509  {
510    (*pDecodedMessageOutputStream) << "  User data payload size: " << sei.userDataLength << "\n";
511  }
[313]512}
513
514/**
515 * parse bitstream bs and unpack a decoded picture hash SEI message
516 * of payloadSize bytes into sei.
517 */
[1029]518Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]519{
[1029]520  UInt bytesRead = 0;
521  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
522
[313]523  UInt val;
[1029]524  sei_read_code( pDecodedMessageOutputStream, 8, val, "hash_type");
525  sei.method = static_cast<SEIDecodedPictureHash::Method>(val); bytesRead++;
526
527  const Char *traceString="\0";
528  switch (sei.method)
[313]529  {
[1029]530    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
531    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
532    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
533    default: assert(false); break;
[313]534  }
[1029]535
[1246]536  if (pDecodedMessageOutputStream)
537  {
538    (*pDecodedMessageOutputStream) << "  " << std::setw(55) << traceString << ": " << std::hex << std::setfill('0');
539  }
[1029]540
541  sei.m_digest.hash.clear();
542  for(;bytesRead < payloadSize; bytesRead++)
543  {
544    sei_read_code( NULL, 8, val, traceString);
545    sei.m_digest.hash.push_back((UChar)val);
[1246]546    if (pDecodedMessageOutputStream)
547    {
548      (*pDecodedMessageOutputStream) << std::setw(2) << val;
549    }
[1029]550  }
551
[1246]552  if (pDecodedMessageOutputStream)
553  {
554    (*pDecodedMessageOutputStream) << std::dec << std::setfill(' ') << "\n";
555  }
[313]556}
[1029]557
558Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]559{
560  UInt val; 
[1029]561  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
[313]562
[1029]563  sei_read_code( pDecodedMessageOutputStream, 4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
564  sei_read_flag( pDecodedMessageOutputStream,    val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag     = (val != 0);
565  sei_read_flag( pDecodedMessageOutputStream,    val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = (val != 0);
566  sei_read_uvlc( pDecodedMessageOutputStream,    val, "num_sps_ids_minus1");              sei.numSpsIdsMinus1 = val;
567
[713]568  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
[884]569#if R0247_SEI_ACTIVE
570  sei.layerSpsIdx.resize(sei.numSpsIdsMinus1 + 1);
571#endif
[313]572  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
573  {
[1029]574    sei_read_uvlc( pDecodedMessageOutputStream, val, "active_seq_parameter_set_id[i]");    sei.activeSeqParameterSetId[i] = val;
[313]575  }
[884]576#if R0247_SEI_ACTIVE
577  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
578  {
[1029]579    sei_read_uvlc( pDecodedMessageOutputStream, val, "layer_sps_idx"); sei.layerSpsIdx[i] = val; 
[884]580  }
[1029]581#endif 
[313]582}
583
[1185]584#if SVC_EXTENSION
[1235]585Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
[894]586#else
[1235]587Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[894]588#endif
[313]589{
590  UInt val;
[1029]591  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
592  sei_read_uvlc( pDecodedMessageOutputStream, val, "decoding_unit_idx");
[313]593  sei.m_decodingUnitIdx = val;
594
[1185]595#if SVC_EXTENSION
[1235]596  const TComHRD *hrd;
[894]597  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
598  {
599    assert( nestingSei );
600    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
601    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
602    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
603    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
604    std::vector<Int> hrdIdx(maxValues, 0);
[1235]605    std::vector<const TComHRD*> hrdVec;
[894]606    std::vector<Int> syntaxElemLen(maxValues, 0);
607    for(Int i = 0; i < maxValues; i++)
608    {
609      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
610      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
611   
612      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
613      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
614      {
615        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
616      }
617      if( i > 0 )
618      {
619        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
620        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
621        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
622        // To be done: Check CpbDpbDelaysPresentFlag
623      }
624    }
625    hrd = hrdVec[0];
626  }
627  else
628  {
[1235]629    const TComVUI *vui = sps->getVuiParameters();
[894]630    hrd = vui->getHrdParameters();
631  }
[1029]632
[894]633  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
[313]634  {
[1029]635    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
[313]636    sei.m_duSptCpbRemovalDelay = val;
637  }
638  else
639  {
640    sei.m_duSptCpbRemovalDelay = 0;
641  }
[1029]642  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
[313]643  if(sei.m_dpbOutputDuDelayPresentFlag)
644  {
[1029]645    sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
[313]646    sei.m_picSptDpbOutputDuDelay = val;
647  }
[1029]648#else
[1235]649  const TComVUI *vui = sps->getVuiParameters(); 
[1029]650
651  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
652  {
653    sei_read_code( pDecodedMessageOutputStream, ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
654    sei.m_duSptCpbRemovalDelay = val;
655  }
656  else
657  {
658    sei.m_duSptCpbRemovalDelay = 0;
659  }
660  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
661  if(sei.m_dpbOutputDuDelayPresentFlag)
662  {
663    sei_read_code( pDecodedMessageOutputStream, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
664    sei.m_picSptDpbOutputDuDelay = val;
665  }
666#endif
[313]667}
668
[1185]669#if SVC_EXTENSION
[1235]670Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
[894]671#else
[1235]672Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[894]673#endif
[313]674{
675  Int i, nalOrVcl;
676  UInt code;
677
[1185]678#if SVC_EXTENSION
[1235]679  const TComHRD *pHRD;
[894]680  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
681  {
682    assert( nestingSei );
683    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
684    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
685    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
686    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
687    std::vector<Int> hrdIdx(maxValues, 0);
[1235]688    std::vector<const TComHRD*> hrdVec;
[894]689    std::vector<Int> syntaxElemLen(maxValues, 0);
690    for(i = 0; i < maxValues; i++)
691    {
692      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
693      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
694   
695      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
696      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
697      {
698        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
699      }
700      if( i > 0 )
701      {
702        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
703        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
704        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
705      }
706    }
707    pHRD = hrdVec[i];
708  }
709  else
710  {
[1235]711    const TComVUI *vui = sps->getVuiParameters();
[894]712    pHRD = vui->getHrdParameters();
713  }
714  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
715#else
[1235]716  const TComVUI *pVUI = sps->getVuiParameters();
717  const TComHRD *pHRD = pVUI->getHrdParameters();
[894]718#endif
[313]719
[1029]720  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
721
722  sei_read_uvlc( pDecodedMessageOutputStream, code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
[313]723  if( !pHRD->getSubPicCpbParamsPresentFlag() )
724  {
[1029]725    sei_read_flag( pDecodedMessageOutputStream, code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
[313]726  }
[595]727  if( sei.m_rapCpbParamsPresentFlag )
728  {
[1029]729    sei_read_code( pDecodedMessageOutputStream, pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
730    sei_read_code( pDecodedMessageOutputStream, pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
[595]731  }
[1029]732
[313]733  //read splicing flag and cpb_removal_delay_delta
[1029]734  sei_read_flag( pDecodedMessageOutputStream, code, "concatenation_flag");
[313]735  sei.m_concatenationFlag = code;
[1029]736  sei_read_code( pDecodedMessageOutputStream, ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
[313]737  sei.m_auCpbRemovalDelayDelta = code + 1;
[1029]738
[313]739  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
740  {
741    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
742        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
743    {
744      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
745      {
[1029]746        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_delay":"nal_initial_cpb_removal_delay" );
[313]747        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
[1029]748        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_offset":"vcl_initial_cpb_removal_offset" );
[313]749        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
750        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
751        {
[1029]752          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_delay":"vcl_initial_alt_cpb_removal_delay" );
[313]753          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
[1029]754          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_offset":"vcl_initial_alt_cpb_removal_offset" );
[313]755          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
756        }
757      }
758    }
759  }
[644]760
761#if P0138_USE_ALT_CPB_PARAMS_FLAG
762  sei.m_useAltCpbParamsFlag = false;
763  sei.m_useAltCpbParamsFlagPresent = false;
764  if (xPayloadExtensionPresent())
765  {
[1029]766    sei_read_flag( pDecodedMessageOutputStream, code, "use_alt_cpb_params_flag");
[644]767    sei.m_useAltCpbParamsFlag = code;
768    sei.m_useAltCpbParamsFlagPresent = true;
769  }
770#endif
[1029]771}
[644]772
[1185]773#if SVC_EXTENSION
[1235]774Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
[894]775#else
[1235]776Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[894]777#endif
[313]778{
779  Int i;
780  UInt code;
781
[1185]782#if SVC_EXTENSION
[1235]783  const TComHRD *hrd;   
784  const TComVUI *vui = sps->getVuiParameters(); 
[894]785  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
786  {
787    assert( nestingSei );
788    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
789    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
790    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
791    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
792    std::vector<Int> hrdIdx(maxValues, 0);
[1235]793    std::vector<const TComHRD*> hrdVec;
[894]794    std::vector<Int> syntaxElemLen(maxValues, 0);
795    for(i = 0; i < maxValues; i++)
796    {
797      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
798      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
799   
800      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
801      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
802      {
803        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
804      }
805      if( i > 0 )
806      {
807        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
808        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
809        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
810        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
811        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
812        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
813        // To be done: Check CpbDpbDelaysPresentFlag
814      }
815    }
816    hrd = hrdVec[0];
817  }
818  else
819  {
820    hrd = vui->getHrdParameters();
821  }
822  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
823#else
[1235]824  const TComVUI *vui = sps->getVuiParameters();
825  const TComHRD *hrd = vui->getHrdParameters();
[894]826#endif
[1029]827  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
[313]828
829  if( vui->getFrameFieldInfoPresentFlag() )
830  {
[1029]831    sei_read_code( pDecodedMessageOutputStream, 4, code, "pic_struct" );             sei.m_picStruct            = code;
832    sei_read_code( pDecodedMessageOutputStream, 2, code, "source_scan_type" );       sei.m_sourceScanType       = code;
833    sei_read_flag( pDecodedMessageOutputStream,    code, "duplicate_flag" );         sei.m_duplicateFlag        = (code == 1);
[313]834  }
835
836  if( hrd->getCpbDpbDelaysPresentFlag())
837  {
[1029]838    sei_read_code( pDecodedMessageOutputStream, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
[313]839    sei.m_auCpbRemovalDelay = code + 1;
[1029]840    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
[313]841    sei.m_picDpbOutputDelay = code;
842
843    if(hrd->getSubPicCpbParamsPresentFlag())
844    {
[1029]845      sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
[313]846      sei.m_picDpbOutputDuDelay = code;
847    }
[1029]848
[313]849    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
850    {
[1029]851      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_decoding_units_minus1");
[313]852      sei.m_numDecodingUnitsMinus1 = code;
[1029]853      sei_read_flag( pDecodedMessageOutputStream, code, "du_common_cpb_removal_delay_flag" );
[313]854      sei.m_duCommonCpbRemovalDelayFlag = code;
855      if( sei.m_duCommonCpbRemovalDelayFlag )
856      {
[1029]857        sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_increment_minus1" );
[313]858        sei.m_duCommonCpbRemovalDelayMinus1 = code;
859      }
860      if( sei.m_numNalusInDuMinus1 != NULL )
861      {
862        delete sei.m_numNalusInDuMinus1;
863      }
864      sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
865      if( sei.m_duCpbRemovalDelayMinus1  != NULL )
866      {
867        delete sei.m_duCpbRemovalDelayMinus1;
868      }
869      sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
870
871      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
872      {
[1029]873        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_nalus_in_du_minus1[i]");
[313]874        sei.m_numNalusInDuMinus1[ i ] = code;
875        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
876        {
[1029]877          sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1[i]" );
[313]878          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
879        }
880      }
881    }
882  }
883}
[1029]884
885Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]886{
887  Int  iCode;
888  UInt uiCode;
[1029]889  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
890
891  sei_read_svlc( pDecodedMessageOutputStream, iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
892  sei_read_flag( pDecodedMessageOutputStream, uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
893  sei_read_flag( pDecodedMessageOutputStream, uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
[313]894}
[1029]895
896Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]897{
898  UInt val;
[1029]899  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
[313]900
[1029]901  sei_read_uvlc( pDecodedMessageOutputStream, val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
902  sei_read_flag( pDecodedMessageOutputStream, val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
903
[313]904  if ( !sei.m_arrangementCancelFlag )
905  {
[1029]906    sei_read_code( pDecodedMessageOutputStream, 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
[313]907    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
908
[1029]909    sei_read_flag( pDecodedMessageOutputStream, val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
[313]910
[1029]911    sei_read_code( pDecodedMessageOutputStream, 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
912    sei_read_flag( pDecodedMessageOutputStream, val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
913    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
914    sei_read_flag( pDecodedMessageOutputStream, val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
915    sei_read_flag( pDecodedMessageOutputStream, val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
916    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
917    sei_read_flag( pDecodedMessageOutputStream, val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
918
[313]919    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
920    {
[1029]921      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
922      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
923      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
924      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
[313]925    }
926
[1029]927    sei_read_code( pDecodedMessageOutputStream, 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
928    sei_read_flag( pDecodedMessageOutputStream, val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = (val != 0);
[313]929  }
[1029]930  sei_read_flag( pDecodedMessageOutputStream, val, "upsampled_aspect_ratio_flag" );                  sei.m_upsampledAspectRatio = val;
931}
[313]932
[1029]933Void SEIReader::xParseSEISegmentedRectFramePacking(SEISegmentedRectFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
934{
935  UInt val;
936  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
937  sei_read_flag( pDecodedMessageOutputStream, val,       "segmented_rect_frame_packing_arrangement_cancel_flag" );       sei.m_arrangementCancelFlag            = val;
938  if( !sei.m_arrangementCancelFlag )
939  {
940    sei_read_code( pDecodedMessageOutputStream, 2, val, "segmented_rect_content_interpretation_type" );                sei.m_contentInterpretationType = val;
941    sei_read_flag( pDecodedMessageOutputStream, val,     "segmented_rect_frame_packing_arrangement_persistence" );                              sei.m_arrangementPersistenceFlag               = val;
942  }
[313]943}
944
[1029]945Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]946{
947  UInt val;
[1029]948  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
949  sei_read_flag( pDecodedMessageOutputStream, val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
950  if( !sei.cancelFlag )
[313]951  {
[1029]952    sei_read_flag( pDecodedMessageOutputStream, val,     "hor_flip" );                              sei.horFlip               = val;
953    sei_read_flag( pDecodedMessageOutputStream, val,     "ver_flip" );                              sei.verFlip               = val;
954    sei_read_code( pDecodedMessageOutputStream, 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
955    sei_read_flag( pDecodedMessageOutputStream, val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
[313]956  }
957}
958
[1029]959Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]960{
961  UInt val;
[1029]962  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
963  sei_read_code( pDecodedMessageOutputStream, 8, val, "temporal_sub_layer_zero_idx" );  sei.tl0Idx = val;
964  sei_read_code( pDecodedMessageOutputStream, 8, val, "irap_pic_id" );  sei.rapIdx = val;
[313]965}
966
[1029]967Void SEIReader::xParseSEIRegionRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]968{
969  UInt val;
[1029]970  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
971  sei_read_flag( pDecodedMessageOutputStream, val, "refreshed_region_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
[313]972}
973
[1029]974Void SEIReader::xParseSEINoDisplay(SEINoDisplay& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[313]975{
[1029]976  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
977  sei.m_noDisplay = true;
978}
979
980Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
981{
[313]982  Int i;
983  UInt val;
[1029]984  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
985  sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_id" );                         sei.m_toneMapId = val;
986  sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
[313]987
988  if ( !sei.m_toneMapCancelFlag )
989  {
[1029]990    sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
991    sei_read_code( pDecodedMessageOutputStream, 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
992    sei_read_code( pDecodedMessageOutputStream, 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
993    sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_model_id" );                 sei.m_modelId = val;
[313]994    switch(sei.m_modelId)
995    {
996    case 0:
997      {
[1029]998        sei_read_code( pDecodedMessageOutputStream, 32, val, "min_value" );                 sei.m_minValue = val;
999        sei_read_code( pDecodedMessageOutputStream, 32, val, "max_value" );                 sei.m_maxValue = val;
[313]1000        break;
1001      }
1002    case 1:
1003      {
[1029]1004        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
1005        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
[313]1006        break;
1007      }
1008    case 2:
1009      {
1010        UInt num = 1u << sei.m_targetBitDepth;
1011        sei.m_startOfCodedInterval.resize(num+1);
1012        for(i = 0; i < num; i++)
1013        {
[1029]1014          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval[i]" );
[313]1015          sei.m_startOfCodedInterval[i] = val;
1016        }
1017        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
1018        break;
1019      }
1020    case 3:
1021      {
[1029]1022        sei_read_code( pDecodedMessageOutputStream, 16, val,  "num_pivots" );                       sei.m_numPivots = val;
[313]1023        sei.m_codedPivotValue.resize(sei.m_numPivots);
1024        sei.m_targetPivotValue.resize(sei.m_numPivots);
1025        for(i = 0; i < sei.m_numPivots; i++ )
1026        {
[1029]1027          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value[i]" );
[313]1028          sei.m_codedPivotValue[i] = val;
[1029]1029          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value[i]" );
[313]1030          sei.m_targetPivotValue[i] = val;
1031        }
1032        break;
1033      }
1034    case 4:
1035      {
[1029]1036        sei_read_code( pDecodedMessageOutputStream, 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
[713]1037        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
[313]1038        {
[1029]1039          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
[313]1040        }
[1029]1041        sei_read_code( pDecodedMessageOutputStream, 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
[713]1042        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
1043        {
[1029]1044          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
[713]1045        }
[1029]1046        sei_read_flag( pDecodedMessageOutputStream, val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
1047        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
1048        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
1049        sei_read_code( pDecodedMessageOutputStream, 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
1050        sei_read_code( pDecodedMessageOutputStream, 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
1051        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_black_level_code_value" );          sei.m_nominalBlackLevelLumaCodeValue = val;
1052        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_white_level_code_value" );          sei.m_nominalWhiteLevelLumaCodeValue= val;
1053        sei_read_code( pDecodedMessageOutputStream, 16, val, "extended_white_level_code_value" );         sei.m_extendedWhiteLevelLumaCodeValue = val;
[313]1054        break;
1055      }
1056    default:
1057      {
1058        assert(!"Undefined SEIToneMapModelId");
1059        break;
1060      }
1061    }//switch model id
[1029]1062  }// if(!sei.m_toneMapCancelFlag)
1063}
[313]1064
[1029]1065Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1066{
1067  Int iCode;
1068  UInt uiCode;
1069  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1070
1071  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
1072  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
1073  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
1074  {
1075    sei_read_code( pDecodedMessageOutputStream, 6, uiCode,                     "sop_vcl_nut[i]" );  sei.m_sopDescVclNaluType[i] = uiCode;
1076    sei_read_code( pDecodedMessageOutputStream, 3, sei.m_sopDescTemporalId[i], "sop_temporal_id[i]"   );  sei.m_sopDescTemporalId[i] = uiCode;
1077    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
1078    {
1079      sei_read_uvlc( pDecodedMessageOutputStream, sei.m_sopDescStRpsIdx[i],    "sop_short_term_rps_idx[i]"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
1080    }
1081    if (i > 0)
1082    {
1083      sei_read_svlc( pDecodedMessageOutputStream, iCode,                       "sop_poc_delta[i]"     ); sei.m_sopDescPocDelta[i] = iCode;
1084    }
1085  }
[313]1086}
1087
[1029]1088#if LAYERS_NOT_PRESENT_SEI
[1235]1089Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[1029]1090#else
[1235]1091Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
[1029]1092#endif
1093{
1094  UInt uiCode;
1095  SEIMessages seis;
1096  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1097
1098  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
1099  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
1100  if (sei.m_nestingOpFlag)
1101  {
1102    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
1103    sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
1104    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
1105    {
1106      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_max_temporal_id_plus1[i]"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
1107      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_op_idx[i]"                  ); sei.m_nestingOpIdx[i] = uiCode;
1108    }
1109  }
1110  else
1111  {
1112    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
1113    if (!sei.m_allLayersFlag)
1114    {
1115      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
1116      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
1117      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
1118      {
1119        sei_read_code( pDecodedMessageOutputStream, 6,           uiCode,     "nesting_layer_id[i]"      ); sei.m_nestingLayerId[i]   = uiCode;
1120      }
1121    }
1122  }
1123
1124  // byte alignment
1125  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1126  {
1127    UInt code;
1128    sei_read_flag( pDecodedMessageOutputStream, code, "nesting_zero_bit" );
1129  }
1130
1131  sei.m_callerOwnsSEIs = false;
1132
1133  // read nested SEI messages
[1246]1134  do
1135  {
[1029]1136#if O0164_MULTI_LAYER_HRD
1137#if LAYERS_NOT_PRESENT_SEI
1138    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &sei);
1139#else
1140    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream, &sei);
1141#endif
1142#else
1143#if LAYERS_NOT_PRESENT_SEI
1144    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
1145#else
1146    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
1147#endif
1148#endif
1149  } while (m_pcBitstream->getNumBitsLeft() > 8);
1150
[1246]1151  if (pDecodedMessageOutputStream)
1152  {
1153    (*pDecodedMessageOutputStream) << "End of scalable nesting SEI message\n";
1154  }
[1029]1155}
1156
1157Void SEIReader::xParseSEITempMotionConstraintsTileSets(SEITempMotionConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1158{
1159  UInt code;
1160  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1161  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);
1162  sei_read_flag( pDecodedMessageOutputStream, code, "each_tile_one_tile_set_flag");                 sei.m_each_tile_one_tile_set_flag                = (code != 0);
1163
1164  if(!sei.m_each_tile_one_tile_set_flag)
1165  {
1166    sei_read_flag( pDecodedMessageOutputStream, code, "limited_tile_set_display_flag");  sei.m_limited_tile_set_display_flag = (code != 0);
1167    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_sets_in_message_minus1");     sei.setNumberOfTileSets(code + 1);
1168
1169    if(sei.getNumberOfTileSets() != 0)
1170    {
1171      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
1172      {
1173        sei_read_uvlc( pDecodedMessageOutputStream, code, "mcts_id");  sei.tileSetData(i).m_mcts_id = code;
1174
1175        if(sei.m_limited_tile_set_display_flag)
1176        {
1177          sei_read_flag( pDecodedMessageOutputStream, code, "display_tile_set_flag");  sei.tileSetData(i).m_display_tile_set_flag = (code != 1);
1178        }
1179
1180        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_tile_rects_in_set_minus1");  sei.tileSetData(i).setNumberOfTileRects(code + 1);
1181
1182        for(Int j=0; j<sei.tileSetData(i).getNumberOfTileRects(); j++)
1183        {
1184          sei_read_uvlc( pDecodedMessageOutputStream, code, "top_left_tile_index");      sei.tileSetData(i).topLeftTileIndex(j)     = code;
1185          sei_read_uvlc( pDecodedMessageOutputStream, code, "bottom_right_tile_index");  sei.tileSetData(i).bottomRightTileIndex(j) = code;
1186        }
1187
1188        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
1189        {
1190          sei_read_flag( pDecodedMessageOutputStream, code, "exact_sample_value_match_flag");   sei.tileSetData(i).m_exact_sample_value_match_flag    = (code != 0);
1191        }
1192        sei_read_flag( pDecodedMessageOutputStream, code, "mcts_tier_level_idc_present_flag");  sei.tileSetData(i).m_mcts_tier_level_idc_present_flag = (code != 0);
1193
1194        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
1195        {
1196          sei_read_flag( pDecodedMessageOutputStream, code,    "mcts_tier_flag"); sei.tileSetData(i).m_mcts_tier_flag = (code != 0);
1197          sei_read_code( pDecodedMessageOutputStream, 8, code, "mcts_level_idc"); sei.tileSetData(i).m_mcts_level_idc =  code;
1198        }
1199      }
1200    }
1201  }
1202  else
1203  {
1204    sei_read_flag( pDecodedMessageOutputStream, code, "max_mcs_tier_level_idc_present_flag");  sei.m_max_mcs_tier_level_idc_present_flag = code;
1205    if(sei.m_max_mcs_tier_level_idc_present_flag)
1206    {
1207      sei_read_flag( pDecodedMessageOutputStream, code, "max_mcts_tier_flag");  sei.m_max_mcts_tier_flag = code;
1208      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_mcts_level_idc"); sei.m_max_mcts_level_idc = code;
1209    }
1210  }
1211}
1212
1213Void SEIReader::xParseSEITimeCode(SEITimeCode& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1214{
1215  UInt code;
1216  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1217  sei_read_code( pDecodedMessageOutputStream, 2, code, "num_clock_ts"); sei.numClockTs = code;
1218  for(Int i = 0; i < sei.numClockTs; i++)
1219  {
1220    TComSEITimeSet currentTimeSet;
1221    sei_read_flag( pDecodedMessageOutputStream, code, "clock_time_stamp_flag[i]"); currentTimeSet.clockTimeStampFlag = code;
1222    if(currentTimeSet.clockTimeStampFlag)
1223    {
1224      sei_read_flag( pDecodedMessageOutputStream, code, "nuit_field_based_flag"); currentTimeSet.numUnitFieldBasedFlag = code;
1225      sei_read_code( pDecodedMessageOutputStream, 5, code, "counting_type"); currentTimeSet.countingType = code;
1226      sei_read_flag( pDecodedMessageOutputStream, code, "full_timestamp_flag"); currentTimeSet.fullTimeStampFlag = code;
1227      sei_read_flag( pDecodedMessageOutputStream, code, "discontinuity_flag"); currentTimeSet.discontinuityFlag = code;
1228      sei_read_flag( pDecodedMessageOutputStream, code, "cnt_dropped_flag"); currentTimeSet.cntDroppedFlag = code;
1229      sei_read_code( pDecodedMessageOutputStream, 9, code, "n_frames"); currentTimeSet.numberOfFrames = code;
1230      if(currentTimeSet.fullTimeStampFlag)
1231      {
1232        sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1233        sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1234        sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
1235      }
1236      else
1237      {
1238        sei_read_flag( pDecodedMessageOutputStream, code, "seconds_flag"); currentTimeSet.secondsFlag = code;
1239        if(currentTimeSet.secondsFlag)
1240        {
1241          sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1242          sei_read_flag( pDecodedMessageOutputStream, code, "minutes_flag"); currentTimeSet.minutesFlag = code;
1243          if(currentTimeSet.minutesFlag)
1244          {
1245            sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1246            sei_read_flag( pDecodedMessageOutputStream, code, "hours_flag"); currentTimeSet.hoursFlag = code;
1247            if(currentTimeSet.hoursFlag)
[1246]1248            {
[1029]1249              sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
[1246]1250            }
[1029]1251          }
1252        }
1253      }
1254      sei_read_code( pDecodedMessageOutputStream, 5, code, "time_offset_length"); currentTimeSet.timeOffsetLength = code;
1255      if(currentTimeSet.timeOffsetLength > 0)
1256      {
1257        sei_read_code( pDecodedMessageOutputStream, currentTimeSet.timeOffsetLength, code, "time_offset_value");
1258        if((code & (1 << (currentTimeSet.timeOffsetLength-1))) == 0)
1259        {
1260          currentTimeSet.timeOffsetValue = code;
1261        }
1262        else
1263        {
1264          code &= (1<< (currentTimeSet.timeOffsetLength-1)) - 1;
1265          currentTimeSet.timeOffsetValue = ~code + 1;
1266        }
1267      }
1268    }
1269    sei.timeSetArray[i] = currentTimeSet;
1270  }
1271}
1272
1273Void SEIReader::xParseSEIChromaSamplingFilterHint(SEIChromaSamplingFilterHint& sei, UInt payloadSize/*, TComSPS* sps*/, std::ostream *pDecodedMessageOutputStream)
1274{
1275  UInt uiCode;
1276  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1277
1278  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "ver_chroma_filter_idc"); sei.m_verChromaFilterIdc = uiCode;
1279  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "hor_chroma_filter_idc"); sei.m_horChromaFilterIdc = uiCode;
1280  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ver_filtering_process_flag"); sei.m_verFilteringProcessFlag = uiCode;
1281  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
1282  {
1283    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "target_format_idc"); sei.m_targetFormatIdc = uiCode;
1284    if(sei.m_verChromaFilterIdc == 1)
1285    {
1286      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_vertical_filters"); sei.m_numVerticalFilters = uiCode;
1287      if(sei.m_numVerticalFilters > 0)
1288      {
1289        sei.m_verTapLengthMinus1 = (Int*)malloc(sei.m_numVerticalFilters * sizeof(Int));
1290        sei.m_verFilterCoeff = (Int**)malloc(sei.m_numVerticalFilters * sizeof(Int*));
1291        for(Int i = 0; i < sei.m_numVerticalFilters; i ++)
1292        {
1293          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ver_tap_length_minus_1"); sei.m_verTapLengthMinus1[i] = uiCode;
1294          sei.m_verFilterCoeff[i] = (Int*)malloc(sei.m_verTapLengthMinus1[i] * sizeof(Int));
1295          for(Int j = 0; j < sei.m_verTapLengthMinus1[i]; j ++)
1296          {
1297            sei_read_svlc( pDecodedMessageOutputStream, sei.m_verFilterCoeff[i][j], "ver_filter_coeff");
1298          }
1299        }
1300      }
1301    }
1302    if(sei.m_horChromaFilterIdc == 1)
1303    {
1304      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_horizontal_filters"); sei.m_numHorizontalFilters = uiCode;
1305      if(sei.m_numHorizontalFilters  > 0)
1306      {
1307        sei.m_horTapLengthMinus1 = (Int*)malloc(sei.m_numHorizontalFilters * sizeof(Int));
1308        sei.m_horFilterCoeff = (Int**)malloc(sei.m_numHorizontalFilters * sizeof(Int*));
1309        for(Int i = 0; i < sei.m_numHorizontalFilters; i ++)
1310        {
1311          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "hor_tap_length_minus_1"); sei.m_horTapLengthMinus1[i] = uiCode;
1312          sei.m_horFilterCoeff[i] = (Int*)malloc(sei.m_horTapLengthMinus1[i] * sizeof(Int));
1313          for(Int j = 0; j < sei.m_horTapLengthMinus1[i]; j ++)
1314          {
1315            sei_read_svlc( pDecodedMessageOutputStream, sei.m_horFilterCoeff[i][j], "hor_filter_coeff");
1316          }
1317        }
1318      }
1319    }
1320  }
1321}
1322
1323Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1324{
[815]1325  Int i;
1326  UInt val;
[1029]1327  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1328
1329  sei_read_uvlc( pDecodedMessageOutputStream, val, "knee_function_id" );                   sei.m_kneeId = val;
1330  sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
[815]1331  if ( !sei.m_kneeCancelFlag )
1332  {
[1029]1333    sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
1334    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
1335    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
1336    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
1337    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
1338    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
[815]1339    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
1340    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1341    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1342    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
1343    {
[1029]1344      sei_read_code( pDecodedMessageOutputStream, 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
1345      sei_read_code( pDecodedMessageOutputStream, 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
[815]1346    }
1347  }
1348}
1349
[1029]1350Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1351{
1352  UInt code;
1353  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1354
1355  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
1356  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
1357
1358  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
1359  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
1360
1361  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
1362  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
1363
1364
1365  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
1366  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
1367
1368  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
1369  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
1370}
1371
[856]1372#if Q0074_COLOUR_REMAPPING_SEI
[1029]1373Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
[713]1374{
1375  UInt  uiVal;
1376  Int   iVal;
1377
[1029]1378  sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
1379  sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
[856]1380  if( !sei.m_colourRemapCancelFlag ) 
[713]1381  {
[1029]1382    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
1383    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
[868]1384    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
[856]1385    {
[1029]1386      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
1387      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
1388      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
1389      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
[713]1390    }
[1029]1391    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
1392    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
[713]1393 
[856]1394    for( Int c=0 ; c<3 ; c++ )
[713]1395    {
[1029]1396      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
[856]1397      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
1398      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
1399      if( uiVal> 0 )
1400        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
1401        {
[1029]1402          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
1403          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
[856]1404        }
1405      else // pre_lut_num_val_minus1[c] == 0
[713]1406      {
[856]1407        sei.m_preLutCodedValue[c][0]  = 0;
1408        sei.m_preLutTargetValue[c][0] = 0;
[868]1409        sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
1410        sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
[713]1411      }
1412    }
[856]1413
[1029]1414    sei_read_flag( pDecodedMessageOutputStream, uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
[856]1415    if( sei.m_colourRemapMatrixPresentFlag )
[713]1416    {
[1029]1417      sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
[856]1418      for ( Int c=0 ; c<3 ; c++ )
1419        for ( Int i=0 ; i<3 ; i++ )
1420        {
[1029]1421          sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
[856]1422        }
[713]1423    }
[856]1424    else // setting default matrix (I3)
[713]1425    {
[856]1426      sei.m_log2MatrixDenom = 0;
1427      for ( Int c=0 ; c<3 ; c++ )
1428        for ( Int i=0 ; i<3 ; i++ )
1429          sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
[713]1430    }
[856]1431    for( Int c=0 ; c<3 ; c++ )
[713]1432    {
[1029]1433      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
[856]1434      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
1435      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
1436      if( uiVal > 0 )
1437        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
1438        {
[1029]1439          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
1440          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
[856]1441        }
1442      else
[713]1443      {
[856]1444        sei.m_postLutCodedValue[c][0]  = 0;
1445        sei.m_postLutTargetValue[c][0] = 0;
[868]1446        sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
1447        sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
[713]1448      }
1449    }
1450  }
1451}
1452#endif
1453
[313]1454
[595]1455#if SVC_EXTENSION
1456#if LAYERS_NOT_PRESENT_SEI
[1235]1457Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
[595]1458{
1459  UInt uiCode;
1460  UInt i = 0;
1461
[1029]1462  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
[595]1463  assert(vps->getVPSId() == sei.m_activeVpsId);
1464  sei.m_vpsMaxLayers = vps->getMaxLayers();
1465  for (; i < sei.m_vpsMaxLayers; i++)
1466  {
[1029]1467    sei_read_flag( pDecodedMessageOutputStream, uiCode,         "layer_not_present_flag"   ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false;
[595]1468  }
1469  for (; i < MAX_LAYERS; i++)
1470  {
1471    sei.m_layerNotPresentFlag[i] = false;
1472  }
1473}
1474#endif
[1029]1475
[595]1476#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
[1029]1477Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
[595]1478{
1479  UInt uiCode;
1480
[1029]1481  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
1482  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
[595]1483  if( !sei.m_ilOneTilePerTileSetFlag )
1484  {
[1029]1485    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
[595]1486    if( sei.m_ilNumSetsInMessageMinus1 )
1487    {
[1029]1488      sei_read_flag( pDecodedMessageOutputStream, uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
[595]1489    }
1490    else
1491    {
1492      sei.m_skippedTileSetPresentFlag = false;
1493    }
1494    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
1495    for( UInt i = 0; i < numSignificantSets; i++ )
1496    {
[1029]1497      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
1498      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
[595]1499      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
1500      {
[1029]1501        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
1502        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
[595]1503      }
[1029]1504      sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
[595]1505      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
1506      {
[1029]1507        sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
[595]1508      }
1509    }
1510  }
1511  else
1512  {
[1029]1513    sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
[595]1514  }
1515}
1516#endif
[1029]1517
[595]1518#if SUB_BITSTREAM_PROPERTY_SEI
[1235]1519Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
[595]1520{
1521  UInt uiCode;
[1029]1522  sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
1523  sei_read_uvlc( pDecodedMessageOutputStream,    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
[595]1524
1525  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
1526  {
[1029]1527    sei_read_code( pDecodedMessageOutputStream,  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
1528    sei_read_uvlc( pDecodedMessageOutputStream,     uiCode, "output_layer_set_idx_to_vps[i]"  );
[1218]1529
1530    // The value of output_layer_set_idx_to_vps[ i ]  shall be in the range of 0 to NumOutputLayerSets − 1, inclusive.
1531    assert(uiCode > 0 && uiCode <= vps->getNumOutputLayerSets()-1);
1532
1533    sei.m_outputLayerSetIdxToVps[i] = uiCode;
1534
[1029]1535    sei_read_code( pDecodedMessageOutputStream,  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
1536    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
1537    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
1538  } 
[595]1539}
1540#endif
[644]1541
1542#if O0164_MULTI_LAYER_HRD
1543#if LAYERS_NOT_PRESENT_SEI
[1235]1544Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
[644]1545#else
[1235]1546Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, const TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
[644]1547#endif
1548{
1549  UInt uiCode;
[1029]1550  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
[644]1551
1552  // byte alignment
1553  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1554  {
1555    UInt code;
[1029]1556    sei_read_flag( pDecodedMessageOutputStream, code, "bsp_nesting_zero_bit" );
[644]1557  }
1558
1559  sei.m_callerOwnsSEIs = false;
1560
1561  // read nested SEI messages
[847]1562  Int numSeiMessages = 0;
[1029]1563  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
[847]1564  numSeiMessages = uiCode;
1565  for(Int i = 0; i < numSeiMessages; i++)
1566  {
[1029]1567    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &nestingSei, &sei);
[847]1568  }
[644]1569}
1570
[1235]1571Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei, std::ostream *pDecodedMessageOutputStream)
[644]1572{
1573  assert(vps->getVpsVuiPresentFlag());
1574
[894]1575  UInt uiCode;
1576  Int psIdx         = bspNestingSei.m_seiPartitioningSchemeIdx;
1577  Int seiOlsIdx     = bspNestingSei.m_seiOlsIdx;
1578  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0];
1579  Int maxValues     = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
1580  std::vector<Int> hrdIdx(0, maxValues);
[1235]1581  std::vector<const TComHRD*> hrdVec;
[894]1582  std::vector<Int> syntaxElemLen;
1583  for(Int i = 0; i < maxValues; i++)
1584  {
1585    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
1586    hrdVec[i] = vps->getBspHrd(hrdIdx[i]);
1587   
1588    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
1589    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
1590    {
1591      assert( syntaxElemLen[i] == 24 ); // Default value of init_cpb_removal_delay_length_minus1 is 23
1592    }
1593    if( i > 0 )
1594    {
1595      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
1596      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
1597    }
1598  }
1599  if (hrdVec[0]->getNalHrdParametersPresentFlag())
1600  {
1601    for(UInt i = 0; i < maxValues; i++)
1602    {
[1029]1603      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
[894]1604    }
1605  }
1606  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
1607  {
1608    for(UInt i = 0; i < maxValues; i++)
1609    {
[1029]1610      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
[894]1611    }
1612  }
[644]1613}
1614
[1029]1615Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1, std::ostream *pDecodedMessageOutputStream)
[644]1616{
1617  UInt  uiCode;
1618  if( commonInfPresentFlag )
1619  {
[1029]1620    sei_read_flag( pDecodedMessageOutputStream, uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
1621    sei_read_flag( pDecodedMessageOutputStream, uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
[644]1622    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
1623    {
[1029]1624      sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
[644]1625      if( hrd->getSubPicCpbParamsPresentFlag() )
1626      {
[1029]1627        sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
1628        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
1629        sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
1630        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
[644]1631      }
[1029]1632      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
1633      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
[644]1634      if( hrd->getSubPicCpbParamsPresentFlag() )
1635      {
[1029]1636        sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
[644]1637      }
[1029]1638      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
1639      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
1640      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
[644]1641    }
1642  }
1643  Int i, j, nalOrVcl;
1644  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1645  {
[1029]1646    sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
[644]1647    if( !hrd->getFixedPicRateFlag( i ) )
1648    {
[1029]1649       sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
[644]1650    }
1651    else
1652    {
1653      hrd->setFixedPicRateWithinCvsFlag( i, true );
1654    }
1655    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
1656    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
1657    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1658    {
[1029]1659      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
[644]1660    }
1661    else
1662    {
[1029]1663      sei_read_flag( pDecodedMessageOutputStream, uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
[644]1664    }
1665    if (!hrd->getLowDelayHrdFlag( i ))
1666    {
[1029]1667      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
[644]1668    }
1669    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1670    {
1671      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1672          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1673      {
1674        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1675        {
[1029]1676          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
1677          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
[644]1678          if( hrd->getSubPicCpbParamsPresentFlag() )
1679          {
[1029]1680            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
1681            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
[644]1682          }
[1029]1683           sei_read_flag( pDecodedMessageOutputStream, uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
[644]1684        }
1685      }
1686    }
1687  }
1688}
1689#endif
1690
[1037]1691#if P0123_ALPHA_CHANNEL_SEI
1692void SEIReader::xParseSEIAlphaChannelInfo(SEIAlphaChannelInfo &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1693{
1694  UInt value;
1695  sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_cancel_flag"); sei.m_alphaChannelCancelFlag = value;
1696  if(!sei.m_alphaChannelCancelFlag)
1697  {
1698    sei_read_code(pDecodedMessageOutputStream, 3, value, "alpha_channel_use_idc");          sei.m_alphaChannelUseIdc = value;
1699    sei_read_code(pDecodedMessageOutputStream, 3, value, "alpha_channel_bit_depth_minus8"); sei.m_alphaChannelBitDepthMinus8 = value;
1700    sei_read_code(pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8 + 9, value, "alpha_transparent_value"); sei.m_alphaTransparentValue = value;
1701    sei_read_code(pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8 + 9, value, "alpha_opaque_value"); sei.m_alphaOpaqueValue = value;
1702    sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_incr_flag");        sei.m_alphaChannelIncrFlag = value;
1703    sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_clip_flag");        sei.m_alphaChannelClipFlag = value;
1704    if(sei.m_alphaChannelClipFlag)
1705    {
1706      sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_clip_type_flag"); sei.m_alphaChannelClipTypeFlag = value;
1707    }
1708  } 
1709}
1710#endif
1711
[912]1712#if Q0096_OVERLAY_SEI
[1029]1713Void SEIReader::xParseSEIOverlayInfo(SEIOverlayInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
1714{
[912]1715  Int i, j;
1716  UInt val;
[1029]1717  sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_cancel_flag" );                 sei.m_overlayInfoCancelFlag = val;
[912]1718  if ( !sei.m_overlayInfoCancelFlag )
1719  {
[1029]1720    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_content_aux_id_minus128" );            sei.m_overlayContentAuxIdMinus128 = val;
1721    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_label_aux_id_minus128" );              sei.m_overlayLabelAuxIdMinus128 = val;
1722    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_alpha_aux_id_minus128" );              sei.m_overlayAlphaAuxIdMinus128 = val;
1723    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_element_label_value_length_minus8" );  sei.m_overlayElementLabelValueLengthMinus8 = val;
1724    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlays_minus1" );                        sei.m_numOverlaysMinus1 = val;
[912]1725
1726    assert( sei.m_numOverlaysMinus1 < MAX_OVERLAYS );
1727    sei.m_overlayIdx.resize( sei.m_numOverlaysMinus1+1 );
1728    sei.m_languageOverlayPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1729    sei.m_overlayContentLayerId.resize( sei.m_numOverlaysMinus1+1 );
1730    sei.m_overlayLabelPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1731    sei.m_overlayLabelLayerId.resize( sei.m_numOverlaysMinus1+1 );
1732    sei.m_overlayAlphaPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1733    sei.m_overlayAlphaLayerId.resize( sei.m_numOverlaysMinus1+1 );
1734    sei.m_numOverlayElementsMinus1.resize( sei.m_numOverlaysMinus1+1 );
1735    sei.m_overlayElementLabelMin.resize( sei.m_numOverlaysMinus1+1 );
1736    sei.m_overlayElementLabelMax.resize( sei.m_numOverlaysMinus1+1 );
1737    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
1738    {
[1029]1739      sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_idx" );                      sei.m_overlayIdx[i] = val;
1740      sei_read_flag( pDecodedMessageOutputStream, val, "language_overlay_present_flag" );    sei.m_languageOverlayPresentFlag[i] = val;
1741      sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_content_layer_id");       sei.m_overlayContentLayerId[i] = val;
1742      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_label_present_flag" );       sei.m_overlayLabelPresentFlag[i] = val;
[912]1743      if ( sei.m_overlayLabelPresentFlag[i] )
1744      {
[1029]1745        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_label_layer_id");     sei.m_overlayLabelLayerId[i] = val;
[912]1746      }
[1029]1747      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_alpha_present_flag" );       sei.m_overlayAlphaPresentFlag[i] = val;
[912]1748      if ( sei.m_overlayAlphaPresentFlag[i] )
1749      {
[1029]1750        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_alpha_layer_id");     sei.m_overlayAlphaLayerId[i] = val;
[912]1751      }
1752      if ( sei.m_overlayLabelPresentFlag[i] )
1753      {
[1029]1754        sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlay_elements_minus1");   sei.m_numOverlayElementsMinus1[i] = val;
[912]1755        assert( sei.m_numOverlayElementsMinus1[i] < MAX_OVERLAY_ELEMENTS );
1756        sei.m_overlayElementLabelMin[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1757        sei.m_overlayElementLabelMax[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1758        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++ )
1759        {
[1029]1760          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_min"); sei.m_overlayElementLabelMin[i][j] = val;
1761          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_max"); sei.m_overlayElementLabelMax[i][j] = val;
[912]1762        }     
1763      }
1764      else
1765      {
1766        sei.m_numOverlayElementsMinus1[i] = 0;
1767      }
1768    }
1769
1770    // byte alignment
1771    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1772    {
[1029]1773      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_zero_bit" );
[912]1774      assert( val==0 );
1775    }
1776
1777    UChar* sval = new UChar[MAX_OVERLAY_STRING_BYTES];
1778    UInt slen;   
1779    sei.m_overlayLanguage.resize( sei.m_numOverlaysMinus1+1, NULL );
1780    sei.m_overlayLanguageLength.resize( sei.m_numOverlaysMinus1+1 );
1781    sei.m_overlayName.resize( sei.m_numOverlaysMinus1+1, NULL );
1782    sei.m_overlayNameLength.resize( sei.m_numOverlaysMinus1+1 );
1783    sei.m_overlayElementName.resize( sei.m_numOverlaysMinus1+1 );
1784    sei.m_overlayElementNameLength.resize( sei.m_numOverlaysMinus1+1 );
1785    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
1786    {
1787      if ( sei.m_languageOverlayPresentFlag[i] )
1788      {
1789        READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_language" );
1790        sei.m_overlayLanguage[i] = new UChar[slen];
1791        memcpy(sei.m_overlayLanguage[i], sval, slen);
1792        sei.m_overlayLanguageLength[i] = slen;
1793      }
1794      READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_name" );
1795      sei.m_overlayName[i] = new UChar[slen];
1796      memcpy(sei.m_overlayName[i], sval, slen);
1797      sei.m_overlayNameLength[i] = slen;
1798      if ( sei.m_overlayLabelPresentFlag[i] )
1799      {
1800        sei.m_overlayElementName[i].resize( sei.m_numOverlayElementsMinus1[i]+1, NULL );
1801        sei.m_overlayElementNameLength[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1802        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++)
1803        {
1804          READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_element_name" );
1805          sei.m_overlayElementName[i][j] = new UChar[slen];
1806          memcpy(sei.m_overlayElementName[i][j], sval, slen);
1807          sei.m_overlayElementNameLength[i][j] = slen;
1808        }
1809      }
1810    }
[1029]1811    sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_persistence_flag" );        sei.m_overlayInfoPersistenceFlag = val;
1812  } 
1813}
1814#endif
1815
1816#if P0138_USE_ALT_CPB_PARAMS_FLAG
1817/**
1818 * Check if SEI message contains payload extension
1819 */
1820Bool SEIReader::xPayloadExtensionPresent()
1821{
1822  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
1823  Bool payloadExtensionPresent = false;
1824
1825  if (payloadBitsRemaining > 8)
1826  {
1827    payloadExtensionPresent = true;
[912]1828  }
[1029]1829  else
1830  {
1831    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
1832    while (payloadBitsRemaining && (finalBits & 1) == 0)
1833    {
1834      payloadBitsRemaining--;
1835      finalBits >>= 1;
1836    }
1837    payloadBitsRemaining--;
1838    if (payloadBitsRemaining > 0)
1839    {
1840      payloadExtensionPresent = true;
1841    }
1842  }
1843
1844  return payloadExtensionPresent;
[912]1845}
1846#endif
1847
[1029]1848#if Q0189_TMVP_CONSTRAINTS
1849Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1850{
1851  UInt uiCode;
1852  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
1853  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "no_intra_layer_col_pic_flag"          ); sei.no_intra_layer_col_pic_flag = uiCode;
1854}
1855#endif
1856
1857#if Q0247_FRAME_FIELD_INFO
1858Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1859{
1860  UInt code;
1861  sei_read_code( pDecodedMessageOutputStream, 4, code, "ffinfo_pic_struct"       );       sei.m_ffinfo_picStruct      = code;
1862  sei_read_code( pDecodedMessageOutputStream, 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
1863  sei_read_flag( pDecodedMessageOutputStream,    code, "ffinfo_duplicate_flag"   );       sei.m_ffinfo_duplicateFlag  = ( code == 1 ? true : false );
1864}
1865#endif
1866
1867
[595]1868#endif //SVC_EXTENSION
1869
[313]1870//! \}
Note: See TracBrowser for help on using the repository browser.