source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/SEIread.cpp @ 1413

Last change on this file since 1413 was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

  • Property svn:eol-style set to native
File size: 110.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2017, 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
101#if NH_MV
102Void SEIReader::sei_read_string(std::ostream *pOS, UInt uiBufSize, UChar* pucCode, UInt& ruiLength, const TChar *pSymbolName)
103{
104  READ_STRING(uiBufSize, pucCode, ruiLength, pSymbolName);
105  if (pOS)
106  {
107    (*pOS) << "  " << pSymbolName << ": " << (const char*) pucCode << "\n";
108  }
109}
110inline Void SEIReader::output_sei_message_header(SEI &sei, std::ostream *pDecodedMessageOutputStream, UInt payloadSize)
111#else
112static inline Void output_sei_message_header(SEI &sei, std::ostream *pDecodedMessageOutputStream, UInt payloadSize)
113#endif
114{
115  if (pDecodedMessageOutputStream)
116  {
117    std::string seiMessageHdr(SEI::getSEIMessageString(sei.payloadType())); seiMessageHdr+=" SEI message";
118    (*pDecodedMessageOutputStream) << std::setfill('-') << std::setw(seiMessageHdr.size()) << "-" << std::setfill(' ') << "\n" << seiMessageHdr << " (" << payloadSize << " bytes)"<< "\n";
119#if NH_MV
120    (*pDecodedMessageOutputStream) << std::setfill(' ') << "LayerId: " << m_layerId << std::setw(2) << " Picture: " << m_decOrder << std::setw( 5 ) << std::endl;
121#endif
122  }
123}
124
125#undef READ_CODE
126#undef READ_SVLC
127#undef READ_UVLC
128#undef READ_FLAG
129
130
131/**
132 * unmarshal a single SEI message from bitstream bs
133 */
134#if NH_MV
135Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
136#else
137Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
138#endif
139{
140  setBitstream(bs);
141
142  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
143  do
144  {
145#if NH_MV
146    xReadSEImessage(seis, nalUnitType, vps, sps, pDecodedMessageOutputStream);
147#else
148    xReadSEImessage(seis, nalUnitType, sps, pDecodedMessageOutputStream);
149#endif
150    /* SEI messages are an integer number of bytes, something has failed
151    * in the parsing if bitstream not byte-aligned */
152    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
153  }
154  while (m_pcBitstream->getNumBitsLeft() > 8);
155
156  xReadRbspTrailingBits();
157}
158
159#if NH_MV
160Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
161#else
162Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
163#endif
164{
165#if ENC_DEC_TRACE
166  xTraceSEIHeader();
167#endif
168  Int payloadType = 0;
169  UInt val = 0;
170
171  do
172  {
173    sei_read_code(NULL, 8, val, "payload_type");
174    payloadType += val;
175  } while (val==0xFF);
176
177  UInt payloadSize = 0;
178  do
179  {
180    sei_read_code(NULL, 8, val, "payload_size");
181    payloadSize += val;
182  } while (val==0xFF);
183
184#if ENC_DEC_TRACE
185  xTraceSEIMessageType((SEI::PayloadType)payloadType);
186#endif
187
188  /* extract the payload for this single SEI message.
189   * This allows greater safety in erroneous parsing of an SEI message
190   * from affecting subsequent messages.
191   * After parsing the payload, bs needs to be restored as the primary
192   * bitstream.
193   */
194  TComInputBitstream *bs = getBitstream();
195  setBitstream(bs->extractSubstream(payloadSize * 8));
196
197  SEI *sei = NULL;
198
199  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
200  {
201    switch (payloadType)
202    {
203    case SEI::BUFFERING_PERIOD:
204      if (!sps)
205      {
206        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
207      }
208      else
209      {
210        sei = new SEIBufferingPeriod;
211        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
212      }
213      break;
214    case SEI::PICTURE_TIMING:
215      if (!sps)
216      {
217        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
218      }
219      else
220      {
221        sei = new SEIPictureTiming;
222        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, pDecodedMessageOutputStream);
223      }
224      break;
225    case SEI::PAN_SCAN_RECT:
226      sei = new SEIPanScanRect;
227      xParseSEIPanScanRect((SEIPanScanRect&) *sei, payloadSize, pDecodedMessageOutputStream);
228      break;
229    case SEI::FILLER_PAYLOAD:
230      sei = new SEIFillerPayload;
231      xParseSEIFillerPayload((SEIFillerPayload&) *sei, payloadSize, pDecodedMessageOutputStream);
232      break;
233    case SEI::USER_DATA_REGISTERED_ITU_T_T35:
234      sei = new SEIUserDataRegistered;
235      xParseSEIUserDataRegistered((SEIUserDataRegistered&) *sei, payloadSize, pDecodedMessageOutputStream);
236      break;
237    case SEI::USER_DATA_UNREGISTERED:
238      sei = new SEIUserDataUnregistered;
239      xParseSEIUserDataUnregistered((SEIUserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
240      break;
241    case SEI::RECOVERY_POINT:
242      sei = new SEIRecoveryPoint;
243      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize, pDecodedMessageOutputStream);
244      break;
245    case SEI::SCENE_INFO:
246      sei = new SEISceneInfo;
247      xParseSEISceneInfo((SEISceneInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
248      break;
249    case SEI::PICTURE_SNAPSHOT:
250      sei = new SEIPictureSnapshot;
251      xParseSEIPictureSnapshot((SEIPictureSnapshot&) *sei, payloadSize, pDecodedMessageOutputStream);
252      break;
253    case SEI::PROGRESSIVE_REFINEMENT_SEGMENT_START:
254      sei = new SEIProgressiveRefinementSegmentStart;
255      xParseSEIProgressiveRefinementSegmentStart((SEIProgressiveRefinementSegmentStart&) *sei, payloadSize, pDecodedMessageOutputStream);
256      break;
257    case SEI::PROGRESSIVE_REFINEMENT_SEGMENT_END:
258      sei = new SEIProgressiveRefinementSegmentEnd;
259      xParseSEIProgressiveRefinementSegmentEnd((SEIProgressiveRefinementSegmentEnd&) *sei, payloadSize, pDecodedMessageOutputStream);
260      break;
261    case SEI::FILM_GRAIN_CHARACTERISTICS:
262      sei = new SEIFilmGrainCharacteristics;
263      xParseSEIFilmGrainCharacteristics((SEIFilmGrainCharacteristics&) *sei, payloadSize, pDecodedMessageOutputStream);
264      break;
265    case SEI::POST_FILTER_HINT:
266      if (!sps)
267      {
268        printf ("Warning: post filter hint SEI message, but no active SPS is available. Ignoring.");
269      }
270      else
271      {
272        sei = new SEIPostFilterHint;
273        xParseSEIPostFilterHint((SEIPostFilterHint&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
274      }
275      break;
276    case SEI::TONE_MAPPING_INFO:
277      sei = new SEIToneMappingInfo;
278      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
279      break;
280    case SEI::FRAME_PACKING:
281      sei = new SEIFramePacking;
282      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
283      break;
284    case SEI::DISPLAY_ORIENTATION:
285      sei = new SEIDisplayOrientation;
286      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize, pDecodedMessageOutputStream);
287      break;
288    case SEI::GREEN_METADATA:
289      sei = new SEIGreenMetadataInfo;
290      xParseSEIGreenMetadataInfo((SEIGreenMetadataInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
291      break;
292    case SEI::SOP_DESCRIPTION:
293      sei = new SEISOPDescription;
294      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize, pDecodedMessageOutputStream);
295      break;
296    case SEI::ACTIVE_PARAMETER_SETS:
297      sei = new SEIActiveParameterSets;
298      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize, pDecodedMessageOutputStream);
299      break;
300    case SEI::DECODING_UNIT_INFO:
301      if (!sps)
302      {
303        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
304      }
305      else
306      {
307        sei = new SEIDecodingUnitInfo;
308        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
309      }
310      break;
311    case SEI::TEMPORAL_LEVEL0_INDEX:
312      sei = new SEITemporalLevel0Index;
313      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize, pDecodedMessageOutputStream);
314      break;
315#if NH_MV
316      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps, pDecodedMessageOutputStream);
317#else
318    case SEI::SCALABLE_NESTING:
319      sei = new SEIScalableNesting;
320      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps, pDecodedMessageOutputStream);
321#endif
322      break;
323    case SEI::REGION_REFRESH_INFO:
324      sei = new SEIRegionRefreshInfo;
325      xParseSEIRegionRefreshInfo((SEIRegionRefreshInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
326      break;
327    case SEI::NO_DISPLAY:
328      sei = new SEINoDisplay;
329      xParseSEINoDisplay((SEINoDisplay&) *sei, payloadSize, pDecodedMessageOutputStream);
330      break;
331    case SEI::TIME_CODE:
332      sei = new SEITimeCode;
333      xParseSEITimeCode((SEITimeCode&) *sei, payloadSize, pDecodedMessageOutputStream);
334      break;
335    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
336      sei = new SEIMasteringDisplayColourVolume;
337      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
338      break;
339    case SEI::SEGM_RECT_FRAME_PACKING:
340      sei = new SEISegmentedRectFramePacking;
341      xParseSEISegmentedRectFramePacking((SEISegmentedRectFramePacking&) *sei, payloadSize, pDecodedMessageOutputStream);
342      break;
343    case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
344      sei = new SEITempMotionConstrainedTileSets;
345      xParseSEITempMotionConstraintsTileSets((SEITempMotionConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream);
346      break;
347    case SEI::CHROMA_RESAMPLING_FILTER_HINT:
348      sei = new SEIChromaResamplingFilterHint;
349      xParseSEIChromaResamplingFilterHint((SEIChromaResamplingFilterHint&) *sei, payloadSize, pDecodedMessageOutputStream);
350      break;
351    case SEI::KNEE_FUNCTION_INFO:
352      sei = new SEIKneeFunctionInfo;
353      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
354      break;
355    case SEI::COLOUR_REMAPPING_INFO:
356      sei = new SEIColourRemappingInfo;
357      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
358      break;
359    case SEI::DEINTERLACE_FIELD_IDENTIFICATION:
360      sei = new SEIDeinterlaceFieldIdentification;
361      xParseSEIDeinterlaceFieldIdentification((SEIDeinterlaceFieldIdentification&) *sei, payloadSize, pDecodedMessageOutputStream);
362      break;
363    case SEI::CONTENT_LIGHT_LEVEL_INFO:
364      sei = new SEIContentLightLevelInfo;
365      xParseSEIContentLightLevelInfo((SEIContentLightLevelInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
366      break;
367    case SEI::DEPENDENT_RAP_INDICATION:
368      sei = new SEIDependentRAPIndication;
369      xParseSEIDependentRAPIndication((SEIDependentRAPIndication&) *sei, payloadSize, pDecodedMessageOutputStream);
370      break;
371    case SEI::CODED_REGION_COMPLETION:
372      sei = new SEICodedRegionCompletion;
373      xParseSEICodedRegionCompletion((SEICodedRegionCompletion&) *sei, payloadSize, pDecodedMessageOutputStream);
374      break;
375    case SEI::ALTERNATIVE_TRANSFER_CHARACTERISTICS:
376      sei = new SEIAlternativeTransferCharacteristics;
377      xParseSEIAlternativeTransferCharacteristics((SEIAlternativeTransferCharacteristics&) *sei, payloadSize, pDecodedMessageOutputStream);
378      break;
379    case SEI::AMBIENT_VIEWING_ENVIRONMENT:
380      sei = new SEIAmbientViewingEnvironment;
381      xParseSEIAmbientViewingEnvironment((SEIAmbientViewingEnvironment&) *sei, payloadSize, pDecodedMessageOutputStream);
382      break;
383#if NH_MV
384    case SEI::LAYERS_NOT_PRESENT:
385      if (!vps)
386      {
387        printf ("Warning: Found Layers not present SEI message, but no active VPS is available. Ignoring.");
388      }
389      else
390      {
391        sei = new SEILayersNotPresent;
392        xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps, pDecodedMessageOutputStream);
393      }
394      break;
395    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
396      sei = new SEIInterLayerConstrainedTileSets;
397      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize, pDecodedMessageOutputStream );
398      break;
399#if NH_MV_TBD
400    case SEI::BSP_NESTING:
401      sei = new SEIBspNesting;
402      xParseSEIBspNesting((SEIBspNesting&) *sei, payloadSize, pDecodedMessageOutputStream );
403      break;
404    case SEI::BSP_INITIAL_ARRIVAL_TIME:
405      sei = new SEIBspInitialArrivalTime;
406      xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, payloadSize, pDecodedMessageOutputStream );
407      break;
408#endif
409    case SEI::SUB_BITSTREAM_PROPERTY:
410      sei = new SEISubBitstreamProperty;
411      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, payloadSize, pDecodedMessageOutputStream );
412      break;
413    case SEI::ALPHA_CHANNEL_INFO:
414      sei = new SEIAlphaChannelInfo;
415      xParseSEIAlphaChannelInfo((SEIAlphaChannelInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
416      break;
417    case SEI::OVERLAY_INFO:
418      sei = new SEIOverlayInfo;
419      xParseSEIOverlayInfo((SEIOverlayInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
420      break;
421    case SEI::TEMPORAL_MV_PREDICTION_CONSTRAINTS:
422      sei = new SEITemporalMvPredictionConstraints;
423      xParseSEITemporalMvPredictionConstraints((SEITemporalMvPredictionConstraints&) *sei, payloadSize, pDecodedMessageOutputStream );
424      break;
425#if NH_MV_SEI_TBD
426    case SEI::FRAME_FIELD_INFO:
427      sei = new SEIFrameFieldInfo;
428      xParseSEIFrameFieldInfo((SEIFrameFieldInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
429      break;
430#endif
431    case SEI::THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO:
432      sei = new SEIThreeDimensionalReferenceDisplaysInfo;
433      xParseSEIThreeDimensionalReferenceDisplaysInfo((SEIThreeDimensionalReferenceDisplaysInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
434      break;
435    case SEI::DEPTH_REPRESENTATION_INFO:
436        sei = new SEIDepthRepresentationInfo;
437        xParseSEIDepthRepresentationInfo((SEIDepthRepresentationInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
438        break;
439    case SEI::MULTIVIEW_SCENE_INFO:
440      sei = new SEIMultiviewSceneInfo;
441      xParseSEIMultiviewSceneInfo((SEIMultiviewSceneInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
442      break;
443
444    case SEI::MULTIVIEW_ACQUISITION_INFO:
445      sei = new SEIMultiviewAcquisitionInfo;
446      xParseSEIMultiviewAcquisitionInfo((SEIMultiviewAcquisitionInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
447      break;
448
449    case SEI::MULTIVIEW_VIEW_POSITION:
450      sei = new SEIMultiviewViewPosition;
451      xParseSEIMultiviewViewPosition((SEIMultiviewViewPosition&) *sei, payloadSize, pDecodedMessageOutputStream );
452      break;
453#if NH_3D
454    case SEI::ALTERNATIVE_DEPTH_INFO:
455      sei = new SEIAlternativeDepthInfo;
456      xParseSEIAlternativeDepthInfo((SEIAlternativeDepthInfo&) *sei, payloadSize, pDecodedMessageOutputStream );
457      break;
458#endif
459#endif
460    default:
461      for (UInt i = 0; i < payloadSize; i++)
462      {
463        UInt seiByte;
464        sei_read_code (NULL, 8, seiByte, "unknown prefix SEI payload byte");
465      }
466      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
467      if (pDecodedMessageOutputStream)
468      {
469        (*pDecodedMessageOutputStream) << "Unknown prefix SEI message (payloadType = " << payloadType << ") was found!\n";
470      }
471      break;
472    }
473  }
474  else
475  {
476    switch (payloadType)
477    {
478      case SEI::FILLER_PAYLOAD:
479        sei = new SEIFillerPayload;
480        xParseSEIFillerPayload((SEIFillerPayload&) *sei, payloadSize, pDecodedMessageOutputStream);
481        break;
482      case SEI::USER_DATA_REGISTERED_ITU_T_T35:
483        sei = new SEIUserDataRegistered;
484        xParseSEIUserDataRegistered((SEIUserDataRegistered&) *sei, payloadSize, pDecodedMessageOutputStream);
485        break;
486      case SEI::USER_DATA_UNREGISTERED:
487        sei = new SEIUserDataUnregistered;
488        xParseSEIUserDataUnregistered((SEIUserDataUnregistered&) *sei, payloadSize, pDecodedMessageOutputStream);
489        break;
490      case SEI::PROGRESSIVE_REFINEMENT_SEGMENT_END:
491        sei = new SEIProgressiveRefinementSegmentEnd;
492        xParseSEIProgressiveRefinementSegmentEnd((SEIProgressiveRefinementSegmentEnd&) *sei, payloadSize, pDecodedMessageOutputStream);
493        break;
494      case SEI::POST_FILTER_HINT:
495        if (!sps)
496        {
497          printf ("Warning: post filter hint SEI message, but no active SPS is available. Ignoring.");
498        }
499        else
500        {
501          sei = new SEIPostFilterHint;
502          xParseSEIPostFilterHint((SEIPostFilterHint&) *sei, payloadSize, sps, pDecodedMessageOutputStream);
503        }
504        break;
505      case SEI::DECODED_PICTURE_HASH:
506        sei = new SEIDecodedPictureHash;
507        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize, pDecodedMessageOutputStream);
508        break;
509      case SEI::CODED_REGION_COMPLETION:
510        sei = new SEICodedRegionCompletion;
511        xParseSEICodedRegionCompletion((SEICodedRegionCompletion&) *sei, payloadSize, pDecodedMessageOutputStream);
512        break;
513      default:
514        for (UInt i = 0; i < payloadSize; i++)
515        {
516          UInt seiByte;
517          sei_read_code( NULL, 8, seiByte, "unknown suffix SEI payload byte");
518        }
519        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
520        if (pDecodedMessageOutputStream)
521        {
522          (*pDecodedMessageOutputStream) << "Unknown suffix SEI message (payloadType = " << payloadType << ") was found!\n";
523        }
524        break;
525    }
526  }
527
528  if (sei != NULL)
529  {
530    seis.push_back(sei);
531  }
532
533  /* By definition the underlying bitstream terminates in a byte-aligned manner.
534   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
535   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
536   * 3. Extract the remainingreserved_payload_extension_data bits.
537   *
538   * If there are fewer than 9 bits available, extract them.
539   */
540  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
541  if (payloadBitsRemaining) /* more_data_in_payload() */
542  {
543    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
544    {
545      UInt reservedPayloadExtensionData;
546      sei_read_code ( pDecodedMessageOutputStream, 1, reservedPayloadExtensionData, "reserved_payload_extension_data");
547    }
548
549    /* 2 */
550    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
551    Int finalPayloadBits = 0;
552    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
553    {
554      continue;
555    }
556
557    /* 3 */
558    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
559    {
560      UInt reservedPayloadExtensionData;
561      sei_read_flag ( 0, reservedPayloadExtensionData, "reserved_payload_extension_data");
562    }
563
564    UInt dummy;
565    sei_read_flag( 0, dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
566    while (payloadBitsRemaining)
567    {
568      sei_read_flag( 0, dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
569    }
570  }
571
572  /* restore primary bitstream for sei_message */
573  delete getBitstream();
574  setBitstream(bs);
575}
576
577
578Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
579{
580  Int i, nalOrVcl;
581  UInt code;
582
583  const TComVUI *pVUI = sps->getVuiParameters();
584  const TComHRD *pHRD = pVUI->getHrdParameters();
585
586  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
587
588  sei_read_uvlc( pDecodedMessageOutputStream, code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
589  if( !pHRD->getSubPicCpbParamsPresentFlag() )
590  {
591    sei_read_flag( pDecodedMessageOutputStream, code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
592  }
593  if( sei.m_rapCpbParamsPresentFlag )
594  {
595    sei_read_code( pDecodedMessageOutputStream, pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
596    sei_read_code( pDecodedMessageOutputStream, pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
597  }
598
599  //read splicing flag and cpb_removal_delay_delta
600  sei_read_flag( pDecodedMessageOutputStream, code, "concatenation_flag");
601  sei.m_concatenationFlag = code;
602  sei_read_code( pDecodedMessageOutputStream, ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
603  sei.m_auCpbRemovalDelayDelta = code + 1;
604
605  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
606  {
607    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
608        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
609    {
610      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
611      {
612        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_delay":"nal_initial_cpb_removal_delay" );
613        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
614        sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_cpb_removal_offset":"nal_initial_cpb_removal_offset" );
615        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
616        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
617        {
618          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_delay":"nal_initial_alt_cpb_removal_delay" );
619          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
620          sei_read_code( pDecodedMessageOutputStream, ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, nalOrVcl?"vcl_initial_alt_cpb_removal_offset":"nal_initial_alt_cpb_removal_offset" );
621          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
622        }
623      }
624    }
625  }
626}
627
628Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
629{
630  Int i;
631  UInt code;
632
633  const TComVUI *vui = sps->getVuiParameters();
634  const TComHRD *hrd = vui->getHrdParameters();
635  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
636
637  if( vui->getFrameFieldInfoPresentFlag() )
638  {
639    sei_read_code( pDecodedMessageOutputStream, 4, code, "pic_struct" );             sei.m_picStruct            = code;
640    sei_read_code( pDecodedMessageOutputStream, 2, code, "source_scan_type" );       sei.m_sourceScanType       = code;
641    sei_read_flag( pDecodedMessageOutputStream,    code, "duplicate_flag" );         sei.m_duplicateFlag        = (code == 1);
642  }
643
644  if( hrd->getCpbDpbDelaysPresentFlag())
645  {
646    sei_read_code( pDecodedMessageOutputStream, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
647    sei.m_auCpbRemovalDelay = code + 1;
648    sei_read_code( pDecodedMessageOutputStream, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
649    sei.m_picDpbOutputDelay = code;
650
651    if(hrd->getSubPicCpbParamsPresentFlag())
652    {
653      sei_read_code( pDecodedMessageOutputStream, hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
654      sei.m_picDpbOutputDuDelay = code;
655    }
656
657    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
658    {
659      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_decoding_units_minus1");
660      sei.m_numDecodingUnitsMinus1 = code;
661      sei_read_flag( pDecodedMessageOutputStream, code, "du_common_cpb_removal_delay_flag" );
662      sei.m_duCommonCpbRemovalDelayFlag = code;
663      if( sei.m_duCommonCpbRemovalDelayFlag )
664      {
665        sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_increment_minus1" );
666        sei.m_duCommonCpbRemovalDelayMinus1 = code;
667      }
668      sei.m_numNalusInDuMinus1.resize(sei.m_numDecodingUnitsMinus1 + 1 );
669      sei.m_duCpbRemovalDelayMinus1.resize( sei.m_numDecodingUnitsMinus1 + 1 );
670
671      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
672      {
673        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_nalus_in_du_minus1[i]");
674        sei.m_numNalusInDuMinus1[ i ] = code;
675        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
676        {
677          sei_read_code( pDecodedMessageOutputStream, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1[i]" );
678          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
679        }
680      }
681    }
682  }
683}
684
685Void SEIReader::xParseSEIPanScanRect(SEIPanScanRect& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
686{
687  UInt code;
688  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
689  sei_read_uvlc( pDecodedMessageOutputStream, code, "pan_scan_rect_id" );          sei.m_panScanRectId = code;
690  sei_read_flag( pDecodedMessageOutputStream, code, "pan_scan_rect_cancel_flag" ); sei.m_panScanRectCancelFlag = code!=0;
691  if (!sei.m_panScanRectCancelFlag)
692  {
693    UInt numRegions;
694    sei_read_uvlc( pDecodedMessageOutputStream, numRegions, "pan_scan_cnt_minus1" ); numRegions++;
695    sei.m_panScanRectRegions.resize(numRegions);
696    for(UInt region=0; region<numRegions; region++)
697    {
698      SEIPanScanRect::PanScanRect &rect=sei.m_panScanRectRegions[region];
699      Int  i;
700      sei_read_svlc( pDecodedMessageOutputStream, i, "pan_scan_rect_left_offset[i]" );   rect.leftOffset   = i;
701      sei_read_svlc( pDecodedMessageOutputStream, i, "pan_scan_rect_right_offset[i]" );  rect.rightOffset  = i;
702      sei_read_svlc( pDecodedMessageOutputStream, i, "pan_scan_rect_top_offset[i]" );    rect.topOffset    = i;
703      sei_read_svlc( pDecodedMessageOutputStream, i, "pan_scan_rect_bottom_offset[i]" ); rect.bottomOffset = i;
704    }
705    sei_read_flag( pDecodedMessageOutputStream, code, "pan_scan_rect_persistence_flag" ); sei.m_panScanRectPersistenceFlag = code!=0;
706  }
707  else
708  {
709    sei.m_panScanRectRegions.clear();
710    sei.m_panScanRectPersistenceFlag=false;
711  }
712}
713
714Void SEIReader::xParseSEIFillerPayload(SEIFillerPayload& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
715{
716  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
717  sei.m_numFillerFFBytes = payloadSize;
718  Bool allBytesWereFF=true;
719  for(UInt k=0; k<payloadSize; k++)
720  {
721    UInt code;
722    sei_read_code( NULL, 8, code, "ff_byte" );
723    if (code!=0xff) allBytesWereFF=false;
724  }
725  if (pDecodedMessageOutputStream && !allBytesWereFF)
726  {
727    (*pDecodedMessageOutputStream) << "  not all filler payload bytes were 0xff\n";
728  }
729}
730
731
732Void SEIReader::xParseSEIUserDataRegistered(SEIUserDataRegistered& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
733  {
734  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
735
736  UInt code;
737  assert(payloadSize>0);
738  sei_read_code( pDecodedMessageOutputStream, 8, code, "itu_t_t35_country_code" ); payloadSize--;
739  if (code == 255)
740  {
741    assert(payloadSize>0);
742    sei_read_code( pDecodedMessageOutputStream, 8, code, "itu_t_t35_country_code_extension_byte" ); payloadSize--;
743    code+=255;
744  }
745  sei.m_ituCountryCode = code;
746  sei.m_userData.resize(payloadSize);
747  for (UInt i = 0; i < sei.m_userData.size(); i++)
748  {
749    sei_read_code( NULL, 8, code, "itu_t_t35_payload_byte" );
750    sei.m_userData[i] = code;
751  }
752  if (pDecodedMessageOutputStream)
753  {
754    (*pDecodedMessageOutputStream) << "  itu_t_t35 payload size: " << sei.m_userData.size() << "\n";
755  }
756}
757
758Void SEIReader::xParseSEIUserDataUnregistered(SEIUserDataUnregistered &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
759    {
760  assert(payloadSize >= ISO_IEC_11578_LEN);
761  UInt val;
762  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
763
764  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
765  {
766    sei_read_code( pDecodedMessageOutputStream, 8, val, "uuid_iso_iec_11578");
767    sei.m_uuid_iso_iec_11578[i] = val;
768    }
769  sei.m_userData.resize(payloadSize - ISO_IEC_11578_LEN);
770  for (UInt i = 0; i < sei.m_userData.size(); i++)
771  {
772    sei_read_code( NULL, 8, val, "user_data_payload_byte" );
773    sei.m_userData[i] = val;
774  }
775  if (pDecodedMessageOutputStream)
776  {
777    (*pDecodedMessageOutputStream) << "  User data payload size: " << sei.m_userData.size() << "\n";
778  }
779}
780
781
782Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
783{
784  Int  iCode;
785  UInt uiCode;
786  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
787
788  sei_read_svlc( pDecodedMessageOutputStream, iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
789  sei_read_flag( pDecodedMessageOutputStream, uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
790  sei_read_flag( pDecodedMessageOutputStream, uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
791}
792
793
794Void SEIReader::xParseSEISceneInfo(SEISceneInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
795  {
796  UInt code;
797  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
798
799  sei_read_flag( pDecodedMessageOutputStream, code, "scene_info_present_flag" ); sei.m_bSceneInfoPresentFlag = code!=0;
800  if (sei.m_bSceneInfoPresentFlag)
801  {
802    sei_read_flag( pDecodedMessageOutputStream, code, "prev_scene_id_valid_flag" ); sei.m_bPrevSceneIdValidFlag = code!=0;
803    sei_read_uvlc( pDecodedMessageOutputStream, code, "scene_id" );                 sei.m_sceneId = code;
804    sei_read_uvlc( pDecodedMessageOutputStream, code, "scene_transition_type" );    sei.m_sceneTransitionType = code;
805    if (sei.m_sceneTransitionType > 3)
806    {
807      sei_read_uvlc( pDecodedMessageOutputStream, code, "second_scene_id" );        sei.m_secondSceneId = code;
808    }
809    else
810    {
811      sei.m_secondSceneId = 0; // set to known value.
812    }
813  }
814}
815
816Void SEIReader::xParseSEIPictureSnapshot(SEIPictureSnapshot& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
817{
818  UInt code;
819  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
820
821  sei_read_uvlc( pDecodedMessageOutputStream, code, "snapshot_id" ); sei.m_snapshotId = code;
822  }
823
824
825Void SEIReader::xParseSEIProgressiveRefinementSegmentStart(SEIProgressiveRefinementSegmentStart& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
826{
827  UInt code;
828  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
829
830  sei_read_uvlc( pDecodedMessageOutputStream, code, "progressive_refinement_id" ); sei.m_progressiveRefinementId = code;
831  sei_read_uvlc( pDecodedMessageOutputStream, code, "pic_order_cnt_delta" );       sei.m_picOrderCntDelta = code;
832}
833
834
835Void SEIReader::xParseSEIProgressiveRefinementSegmentEnd(SEIProgressiveRefinementSegmentEnd& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
836{
837  UInt code;
838  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
839
840  sei_read_uvlc( pDecodedMessageOutputStream, code, "progressive_refinement_id" ); sei.m_progressiveRefinementId = code;
841}
842
843
844Void SEIReader::xParseSEIFilmGrainCharacteristics(SEIFilmGrainCharacteristics& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
845{
846  UInt code;
847  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
848
849  sei_read_flag( pDecodedMessageOutputStream, code, "film_grain_characteristics_cancel_flag" );     sei.m_filmGrainCharacteristicsCancelFlag = code!=0;
850  if (!sei.m_filmGrainCharacteristicsCancelFlag)
851  {
852    sei_read_code( pDecodedMessageOutputStream, 2, code, "film_grain_model_id" );                   sei.m_filmGrainModelId = code;
853    sei_read_flag( pDecodedMessageOutputStream,    code, "separate_colour_description_present_flag" ); sei.m_separateColourDescriptionPresentFlag = code!=0;
854    if (sei.m_separateColourDescriptionPresentFlag)
855    {
856      sei_read_code( pDecodedMessageOutputStream, 3, code, "film_grain_bit_depth_luma_minus8" );    sei.m_filmGrainBitDepthLumaMinus8      = code;
857      sei_read_code( pDecodedMessageOutputStream, 3, code, "film_grain_bit_depth_chroma_minus8" );  sei.m_filmGrainBitDepthChromaMinus8    = code;
858      sei_read_flag( pDecodedMessageOutputStream,    code, "film_grain_full_range_flag" );          sei.m_filmGrainFullRangeFlag           = code!=0;
859      sei_read_code( pDecodedMessageOutputStream, 8, code, "film_grain_colour_primaries" );         sei.m_filmGrainColourPrimaries         = code;
860      sei_read_code( pDecodedMessageOutputStream, 8, code, "film_grain_transfer_characteristics" ); sei.m_filmGrainTransferCharacteristics = code;
861      sei_read_code( pDecodedMessageOutputStream, 8, code, "film_grain_matrix_coeffs" );            sei.m_filmGrainMatrixCoeffs            = code;
862    }
863    sei_read_code( pDecodedMessageOutputStream, 2, code, "blending_mode_id" );                      sei.m_blendingModeId                   = code;
864    sei_read_code( pDecodedMessageOutputStream, 4, code, "log2_scale_factor" );                     sei.m_log2ScaleFactor                  = code;
865    for(Int c=0; c<3; c++)
866    {
867      sei_read_flag( pDecodedMessageOutputStream,    code, "comp_model_present_flag[c]" );          sei.m_compModel[c].bPresentFlag        = code!=0;
868    }
869    for(Int c=0; c<3; c++)
870    {
871      SEIFilmGrainCharacteristics::CompModel &cm=sei.m_compModel[c];
872      if (cm.bPresentFlag)
873      {
874        UInt numIntensityIntervals;
875        sei_read_code( pDecodedMessageOutputStream, 8, code, "num_intensity_intervals_minus1[c]" ); numIntensityIntervals = code+1;
876        sei_read_code( pDecodedMessageOutputStream, 3, code, "num_model_values_minus1[c]" );        cm.numModelValues     = code+1;
877        cm.intensityValues.resize(numIntensityIntervals);
878        for(UInt interval=0; interval<numIntensityIntervals; interval++)
879        {
880          SEIFilmGrainCharacteristics::CompModelIntensityValues &cmiv=cm.intensityValues[interval];
881          sei_read_code( pDecodedMessageOutputStream, 8, code, "intensity_interval_lower_bound[c][i]" ); cmiv.intensityIntervalLowerBound=code;
882          sei_read_code( pDecodedMessageOutputStream, 8, code, "intensity_interval_upper_bound[c][i]" ); cmiv.intensityIntervalUpperBound=code;
883          cmiv.compModelValue.resize(cm.numModelValues);
884          for(UInt j=0; j<cm.numModelValues; j++)
885          {
886            sei_read_svlc( pDecodedMessageOutputStream, cmiv.compModelValue[j], "comp_model_value[c][i]" );
887          }
888        }
889      }
890    } // for c
891    sei_read_flag( pDecodedMessageOutputStream, code, "film_grain_characteristics_persistence_flag" ); sei.m_filmGrainCharacteristicsPersistenceFlag = code!=0;
892  } // cancel flag
893}
894
895Void SEIReader::xParseSEIPostFilterHint(SEIPostFilterHint& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
896{
897  UInt code;
898  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
899
900  sei_read_uvlc( pDecodedMessageOutputStream,    code, "filter_hint_size_y" ); sei.m_filterHintSizeY = code;
901  sei_read_uvlc( pDecodedMessageOutputStream,    code, "filter_hint_size_x" ); sei.m_filterHintSizeX = code;
902  sei_read_code( pDecodedMessageOutputStream, 2, code, "filter_hint_type"   ); sei.m_filterHintType  = code;
903
904  sei.m_bIsMonochrome = (sps->getChromaFormatIdc() == CHROMA_400);
905  const UInt numChromaChannels = sei.m_bIsMonochrome ? 1:3;
906
907  sei.m_filterHintValues.resize(numChromaChannels * sei.m_filterHintSizeX * sei.m_filterHintSizeY);
908  for(std::size_t i=0; i<sei.m_filterHintValues.size(); i++)
909  {
910    Int v;
911    sei_read_svlc( pDecodedMessageOutputStream, v, "filter_hint_value[][][]" ); sei.m_filterHintValues[i] = code;
912
913}
914}
915
916
917Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
918{
919  Int i;
920  UInt val;
921  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
922  sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_id" );                         sei.m_toneMapId = val;
923  sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
924
925  if ( !sei.m_toneMapCancelFlag )
926  {
927    sei_read_flag( pDecodedMessageOutputStream, val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
928    sei_read_code( pDecodedMessageOutputStream, 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
929    sei_read_code( pDecodedMessageOutputStream, 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
930    sei_read_uvlc( pDecodedMessageOutputStream, val, "tone_map_model_id" );                 sei.m_modelId = val;
931    switch(sei.m_modelId)
932    {
933    case 0:
934      {
935        sei_read_code( pDecodedMessageOutputStream, 32, val, "min_value" );                 sei.m_minValue = val;
936        sei_read_code( pDecodedMessageOutputStream, 32, val, "max_value" );                 sei.m_maxValue = val;
937        break;
938      }
939    case 1:
940      {
941        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
942        sei_read_code( pDecodedMessageOutputStream, 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
943        break;
944      }
945    case 2:
946      {
947        UInt num = 1u << sei.m_targetBitDepth;
948        sei.m_startOfCodedInterval.resize(num+1);
949        for(i = 0; i < num; i++)
950        {
951          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval[i]" );
952          sei.m_startOfCodedInterval[i] = val;
953        }
954        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
955        break;
956      }
957    case 3:
958      {
959        sei_read_code( pDecodedMessageOutputStream, 16, val,  "num_pivots" );                       sei.m_numPivots = val;
960        sei.m_codedPivotValue.resize(sei.m_numPivots);
961        sei.m_targetPivotValue.resize(sei.m_numPivots);
962        for(i = 0; i < sei.m_numPivots; i++ )
963        {
964          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value[i]" );
965          sei.m_codedPivotValue[i] = val;
966          sei_read_code( pDecodedMessageOutputStream, ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value[i]" );
967          sei.m_targetPivotValue[i] = val;
968        }
969        break;
970      }
971    case 4:
972      {
973        sei_read_code( pDecodedMessageOutputStream, 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
974        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
975        {
976          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
977        }
978        sei_read_code( pDecodedMessageOutputStream, 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
979        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
980        {
981          sei_read_code( pDecodedMessageOutputStream, 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
982        }
983        sei_read_flag( pDecodedMessageOutputStream, val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
984        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
985        sei_read_code( pDecodedMessageOutputStream, 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
986        sei_read_code( pDecodedMessageOutputStream, 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
987        sei_read_code( pDecodedMessageOutputStream, 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
988        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_black_level_code_value" );          sei.m_nominalBlackLevelLumaCodeValue = val;
989        sei_read_code( pDecodedMessageOutputStream, 16, val, "nominal_white_level_code_value" );          sei.m_nominalWhiteLevelLumaCodeValue= val;
990        sei_read_code( pDecodedMessageOutputStream, 16, val, "extended_white_level_code_value" );         sei.m_extendedWhiteLevelLumaCodeValue = val;
991        break;
992      }
993    default:
994      {
995        assert(!"Undefined SEIToneMapModelId");
996        break;
997      }
998    }//switch model id
999  }// if(!sei.m_toneMapCancelFlag)
1000}
1001
1002
1003Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1004{
1005  UInt val;
1006  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1007
1008  sei_read_uvlc( pDecodedMessageOutputStream, val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
1009  sei_read_flag( pDecodedMessageOutputStream, val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
1010
1011  if ( !sei.m_arrangementCancelFlag )
1012  {
1013    sei_read_code( pDecodedMessageOutputStream, 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
1014    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
1015
1016    sei_read_flag( pDecodedMessageOutputStream, val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
1017
1018    sei_read_code( pDecodedMessageOutputStream, 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
1019    sei_read_flag( pDecodedMessageOutputStream, val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
1020    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
1021    sei_read_flag( pDecodedMessageOutputStream, val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
1022    sei_read_flag( pDecodedMessageOutputStream, val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
1023    sei_read_flag( pDecodedMessageOutputStream, val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
1024    sei_read_flag( pDecodedMessageOutputStream, val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
1025
1026    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
1027    {
1028      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
1029      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
1030      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
1031      sei_read_code( pDecodedMessageOutputStream, 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
1032    }
1033
1034    sei_read_code( pDecodedMessageOutputStream, 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
1035    sei_read_flag( pDecodedMessageOutputStream, val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = (val != 0);
1036  }
1037  sei_read_flag( pDecodedMessageOutputStream, val, "upsampled_aspect_ratio_flag" );                  sei.m_upsampledAspectRatio = val;
1038}
1039
1040
1041Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1042{
1043  UInt val;
1044  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1045  sei_read_flag( pDecodedMessageOutputStream, val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
1046  if( !sei.cancelFlag )
1047  {
1048    sei_read_flag( pDecodedMessageOutputStream, val,     "hor_flip" );                              sei.horFlip               = val;
1049    sei_read_flag( pDecodedMessageOutputStream, val,     "ver_flip" );                              sei.verFlip               = val;
1050    sei_read_code( pDecodedMessageOutputStream, 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
1051    sei_read_flag( pDecodedMessageOutputStream, val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
1052  }
1053}
1054
1055
1056Void SEIReader::xParseSEIGreenMetadataInfo(SEIGreenMetadataInfo& sei, UInt payloadSize, ostream* pDecodedMessageOutputStream)
1057{
1058  UInt code;
1059  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1060
1061  sei_read_code(pDecodedMessageOutputStream, 8, code, "green_metadata_type");
1062  sei.m_greenMetadataType = code;
1063
1064  sei_read_code(pDecodedMessageOutputStream, 8, code, "xsd_metric_type");
1065  sei.m_xsdMetricType = code;
1066
1067  sei_read_code(pDecodedMessageOutputStream, 16, code, "xsd_metric_value");
1068  sei.m_xsdMetricValue = code;
1069}
1070
1071
1072Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1073{
1074  Int iCode;
1075  UInt uiCode;
1076  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1077
1078  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
1079  sei_read_uvlc( pDecodedMessageOutputStream, uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
1080  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
1081  {
1082    sei_read_code( pDecodedMessageOutputStream, 6, uiCode,                     "sop_vcl_nut[i]" );  sei.m_sopDescVclNaluType[i] = uiCode;
1083    sei_read_code( pDecodedMessageOutputStream, 3, sei.m_sopDescTemporalId[i], "sop_temporal_id[i]"   );  sei.m_sopDescTemporalId[i] = uiCode;
1084    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
1085    {
1086      sei_read_uvlc( pDecodedMessageOutputStream, sei.m_sopDescStRpsIdx[i],    "sop_short_term_rps_idx[i]"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
1087    }
1088    if (i > 0)
1089    {
1090      sei_read_svlc( pDecodedMessageOutputStream, iCode,                       "sop_poc_delta[i]"     ); sei.m_sopDescPocDelta[i] = iCode;
1091    }
1092  }
1093}
1094
1095Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1096{
1097  UInt val;
1098  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1099
1100  sei_read_code( pDecodedMessageOutputStream, 4, val, "active_video_parameter_set_id");   sei.activeVPSId = val;
1101  sei_read_flag( pDecodedMessageOutputStream,    val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag     = (val != 0);
1102  sei_read_flag( pDecodedMessageOutputStream,    val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = (val != 0);
1103  sei_read_uvlc( pDecodedMessageOutputStream,    val, "num_sps_ids_minus1");              sei.numSpsIdsMinus1 = val;
1104
1105  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
1106  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
1107  {
1108    sei_read_uvlc( pDecodedMessageOutputStream, val, "active_seq_parameter_set_id[i]");    sei.activeSeqParameterSetId[i] = val;
1109  }
1110}
1111
1112
1113Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
1114{
1115  UInt val;
1116  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1117  sei_read_uvlc( pDecodedMessageOutputStream, val, "decoding_unit_idx");
1118  sei.m_decodingUnitIdx = val;
1119
1120  const TComVUI *vui = sps->getVuiParameters();
1121  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
1122  {
1123    sei_read_code( pDecodedMessageOutputStream, ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay_increment");
1124    sei.m_duSptCpbRemovalDelay = val;
1125  }
1126  else
1127  {
1128    sei.m_duSptCpbRemovalDelay = 0;
1129  }
1130  sei_read_flag( pDecodedMessageOutputStream, val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = (val != 0);
1131  if(sei.m_dpbOutputDuDelayPresentFlag)
1132  {
1133    sei_read_code( pDecodedMessageOutputStream, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
1134    sei.m_picSptDpbOutputDuDelay = val;
1135  }
1136}
1137
1138
1139Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1140{
1141  UInt val;
1142  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1143  sei_read_code( pDecodedMessageOutputStream, 8, val, "temporal_sub_layer_zero_idx" );  sei.tl0Idx = val;
1144  sei_read_code( pDecodedMessageOutputStream, 8, val, "irap_pic_id" );  sei.rapIdx = val;
1145}
1146
1147
1148Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1149{
1150  UInt bytesRead = 0;
1151  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1152
1153  UInt val;
1154  sei_read_code( pDecodedMessageOutputStream, 8, val, "hash_type");
1155  sei.method = static_cast<HashType>(val); bytesRead++;
1156
1157  const TChar *traceString="\0";
1158  switch (sei.method)
1159  {
1160    case HASHTYPE_MD5: traceString="picture_md5"; break;
1161    case HASHTYPE_CRC: traceString="picture_crc"; break;
1162    case HASHTYPE_CHECKSUM: traceString="picture_checksum"; break;
1163    default: assert(false); break;
1164  }
1165
1166  if (pDecodedMessageOutputStream)
1167  {
1168    (*pDecodedMessageOutputStream) << "  " << std::setw(55) << traceString << ": " << std::hex << std::setfill('0');
1169  }
1170
1171  sei.m_pictureHash.hash.clear();
1172  for(;bytesRead < payloadSize; bytesRead++)
1173  {
1174    sei_read_code( NULL, 8, val, traceString);
1175    sei.m_pictureHash.hash.push_back((UChar)val);
1176    if (pDecodedMessageOutputStream)
1177    {
1178      (*pDecodedMessageOutputStream) << std::setw(2) << val;
1179    }
1180  }
1181
1182  if (pDecodedMessageOutputStream)
1183  {
1184    (*pDecodedMessageOutputStream) << std::dec << std::setfill(' ') << "\n";
1185  }
1186}
1187
1188#if NH_MV
1189Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
1190#else
1191Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
1192#endif
1193{
1194  UInt uiCode;
1195  SEIMessages seis;
1196  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1197
1198  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
1199  sei_read_flag( pDecodedMessageOutputStream, uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
1200  if (sei.m_nestingOpFlag)
1201  {
1202    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
1203    sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
1204    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
1205    {
1206      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_max_temporal_id_plus1[i]"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
1207      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_op_idx[i]"                  ); sei.m_nestingOpIdx[i] = uiCode;
1208    }
1209  }
1210  else
1211  {
1212    sei_read_flag( pDecodedMessageOutputStream, uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
1213    if (!sei.m_allLayersFlag)
1214    {
1215      sei_read_code( pDecodedMessageOutputStream, 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
1216      sei_read_uvlc( pDecodedMessageOutputStream, uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
1217      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
1218      {
1219        sei_read_code( pDecodedMessageOutputStream, 6,           uiCode,     "nesting_layer_id[i]"      ); sei.m_nestingLayerId[i]   = uiCode;
1220      }
1221    }
1222  }
1223
1224  // byte alignment
1225  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1226  {
1227    UInt code;
1228    sei_read_flag( pDecodedMessageOutputStream, code, "nesting_zero_bit" );
1229  }
1230
1231  // read nested SEI messages
1232  do
1233  {
1234#if NH_MV
1235    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
1236#else
1237    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
1238#endif
1239  } while (m_pcBitstream->getNumBitsLeft() > 8);
1240
1241  if (pDecodedMessageOutputStream)
1242  {
1243    (*pDecodedMessageOutputStream) << "End of scalable nesting SEI message\n";
1244  }
1245}
1246
1247
1248Void SEIReader::xParseSEIRegionRefreshInfo(SEIRegionRefreshInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1249{
1250  UInt val;
1251  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1252  sei_read_flag( pDecodedMessageOutputStream, val, "refreshed_region_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
1253        }
1254
1255
1256Void SEIReader::xParseSEINoDisplay(SEINoDisplay& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1257        {
1258  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1259  sei.m_noDisplay = true;
1260        }
1261
1262
1263Void SEIReader::xParseSEITimeCode(SEITimeCode& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1264{
1265  UInt code;
1266  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1267  sei_read_code( pDecodedMessageOutputStream, 2, code, "num_clock_ts"); sei.numClockTs = code;
1268  for(Int i = 0; i < sei.numClockTs; i++)
1269  {
1270    TComSEITimeSet currentTimeSet;
1271    sei_read_flag( pDecodedMessageOutputStream, code, "clock_time_stamp_flag[i]"); currentTimeSet.clockTimeStampFlag = code;
1272    if(currentTimeSet.clockTimeStampFlag)
1273    {
1274      sei_read_flag( pDecodedMessageOutputStream, code, "nuit_field_based_flag"); currentTimeSet.numUnitFieldBasedFlag = code;
1275      sei_read_code( pDecodedMessageOutputStream, 5, code, "counting_type"); currentTimeSet.countingType = code;
1276      sei_read_flag( pDecodedMessageOutputStream, code, "full_timestamp_flag"); currentTimeSet.fullTimeStampFlag = code;
1277      sei_read_flag( pDecodedMessageOutputStream, code, "discontinuity_flag"); currentTimeSet.discontinuityFlag = code;
1278      sei_read_flag( pDecodedMessageOutputStream, code, "cnt_dropped_flag"); currentTimeSet.cntDroppedFlag = code;
1279      sei_read_code( pDecodedMessageOutputStream, 9, code, "n_frames"); currentTimeSet.numberOfFrames = code;
1280      if(currentTimeSet.fullTimeStampFlag)
1281      {
1282        sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1283        sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1284        sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
1285      }
1286      else
1287      {
1288        sei_read_flag( pDecodedMessageOutputStream, code, "seconds_flag"); currentTimeSet.secondsFlag = code;
1289        if(currentTimeSet.secondsFlag)
1290        {
1291          sei_read_code( pDecodedMessageOutputStream, 6, code, "seconds_value"); currentTimeSet.secondsValue = code;
1292          sei_read_flag( pDecodedMessageOutputStream, code, "minutes_flag"); currentTimeSet.minutesFlag = code;
1293          if(currentTimeSet.minutesFlag)
1294          {
1295            sei_read_code( pDecodedMessageOutputStream, 6, code, "minutes_value"); currentTimeSet.minutesValue = code;
1296            sei_read_flag( pDecodedMessageOutputStream, code, "hours_flag"); currentTimeSet.hoursFlag = code;
1297            if(currentTimeSet.hoursFlag)
1298            {
1299              sei_read_code( pDecodedMessageOutputStream, 5, code, "hours_value"); currentTimeSet.hoursValue = code;
1300            }
1301          }
1302        }
1303      }
1304      sei_read_code( pDecodedMessageOutputStream, 5, code, "time_offset_length"); currentTimeSet.timeOffsetLength = code;
1305      if(currentTimeSet.timeOffsetLength > 0)
1306      {
1307        sei_read_code( pDecodedMessageOutputStream, currentTimeSet.timeOffsetLength, code, "time_offset_value");
1308        if((code & (1 << (currentTimeSet.timeOffsetLength-1))) == 0)
1309        {
1310          currentTimeSet.timeOffsetValue = code;
1311        }
1312        else
1313        {
1314          code &= (1<< (currentTimeSet.timeOffsetLength-1)) - 1;
1315          currentTimeSet.timeOffsetValue = ~code + 1;
1316        }
1317      }
1318    }
1319    sei.timeSetArray[i] = currentTimeSet;
1320  }
1321}
1322
1323
1324Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1325{
1326  UInt code;
1327  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1328
1329  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
1330  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
1331
1332  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
1333  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
1334
1335  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
1336  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
1337
1338
1339  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
1340  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
1341
1342  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
1343  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
1344}
1345
1346
1347Void SEIReader::xParseSEISegmentedRectFramePacking(SEISegmentedRectFramePacking& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1348{
1349  UInt val;
1350  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1351  sei_read_flag( pDecodedMessageOutputStream, val,       "segmented_rect_frame_packing_arrangement_cancel_flag" );       sei.m_arrangementCancelFlag            = val;
1352  if( !sei.m_arrangementCancelFlag )
1353  {
1354    sei_read_code( pDecodedMessageOutputStream, 2, val, "segmented_rect_content_interpretation_type" );                sei.m_contentInterpretationType = val;
1355    sei_read_flag( pDecodedMessageOutputStream, val,     "segmented_rect_frame_packing_arrangement_persistence" );                              sei.m_arrangementPersistenceFlag               = val;
1356  }
1357}
1358
1359
1360Void SEIReader::xParseSEITempMotionConstraintsTileSets(SEITempMotionConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1361{
1362  UInt code;
1363  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1364  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);
1365  sei_read_flag( pDecodedMessageOutputStream, code, "each_tile_one_tile_set_flag");                 sei.m_each_tile_one_tile_set_flag                = (code != 0);
1366
1367  if(!sei.m_each_tile_one_tile_set_flag)
1368  {
1369    sei_read_flag( pDecodedMessageOutputStream, code, "limited_tile_set_display_flag");  sei.m_limited_tile_set_display_flag = (code != 0);
1370    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_sets_in_message_minus1");     sei.setNumberOfTileSets(code + 1);
1371
1372    if(sei.getNumberOfTileSets() != 0)
1373    {
1374      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
1375      {
1376        sei_read_uvlc( pDecodedMessageOutputStream, code, "mcts_id");  sei.tileSetData(i).m_mcts_id = code;
1377
1378        if(sei.m_limited_tile_set_display_flag)
1379        {
1380          sei_read_flag( pDecodedMessageOutputStream, code, "display_tile_set_flag");  sei.tileSetData(i).m_display_tile_set_flag = (code != 1);
1381        }
1382
1383        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_tile_rects_in_set_minus1");  sei.tileSetData(i).setNumberOfTileRects(code + 1);
1384
1385        for(Int j=0; j<sei.tileSetData(i).getNumberOfTileRects(); j++)
1386        {
1387          sei_read_uvlc( pDecodedMessageOutputStream, code, "top_left_tile_index");      sei.tileSetData(i).topLeftTileIndex(j)     = code;
1388          sei_read_uvlc( pDecodedMessageOutputStream, code, "bottom_right_tile_index");  sei.tileSetData(i).bottomRightTileIndex(j) = code;
1389        }
1390
1391        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
1392        {
1393          sei_read_flag( pDecodedMessageOutputStream, code, "exact_sample_value_match_flag");   sei.tileSetData(i).m_exact_sample_value_match_flag    = (code != 0);
1394        }
1395        sei_read_flag( pDecodedMessageOutputStream, code, "mcts_tier_level_idc_present_flag");  sei.tileSetData(i).m_mcts_tier_level_idc_present_flag = (code != 0);
1396
1397        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
1398        {
1399          sei_read_flag( pDecodedMessageOutputStream, code,    "mcts_tier_flag"); sei.tileSetData(i).m_mcts_tier_flag = (code != 0);
1400          sei_read_code( pDecodedMessageOutputStream, 8, code, "mcts_level_idc"); sei.tileSetData(i).m_mcts_level_idc =  code;
1401        }
1402      }
1403    }
1404  }
1405  else
1406  {
1407    sei_read_flag( pDecodedMessageOutputStream, code, "max_mcs_tier_level_idc_present_flag");  sei.m_max_mcs_tier_level_idc_present_flag = code;
1408    if(sei.m_max_mcs_tier_level_idc_present_flag)
1409    {
1410      sei_read_flag( pDecodedMessageOutputStream, code, "max_mcts_tier_flag");  sei.m_max_mcts_tier_flag = code;
1411      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_mcts_level_idc"); sei.m_max_mcts_level_idc = code;
1412    }
1413  }
1414}
1415
1416
1417Void SEIReader::xParseSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1418{
1419  UInt uiCode;
1420  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1421
1422  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "ver_chroma_filter_idc"); sei.m_verChromaFilterIdc = uiCode;
1423  sei_read_code( pDecodedMessageOutputStream, 8, uiCode, "hor_chroma_filter_idc"); sei.m_horChromaFilterIdc = uiCode;
1424  sei_read_flag( pDecodedMessageOutputStream, uiCode, "ver_filtering_field_processing_flag"); sei.m_verFilteringFieldProcessingFlag = uiCode;
1425  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
1426  {
1427    sei_read_uvlc( pDecodedMessageOutputStream, uiCode, "target_format_idc"); sei.m_targetFormatIdc = uiCode;
1428    if(sei.m_verChromaFilterIdc == 1)
1429    {
1430      UInt numVerticalFilters;
1431      sei_read_uvlc( pDecodedMessageOutputStream, numVerticalFilters, "num_vertical_filters"); sei.m_verFilterCoeff.resize(numVerticalFilters);
1432      if(numVerticalFilters > 0)
1433      {
1434        for(Int i = 0; i < numVerticalFilters; i++)
1435        {
1436          UInt verTapLengthMinus1;
1437          sei_read_uvlc( pDecodedMessageOutputStream, verTapLengthMinus1, "ver_tap_length_minus_1"); sei.m_verFilterCoeff[i].resize(verTapLengthMinus1+1);
1438          for(Int j = 0; j < (verTapLengthMinus1 + 1); j++)
1439          {
1440            sei_read_svlc( pDecodedMessageOutputStream, sei.m_verFilterCoeff[i][j], "ver_filter_coeff");
1441          }
1442        }
1443      }
1444    }
1445    if(sei.m_horChromaFilterIdc == 1)
1446    {
1447      UInt numHorizontalFilters;
1448      sei_read_uvlc( pDecodedMessageOutputStream, numHorizontalFilters, "num_horizontal_filters"); sei.m_horFilterCoeff.resize(numHorizontalFilters);
1449      if(numHorizontalFilters  > 0)
1450      {
1451        for(Int i = 0; i < numHorizontalFilters; i++)
1452        {
1453          UInt horTapLengthMinus1;
1454          sei_read_uvlc( pDecodedMessageOutputStream, horTapLengthMinus1, "hor_tap_length_minus_1"); sei.m_horFilterCoeff[i].resize(horTapLengthMinus1+1);
1455          for(Int j = 0; j < (horTapLengthMinus1 + 1); j++)
1456          {
1457            sei_read_svlc( pDecodedMessageOutputStream, sei.m_horFilterCoeff[i][j], "hor_filter_coeff");
1458          }
1459        }
1460      }
1461    }
1462  }
1463}
1464
1465Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1466{
1467  Int i;
1468  UInt val;
1469  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1470
1471  sei_read_uvlc( pDecodedMessageOutputStream, val, "knee_function_id" );                   sei.m_kneeId = val;
1472  sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
1473  if ( !sei.m_kneeCancelFlag )
1474  {
1475    sei_read_flag( pDecodedMessageOutputStream, val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
1476    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
1477    sei_read_code( pDecodedMessageOutputStream, 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
1478    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
1479    sei_read_code( pDecodedMessageOutputStream, 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
1480    sei_read_uvlc( pDecodedMessageOutputStream, val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
1481    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
1482    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1483    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
1484    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
1485    {
1486      sei_read_code( pDecodedMessageOutputStream, 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
1487      sei_read_code( pDecodedMessageOutputStream, 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
1488    }
1489  }
1490}
1491
1492Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1493{
1494  UInt  uiVal;
1495  Int   iVal;
1496  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1497
1498  sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
1499  sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
1500  if( !sei.m_colourRemapCancelFlag ) 
1501  {
1502    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
1503    sei_read_flag( pDecodedMessageOutputStream, uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
1504    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
1505    {
1506      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );            sei.m_colourRemapFullRangeFlag = uiVal;
1507      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                  sei.m_colourRemapPrimaries = uiVal;
1508      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );          sei.m_colourRemapTransferFunction = uiVal;
1509      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );        sei.m_colourRemapMatrixCoefficients = uiVal;
1510    }
1511    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" );              sei.m_colourRemapInputBitDepth = uiVal;
1512    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" );                    sei.m_colourRemapBitDepth = uiVal;
1513 
1514    for( Int c=0 ; c<3 ; c++ )
1515    {
1516      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
1517      sei.m_preLut[c].resize(sei.m_preLutNumValMinus1[c]+1);
1518      if( uiVal> 0 )
1519      {
1520        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
1521        {
1522          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLut[c][i].codedValue  = uiVal;
1523          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLut[c][i].targetValue = uiVal;
1524        }
1525      }
1526      else // pre_lut_num_val_minus1[c] == 0
1527      {
1528        sei.m_preLut[c][0].codedValue  = 0;
1529        sei.m_preLut[c][0].targetValue = 0;
1530        sei.m_preLut[c][1].codedValue  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
1531        sei.m_preLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1 ;
1532      }
1533    }
1534
1535    sei_read_flag( pDecodedMessageOutputStream, uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
1536    if( sei.m_colourRemapMatrixPresentFlag )
1537    {
1538      sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
1539      for ( Int c=0 ; c<3 ; c++ )
1540      {
1541        for ( Int i=0 ; i<3 ; i++ )
1542        {
1543          sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
1544        }
1545      }
1546    }
1547    else // setting default matrix (I3)
1548    {
1549      sei.m_log2MatrixDenom = 10;
1550      for ( Int c=0 ; c<3 ; c++ )
1551      {
1552        for ( Int i=0 ; i<3 ; i++ )
1553        {
1554          sei.m_colourRemapCoeffs[c][i] = (c==i) << sei.m_log2MatrixDenom;
1555        }
1556      }
1557    }
1558    for( Int c=0 ; c<3 ; c++ )
1559    {
1560      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
1561      sei.m_postLut[c].resize(sei.m_postLutNumValMinus1[c]+1);
1562      if( uiVal > 0 )
1563      {
1564        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
1565        {
1566          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLut[c][i].codedValue = uiVal;
1567          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLut[c][i].targetValue = uiVal;
1568        }
1569      }
1570      else
1571      {
1572        sei.m_postLut[c][0].codedValue  = 0;
1573        sei.m_postLut[c][0].targetValue = 0;
1574        sei.m_postLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1;
1575        sei.m_postLut[c][1].codedValue  = (1 << sei.m_colourRemapBitDepth) - 1;
1576      }
1577    }
1578  }
1579}
1580
1581Void SEIReader::xParseSEIDeinterlaceFieldIdentification( SEIDeinterlaceFieldIdentification& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
1582{
1583  UInt code;
1584  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1585
1586  sei_read_flag(pDecodedMessageOutputStream, code, "deinterlaced_picture_source_parity_flag"); sei.m_deinterlacedPictureSourceParityFlag = code!=0;
1587}
1588
1589
1590Void SEIReader::xParseSEIContentLightLevelInfo( SEIContentLightLevelInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
1591{
1592  UInt code;
1593  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1594
1595  sei_read_code(pDecodedMessageOutputStream, 16, code, "max_content_light_level");     sei.m_maxContentLightLevel    = code;
1596  sei_read_code(pDecodedMessageOutputStream, 16, code, "max_pic_average_light_level"); sei.m_maxPicAverageLightLevel = code;
1597}
1598
1599
1600Void SEIReader::xParseSEIDependentRAPIndication( SEIDependentRAPIndication& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
1601{
1602  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1603}
1604
1605
1606Void SEIReader::xParseSEICodedRegionCompletion( SEICodedRegionCompletion& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
1607{
1608  UInt code;
1609  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1610
1611  sei_read_uvlc(pDecodedMessageOutputStream, code, "next_segment_address"); sei.m_nextSegmentAddress= code;
1612  if (code)
1613  {
1614    sei_read_flag(pDecodedMessageOutputStream, code, "independent_slice_segment_flag"); sei.m_independentSliceSegmentFlag = code!=0;
1615  }
1616  else
1617  {
1618    sei.m_independentSliceSegmentFlag=false; // initialise to known value.
1619  }
1620}
1621
1622
1623Void SEIReader::xParseSEIAlternativeTransferCharacteristics(SEIAlternativeTransferCharacteristics& sei, UInt payloadSize, ostream* pDecodedMessageOutputStream)
1624{
1625  UInt code;
1626  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1627
1628  sei_read_code(pDecodedMessageOutputStream, 8, code, "preferred_transfer_characteristics"); sei.m_preferredTransferCharacteristics = code;
1629}
1630
1631
1632Void SEIReader::xParseSEIAmbientViewingEnvironment( SEIAmbientViewingEnvironment& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream )
1633{
1634  UInt code;
1635  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1636
1637  sei_read_code(pDecodedMessageOutputStream, 32, code, "ambient_illuminance"); sei.m_ambientIlluminance= code;
1638  sei_read_code(pDecodedMessageOutputStream, 16, code, "ambient_light_x");     sei.m_ambientLightX     = (UShort)code;
1639  sei_read_code(pDecodedMessageOutputStream, 16, code, "ambient_light_y");     sei.m_ambientLightY     = (UShort)code;
1640}
1641
1642
1643#if NH_MV
1644Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
1645{
1646  UInt code;
1647
1648  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1649  sei_read_code( pDecodedMessageOutputStream, 4, code, "lnp_sei_active_vps_id" ); sei.m_lnpSeiActiveVpsId = code;
1650  assert(vps->getVPSId() == sei.m_lnpSeiActiveVpsId);
1651
1652  sei.m_lnpSeiMaxLayers = vps->getMaxLayersMinus1() + 1;
1653  sei.resizeDimI(sei.m_lnpSeiMaxLayers);
1654  for (Int i = 0; i < sei.m_lnpSeiMaxLayers; i++)
1655  {
1656    sei_read_flag( pDecodedMessageOutputStream, code, "layer_not_present_flag" );
1657    sei.m_layerNotPresentFlag[i] = (code == 1);
1658  }
1659};
1660
1661Void SEIReader::xParseSEIInterLayerConstrainedTileSets(SEIInterLayerConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1662{
1663  UInt code;
1664  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1665
1666  sei_read_flag( pDecodedMessageOutputStream, code, "il_all_tiles_exact_sample_value_match_flag" ); sei.m_ilAllTilesExactSampleValueMatchFlag = (code == 1);
1667  sei_read_flag( pDecodedMessageOutputStream, code, "il_one_tile_per_tile_set_flag"              ); sei.m_ilOneTilePerTileSetFlag             = (code == 1);
1668  if( !sei.m_ilOneTilePerTileSetFlag )
1669  {
1670    sei_read_uvlc( pDecodedMessageOutputStream, code, "il_num_sets_in_message_minus1" ); sei.m_ilNumSetsInMessageMinus1 = code;
1671    if( sei.m_ilNumSetsInMessageMinus1 )
1672    {
1673      sei_read_flag( pDecodedMessageOutputStream, code, "skipped_tile_set_present_flag" ); sei.m_skippedTileSetPresentFlag = (code == 1);
1674    }
1675    Int numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - sei.m_skippedTileSetPresentFlag + 1;
1676
1677    sei.resizeDimI( numSignificantSets );
1678    for( Int i = 0; i < numSignificantSets; i++ )
1679    {
1680      sei_read_uvlc( pDecodedMessageOutputStream, code, "ilcts_id"                        ); sei.m_ilctsId                  [i] = code;
1681      sei_read_uvlc( pDecodedMessageOutputStream, code, "il_num_tile_rects_in_set_minus1" ); sei.m_ilNumTileRectsInSetMinus1[i] = code;
1682
1683      sei.resizeDimJ( i, sei.m_ilNumTileRectsInSetMinus1[ i ] + 1 );
1684      for( Int j = 0; j  <=  sei.m_ilNumTileRectsInSetMinus1[ i ]; j++ )
1685      {
1686        sei_read_uvlc( pDecodedMessageOutputStream, code, "il_top_left_tile_index"     ); sei.m_ilTopLeftTileIndex    [i][j] = code;
1687        sei_read_uvlc( pDecodedMessageOutputStream, code, "il_bottom_right_tile_index" ); sei.m_ilBottomRightTileIndex[i][j] = code;
1688      }
1689      sei_read_code( pDecodedMessageOutputStream, 2, code, "ilc_idc" ); sei.m_ilcIdc[i] = code;
1690      if ( !sei.m_ilAllTilesExactSampleValueMatchFlag )
1691      {
1692        sei_read_flag( pDecodedMessageOutputStream, code, "il_exact_sample_value_match_flag" ); sei.m_ilExactSampleValueMatchFlag[i] = (code == 1);
1693      }
1694    }
1695  }
1696  else
1697  {
1698    sei_read_code( pDecodedMessageOutputStream, 2, code, "all_tiles_ilc_idc" ); sei.m_allTilesIlcIdc = code;
1699  }
1700};
1701
1702#if NH_MV_SEI_TBD
1703Void SEIReader::xParseSEIBspNesting(SEIBspNesting& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1704{
1705  UInt code;
1706  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1707
1708  sei_read_uvlc( pDecodedMessageOutputStream, code, "sei_ols_idx" ); sei.m_seiOlsIdx = code;
1709  sei_read_uvlc( pDecodedMessageOutputStream, code, "sei_partitioning_scheme_idx" ); sei.m_seiPartitioningSchemeIdx = code;
1710  sei_read_uvlc( pDecodedMessageOutputStream, code, "bsp_idx" ); sei.m_bspIdx = code;
1711  while( !ByteaLigned(() ) );
1712  {
1713    sei_read_code( pDecodedMessageOutputStream, *equalto0*/u1, code, "bsp_nesting_zero_bit" ); sei.m_bspNestingZeroBit = code;
1714  }
1715  sei_read_uvlc( pDecodedMessageOutputStream, code, "num_seis_in_bsp_minus1" ); sei.m_numSeisInBspMinus1 = code;
1716  for( Int i = 0; i  <=  NumSeisInBspMinus1( ); i++ )
1717  {
1718    SeiMessage(() );
1719  }
1720};
1721
1722Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1723{
1724  UInt code;
1725  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1726
1727  psIdx = SeiPartitioningSchemeIdx();
1728  if( nalInitialArrivalDelayPresent )
1729  {
1730    for( Int i = 0; i < BspSchedCnt( SeiOlsIdx(), psIdx, MaxTemporalId( 0 ) ); i++ )
1731    {
1732      sei_read_code( pDecodedMessageOutputStream, getNalInitialArrivalDelayLen ), code, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = code;
1733    }
1734  }
1735  if( vclInitialArrivalDelayPresent )
1736  {
1737    for( Int i = 0; i < BspSchedCnt( SeiOlsIdx(), psIdx, MaxTemporalId( 0 ) ); i++ )
1738    {
1739      sei_read_code( pDecodedMessageOutputStream, getVclInitialArrivalDelayLen ), code, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = code;
1740    }
1741  }
1742};
1743#endif
1744
1745Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1746{
1747  UInt code;
1748  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1749
1750  sei_read_code( pDecodedMessageOutputStream, 4, code, "sb_property_active_vps_id" ); sei.m_sbPropertyActiveVpsId = code;
1751  sei_read_uvlc( pDecodedMessageOutputStream, code, "num_additional_sub_streams_minus1" ); sei.m_numAdditionalSubStreamsMinus1 = code;
1752  sei.resizeArrays( );
1753  for( Int i = 0; i  <=  sei.m_numAdditionalSubStreamsMinus1; i++ )
1754  {
1755    sei_read_code( pDecodedMessageOutputStream, 2, code, "sub_bitstream_mode" ); sei.m_subBitstreamMode[i] = code;
1756    sei_read_uvlc( pDecodedMessageOutputStream, code, "ols_idx_to_vps" ); sei.m_olsIdxToVps[i] = code;
1757    sei_read_code( pDecodedMessageOutputStream, 3, code, "highest_sublayer_id" ); sei.m_highestSublayerId[i] = code;
1758    sei_read_code( pDecodedMessageOutputStream, 16, code, "avg_sb_property_bit_rate" ); sei.m_avgSbPropertyBitRate[i] = code;
1759    sei_read_code( pDecodedMessageOutputStream, 16, code, "max_sb_property_bit_rate" ); sei.m_maxSbPropertyBitRate[i] = code;
1760  }
1761};
1762
1763Void SEIReader::xParseSEIAlphaChannelInfo(SEIAlphaChannelInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1764{
1765  UInt code;
1766  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1767
1768  sei_read_flag( pDecodedMessageOutputStream, code, "alpha_channel_cancel_flag" ); sei.m_alphaChannelCancelFlag = (code == 1);
1769  if( !sei.m_alphaChannelCancelFlag )
1770  {
1771    sei_read_code( pDecodedMessageOutputStream, 3, code, "alpha_channel_use_idc" ); sei.m_alphaChannelUseIdc = code;
1772    sei_read_code( pDecodedMessageOutputStream, 3, code, "alpha_channel_bit_depth_minus8" ); sei.m_alphaChannelBitDepthMinus8 = code;
1773    sei_read_code( pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8+9, code, "alpha_transparent_value" ); sei.m_alphaTransparentValue = code;
1774    sei_read_code( pDecodedMessageOutputStream, sei.m_alphaChannelBitDepthMinus8+9, code, "alpha_opaque_value" ); sei.m_alphaOpaqueValue = code;
1775    sei_read_flag( pDecodedMessageOutputStream, code, "alpha_channel_incr_flag" ); sei.m_alphaChannelIncrFlag = (code == 1);
1776    sei_read_flag( pDecodedMessageOutputStream, code, "alpha_channel_clip_flag" ); sei.m_alphaChannelClipFlag = (code == 1);
1777    if( sei.m_alphaChannelClipFlag )
1778    {
1779      sei_read_flag( pDecodedMessageOutputStream, code, "alpha_channel_clip_type_flag" ); sei.m_alphaChannelClipTypeFlag = (code == 1);
1780    }
1781  }
1782};
1783
1784Void SEIReader::xParseSEIOverlayInfo(SEIOverlayInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1785{
1786  UInt code;
1787  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1788
1789  sei_read_flag( pDecodedMessageOutputStream, code, "overlay_info_cancel_flag" ); sei.m_overlayInfoCancelFlag = (code == 1);
1790  if( !sei.m_overlayInfoCancelFlag )
1791  {
1792    sei_read_uvlc( pDecodedMessageOutputStream, code, "overlay_content_aux_id_minus128" );            sei.m_overlayContentAuxIdMinus128 = code;
1793    sei_read_uvlc( pDecodedMessageOutputStream, code, "overlay_label_aux_id_minus128" );              sei.m_overlayLabelAuxIdMinus128 = code;
1794    sei_read_uvlc( pDecodedMessageOutputStream, code, "overlay_alpha_aux_id_minus128" );              sei.m_overlayAlphaAuxIdMinus128 = code;
1795    sei_read_uvlc( pDecodedMessageOutputStream, code, "overlay_element_label_value_length_minus8" );  sei.m_overlayElementLabelValueLengthMinus8 = code;
1796    sei_read_uvlc( pDecodedMessageOutputStream, code, "num_overlays_minus1" );                        sei.m_numOverlaysMinus1 = code;
1797
1798    sei.m_overlayIdx.resize( sei.m_numOverlaysMinus1+1 );
1799    sei.m_languageOverlayPresentFlag.resize( sei.m_numOverlaysMinus1+1 );
1800    sei.m_overlayContentLayerId.resize     ( sei.m_numOverlaysMinus1+1 );
1801    sei.m_overlayLabelPresentFlag.resize   ( sei.m_numOverlaysMinus1+1 );
1802    sei.m_overlayLabelLayerId.resize       ( sei.m_numOverlaysMinus1+1 );
1803    sei.m_overlayAlphaPresentFlag.resize   ( sei.m_numOverlaysMinus1+1 );
1804    sei.m_overlayAlphaLayerId.resize       ( sei.m_numOverlaysMinus1+1 );
1805    sei.m_numOverlayElementsMinus1.resize  ( sei.m_numOverlaysMinus1+1 );
1806    sei.m_overlayElementLabelMin.resize    ( sei.m_numOverlaysMinus1+1 );
1807    sei.m_overlayElementLabelMax.resize    ( sei.m_numOverlaysMinus1+1 );
1808    for( Int i = 0; i  <=  sei.m_numOverlaysMinus1; i++ )
1809    {
1810      sei_read_uvlc( pDecodedMessageOutputStream, code, "overlay_idx" );                    sei.m_overlayIdx[i]                 = code;
1811      sei_read_flag( pDecodedMessageOutputStream, code, "language_overlay_present_flag" );  sei.m_languageOverlayPresentFlag[i] = (code == 1);
1812      sei_read_code( pDecodedMessageOutputStream, 6, code, "overlay_content_layer_id" );    sei.m_overlayContentLayerId[i]      = code;
1813      sei_read_flag( pDecodedMessageOutputStream, code, "overlay_label_present_flag" );     sei.m_overlayLabelPresentFlag[i]    = (code == 1);
1814      if( sei.m_overlayLabelPresentFlag[i] )
1815      {
1816        sei_read_code( pDecodedMessageOutputStream, 6, code, "overlay_label_layer_id" );     sei.m_overlayLabelLayerId[i]       = code;
1817      }
1818      sei_read_flag( pDecodedMessageOutputStream, code, "overlay_alpha_present_flag" );      sei.m_overlayAlphaPresentFlag[i]   = (code == 1);
1819      if( sei.m_overlayAlphaPresentFlag[i] )
1820      {
1821        sei_read_code( pDecodedMessageOutputStream, 6, code, "overlay_alpha_layer_id" );     sei.m_overlayAlphaLayerId[i]       = code;
1822      }
1823      if( sei.m_overlayLabelPresentFlag[i] )
1824      {
1825        sei_read_uvlc( pDecodedMessageOutputStream, code, "num_overlay_elements_minus1" );   sei.m_numOverlayElementsMinus1[i]  = code;
1826        sei.m_overlayElementLabelMin[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1827        sei.m_overlayElementLabelMax[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1828        for( Int j = 0; j  <=  sei.m_numOverlayElementsMinus1[i]; j++ )
1829        {
1830          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, code, "overlay_element_label_min" ); sei.m_overlayElementLabelMin[i][j] = code;
1831          sei_read_code( pDecodedMessageOutputStream, sei.m_overlayElementLabelValueLengthMinus8 + 8, code, "overlay_element_label_max" ); sei.m_overlayElementLabelMax[i][j] = code;
1832        }
1833      }
1834    }
1835
1836    // byte alignment
1837    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1838    {
1839      sei_read_flag( pDecodedMessageOutputStream, code, "overlay_zero_bit" );
1840      assert( code==0 );
1841    }
1842
1843    UChar* sval = new UChar[sei.m_numStringBytesMax];
1844    UInt slen;
1845    sei.m_overlayLanguage   .resize( sei.m_numOverlaysMinus1 + 1 );
1846    sei.m_overlayName       .resize( sei.m_numOverlaysMinus1 + 1 );
1847    sei.m_overlayElementName.resize( sei.m_numOverlaysMinus1 + 1 );
1848    for( Int i = 0; i  <=  sei.m_numOverlaysMinus1; i++ )
1849    {
1850      if( sei.m_languageOverlayPresentFlag[i] )
1851      {
1852        sei_read_string(pDecodedMessageOutputStream, sei.m_numStringBytesMax, sval, slen, "overlay_language");
1853        sei.m_overlayLanguage[i] = std::string((const char*) sval);
1854      }
1855      sei_read_string(pDecodedMessageOutputStream, sei.m_numStringBytesMax, sval, slen, "overlay_name");
1856      sei.m_overlayName[i] = std::string((const char*) sval);
1857      if( sei.m_overlayLabelPresentFlag[i] )
1858      {
1859        sei.m_overlayElementName[i].resize( sei.m_numOverlayElementsMinus1[i]+1 );
1860        for( Int j = 0; j  <=  sei.m_numOverlayElementsMinus1[i]; j++ )
1861        {
1862          sei_read_string(pDecodedMessageOutputStream, sei.m_numStringBytesMax, sval, slen, "overlay_element_name");
1863          sei.m_overlayElementName[i][j] = std::string((const char*) sval);
1864        }
1865      }
1866    }
1867    delete [] sval;
1868    sei_read_flag( pDecodedMessageOutputStream, code, "overlay_info_persistence_flag" ); sei.m_overlayInfoPersistenceFlag = (code == 1);
1869  }
1870};
1871
1872Void SEIReader::xParseSEITemporalMvPredictionConstraints(SEITemporalMvPredictionConstraints& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1873{
1874  UInt code;
1875  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1876
1877  sei_read_flag( pDecodedMessageOutputStream, code, "prev_pics_not_used_flag"     ); sei.m_prevPicsNotUsedFlag    = (code == 1);
1878  sei_read_flag( pDecodedMessageOutputStream, code, "no_intra_layer_col_pic_flag" ); sei.m_noIntraLayerColPicFlag = (code == 1);
1879};
1880
1881#if NH_MV_SEI_TBD
1882Void SEIReader::xParseSEIFrameFieldInfo(SEIFrameFieldInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1883{
1884  UInt code;
1885  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1886
1887  sei_read_code( pDecodedMessageOutputStream, 4, code, "ffinfo_pic_struct" ); sei.m_ffinfoPicStruct = code;
1888  sei_read_code( pDecodedMessageOutputStream, 2, code, "ffinfo_source_scan_type" ); sei.m_ffinfoSourceScanType = code;
1889  sei_read_flag( pDecodedMessageOutputStream, code, "ffinfo_duplicate_flag" ); sei.m_ffinfoDuplicateFlag = (code == 1);
1890};
1891#endif
1892
1893Void SEIReader::xParseSEIThreeDimensionalReferenceDisplaysInfo(SEIThreeDimensionalReferenceDisplaysInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1894{
1895  UInt code;
1896  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1897
1898  sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_ref_display_width" ); sei.m_precRefDisplayWidth = code;
1899  sei_read_flag( pDecodedMessageOutputStream, code, "ref_viewing_distance_flag" ); sei.m_refViewingDistanceFlag = (code == 1);
1900  if( sei.m_refViewingDistanceFlag )
1901  {
1902    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_ref_viewing_dist" ); sei.m_precRefViewingDist = code;
1903  }
1904  sei_read_uvlc( pDecodedMessageOutputStream, code, "num_ref_displays_minus1" ); sei.m_numRefDisplaysMinus1 = code;
1905  sei.resizeArrays( );
1906  for( Int i = 0; i  <=  sei.getNumRefDisplaysMinus1( ); i++ )
1907  {
1908    sei_read_uvlc( pDecodedMessageOutputStream, code, "left_view_id" ); sei.m_leftViewId[i] = code;
1909    sei_read_uvlc( pDecodedMessageOutputStream, code, "right_view_id" ); sei.m_rightViewId[i] = code;
1910    sei_read_code( pDecodedMessageOutputStream, 6, code, "exponent_ref_display_width" ); sei.m_exponentRefDisplayWidth[i] = code;
1911    sei_read_code( pDecodedMessageOutputStream, sei.getMantissaReferenceDisplayWidthLen(i), code, "mantissa_ref_display_width" ); sei.m_mantissaRefDisplayWidth[i] =  code      ;
1912    if( sei.m_refViewingDistanceFlag )
1913    {
1914      sei_read_code( pDecodedMessageOutputStream, 6, code, "exponent_ref_viewing_distance" ); sei.m_exponentRefViewingDistance[i] = code;
1915      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaReferenceViewingDistanceLen(i), code, "mantissa_ref_viewing_distance" ); sei.m_mantissaRefViewingDistance[i] = code;
1916    }
1917    sei_read_flag( pDecodedMessageOutputStream, code, "additional_shift_present_flag" ); sei.m_additionalShiftPresentFlag[i] = (code == 1);
1918    if( sei.m_additionalShiftPresentFlag[i] )
1919    {
1920      sei_read_code( pDecodedMessageOutputStream, 10, code, "num_sample_shift_plus512" ); sei.m_numSampleShiftPlus512[i] = code;
1921    }
1922  }
1923  sei_read_flag( pDecodedMessageOutputStream, code, "three_dimensional_reference_displays_extension_flag" ); sei.m_threeDimensionalReferenceDisplaysExtensionFlag = (code == 1);
1924};
1925
1926Void SEIReader::xParseSEIDepthRepInfoElement(double& f,std::ostream *pDecodedMessageOutputStream)
1927{
1928    UInt val;
1929    UInt x_sign,x_mantissa_len,x_mantissa;
1930    Int x_exp;
1931
1932    sei_read_flag(pDecodedMessageOutputStream,     val,"da_sign_flag");  x_sign = val ? 1 : 0 ;
1933    sei_read_code(pDecodedMessageOutputStream,  7, val, "da_exponent" );         x_exp = val-31;
1934    sei_read_code(pDecodedMessageOutputStream,  5, val, "da_mantissa_len_minus1" );         x_mantissa_len = val+1;
1935    sei_read_code(pDecodedMessageOutputStream,  x_mantissa_len, val, "da_mantissa" );         x_mantissa = val;
1936    if (x_mantissa_len>=16)
1937    {
1938        f =1.0 +  (x_mantissa*1.0)/(1u<<(x_mantissa_len-16))/(256.0*256.0 );
1939    }else
1940    {
1941        f =1.0 +  (x_mantissa*1.0)/(1u<<x_mantissa_len);
1942    }
1943    double m=1.0;
1944    int i;
1945    if (x_exp<0)
1946    {
1947        for(i=0;i<-x_exp;i++)
1948            m = m * 2;
1949
1950        f = f/m;
1951    }
1952    else
1953    {
1954        for(i=0;i<x_exp;i++)
1955            m = m * 2;
1956
1957        f= f * m;
1958    }
1959    if (x_sign==1)
1960    {
1961        f= -f;
1962    }
1963};
1964
1965Void SEIReader::xParseSEIDepthRepresentationInfo(SEIDepthRepresentationInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
1966{
1967    UInt code;
1968    double zNear,zFar,dMin,dMax;
1969    bool zNearFlag,zFarFlag,dMinFlag,dMaxFlag;
1970    int depth_representation_type,disparityRefViewId,depthNonlinearRepresentationNumMinus1;
1971    std::vector<int> DepthNonlinearRepresentationModel;
1972
1973    sei.clear();
1974
1975    output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
1976
1977    sei_read_flag( pDecodedMessageOutputStream, code, "z_near_flag" );    zNearFlag  = (code == 1);
1978    sei_read_flag( pDecodedMessageOutputStream, code, "z_far_flag" );     zFarFlag = (code == 1);
1979    sei_read_flag( pDecodedMessageOutputStream, code, "d_min_flag" );     dMinFlag = (code == 1);
1980    sei_read_flag( pDecodedMessageOutputStream, code, "d_max_flag" );     dMaxFlag = (code == 1);
1981    sei_read_uvlc( pDecodedMessageOutputStream, code, "depth_representation_type" ); depth_representation_type = code;
1982
1983    sei.m_zNearFlag.push_back(zNearFlag);
1984    sei.m_zFarFlag.push_back(zFarFlag);
1985    sei.m_dMinFlag.push_back(dMinFlag);
1986    sei.m_dMaxFlag.push_back(dMaxFlag);
1987
1988    sei.m_depthRepresentationType.push_back(IntAry1d(1,depth_representation_type));
1989
1990    if( dMinFlag  ||  dMaxFlag )
1991    {
1992        sei_read_uvlc( pDecodedMessageOutputStream, code, "disparity_ref_view_id" ); disparityRefViewId = code;
1993        sei.m_disparityRefViewId.push_back(IntAry1d(1,disparityRefViewId));
1994    }
1995    if( zNearFlag )
1996    {
1997        xParseSEIDepthRepInfoElement(zNear , pDecodedMessageOutputStream);
1998        sei.m_zNear.push_back(std::vector<double>(1,zNear));
1999    }
2000    if( zFarFlag )
2001    {
2002        xParseSEIDepthRepInfoElement(zFar , pDecodedMessageOutputStream);
2003        sei.m_zFar.push_back(std::vector<double>(1,zFar));
2004    }
2005    if( dMinFlag )
2006    {
2007        xParseSEIDepthRepInfoElement(dMin , pDecodedMessageOutputStream);
2008        sei.m_dMin.push_back(std::vector<double>(1,dMin));
2009    }
2010    if( dMaxFlag )
2011    {
2012        xParseSEIDepthRepInfoElement(dMax , pDecodedMessageOutputStream);
2013        sei.m_dMax.push_back(std::vector<double>(1,dMax));
2014    }
2015    if( depth_representation_type  ==  3 )
2016    {
2017        sei_read_uvlc( pDecodedMessageOutputStream, code, "depth_nonlinear_representation_num_minus1" ); depthNonlinearRepresentationNumMinus1 = code;
2018        sei.m_depthNonlinearRepresentationNumMinus1.push_back(IntAry1d(1,depthNonlinearRepresentationNumMinus1));
2019        for( Int i = 1; i  <=  depthNonlinearRepresentationNumMinus1 + 1; i++ )
2020        {
2021            sei_read_uvlc(pDecodedMessageOutputStream,code,"DepthNonlinearRepresentationModel" ) ;
2022            DepthNonlinearRepresentationModel.push_back(code);
2023        }
2024
2025        sei.m_depth_nonlinear_representation_model.push_back(DepthNonlinearRepresentationModel);
2026    }
2027}
2028
2029Void SEIReader::xParseSEIMultiviewSceneInfo(SEIMultiviewSceneInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
2030{
2031  UInt  code;
2032  Int  sCode;
2033  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
2034
2035  sei_read_svlc( pDecodedMessageOutputStream, sCode, "min_disparity" )      ; sei.m_minDisparity      = sCode;
2036  sei_read_uvlc( pDecodedMessageOutputStream, code , "max_disparity_range" ); sei.m_maxDisparityRange = code;
2037};
2038
2039Void SEIReader::xParseSEIMultiviewAcquisitionInfo(SEIMultiviewAcquisitionInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
2040{
2041  UInt code;
2042  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
2043
2044  sei.resizeArrays( );
2045  sei_read_flag( pDecodedMessageOutputStream, code, "intrinsic_param_flag" ); sei.m_intrinsicParamFlag = (code == 1);
2046  sei_read_flag( pDecodedMessageOutputStream, code, "extrinsic_param_flag" ); sei.m_extrinsicParamFlag = (code == 1);
2047  if( sei.m_intrinsicParamFlag )
2048  {
2049    sei_read_flag( pDecodedMessageOutputStream, code, "intrinsic_params_equal_flag" ); sei.m_intrinsicParamsEqualFlag = (code == 1);
2050    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_focal_length"           ); sei.m_precFocalLength          =  code      ;
2051    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_principal_point"        ); sei.m_precPrincipalPoint       =  code      ;
2052    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_skew_factor"            ); sei.m_precSkewFactor           =  code      ;
2053
2054    for( Int i = 0; i  <=  ( sei.m_intrinsicParamsEqualFlag ? 0 : sei.getNumViewsMinus1() ); i++ )
2055    {
2056      sei_read_flag( pDecodedMessageOutputStream,                                         code, "sign_focal_length_x"        ); sei.m_signFocalLengthX       [i] = (code == 1);
2057      sei_read_code( pDecodedMessageOutputStream, 6,                                      code, "exponent_focal_length_x"    ); sei.m_exponentFocalLengthX   [i] =  code      ;
2058      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaFocalLengthXLen   ( i ), code, "mantissa_focal_length_x"    ); sei.m_mantissaFocalLengthX   [i] =  code      ;
2059      sei_read_flag( pDecodedMessageOutputStream,                                         code, "sign_focal_length_y"        ); sei.m_signFocalLengthY       [i] = (code == 1);
2060      sei_read_code( pDecodedMessageOutputStream, 6,                                      code, "exponent_focal_length_y"    ); sei.m_exponentFocalLengthY   [i] =  code      ;
2061      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaFocalLengthYLen   ( i ), code, "mantissa_focal_length_y"    ); sei.m_mantissaFocalLengthY   [i] =  code      ;
2062      sei_read_flag( pDecodedMessageOutputStream,                                         code, "sign_principal_point_x"     ); sei.m_signPrincipalPointX    [i] = (code == 1);
2063      sei_read_code( pDecodedMessageOutputStream, 6,                                      code, "exponent_principal_point_x" ); sei.m_exponentPrincipalPointX[i] =  code      ;
2064      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaPrincipalPointXLen( i ), code, "mantissa_principal_point_x" ); sei.m_mantissaPrincipalPointX[i] =  code      ;
2065      sei_read_flag( pDecodedMessageOutputStream,                                         code, "sign_principal_point_y"     ); sei.m_signPrincipalPointY    [i] = (code == 1);
2066      sei_read_code( pDecodedMessageOutputStream, 6,                                      code, "exponent_principal_point_y" ); sei.m_exponentPrincipalPointY[i] =  code      ;
2067      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaPrincipalPointYLen( i ), code, "mantissa_principal_point_y" ); sei.m_mantissaPrincipalPointY[i] =  code      ;
2068      sei_read_flag( pDecodedMessageOutputStream,                                         code, "sign_skew_factor"           ); sei.m_signSkewFactor         [i] = (code == 1);
2069      sei_read_code( pDecodedMessageOutputStream, 6,                                      code, "exponent_skew_factor"       ); sei.m_exponentSkewFactor     [i] =  code      ;
2070      sei_read_code( pDecodedMessageOutputStream, sei.getMantissaSkewFactorLen     ( i ), code, "mantissa_skew_factor"       ); sei.m_mantissaSkewFactor     [i] =  code      ;
2071    }
2072  }
2073  if( sei.m_extrinsicParamFlag )
2074  {
2075    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_rotation_param"    ); sei.m_precRotationParam    = code;
2076    sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_translation_param" ); sei.m_precTranslationParam = code;
2077
2078    for( Int i = 0; i  <=  sei.getNumViewsMinus1(); i++ )
2079    {
2080      for( Int j = 0; j  <=  2; j++ )  /* row */
2081      {
2082        for( Int k = 0; k  <=  2; k++ )  /* column */
2083        {
2084          sei_read_flag( pDecodedMessageOutputStream,                                 code, "sign_r"     ); sei.m_signR    [i][j][k] = (code == 1);
2085          sei_read_code( pDecodedMessageOutputStream, 6,                              code, "exponent_r" ); sei.m_exponentR[i][j][k] =  code      ;
2086          sei_read_code( pDecodedMessageOutputStream, sei.getMantissaRLen( i, j, k ), code, "mantissa_r" ); sei.m_mantissaR[i][j][k] =  code      ;
2087        }
2088        sei_read_flag( pDecodedMessageOutputStream,                              code, "sign_t"     ); sei.m_signT    [i][j] = (code == 1);
2089        sei_read_code( pDecodedMessageOutputStream, 6,                           code, "exponent_t" ); sei.m_exponentT[i][j] =  code      ;
2090        sei_read_code( pDecodedMessageOutputStream, sei.getMantissaTLen( i, j ), code, "mantissa_t" ); sei.m_mantissaT[i][j] =  code      ;
2091      }
2092    }
2093  }
2094};
2095
2096
2097
2098Void SEIReader::xParseSEIMultiviewViewPosition(SEIMultiviewViewPosition& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
2099{
2100  UInt code;
2101  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
2102
2103  sei_read_uvlc( pDecodedMessageOutputStream, code, "num_views_minus1" ); sei.m_numViewsMinus1 = code;
2104  sei.m_viewPosition.resize( sei.m_numViewsMinus1 + 1 );
2105  for( Int i = 0; i  <=  sei.m_numViewsMinus1; i++ )
2106  {
2107    sei_read_uvlc( pDecodedMessageOutputStream, code, "view_position" ); sei.m_viewPosition[i] = code;
2108  }
2109};
2110
2111#if NH_3D
2112Void SEIReader::xParseSEIAlternativeDepthInfo(SEIAlternativeDepthInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
2113{
2114  UInt code;
2115  Int scode;
2116  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
2117
2118  sei.resizeArrays( );
2119  sei_read_flag( pDecodedMessageOutputStream, code, "alternative_depth_info_cancel_flag" ); sei.m_alternativeDepthInfoCancelFlag = (code == 1);
2120  if( sei.m_alternativeDepthInfoCancelFlag  ==  0 )
2121  {
2122    sei_read_code( pDecodedMessageOutputStream, 2, code, "depth_type" ); sei.m_depthType = code;
2123    if( sei.m_depthType  ==  0 )
2124    {
2125      sei_read_uvlc( pDecodedMessageOutputStream, code, "num_constituent_views_gvd_minus1" ); sei.m_numConstituentViewsGvdMinus1 = code;
2126      sei_read_flag( pDecodedMessageOutputStream, code, "depth_present_gvd_flag" ); sei.m_depthPresentGvdFlag = (code == 1);
2127      sei_read_flag( pDecodedMessageOutputStream, code, "z_gvd_flag" ); sei.m_zGvdFlag = (code == 1);
2128      sei_read_flag( pDecodedMessageOutputStream, code, "intrinsic_param_gvd_flag" ); sei.m_intrinsicParamGvdFlag = (code == 1);
2129      sei_read_flag( pDecodedMessageOutputStream, code, "rotation_gvd_flag" ); sei.m_rotationGvdFlag = (code == 1);
2130      sei_read_flag( pDecodedMessageOutputStream, code, "translation_gvd_flag" ); sei.m_translationGvdFlag = (code == 1);
2131      if( sei.m_zGvdFlag )
2132      {
2133        for( Int i = 0, j = 0; j <=  sei.m_numConstituentViewsGvdMinus1 + 1; j++ )
2134        {
2135          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_z_near_flag" ); sei.m_signGvdZNearFlag[i][j] = (code == 1);
2136          sei_read_code( pDecodedMessageOutputStream, 7, code, "exp_gvd_z_near" ); sei.m_expGvdZNear[i][j] = code;
2137          sei_read_code( pDecodedMessageOutputStream, 5, code, "man_len_gvd_z_near_minus1" ); sei.m_manLenGvdZNearMinus1[i][j] = code;
2138          sei_read_code( pDecodedMessageOutputStream, sei.m_manLenGvdZNearMinus1[i][j]+1, code, "man_gvd_z_near" ); sei.m_manGvdZNear[i][j] = code;
2139          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_z_far_flag" ); sei.m_signGvdZFarFlag[i][j] = (code == 1);
2140          sei_read_code( pDecodedMessageOutputStream, 7, code, "exp_gvd_z_far" ); sei.m_expGvdZFar[i][j] = code;
2141          sei_read_code( pDecodedMessageOutputStream, 5, code, "man_len_gvd_z_far_minus1" ); sei.m_manLenGvdZFarMinus1[i][j] = code;
2142          sei_read_code( pDecodedMessageOutputStream, sei.m_manLenGvdZFarMinus1[i][j]+1, code, "man_gvd_z_far" ); sei.m_manGvdZFar[i][j] = code;
2143        }
2144      }
2145      if( sei.m_intrinsicParamGvdFlag )
2146      {
2147        sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_gvd_focal_length" ); sei.m_precGvdFocalLength = code;
2148        sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_gvd_principal_point" ); sei.m_precGvdPrincipalPoint = code;
2149      }
2150      if( sei.m_rotationGvdFlag )
2151      {
2152        sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_gvd_rotation_param" ); sei.m_precGvdRotationParam = code;
2153      }
2154      if( sei.m_translationGvdFlag )
2155      {
2156        sei_read_uvlc( pDecodedMessageOutputStream, code, "prec_gvd_translation_param" ); sei.m_precGvdTranslationParam = code;
2157      }
2158      for( Int i = 0, j = 0; j <= sei.m_numConstituentViewsGvdMinus1 + 1; j++ )
2159      {
2160        if( sei.m_intrinsicParamGvdFlag )
2161        {
2162          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_focal_length_x" ); sei.m_signGvdFocalLengthX[i][j] = (code == 1);
2163          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_focal_length_x" ); sei.m_expGvdFocalLengthX[i][j] = code;
2164          sei_read_code( pDecodedMessageOutputStream, sei.getManGvdFocalLengthXLen(i,j), code, "man_gvd_focal_length_x" ); sei.m_manGvdFocalLengthX[i][j] = code;
2165          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_focal_length_y" ); sei.m_signGvdFocalLengthY[i][j] = (code == 1);
2166          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_focal_length_y" ); sei.m_expGvdFocalLengthY[i][j] = code;
2167          sei_read_code( pDecodedMessageOutputStream, sei.getManGvdFocalLengthYLen(i,j), code, "man_gvd_focal_length_y" ); sei.m_manGvdFocalLengthY[i][j] = code;
2168          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_principal_point_x" ); sei.m_signGvdPrincipalPointX[i][j] = (code == 1);
2169          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_principal_point_x" ); sei.m_expGvdPrincipalPointX[i][j] = code;
2170          sei_read_code( pDecodedMessageOutputStream, sei.getManGvdPrincipalPointXLen(i,j), code, "man_gvd_principal_point_x" ); sei.m_manGvdPrincipalPointX[i][j] = code;
2171          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_principal_point_y" ); sei.m_signGvdPrincipalPointY[i][j] = (code == 1);
2172          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_principal_point_y" ); sei.m_expGvdPrincipalPointY[i][j] = code;
2173          sei_read_code( pDecodedMessageOutputStream, sei.getManGvdPrincipalPointYLen(i,j), code, "man_gvd_principal_point_y" ); sei.m_manGvdPrincipalPointY[i][j] = code;
2174        }
2175        if( sei.m_rotationGvdFlag )
2176        {
2177          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r00" ); sei.m_signGvdR00[i][j] = (code == 1);
2178          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r00" ); sei.m_expGvdR00[i][j] = code;
2179          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r00" ); sei.m_manGvdR00[i][j] = code;
2180          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r01" ); sei.m_signGvdR01[i][j] = (code == 1);
2181          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r01" ); sei.m_expGvdR01[i][j] = code;
2182          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r01" ); sei.m_manGvdR01[i][j] = code;
2183          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r02" ); sei.m_signGvdR02[i][j] = (code == 1);
2184          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r02" ); sei.m_expGvdR02[i][j] = code;
2185          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r02" ); sei.m_manGvdR02[i][j] = code;
2186          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r10" ); sei.m_signGvdR10[i][j] = (code == 1);
2187          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r10" ); sei.m_expGvdR10[i][j] = code;
2188          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r10" ); sei.m_manGvdR10[i][j] = code;
2189          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r11" ); sei.m_signGvdR11[i][j] = (code == 1);
2190          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r11" ); sei.m_expGvdR11[i][j] = code;
2191          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r11" ); sei.m_manGvdR11[i][j] = code;
2192          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r12" ); sei.m_signGvdR12[i][j] = (code == 1);
2193          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r12" ); sei.m_expGvdR12[i][j] = code;
2194          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r12" ); sei.m_manGvdR12[i][j] = code;
2195          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r20" ); sei.m_signGvdR20[i][j] = (code == 1);
2196          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r20" ); sei.m_expGvdR20[i][j] = code;
2197          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r20" ); sei.m_manGvdR20[i][j] = code;
2198          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r21" ); sei.m_signGvdR21[i][j] = (code == 1);
2199          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r21" ); sei.m_expGvdR21[i][j] = code;
2200          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r21" ); sei.m_manGvdR21[i][j] = code;
2201          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_r22" ); sei.m_signGvdR22[i][j] = (code == 1);
2202          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_r22" ); sei.m_expGvdR22[i][j] = code;
2203          sei_read_code( pDecodedMessageOutputStream, sei.m_precGvdRotationParam, code, "man_gvd_r22" ); sei.m_manGvdR22[i][j] = code;
2204          //sei_read_code( pDecodedMessageOutputStream, sei.getManGvdRLen(i,j,k), code, "man_gvd_r" ); sei.m_manGvdR[i][j] = code;
2205        }
2206        if( sei.m_translationGvdFlag )
2207        {
2208          sei_read_flag( pDecodedMessageOutputStream, code, "sign_gvd_t_x" ); sei.m_signGvdTX[i][j] = (code == 1);
2209          sei_read_code( pDecodedMessageOutputStream, 6, code, "exp_gvd_t_x" ); sei.m_expGvdTX[i][j] = code;
2210          sei_read_code( pDecodedMessageOutputStream, sei.getManGvdTXLen(i,j), code, "man_gvd_t_x" ); sei.m_manGvdTX[i][j] = code;
2211        }
2212      }
2213    }
2214
2215    if( sei.m_depthType  ==  1 )
2216    {
2217      sei_read_svlc( pDecodedMessageOutputStream, scode, "min_offset_x_int" ); sei.m_minOffsetXInt = scode;
2218      sei_read_code( pDecodedMessageOutputStream, 8, code, "min_offset_x_frac" ); sei.m_minOffsetXFrac = code;
2219      sei_read_svlc( pDecodedMessageOutputStream, scode, "max_offset_x_int" ); sei.m_maxOffsetXInt = scode;
2220      sei_read_code( pDecodedMessageOutputStream, 8, code, "max_offset_x_frac" ); sei.m_maxOffsetXFrac = code;
2221      sei_read_flag( pDecodedMessageOutputStream, code, "offset_y_present_flag" ); sei.m_offsetYPresentFlag = (code == 1);
2222      if( sei.m_offsetYPresentFlag )
2223      {
2224        sei_read_svlc( pDecodedMessageOutputStream, scode, "min_offset_y_int" ); sei.m_minOffsetYInt = scode;
2225        sei_read_code( pDecodedMessageOutputStream, 8, code, "min_offset_y_frac" ); sei.m_minOffsetYFrac = code;
2226        sei_read_svlc( pDecodedMessageOutputStream, scode, "max_offset_y_int" ); sei.m_maxOffsetYInt = scode;
2227        sei_read_code( pDecodedMessageOutputStream, 8, code, "max_offset_y_frac" ); sei.m_maxOffsetYFrac = code;
2228      }
2229      sei_read_flag( pDecodedMessageOutputStream, code, "warp_map_size_present_flag" ); sei.m_warpMapSizePresentFlag = (code == 1);
2230      if( sei.m_warpMapSizePresentFlag )
2231      {
2232        sei_read_uvlc( pDecodedMessageOutputStream, code, "warp_map_width_minus2" ); sei.m_warpMapWidthMinus2 = code;
2233        sei_read_uvlc( pDecodedMessageOutputStream, code, "warp_map_height_minus2" ); sei.m_warpMapHeightMinus2 = code;
2234      }
2235    }
2236  }
2237};
2238#endif
2239#endif
2240
2241//! \}
Note: See TracBrowser for help on using the repository browser.