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

Last change on this file since 1590 was 1572, checked in by seregin, 9 years ago

port rev 4752

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