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

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

port rev 4219 and rev 4246

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