source: SHVCSoftware/trunk/source/Lib/TLibDecoder/SEIread.cpp @ 915

Last change on this file since 915 was 906, checked in by seregin, 10 years ago

merge SHM-dev

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