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

Last change on this file since 1547 was 1538, checked in by seregin, 9 years ago

port rev 4690

  • Property svn:eol-style set to native
File size: 86.8 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-2015, 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      default:
417        for (UInt i = 0; i < payloadSize; i++)
418        {
419          UInt seiByte;
420          sei_read_code( NULL, 8, seiByte, "unknown suffix SEI payload byte");
421        }
422        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
423        if (pDecodedMessageOutputStream)
424        {
425          (*pDecodedMessageOutputStream) << "Unknown suffix SEI message (payloadType = " << payloadType << ") was found!\n";
426        }
427        break;
428    }
429  }
430
431  if (sei != NULL)
432  {
433    seis.push_back(sei);
434  }
435
436  /* By definition the underlying bitstream terminates in a byte-aligned manner.
437   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
438   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
439   * 3. Extract the remainingreserved_payload_extension_data bits.
440   *
441   * If there are fewer than 9 bits available, extract them.
442   */
443  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
444  if (payloadBitsRemaining) /* more_data_in_payload() */
445  {
446    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
447    {
448      UInt reservedPayloadExtensionData;
449      sei_read_code ( pDecodedMessageOutputStream, 1, reservedPayloadExtensionData, "reserved_payload_extension_data");
450    }
451
452    /* 2 */
453    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
454    Int finalPayloadBits = 0;
455    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
456    {
457      continue;
458    }
459
460    /* 3 */
461    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
462    {
463      UInt reservedPayloadExtensionData;
464      sei_read_flag ( 0, reservedPayloadExtensionData, "reserved_payload_extension_data");
465    }
466
467    UInt dummy;
468    sei_read_flag( 0, dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
469    while (payloadBitsRemaining)
470    {
471      sei_read_flag( 0, dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
472    }
473  }
474
475  /* restore primary bitstream for sei_message */
476  delete getBitstream();
477  setBitstream(bs);
478}
479
480/**
481 * parse bitstream bs and unpack a user_data_unregistered SEI message
482 * of payloasSize bytes into sei.
483 */
484
485Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
486{
487  assert(payloadSize >= ISO_IEC_11578_LEN);
488  UInt val;
489  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
490
491  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
492  {
493    sei_read_code( pDecodedMessageOutputStream, 8, val, "uuid_iso_iec_11578");
494    sei.uuid_iso_iec_11578[i] = val;
495  }
496
497  sei.userDataLength = payloadSize - ISO_IEC_11578_LEN;
498  if (!sei.userDataLength)
499  {
500    sei.userData = 0;
501    return;
502  }
503
504  sei.userData = new UChar[sei.userDataLength];
505  for (UInt i = 0; i < sei.userDataLength; i++)
506  {
507    sei_read_code( NULL, 8, val, "user_data_payload_byte" );
508    sei.userData[i] = val;
509  }
510  if (pDecodedMessageOutputStream)
511  {
512    (*pDecodedMessageOutputStream) << "  User data payload size: " << sei.userDataLength << "\n";
513  }
514}
515
516/**
517 * parse bitstream bs and unpack a decoded picture hash SEI message
518 * of payloadSize bytes into sei.
519 */
520Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
521{
522  UInt bytesRead = 0;
523  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
524
525  UInt val;
526  sei_read_code( pDecodedMessageOutputStream, 8, val, "hash_type");
527  sei.method = static_cast<HashType>(val); bytesRead++;
528
529  const TChar *traceString="\0";
530  switch (sei.method)
531  {
532    case HASHTYPE_MD5: traceString="picture_md5"; break;
533    case HASHTYPE_CRC: traceString="picture_crc"; break;
534    case HASHTYPE_CHECKSUM: traceString="picture_checksum"; break;
535    default: assert(false); break;
536  }
537
538  if (pDecodedMessageOutputStream)
539  {
540    (*pDecodedMessageOutputStream) << "  " << std::setw(55) << traceString << ": " << std::hex << std::setfill('0');
541  }
542
543  sei.m_pictureHash.hash.clear();
544  for(;bytesRead < payloadSize; bytesRead++)
545  {
546    sei_read_code( NULL, 8, val, traceString);
547    sei.m_pictureHash.hash.push_back((UChar)val);
548    if (pDecodedMessageOutputStream)
549    {
550      (*pDecodedMessageOutputStream) << std::setw(2) << val;
551    }
552  }
553
554  if (pDecodedMessageOutputStream)
555  {
556    (*pDecodedMessageOutputStream) << std::dec << std::setfill(' ') << "\n";
557  }
558}
559
560Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
561{
562  UInt val; 
563  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
564
565  sei_read_code( pDecodedMessageOutputStream, 4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
566  sei_read_flag( pDecodedMessageOutputStream,    val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag     = (val != 0);
567  sei_read_flag( pDecodedMessageOutputStream,    val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = (val != 0);
568  sei_read_uvlc( pDecodedMessageOutputStream,    val, "num_sps_ids_minus1");              sei.numSpsIdsMinus1 = val;
569
570  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
571#if R0247_SEI_ACTIVE
572  sei.layerSpsIdx.resize(sei.numSpsIdsMinus1 + 1);
573#endif
574  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
575  {
576    sei_read_uvlc( pDecodedMessageOutputStream, val, "active_seq_parameter_set_id[i]");    sei.activeSeqParameterSetId[i] = val;
577  }
578#if R0247_SEI_ACTIVE
579  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
580  {
581    sei_read_uvlc( pDecodedMessageOutputStream, val, "layer_sps_idx"); sei.layerSpsIdx[i] = val; 
582  }
583#endif 
584}
585
586#if SVC_EXTENSION
587Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
588#else
589Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
590#endif
591{
592  UInt val;
593  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
594  sei_read_uvlc( pDecodedMessageOutputStream, val, "decoding_unit_idx");
595  sei.m_decodingUnitIdx = val;
596
597#if SVC_EXTENSION
598  const TComHRD *hrd;
599  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
600  {
601    assert( nestingSei );
602    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
603    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
604    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
605    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
606    std::vector<Int> hrdIdx(maxValues, 0);
607    std::vector<const TComHRD*> hrdVec;
608    std::vector<Int> syntaxElemLen(maxValues, 0);
609    for(Int i = 0; i < maxValues; i++)
610    {
611      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
612      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
613   
614      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
615      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
616      {
617        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
618      }
619      if( i > 0 )
620      {
621        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
622        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
623        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
624        // To be done: Check CpbDpbDelaysPresentFlag
625      }
626    }
627    hrd = hrdVec[0];
628  }
629  else
630  {
631    const TComVUI *vui = sps->getVuiParameters();
632    hrd = vui->getHrdParameters();
633  }
634
635  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
636  {
637    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
638    sei.m_duSptCpbRemovalDelay = val;
639  }
640  else
641  {
642    sei.m_duSptCpbRemovalDelay = 0;
643  }
644  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
645  if(sei.m_dpbOutputDuDelayPresentFlag)
646  {
647    sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
648    sei.m_picSptDpbOutputDuDelay = val;
649  }
650#else
651  const TComVUI *vui = sps->getVuiParameters();
652  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
653  {
654    sei_read_code( pDecodedMessageOutputStream, ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
655    sei.m_duSptCpbRemovalDelay = val;
656  }
657  else
658  {
659    sei.m_duSptCpbRemovalDelay = 0;
660  }
661  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
662  if(sei.m_dpbOutputDuDelayPresentFlag)
663  {
664    sei_read_code( pDecodedMessageOutputStream, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
665    sei.m_picSptDpbOutputDuDelay = val;
666  }
667#endif
668}
669
670#if SVC_EXTENSION
671Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
672#else
673Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
674#endif
675{
676  Int i, nalOrVcl;
677  UInt code;
678
679#if SVC_EXTENSION
680  const TComHRD *pHRD;
681  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
682  {
683    assert( nestingSei );
684    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
685    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
686    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
687    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
688    std::vector<Int> hrdIdx(maxValues, 0);
689    std::vector<const TComHRD*> hrdVec;
690    std::vector<Int> syntaxElemLen(maxValues, 0);
691
692    Int schedSelIdx = 0;
693
694    for(i = 0; i < maxValues; i++)
695    {
696      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
697      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
698   
699      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
700      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
701      {
702        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
703      }
704      if( i > 0 )
705      {
706        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
707        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
708        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
709      }
710    }
711    pHRD = hrdVec[schedSelIdx];
712  }
713  else
714  {
715    const TComVUI *vui = sps->getVuiParameters();
716    pHRD = vui->getHrdParameters();
717  }
718  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
719#else
720  const TComVUI *pVUI = sps->getVuiParameters();
721  const TComHRD *pHRD = pVUI->getHrdParameters();
722#endif
723
724  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
725
726  sei_read_uvlc( pDecodedMessageOutputStream, code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
727  if( !pHRD->getSubPicCpbParamsPresentFlag() )
728  {
729    sei_read_flag( pDecodedMessageOutputStream, code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
730  }
731  if( sei.m_rapCpbParamsPresentFlag )
732  {
733    sei_read_code( pDecodedMessageOutputStream, pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
734    sei_read_code( pDecodedMessageOutputStream, pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
735  }
736
737  //read splicing flag and cpb_removal_delay_delta
738  sei_read_flag( pDecodedMessageOutputStream, code, "concatenation_flag");
739  sei.m_concatenationFlag = code;
740  sei_read_code( pDecodedMessageOutputStream, ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
741  sei.m_auCpbRemovalDelayDelta = code + 1;
742
743  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
744  {
745    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
746        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
747    {
748      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
749      {
750        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_delay":"nal_initial_cpb_removal_delay" );
751        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
752        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_offset":"nal_initial_cpb_removal_offset" );
753        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
754        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
755        {
756          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_delay":"nal_initial_alt_cpb_removal_delay" );
757          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
758          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_offset":"nal_initial_alt_cpb_removal_offset" );
759          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
760        }
761      }
762    }
763  }
764
765#if P0138_USE_ALT_CPB_PARAMS_FLAG
766  sei.m_useAltCpbParamsFlag = false;
767  sei.m_useAltCpbParamsFlagPresent = false;
768  if (xPayloadExtensionPresent())
769  {
770    sei_read_flag( pDecodedMessageOutputStream, code, "use_alt_cpb_params_flag");
771    sei.m_useAltCpbParamsFlag = code;
772    sei.m_useAltCpbParamsFlagPresent = true;
773  }
774#endif
775}
776
777#if SVC_EXTENSION
778Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
779#else
780Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
781#endif
782{
783  Int i;
784  UInt code;
785
786#if SVC_EXTENSION
787  const TComHRD *hrd;   
788  const TComVUI *vui = sps->getVuiParameters(); 
789  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
790  {
791    assert( nestingSei );
792    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
793    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
794    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
795    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
796    std::vector<Int> hrdIdx(maxValues, 0);
797    std::vector<const TComHRD*> hrdVec;
798    std::vector<Int> syntaxElemLen(maxValues, 0);
799    for(i = 0; i < maxValues; i++)
800    {
801      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
802      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
803   
804      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
805      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
806      {
807        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
808      }
809      if( i > 0 )
810      {
811        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
812        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
813        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
814        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
815        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
816        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
817        // To be done: Check CpbDpbDelaysPresentFlag
818      }
819    }
820    hrd = hrdVec[0];
821  }
822  else
823  {
824    hrd = vui->getHrdParameters();
825  }
826  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
827#else
828  const TComVUI *vui = sps->getVuiParameters();
829  const TComHRD *hrd = vui->getHrdParameters();
830#endif
831  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
832
833  if( vui->getFrameFieldInfoPresentFlag() )
834  {
835    sei_read_code( pDecodedMessageOutputStream, 4, code, "pic_struct" );             sei.m_picStruct            = code;
836    sei_read_code( pDecodedMessageOutputStream, 2, code, "source_scan_type" );       sei.m_sourceScanType       = code;
837    sei_read_flag( pDecodedMessageOutputStream,    code, "duplicate_flag" );         sei.m_duplicateFlag        = (code == 1);
838  }
839
840  if( hrd->getCpbDpbDelaysPresentFlag())
841  {
842    sei_read_code( pDecodedMessageOutputStream, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
843    sei.m_auCpbRemovalDelay = code + 1;
844    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
845    sei.m_picDpbOutputDelay = code;
846
847    if(hrd->getSubPicCpbParamsPresentFlag())
848    {
849      sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
850      sei.m_picDpbOutputDuDelay = code;
851    }
852
853    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
854    {
855      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_decoding_units_minus1");
856      sei.m_numDecodingUnitsMinus1 = code;
857      sei_read_flag( pDecodedMessageOutputStream, code, "du_common_cpb_removal_delay_flag" );
858      sei.m_duCommonCpbRemovalDelayFlag = code;
859      if( sei.m_duCommonCpbRemovalDelayFlag )
860      {
861        sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_increment_minus1" );
862        sei.m_duCommonCpbRemovalDelayMinus1 = code;
863      }
864      sei.m_numNalusInDuMinus1.resize(sei.m_numDecodingUnitsMinus1 + 1 );
865      sei.m_duCpbRemovalDelayMinus1.resize( sei.m_numDecodingUnitsMinus1 + 1 );
866
867      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
868      {
869        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_nalus_in_du_minus1[i]");
870        sei.m_numNalusInDuMinus1[ i ] = code;
871        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
872        {
873          sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1[i]" );
874          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
875        }
876      }
877    }
878  }
879}
880
881Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
882{
883  Int  iCode;
884  UInt uiCode;
885  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
886
887  sei_read_svlc( pDecodedMessageOutputStream, iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
888  sei_read_flag( pDecodedMessageOutputStream, uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
889  sei_read_flag( pDecodedMessageOutputStream, uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
890}
891
892Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
893{
894  UInt val;
895  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
896
897  sei_read_uvlc( pDecodedMessageOutputStream, val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
898  sei_read_flag( pDecodedMessageOutputStream, val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
899
900  if ( !sei.m_arrangementCancelFlag )
901  {
902    sei_read_code( pDecodedMessageOutputStream, 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
903    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
904
905    sei_read_flag( pDecodedMessageOutputStream, val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
906
907    sei_read_code( pDecodedMessageOutputStream, 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
908    sei_read_flag( pDecodedMessageOutputStream, val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
909    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
910    sei_read_flag( pDecodedMessageOutputStream, val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
911    sei_read_flag( pDecodedMessageOutputStream, val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
912    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
913    sei_read_flag( pDecodedMessageOutputStream, val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
914
915    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
916    {
917      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
918      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
919      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
920      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
921    }
922
923    sei_read_code( pDecodedMessageOutputStream, 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
924    sei_read_flag( pDecodedMessageOutputStream, val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = (val != 0);
925  }
926  sei_read_flag( pDecodedMessageOutputStream, val, "upsampled_aspect_ratio_flag" );                  sei.m_upsampledAspectRatio = val;
927}
928
929Void SEIReader::xParseSEISegmentedRectFramePacking(SEISegmentedRectFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
930{
931  UInt val;
932  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
933  sei_read_flag( pDecodedMessageOutputStream, val,       "segmented_rect_frame_packing_arrangement_cancel_flag" );       sei.m_arrangementCancelFlag            = val;
934  if( !sei.m_arrangementCancelFlag )
935  {
936    sei_read_code( pDecodedMessageOutputStream, 2, val, "segmented_rect_content_interpretation_type" );                sei.m_contentInterpretationType = val;
937    sei_read_flag( pDecodedMessageOutputStream, val,     "segmented_rect_frame_packing_arrangement_persistence" );                              sei.m_arrangementPersistenceFlag               = val;
938  }
939}
940
941Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
942{
943  UInt val;
944  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
945  sei_read_flag( pDecodedMessageOutputStream, val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
946  if( !sei.cancelFlag )
947  {
948    sei_read_flag( pDecodedMessageOutputStream, val,     "hor_flip" );                              sei.horFlip               = val;
949    sei_read_flag( pDecodedMessageOutputStream, val,     "ver_flip" );                              sei.verFlip               = val;
950    sei_read_code( pDecodedMessageOutputStream, 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
951    sei_read_flag( pDecodedMessageOutputStream, val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
952  }
953}
954
955Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
956{
957  UInt val;
958  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
959  sei_read_code( pDecodedMessageOutputStream, 8, val, "temporal_sub_layer_zero_idx" );  sei.tl0Idx = val;
960  sei_read_code( pDecodedMessageOutputStream, 8, val, "irap_pic_id" );  sei.rapIdx = val;
961}
962
963Void SEIReader::xParseSEIRegionRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
964{
965  UInt val;
966  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
967  sei_read_flag( pDecodedMessageOutputStream, val, "refreshed_region_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
968}
969
970Void SEIReader::xParseSEINoDisplay(SEINoDisplay& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
971{
972  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
973  sei.m_noDisplay = true;
974}
975
976Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
977{
978  Int i;
979  UInt val;
980  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
981  sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_id" );                         sei.m_toneMapId = val;
982  sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
983
984  if ( !sei.m_toneMapCancelFlag )
985  {
986    sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
987    sei_read_code( pDecodedMessageOutputStream, 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
988    sei_read_code( pDecodedMessageOutputStream, 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
989    sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_model_id" );                 sei.m_modelId = val;
990    switch(sei.m_modelId)
991    {
992    case 0:
993      {
994        sei_read_code( pDecodedMessageOutputStream, 32, val, "min_value" );                 sei.m_minValue = val;
995        sei_read_code( pDecodedMessageOutputStream, 32, val, "max_value" );                 sei.m_maxValue = val;
996        break;
997      }
998    case 1:
999      {
1000        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
1001        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
1002        break;
1003      }
1004    case 2:
1005      {
1006        UInt num = 1u << sei.m_targetBitDepth;
1007        sei.m_startOfCodedInterval.resize(num+1);
1008        for(i = 0; i < num; i++)
1009        {
1010          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval[i]" );
1011          sei.m_startOfCodedInterval[i] = val;
1012        }
1013        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
1014        break;
1015      }
1016    case 3:
1017      {
1018        sei_read_code( pDecodedMessageOutputStream, 16, val,  "num_pivots" );                       sei.m_numPivots = val;
1019        sei.m_codedPivotValue.resize(sei.m_numPivots);
1020        sei.m_targetPivotValue.resize(sei.m_numPivots);
1021        for(i = 0; i < sei.m_numPivots; i++ )
1022        {
1023          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value[i]" );
1024          sei.m_codedPivotValue[i] = val;
1025          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value[i]" );
1026          sei.m_targetPivotValue[i] = val;
1027        }
1028        break;
1029      }
1030    case 4:
1031      {
1032        sei_read_code( pDecodedMessageOutputStream, 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
1033        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
1034        {
1035          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
1036        }
1037        sei_read_code( pDecodedMessageOutputStream, 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
1038        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
1039        {
1040          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
1041        }
1042        sei_read_flag( pDecodedMessageOutputStream, val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
1043        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
1044        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
1045        sei_read_code( pDecodedMessageOutputStream, 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
1046        sei_read_code( pDecodedMessageOutputStream, 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
1047        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_black_level_code_value" );          sei.m_nominalBlackLevelLumaCodeValue = val;
1048        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_white_level_code_value" );          sei.m_nominalWhiteLevelLumaCodeValue= val;
1049        sei_read_code( pDecodedMessageOutputStream, 16, val, "extended_white_level_code_value" );         sei.m_extendedWhiteLevelLumaCodeValue = val;
1050        break;
1051      }
1052    default:
1053      {
1054        assert(!"Undefined SEIToneMapModelId");
1055        break;
1056      }
1057    }//switch model id
1058  }// if(!sei.m_toneMapCancelFlag)
1059}
1060
1061Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1062{
1063  Int iCode;
1064  UInt uiCode;
1065  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1066
1067  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
1068  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
1069  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
1070  {
1071    sei_read_code( pDecodedMessageOutputStream, 6, uiCode,                     "sop_vcl_nut[i]" );  sei.m_sopDescVclNaluType[i] = uiCode;
1072    sei_read_code( pDecodedMessageOutputStream, 3, sei.m_sopDescTemporalId[i], "sop_temporal_id[i]"   );  sei.m_sopDescTemporalId[i] = uiCode;
1073    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
1074    {
1075      sei_read_uvlc( pDecodedMessageOutputStream, sei.m_sopDescStRpsIdx[i],    "sop_short_term_rps_idx[i]"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
1076    }
1077    if (i > 0)
1078    {
1079      sei_read_svlc( pDecodedMessageOutputStream, iCode,                       "sop_poc_delta[i]"     ); sei.m_sopDescPocDelta[i] = iCode;
1080    }
1081  }
1082}
1083
1084#if LAYERS_NOT_PRESENT_SEI
1085Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
1086#else
1087Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
1088#endif
1089{
1090  UInt uiCode;
1091  SEIMessages seis;
1092  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1093
1094  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
1095  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
1096  if (sei.m_nestingOpFlag)
1097  {
1098    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
1099    sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
1100    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
1101    {
1102      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_max_temporal_id_plus1[i]"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
1103      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_op_idx[i]"                  ); sei.m_nestingOpIdx[i] = uiCode;
1104    }
1105  }
1106  else
1107  {
1108    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
1109    if (!sei.m_allLayersFlag)
1110    {
1111      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
1112      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
1113      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
1114      {
1115        sei_read_code( pDecodedMessageOutputStream, 6,           uiCode,     "nesting_layer_id[i]"      ); sei.m_nestingLayerId[i]   = uiCode;
1116      }
1117    }
1118  }
1119
1120  // byte alignment
1121  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1122  {
1123    UInt code;
1124    sei_read_flag( pDecodedMessageOutputStream, code, "nesting_zero_bit" );
1125  }
1126
1127  // read nested SEI messages
1128  do
1129  {
1130#if O0164_MULTI_LAYER_HRD
1131#if LAYERS_NOT_PRESENT_SEI
1132    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &sei);
1133#else
1134    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream, &sei);
1135#endif
1136#else
1137#if LAYERS_NOT_PRESENT_SEI
1138    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
1139#else
1140    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
1141#endif
1142#endif
1143  } while (m_pcBitstream->getNumBitsLeft() > 8);
1144
1145  if (pDecodedMessageOutputStream)
1146  {
1147    (*pDecodedMessageOutputStream) << "End of scalable nesting SEI message\n";
1148  }
1149}
1150
1151Void SEIReader::xParseSEITempMotionConstraintsTileSets(SEITempMotionConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1152{
1153  UInt code;
1154  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1155  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);
1156  sei_read_flag( pDecodedMessageOutputStream, code, "each_tile_one_tile_set_flag");                 sei.m_each_tile_one_tile_set_flag                = (code != 0);
1157
1158  if(!sei.m_each_tile_one_tile_set_flag)
1159  {
1160    sei_read_flag( pDecodedMessageOutputStream, code, "limited_tile_set_display_flag");  sei.m_limited_tile_set_display_flag = (code != 0);
1161    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_sets_in_message_minus1");     sei.setNumberOfTileSets(code + 1);
1162
1163    if(sei.getNumberOfTileSets() != 0)
1164    {
1165      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
1166      {
1167        sei_read_uvlc( pDecodedMessageOutputStream, code, "mcts_id");  sei.tileSetData(i).m_mcts_id = code;
1168
1169        if(sei.m_limited_tile_set_display_flag)
1170        {
1171          sei_read_flag( pDecodedMessageOutputStream, code, "display_tile_set_flag");  sei.tileSetData(i).m_display_tile_set_flag = (code != 1);
1172        }
1173
1174        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_tile_rects_in_set_minus1");  sei.tileSetData(i).setNumberOfTileRects(code + 1);
1175
1176        for(Int j=0; j<sei.tileSetData(i).getNumberOfTileRects(); j++)
1177        {
1178          sei_read_uvlc( pDecodedMessageOutputStream, code, "top_left_tile_index");      sei.tileSetData(i).topLeftTileIndex(j)     = code;
1179          sei_read_uvlc( pDecodedMessageOutputStream, code, "bottom_right_tile_index");  sei.tileSetData(i).bottomRightTileIndex(j) = code;
1180        }
1181
1182        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
1183        {
1184          sei_read_flag( pDecodedMessageOutputStream, code, "exact_sample_value_match_flag");   sei.tileSetData(i).m_exact_sample_value_match_flag    = (code != 0);
1185        }
1186        sei_read_flag( pDecodedMessageOutputStream, code, "mcts_tier_level_idc_present_flag");  sei.tileSetData(i).m_mcts_tier_level_idc_present_flag = (code != 0);
1187
1188        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
1189        {
1190          sei_read_flag( pDecodedMessageOutputStream, code,    "mcts_tier_flag"); sei.tileSetData(i).m_mcts_tier_flag = (code != 0);
1191          sei_read_code( pDecodedMessageOutputStream, 8, code, "mcts_level_idc"); sei.tileSetData(i).m_mcts_level_idc =  code;
1192        }
1193      }
1194    }
1195  }
1196  else
1197  {
1198    sei_read_flag( pDecodedMessageOutputStream, code, "max_mcs_tier_level_idc_present_flag");  sei.m_max_mcs_tier_level_idc_present_flag = code;
1199    if(sei.m_max_mcs_tier_level_idc_present_flag)
1200    {
1201      sei_read_flag( pDecodedMessageOutputStream, code, "max_mcts_tier_flag");  sei.m_max_mcts_tier_flag = code;
1202      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_mcts_level_idc"); sei.m_max_mcts_level_idc = code;
1203    }
1204  }
1205}
1206
1207Void SEIReader::xParseSEITimeCode(SEITimeCode& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1208{
1209  UInt code;
1210  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1211  sei_read_code( pDecodedMessageOutputStream, 2, code, "num_clock_ts"); sei.numClockTs = code;
1212  for(Int i = 0; i < sei.numClockTs; i++)
1213  {
1214    TComSEITimeSet currentTimeSet;
1215    sei_read_flag( pDecodedMessageOutputStream, code, "clock_time_stamp_flag[i]"); currentTimeSet.clockTimeStampFlag = code;
1216    if(currentTimeSet.clockTimeStampFlag)
1217    {
1218      sei_read_flag( pDecodedMessageOutputStream, code, "nuit_field_based_flag"); currentTimeSet.numUnitFieldBasedFlag = code;
1219      sei_read_code( pDecodedMessageOutputStream, 5, code, "counting_type"); currentTimeSet.countingType = code;
1220      sei_read_flag( pDecodedMessageOutputStream, code, "full_timestamp_flag"); currentTimeSet.fullTimeStampFlag = code;
1221      sei_read_flag( pDecodedMessageOutputStream, code, "discontinuity_flag"); currentTimeSet.discontinuityFlag = code;
1222      sei_read_flag( pDecodedMessageOutputStream, code, "cnt_dropped_flag"); currentTimeSet.cntDroppedFlag = code;
1223      sei_read_code( pDecodedMessageOutputStream, 9, code, "n_frames"); currentTimeSet.numberOfFrames = code;
1224      if(currentTimeSet.fullTimeStampFlag)
1225      {
1226        sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1227        sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1228        sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
1229      }
1230      else
1231      {
1232        sei_read_flag( pDecodedMessageOutputStream, code, "seconds_flag"); currentTimeSet.secondsFlag = code;
1233        if(currentTimeSet.secondsFlag)
1234        {
1235          sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1236          sei_read_flag( pDecodedMessageOutputStream, code, "minutes_flag"); currentTimeSet.minutesFlag = code;
1237          if(currentTimeSet.minutesFlag)
1238          {
1239            sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1240            sei_read_flag( pDecodedMessageOutputStream, code, "hours_flag"); currentTimeSet.hoursFlag = code;
1241            if(currentTimeSet.hoursFlag)
1242            {
1243              sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
1244            }
1245          }
1246        }
1247      }
1248      sei_read_code( pDecodedMessageOutputStream, 5, code, "time_offset_length"); currentTimeSet.timeOffsetLength = code;
1249      if(currentTimeSet.timeOffsetLength > 0)
1250      {
1251        sei_read_code( pDecodedMessageOutputStream, currentTimeSet.timeOffsetLength, code, "time_offset_value");
1252        if((code & (1 << (currentTimeSet.timeOffsetLength-1))) == 0)
1253        {
1254          currentTimeSet.timeOffsetValue = code;
1255        }
1256        else
1257        {
1258          code &= (1<< (currentTimeSet.timeOffsetLength-1)) - 1;
1259          currentTimeSet.timeOffsetValue = ~code + 1;
1260        }
1261      }
1262    }
1263    sei.timeSetArray[i] = currentTimeSet;
1264  }
1265}
1266
1267Void SEIReader::xParseSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1268{
1269  UInt uiCode;
1270  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1271
1272  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "ver_chroma_filter_idc"); sei.m_verChromaFilterIdc = uiCode;
1273  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "hor_chroma_filter_idc"); sei.m_horChromaFilterIdc = uiCode;
1274  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ver_filtering_field_processing_flag"); sei.m_verFilteringFieldProcessingFlag = uiCode;
1275  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
1276  {
1277    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "target_format_idc"); sei.m_targetFormatIdc = uiCode;
1278    if(sei.m_verChromaFilterIdc == 1)
1279    {
1280      UInt numVerticalFilters;
1281      sei_read_uvlc( pDecodedMessageOutputStream, numVerticalFilters, "num_vertical_filters"); sei.m_verFilterCoeff.resize(numVerticalFilters);
1282      if(numVerticalFilters > 0)
1283      {
1284        for(Int i = 0; i < numVerticalFilters; i++)
1285        {
1286          UInt verTapLengthMinus1;
1287          sei_read_uvlc( pDecodedMessageOutputStream, verTapLengthMinus1, "ver_tap_length_minus_1"); sei.m_verFilterCoeff[i].resize(verTapLengthMinus1+1);
1288          for(Int j = 0; j < (verTapLengthMinus1 + 1); j++)
1289          {
1290            sei_read_svlc( pDecodedMessageOutputStream, sei.m_verFilterCoeff[i][j], "ver_filter_coeff");
1291          }
1292        }
1293      }
1294    }
1295    if(sei.m_horChromaFilterIdc == 1)
1296    {
1297      UInt numHorizontalFilters;
1298      sei_read_uvlc( pDecodedMessageOutputStream, numHorizontalFilters, "num_horizontal_filters"); sei.m_horFilterCoeff.resize(numHorizontalFilters);
1299      if(numHorizontalFilters  > 0)
1300      {
1301        for(Int i = 0; i < numHorizontalFilters; i++)
1302        {
1303          UInt horTapLengthMinus1;
1304          sei_read_uvlc( pDecodedMessageOutputStream, horTapLengthMinus1, "hor_tap_length_minus_1"); sei.m_horFilterCoeff[i].resize(horTapLengthMinus1+1);
1305          for(Int j = 0; j < (horTapLengthMinus1 + 1); j++)
1306          {
1307            sei_read_svlc( pDecodedMessageOutputStream, sei.m_horFilterCoeff[i][j], "hor_filter_coeff");
1308          }
1309        }
1310      }
1311    }
1312  }
1313}
1314
1315Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1316{
1317  Int i;
1318  UInt val;
1319  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1320
1321  sei_read_uvlc( pDecodedMessageOutputStream, val, "knee_function_id" );                   sei.m_kneeId = val;
1322  sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
1323  if ( !sei.m_kneeCancelFlag )
1324  {
1325    sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
1326    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
1327    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
1328    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
1329    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
1330    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
1331    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
1332    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1333    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1334    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
1335    {
1336      sei_read_code( pDecodedMessageOutputStream, 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
1337      sei_read_code( pDecodedMessageOutputStream, 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
1338    }
1339  }
1340}
1341
1342Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1343{
1344  UInt  uiVal;
1345  Int   iVal;
1346  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1347
1348  sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
1349  sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
1350  if( !sei.m_colourRemapCancelFlag ) 
1351  {
1352    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
1353    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
1354    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
1355    {
1356      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );            sei.m_colourRemapFullRangeFlag = uiVal;
1357      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                  sei.m_colourRemapPrimaries = uiVal;
1358      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );          sei.m_colourRemapTransferFunction = uiVal;
1359      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );        sei.m_colourRemapMatrixCoefficients = uiVal;
1360    }
1361    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" );              sei.m_colourRemapInputBitDepth = uiVal;
1362    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" );                    sei.m_colourRemapBitDepth = uiVal;
1363 
1364    for( Int c=0 ; c<3 ; c++ )
1365    {
1366      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
1367      sei.m_preLut[c].resize(sei.m_preLutNumValMinus1[c]+1);
1368      if( uiVal> 0 )
1369      {
1370        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
1371        {
1372          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLut[c][i].codedValue  = uiVal;
1373          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLut[c][i].targetValue = uiVal;
1374        }
1375      }
1376      else // pre_lut_num_val_minus1[c] == 0
1377      {
1378        sei.m_preLut[c][0].codedValue  = 0;
1379        sei.m_preLut[c][0].targetValue = 0;
1380        sei.m_preLut[c][1].codedValue  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
1381        sei.m_preLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1 ;
1382      }
1383    }
1384
1385    sei_read_flag( pDecodedMessageOutputStream, uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
1386    if( sei.m_colourRemapMatrixPresentFlag )
1387    {
1388      sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
1389      for ( Int c=0 ; c<3 ; c++ )
1390      {
1391        for ( Int i=0 ; i<3 ; i++ )
1392        {
1393          sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
1394        }
1395      }
1396    }
1397    else // setting default matrix (I3)
1398    {
1399      sei.m_log2MatrixDenom = 10;
1400      for ( Int c=0 ; c<3 ; c++ )
1401      {
1402        for ( Int i=0 ; i<3 ; i++ )
1403        {
1404          sei.m_colourRemapCoeffs[c][i] = (c==i) << sei.m_log2MatrixDenom;
1405        }
1406      }
1407    }
1408    for( Int c=0 ; c<3 ; c++ )
1409    {
1410      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
1411      sei.m_postLut[c].resize(sei.m_postLutNumValMinus1[c]+1);
1412      if( uiVal > 0 )
1413      {
1414        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
1415        {
1416          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLut[c][i].codedValue = uiVal;
1417          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLut[c][i].targetValue = uiVal;
1418        }
1419      }
1420      else
1421      {
1422        sei.m_postLut[c][0].codedValue  = 0;
1423        sei.m_postLut[c][0].targetValue = 0;
1424        sei.m_postLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1;
1425        sei.m_postLut[c][1].codedValue  = (1 << sei.m_colourRemapBitDepth) - 1;
1426      }
1427    }
1428  }
1429}
1430
1431Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1432{
1433  UInt code;
1434  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1435
1436  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
1437  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
1438
1439  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
1440  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
1441
1442  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
1443  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
1444
1445
1446  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
1447  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
1448
1449  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
1450  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
1451}
1452
1453#if U0033_ALTERNATIVE_TRANSFER_CHARACTERISTICS_SEI
1454Void SEIReader::xParseSEIAlternativeTransferCharacteristics(SEIAlternativeTransferCharacteristics& sei, UInt payloadSize, ostream* pDecodedMessageOutputStream)
1455{
1456  UInt code;
1457  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1458
1459  sei_read_code(pDecodedMessageOutputStream, 8, code, "preferred_transfer_characteristics"); sei.m_preferredTransferCharacteristics = code;
1460}
1461#endif
1462
1463#if SVC_EXTENSION
1464#if LAYERS_NOT_PRESENT_SEI
1465Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
1466{
1467  UInt uiCode;
1468  UInt i = 0;
1469
1470  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
1471  assert(vps->getVPSId() == sei.m_activeVpsId);
1472  sei.m_vpsMaxLayers = vps->getMaxLayers();
1473  for (; i < sei.m_vpsMaxLayers; i++)
1474  {
1475    sei_read_flag( pDecodedMessageOutputStream, uiCode,         "layer_not_present_flag"   ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false;
1476  }
1477  for (; i < MAX_LAYERS; i++)
1478  {
1479    sei.m_layerNotPresentFlag[i] = false;
1480  }
1481}
1482#endif
1483
1484#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
1485Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1486{
1487  UInt uiCode;
1488
1489  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
1490  sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
1491  if( !sei.m_ilOneTilePerTileSetFlag )
1492  {
1493    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
1494    if( sei.m_ilNumSetsInMessageMinus1 )
1495    {
1496      sei_read_flag( pDecodedMessageOutputStream, uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
1497    }
1498    else
1499    {
1500      sei.m_skippedTileSetPresentFlag = false;
1501    }
1502    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
1503    for( UInt i = 0; i < numSignificantSets; i++ )
1504    {
1505      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
1506      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
1507      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
1508      {
1509        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
1510        sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
1511      }
1512      sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
1513      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
1514      {
1515        sei_read_flag( pDecodedMessageOutputStream, uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
1516      }
1517    }
1518  }
1519  else
1520  {
1521    sei_read_code( pDecodedMessageOutputStream, 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
1522  }
1523}
1524#endif
1525
1526#if SUB_BITSTREAM_PROPERTY_SEI
1527Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
1528{
1529  UInt uiCode;
1530  sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
1531  sei_read_uvlc( pDecodedMessageOutputStream,    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
1532
1533  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
1534  {
1535    sei_read_code( pDecodedMessageOutputStream,  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
1536    sei_read_uvlc( pDecodedMessageOutputStream,     uiCode, "output_layer_set_idx_to_vps[i]"  );
1537
1538    // The value of output_layer_set_idx_to_vps[ i ]  shall be in the range of 0 to NumOutputLayerSets − 1, inclusive.
1539    assert(uiCode > 0 && uiCode <= vps->getNumOutputLayerSets()-1);
1540
1541    sei.m_outputLayerSetIdxToVps[i] = uiCode;
1542
1543    sei_read_code( pDecodedMessageOutputStream,  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
1544    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
1545    sei_read_code( pDecodedMessageOutputStream, 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
1546  } 
1547}
1548#endif
1549
1550#if O0164_MULTI_LAYER_HRD
1551#if LAYERS_NOT_PRESENT_SEI
1552Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
1553#else
1554Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, const TComSPS *sps, const SEIScalableNesting &nestingSei, std::ostream *pDecodedMessageOutputStream)
1555#endif
1556{
1557  UInt uiCode;
1558  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
1559
1560  // byte alignment
1561  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1562  {
1563    UInt code;
1564    sei_read_flag( pDecodedMessageOutputStream, code, "bsp_nesting_zero_bit" );
1565  }
1566
1567  sei.m_callerOwnsSEIs = false;
1568
1569  // read nested SEI messages
1570  Int numSeiMessages = 0;
1571  sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
1572  numSeiMessages = uiCode;
1573  for(Int i = 0; i < numSeiMessages; i++)
1574  {
1575    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream, &nestingSei, &sei);
1576  }
1577}
1578
1579Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei, std::ostream *pDecodedMessageOutputStream)
1580{
1581  assert(vps->getVpsVuiPresentFlag());
1582
1583  UInt uiCode;
1584  Int psIdx         = bspNestingSei.m_seiPartitioningSchemeIdx;
1585  Int seiOlsIdx     = bspNestingSei.m_seiOlsIdx;
1586  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0];
1587  Int maxValues     = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
1588  std::vector<Int> hrdIdx(0, maxValues);
1589  std::vector<const TComHRD*> hrdVec;
1590  std::vector<Int> syntaxElemLen;
1591  for(Int i = 0; i < maxValues; i++)
1592  {
1593    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
1594    hrdVec[i] = vps->getBspHrd(hrdIdx[i]);
1595   
1596    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
1597    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
1598    {
1599      assert( syntaxElemLen[i] == 24 ); // Default value of init_cpb_removal_delay_length_minus1 is 23
1600    }
1601    if( i > 0 )
1602    {
1603      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
1604      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
1605    }
1606  }
1607  if (hrdVec[0]->getNalHrdParametersPresentFlag())
1608  {
1609    for(UInt i = 0; i < maxValues; i++)
1610    {
1611      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
1612    }
1613  }
1614  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
1615  {
1616    for(UInt i = 0; i < maxValues; i++)
1617    {
1618      sei_read_code( pDecodedMessageOutputStream, syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
1619    }
1620  }
1621}
1622
1623Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1, std::ostream *pDecodedMessageOutputStream)
1624{
1625  UInt  uiCode;
1626  if( commonInfPresentFlag )
1627  {
1628    sei_read_flag( pDecodedMessageOutputStream, uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
1629    sei_read_flag( pDecodedMessageOutputStream, uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
1630    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
1631    {
1632      sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
1633      if( hrd->getSubPicCpbParamsPresentFlag() )
1634      {
1635        sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
1636        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
1637        sei_read_flag( pDecodedMessageOutputStream, uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
1638        sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
1639      }
1640      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
1641      sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
1642      if( hrd->getSubPicCpbParamsPresentFlag() )
1643      {
1644        sei_read_code( pDecodedMessageOutputStream, 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
1645      }
1646      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
1647      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
1648      sei_read_code( pDecodedMessageOutputStream, 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
1649    }
1650  }
1651  Int i, j, nalOrVcl;
1652  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1653  {
1654    sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
1655    if( !hrd->getFixedPicRateFlag( i ) )
1656    {
1657       sei_read_flag( pDecodedMessageOutputStream, uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
1658    }
1659    else
1660    {
1661      hrd->setFixedPicRateWithinCvsFlag( i, true );
1662    }
1663    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
1664    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
1665    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1666    {
1667      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
1668    }
1669    else
1670    {
1671      sei_read_flag( pDecodedMessageOutputStream, uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
1672    }
1673    if (!hrd->getLowDelayHrdFlag( i ))
1674    {
1675      sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
1676    }
1677    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1678    {
1679      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1680          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1681      {
1682        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1683        {
1684          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
1685          sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
1686          if( hrd->getSubPicCpbParamsPresentFlag() )
1687          {
1688            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
1689            sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
1690          }
1691           sei_read_flag( pDecodedMessageOutputStream, uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
1692        }
1693      }
1694    }
1695  }
1696}
1697#endif
1698
1699#if P0123_ALPHA_CHANNEL_SEI
1700void SEIReader::xParseSEIAlphaChannelInfo(SEIAlphaChannelInfo &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1701{
1702  UInt value;
1703  sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_cancel_flag"); sei.m_alphaChannelCancelFlag = value;
1704  if(!sei.m_alphaChannelCancelFlag)
1705  {
1706    sei_read_code(pDecodedMessageOutputStream, 3, value, "alpha_channel_use_idc");          sei.m_alphaChannelUseIdc = value;
1707    sei_read_code(pDecodedMessageOutputStream, 3, value, "alpha_channel_bit_depth_minus8"); sei.m_alphaChannelBitDepthMinus8 = value;
1708    sei_read_code(pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8 + 9, value, "alpha_transparent_value"); sei.m_alphaTransparentValue = value;
1709    sei_read_code(pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8 + 9, value, "alpha_opaque_value"); sei.m_alphaOpaqueValue = value;
1710    sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_incr_flag");        sei.m_alphaChannelIncrFlag = value;
1711    sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_clip_flag");        sei.m_alphaChannelClipFlag = value;
1712    if(sei.m_alphaChannelClipFlag)
1713    {
1714      sei_read_flag(pDecodedMessageOutputStream, value, "alpha_channel_clip_type_flag"); sei.m_alphaChannelClipTypeFlag = value;
1715    }
1716  } 
1717}
1718#endif
1719
1720#if Q0096_OVERLAY_SEI
1721Void SEIReader::xParseSEIOverlayInfo(SEIOverlayInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
1722{
1723  Int i, j;
1724  UInt val;
1725  sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_cancel_flag" );                 sei.m_overlayInfoCancelFlag = val;
1726  if ( !sei.m_overlayInfoCancelFlag )
1727  {
1728    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_content_aux_id_minus128" );            sei.m_overlayContentAuxIdMinus128 = val;
1729    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_label_aux_id_minus128" );              sei.m_overlayLabelAuxIdMinus128 = val;
1730    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_alpha_aux_id_minus128" );              sei.m_overlayAlphaAuxIdMinus128 = val;
1731    sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_element_label_value_length_minus8" );  sei.m_overlayElementLabelValueLengthMinus8 = val;
1732    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlays_minus1" );                        sei.m_numOverlaysMinus1 = val;
1733
1734    assert( sei.m_numOverlaysMinus1 < MAX_OVERLAYS );
1735    sei.m_overlayIdx.resize( sei.m_numOverlaysMinus1+1 );
1736    sei.m_languageOverlayPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1737    sei.m_overlayContentLayerId.resize( sei.m_numOverlaysMinus1+1 );
1738    sei.m_overlayLabelPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1739    sei.m_overlayLabelLayerId.resize( sei.m_numOverlaysMinus1+1 );
1740    sei.m_overlayAlphaPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1741    sei.m_overlayAlphaLayerId.resize( sei.m_numOverlaysMinus1+1 );
1742    sei.m_numOverlayElementsMinus1.resize( sei.m_numOverlaysMinus1+1 );
1743    sei.m_overlayElementLabelMin.resize( sei.m_numOverlaysMinus1+1 );
1744    sei.m_overlayElementLabelMax.resize( sei.m_numOverlaysMinus1+1 );
1745    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
1746    {
1747      sei_read_uvlc( pDecodedMessageOutputStream, val, "overlay_idx" );                      sei.m_overlayIdx[i] = val;
1748      sei_read_flag( pDecodedMessageOutputStream, val, "language_overlay_present_flag" );    sei.m_languageOverlayPresentFlag[i] = val;
1749      sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_content_layer_id");       sei.m_overlayContentLayerId[i] = val;
1750      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_label_present_flag" );       sei.m_overlayLabelPresentFlag[i] = val;
1751      if ( sei.m_overlayLabelPresentFlag[i] )
1752      {
1753        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_label_layer_id");     sei.m_overlayLabelLayerId[i] = val;
1754      }
1755      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_alpha_present_flag" );       sei.m_overlayAlphaPresentFlag[i] = val;
1756      if ( sei.m_overlayAlphaPresentFlag[i] )
1757      {
1758        sei_read_code( pDecodedMessageOutputStream, 6, val, "overlay_alpha_layer_id");     sei.m_overlayAlphaLayerId[i] = val;
1759      }
1760      if ( sei.m_overlayLabelPresentFlag[i] )
1761      {
1762        sei_read_uvlc( pDecodedMessageOutputStream, val, "num_overlay_elements_minus1");   sei.m_numOverlayElementsMinus1[i] = val;
1763        assert( sei.m_numOverlayElementsMinus1[i] < MAX_OVERLAY_ELEMENTS );
1764        sei.m_overlayElementLabelMin[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1765        sei.m_overlayElementLabelMax[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1766        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++ )
1767        {
1768          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_min"); sei.m_overlayElementLabelMin[i][j] = val;
1769          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, val, "overlay_element_label_max"); sei.m_overlayElementLabelMax[i][j] = val;
1770        }     
1771      }
1772      else
1773      {
1774        sei.m_numOverlayElementsMinus1[i] = 0;
1775      }
1776    }
1777
1778    // byte alignment
1779    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1780    {
1781      sei_read_flag( pDecodedMessageOutputStream, val, "overlay_zero_bit" );
1782      assert( val==0 );
1783    }
1784
1785    UChar* sval = new UChar[MAX_OVERLAY_STRING_BYTES];
1786    UInt slen;   
1787    sei.m_overlayLanguage.resize( sei.m_numOverlaysMinus1+1, NULL );
1788    sei.m_overlayLanguageLength.resize( sei.m_numOverlaysMinus1+1 );
1789    sei.m_overlayName.resize( sei.m_numOverlaysMinus1+1, NULL );
1790    sei.m_overlayNameLength.resize( sei.m_numOverlaysMinus1+1 );
1791    sei.m_overlayElementName.resize( sei.m_numOverlaysMinus1+1 );
1792    sei.m_overlayElementNameLength.resize( sei.m_numOverlaysMinus1+1 );
1793    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
1794    {
1795      if ( sei.m_languageOverlayPresentFlag[i] )
1796      {
1797        READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_language" );
1798        sei.m_overlayLanguage[i] = new UChar[slen];
1799        memcpy(sei.m_overlayLanguage[i], sval, slen);
1800        sei.m_overlayLanguageLength[i] = slen;
1801      }
1802      READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_name" );
1803      sei.m_overlayName[i] = new UChar[slen];
1804      memcpy(sei.m_overlayName[i], sval, slen);
1805      sei.m_overlayNameLength[i] = slen;
1806      if ( sei.m_overlayLabelPresentFlag[i] )
1807      {
1808        sei.m_overlayElementName[i].resize( sei.m_numOverlayElementsMinus1[i]+1, NULL );
1809        sei.m_overlayElementNameLength[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1810        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++)
1811        {
1812          READ_STRING( MAX_OVERLAY_STRING_BYTES, sval, slen, "overlay_element_name" );
1813          sei.m_overlayElementName[i][j] = new UChar[slen];
1814          memcpy(sei.m_overlayElementName[i][j], sval, slen);
1815          sei.m_overlayElementNameLength[i][j] = slen;
1816        }
1817      }
1818    }
1819    sei_read_flag( pDecodedMessageOutputStream, val, "overlay_info_persistence_flag" );        sei.m_overlayInfoPersistenceFlag = val;
1820  } 
1821}
1822#endif
1823
1824#if P0138_USE_ALT_CPB_PARAMS_FLAG
1825/**
1826 * Check if SEI message contains payload extension
1827 */
1828Bool SEIReader::xPayloadExtensionPresent()
1829{
1830  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
1831  Bool payloadExtensionPresent = false;
1832
1833  if (payloadBitsRemaining > 8)
1834  {
1835    payloadExtensionPresent = true;
1836  }
1837  else
1838  {
1839    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
1840    while (payloadBitsRemaining && (finalBits & 1) == 0)
1841    {
1842      payloadBitsRemaining--;
1843      finalBits >>= 1;
1844    }
1845    payloadBitsRemaining--;
1846    if (payloadBitsRemaining > 0)
1847    {
1848      payloadExtensionPresent = true;
1849    }
1850  }
1851
1852  return payloadExtensionPresent;
1853}
1854#endif
1855
1856#if Q0189_TMVP_CONSTRAINTS
1857Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1858{
1859  UInt uiCode;
1860  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
1861  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "no_intra_layer_col_pic_flag"          ); sei.no_intra_layer_col_pic_flag = uiCode;
1862}
1863#endif
1864
1865#if Q0247_FRAME_FIELD_INFO
1866Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1867{
1868  UInt code;
1869  sei_read_code( pDecodedMessageOutputStream, 4, code, "ffinfo_pic_struct"       );       sei.m_ffinfo_picStruct      = code;
1870  sei_read_code( pDecodedMessageOutputStream, 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
1871  sei_read_flag( pDecodedMessageOutputStream,    code, "ffinfo_duplicate_flag"   );       sei.m_ffinfo_duplicateFlag  = ( code == 1 ? true : false );
1872}
1873#endif
1874
1875
1876#endif //SVC_EXTENSION
1877
1878//! \}
Note: See TracBrowser for help on using the repository browser.