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

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

port rev 4600, remove macro Q0074_COLOUR_REMAPPING_SEI

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