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

Last change on this file since 444 was 442, checked in by seregin, 11 years ago

reintegrate SHM-3.1-dev branch

  • Property svn:eol-style set to native
File size: 33.1 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2013, 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 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;
95#if M0043_LAYERS_PRESENT_SEI
96  case SEI::LAYERS_PRESENT:
97    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
98    break;
99#endif
100  case SEI::SOP_DESCRIPTION:
101    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
102    break;
103#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
104  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
105    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
106    break;
107#endif
108  case SEI::SCALABLE_NESTING:
109    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
110    break;
111  default:
112    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
113    break;
114  }
115}
116#endif
117
118/**
119 * unmarshal a single SEI message from bitstream bs
120 */
121#if M0043_LAYERS_PRESENT_SEI
122void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
123#else
124void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
125#endif
126{
127  setBitstream(bs);
128
129  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
130  do
131  {
132#if M0043_LAYERS_PRESENT_SEI
133    xReadSEImessage(seis, nalUnitType, vps, sps);
134#else
135    xReadSEImessage(seis, nalUnitType, sps);
136#endif
137    /* SEI messages are an integer number of bytes, something has failed
138    * in the parsing if bitstream not byte-aligned */
139    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
140  } while (m_pcBitstream->getNumBitsLeft() > 8);
141
142  UInt rbspTrailingBits;
143  READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
144  assert(rbspTrailingBits == 0x80);
145}
146
147#if M0043_LAYERS_PRESENT_SEI
148Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
149#else
150Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
151#endif
152{
153#if ENC_DEC_TRACE
154  xTraceSEIHeader();
155#endif
156  Int payloadType = 0;
157  UInt val = 0;
158
159  do
160  {
161    READ_CODE (8, val, "payload_type");
162    payloadType += val;
163  } while (val==0xFF);
164
165  UInt payloadSize = 0;
166  do
167  {
168    READ_CODE (8, val, "payload_size");
169    payloadSize += val;
170  } while (val==0xFF);
171
172#if ENC_DEC_TRACE
173  xTraceSEIMessageType((SEI::PayloadType)payloadType);
174#endif
175
176  /* extract the payload for this single SEI message.
177   * This allows greater safety in erroneous parsing of an SEI message
178   * from affecting subsequent messages.
179   * After parsing the payload, bs needs to be restored as the primary
180   * bitstream.
181   */
182  TComInputBitstream *bs = getBitstream();
183  setBitstream(bs->extractSubstream(payloadSize * 8));
184
185  SEI *sei = NULL;
186
187  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
188  {
189    switch (payloadType)
190    {
191    case SEI::USER_DATA_UNREGISTERED:
192      sei = new SEIuserDataUnregistered;
193      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
194      break;
195    case SEI::ACTIVE_PARAMETER_SETS:
196      sei = new SEIActiveParameterSets; 
197      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); 
198      break; 
199    case SEI::DECODING_UNIT_INFO:
200      if (!sps)
201      {
202        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
203      }
204      else
205      {
206        sei = new SEIDecodingUnitInfo; 
207        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
208      }
209      break; 
210    case SEI::BUFFERING_PERIOD:
211      if (!sps)
212      {
213        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
214      }
215      else
216      {
217        sei = new SEIBufferingPeriod;
218        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
219      }
220      break;
221    case SEI::PICTURE_TIMING:
222      if (!sps)
223      {
224        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
225      }
226      else
227      {
228        sei = new SEIPictureTiming;
229        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
230      }
231      break;
232    case SEI::RECOVERY_POINT:
233      sei = new SEIRecoveryPoint;
234      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
235      break;
236    case SEI::FRAME_PACKING:
237      sei = new SEIFramePacking;
238      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
239      break;
240    case SEI::DISPLAY_ORIENTATION:
241      sei = new SEIDisplayOrientation;
242      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
243      break;
244    case SEI::TEMPORAL_LEVEL0_INDEX:
245      sei = new SEITemporalLevel0Index;
246      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
247      break;
248    case SEI::REGION_REFRESH_INFO:
249      sei = new SEIGradualDecodingRefreshInfo;
250      xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
251      break;
252    case SEI::TONE_MAPPING_INFO:
253      sei = new SEIToneMappingInfo;
254      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
255      break;
256#if M0043_LAYERS_PRESENT_SEI
257    case SEI::LAYERS_PRESENT:
258      if (!vps)
259      {
260        printf ("Warning: Found Layers present SEI message, but no active VPS is available. Ignoring.");
261      }
262      else
263      {
264        sei = new SEILayersPresent;
265        xParseSEILayersPresent((SEILayersPresent&) *sei, payloadSize, vps);
266      }
267      break;
268#endif
269    case SEI::SOP_DESCRIPTION:
270      sei = new SEISOPDescription;
271      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
272      break;
273#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
274    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
275      sei = new SEIInterLayerConstrainedTileSets;
276      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize);
277      break;
278#endif
279    case SEI::SCALABLE_NESTING:
280      sei = new SEIScalableNesting;
281#if M0043_LAYERS_PRESENT_SEI
282      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps);
283#else
284      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
285#endif
286      break;
287    default:
288      for (UInt i = 0; i < payloadSize; i++)
289      {
290        UInt seiByte;
291        READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
292      }
293      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
294    }
295  }
296  else
297  {
298    switch (payloadType)
299    {
300      case SEI::USER_DATA_UNREGISTERED:
301        sei = new SEIuserDataUnregistered;
302        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
303        break;
304      case SEI::DECODED_PICTURE_HASH:
305        sei = new SEIDecodedPictureHash;
306        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
307        break;
308      default:
309        for (UInt i = 0; i < payloadSize; i++)
310        {
311          UInt seiByte;
312          READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
313        }
314        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
315    }
316  }
317  if (sei != NULL)
318  {
319    seis.push_back(sei);
320  }
321
322  /* By definition the underlying bitstream terminates in a byte-aligned manner.
323   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
324   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
325   * 3. Extract the remainingreserved_payload_extension_data bits.
326   *
327   * If there are fewer than 9 bits available, extract them.
328   */
329  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
330  if (payloadBitsRemaining) /* more_data_in_payload() */
331  {
332    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
333    {
334      UInt reservedPayloadExtensionData;
335      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
336    }
337
338    /* 2 */
339    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
340    Int finalPayloadBits = 0;
341    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
342    {
343      continue;
344    }
345
346    /* 3 */
347    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
348    {
349      UInt reservedPayloadExtensionData;
350      READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
351    }
352
353    UInt dummy;
354    READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
355    while (payloadBitsRemaining)
356    {
357      READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
358    }
359  }
360
361  /* restore primary bitstream for sei_message */
362  getBitstream()->deleteFifo();
363  delete getBitstream();
364  setBitstream(bs);
365}
366
367/**
368 * parse bitstream bs and unpack a user_data_unregistered SEI message
369 * of payloasSize bytes into sei.
370 */
371Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
372{
373  assert(payloadSize >= 16);
374  UInt val;
375
376  for (UInt i = 0; i < 16; i++)
377  {
378    READ_CODE (8, val, "uuid_iso_iec_11578");
379    sei.uuid_iso_iec_11578[i] = val;
380  }
381
382  sei.userDataLength = payloadSize - 16;
383  if (!sei.userDataLength)
384  {
385    sei.userData = 0;
386    return;
387  }
388
389  sei.userData = new UChar[sei.userDataLength];
390  for (UInt i = 0; i < sei.userDataLength; i++)
391  {
392    READ_CODE (8, val, "user_data" );
393    sei.userData[i] = val;
394  }
395}
396
397/**
398 * parse bitstream bs and unpack a decoded picture hash SEI message
399 * of payloadSize bytes into sei.
400 */
401Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
402{
403  UInt val;
404  READ_CODE (8, val, "hash_type");
405  sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
406  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
407  {
408    if(SEIDecodedPictureHash::MD5 == sei.method)
409    {
410      for (UInt i = 0; i < 16; i++)
411      {
412        READ_CODE(8, val, "picture_md5");
413        sei.digest[yuvIdx][i] = val;
414      }
415    }
416    else if(SEIDecodedPictureHash::CRC == sei.method)
417    {
418      READ_CODE(16, val, "picture_crc");
419      sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
420      sei.digest[yuvIdx][1] = val & 0xFF;
421    }
422    else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
423    {
424      READ_CODE(32, val, "picture_checksum");
425      sei.digest[yuvIdx][0] = (val>>24) & 0xff;
426      sei.digest[yuvIdx][1] = (val>>16) & 0xff;
427      sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
428      sei.digest[yuvIdx][3] =  val      & 0xff;
429    }
430  }
431}
432Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
433{
434  UInt val; 
435  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
436  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
437  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
438  READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
439
440  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
441  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
442  {
443    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val; 
444  }
445
446  UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 
447 
448  while(uibits--)
449  {
450    READ_FLAG(val, "alignment_bit");
451  }
452}
453
454Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
455{
456  UInt val;
457  READ_UVLC(val, "decoding_unit_idx");
458  sei.m_decodingUnitIdx = val;
459
460  TComVUI *vui = sps->getVuiParameters();
461  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
462  {
463    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
464    sei.m_duSptCpbRemovalDelay = val;
465  }
466  else
467  {
468    sei.m_duSptCpbRemovalDelay = 0;
469  }
470  READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
471  if(sei.m_dpbOutputDuDelayPresentFlag)
472  {
473    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
474    sei.m_picSptDpbOutputDuDelay = val;
475  }
476  xParseByteAlign();
477}
478
479Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
480{
481  Int i, nalOrVcl;
482  UInt code;
483
484  TComVUI *pVUI = sps->getVuiParameters();
485  TComHRD *pHRD = pVUI->getHrdParameters();
486
487  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
488  if( !pHRD->getSubPicCpbParamsPresentFlag() )
489  {
490    READ_FLAG( code, "rap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
491  }
492  //read splicing flag and cpb_removal_delay_delta
493  READ_FLAG( code, "concatenation_flag"); 
494  sei.m_concatenationFlag = code;
495  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
496  sei.m_auCpbRemovalDelayDelta = code + 1;
497  if( sei.m_rapCpbParamsPresentFlag )
498  {
499    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
500    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
501  }
502  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
503  {
504    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
505        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
506    {
507      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
508      {
509        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
510        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
511        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
512        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
513        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
514        {
515          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
516          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
517          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
518          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
519        }
520      }
521    }
522  }
523  xParseByteAlign();
524}
525Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
526{
527  Int i;
528  UInt code;
529
530  TComVUI *vui = sps->getVuiParameters();
531  TComHRD *hrd = vui->getHrdParameters();
532
533  if( vui->getFrameFieldInfoPresentFlag() )
534  {
535    READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
536    READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
537    READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
538  }
539
540  if( hrd->getCpbDpbDelaysPresentFlag())
541  {
542    READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
543    sei.m_auCpbRemovalDelay = code + 1;
544    READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
545    sei.m_picDpbOutputDelay = code;
546
547    if(hrd->getSubPicCpbParamsPresentFlag())
548    {
549      READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
550      sei.m_picDpbOutputDuDelay = code;
551    }
552    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
553    {
554      READ_UVLC( code, "num_decoding_units_minus1");
555      sei.m_numDecodingUnitsMinus1 = code;
556      READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
557      sei.m_duCommonCpbRemovalDelayFlag = code;
558      if( sei.m_duCommonCpbRemovalDelayFlag )
559      {
560        READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
561        sei.m_duCommonCpbRemovalDelayMinus1 = code;
562      }
563      if( sei.m_numNalusInDuMinus1 != NULL )
564      {
565        delete sei.m_numNalusInDuMinus1;
566      }
567      sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
568      if( sei.m_duCpbRemovalDelayMinus1  != NULL )
569      {
570        delete sei.m_duCpbRemovalDelayMinus1;
571      }
572      sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
573
574      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
575      {
576        READ_UVLC( code, "num_nalus_in_du_minus1");
577        sei.m_numNalusInDuMinus1[ i ] = code;
578        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
579        {
580          READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
581          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
582        }
583      }
584    }
585  }
586  xParseByteAlign();
587}
588Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
589{
590  Int  iCode;
591  UInt uiCode;
592  READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
593  READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
594  READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
595  xParseByteAlign();
596}
597Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
598{
599  UInt val;
600  READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
601  READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
602
603  if ( !sei.m_arrangementCancelFlag )
604  {
605    READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
606    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
607    READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
608
609    READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
610    READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
611    READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
612    READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
613    READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
614    READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
615    READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
616
617    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
618    {
619      READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
620      READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
621      READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
622      READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
623    }
624
625    READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
626    READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
627  }
628  READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
629
630  xParseByteAlign();
631}
632
633Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
634{
635  UInt val;
636  READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
637  if( !sei.cancelFlag ) 
638  {
639    READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
640    READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
641    READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
642    READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
643  }
644  xParseByteAlign();
645}
646
647Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
648{
649  UInt val;
650  READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
651  READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
652  xParseByteAlign();
653}
654
655Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
656{
657  UInt val;
658  READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
659  xParseByteAlign();
660}
661
662Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
663{
664  Int i;
665  UInt val;
666  READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
667  READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
668
669  if ( !sei.m_toneMapCancelFlag )
670  {
671    READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val; 
672    READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
673    READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
674    READ_UVLC( val, "model_id" );                          sei.m_modelId = val; 
675    switch(sei.m_modelId)
676    {
677    case 0:
678      {
679        READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
680        READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
681        break;
682      }
683    case 1:
684      {
685        READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
686        READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
687        break;
688      }
689    case 2:
690      {
691        UInt num = 1u << sei.m_targetBitDepth;
692        sei.m_startOfCodedInterval.resize(num+1);
693        for(i = 0; i < num; i++)
694        {
695          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
696          sei.m_startOfCodedInterval[i] = val;
697        }
698        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
699        break;
700      }
701    case 3:
702      {
703        READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
704        sei.m_codedPivotValue.resize(sei.m_numPivots);
705        sei.m_targetPivotValue.resize(sei.m_numPivots);
706        for(i = 0; i < sei.m_numPivots; i++ )
707        {
708          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
709          sei.m_codedPivotValue[i] = val;
710          READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
711          sei.m_targetPivotValue[i] = val;
712        }
713        break;
714      }
715    case 4:
716      {
717        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
718        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
719        {
720          READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
721        }
722        READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
723        READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
724        READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
725        READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
726        READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
727        READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
728        READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
729        READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
730        break;
731      }
732    default:
733      {
734        assert(!"Undefined SEIToneMapModelId");
735        break;
736      }
737    }//switch model id
738  }// if(!sei.m_toneMapCancelFlag)
739
740  xParseByteAlign();
741}
742
743#if M0043_LAYERS_PRESENT_SEI
744Void SEIReader::xParseSEILayersPresent(SEILayersPresent &sei, UInt payloadSize, TComVPS *vps)
745{
746  UInt uiCode;
747  UInt i = 0;
748
749  READ_UVLC( uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
750  assert(vps->getVPSId() == sei.m_activeVpsId);
751  sei.m_vpsMaxLayers = vps->getMaxLayers();
752  for (; i < sei.m_vpsMaxLayers; i++)
753  {
754    READ_FLAG( uiCode,         "layer_present_flag"   ); sei.m_layerPresentFlag[i] = uiCode ? true : false;
755  }
756  for (; i < MAX_LAYERS; i++)
757  {
758    sei.m_layerPresentFlag[i] = false;
759  }
760  xParseByteAlign();
761}
762#endif
763
764Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
765{
766  Int iCode;
767  UInt uiCode;
768
769  READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
770  READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
771  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
772  {
773    READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
774    READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
775    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
776    {
777      READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
778    }
779    if (i > 0)
780    {
781      READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
782    }
783  }
784
785  xParseByteAlign();
786}
787
788#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
789Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize)
790{
791  UInt uiCode;
792
793  READ_FLAG( uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
794  READ_FLAG( uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
795  if( !sei.m_ilOneTilePerTileSetFlag )
796  {
797    READ_UVLC( uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
798    if( sei.m_ilNumSetsInMessageMinus1 )
799    {
800      READ_FLAG( uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
801    }
802    else
803    {
804      sei.m_skippedTileSetPresentFlag = false;
805    }
806    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
807    for( UInt i = 0; i < numSignificantSets; i++ )
808    {
809      READ_UVLC( uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
810      READ_UVLC( uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
811      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
812      {
813        READ_UVLC( uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
814        READ_UVLC( uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
815      }
816      READ_CODE( 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
817      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
818      {
819        READ_FLAG( uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
820      }
821    }
822  }
823  else
824  {
825    READ_CODE( 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
826  }
827
828  xParseByteAlign();
829}
830#endif
831
832#if M0043_LAYERS_PRESENT_SEI
833Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
834#else
835Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
836#endif
837{
838  UInt uiCode;
839  SEIMessages seis;
840
841  READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
842  READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
843  if (sei.m_nestingOpFlag)
844  {
845    READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
846    READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
847    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
848    {
849      READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
850      READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
851    }
852  }
853  else
854  {
855    READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
856    if (!sei.m_allLayersFlag)
857    {
858      READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
859      READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
860      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
861      {
862        READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
863      }
864    }
865  }
866
867  // byte alignment
868  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
869  {
870    UInt code;
871    READ_FLAG( code, "nesting_zero_bit" );
872  }
873
874  sei.m_callerOwnsSEIs = false;
875
876  // read nested SEI messages
877  do {
878#if M0043_LAYERS_PRESENT_SEI
879    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
880#else
881    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
882#endif
883  } while (m_pcBitstream->getNumBitsLeft() > 8);
884
885}
886
887Void SEIReader::xParseByteAlign()
888{
889  UInt code;
890  if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
891  {
892    READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
893  }
894  while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
895  {
896    READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
897  }
898}
899//! \}
Note: See TracBrowser for help on using the repository browser.