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

Last change on this file since 1163 was 1134, checked in by seregin, 9 years ago

macro cleanup: NESTING_SEI_EXTENSIBILITY

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