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

Last change on this file since 964 was 964, checked in by tech, 10 years ago
  • Merged 11.0-dev0@963. (Update to HM 14.0 + MV-HEVC Draft 8 HLS)
  • Added coding results.
  • Changed version number.
  • Property svn:eol-style set to native
File size: 30.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/**
35 \file     SEIread.cpp
36 \brief    reading 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  case SEI::SOP_DESCRIPTION:
96    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
97    break;
98  case SEI::SCALABLE_NESTING:
99    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
100    break;
101#if H_MV
102  case SEI::SUB_BITSTREAM_PROPERTY:
103    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
104    break;
105#endif
106  default:
107    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
108    break;
109  }
110}
111#endif
112
113/**
114 * unmarshal a single SEI message from bitstream bs
115 */
116void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
117{
118  setBitstream(bs);
119
120  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
121  do
122  {
123    xReadSEImessage(seis, nalUnitType, sps);
124    /* SEI messages are an integer number of bytes, something has failed
125    * in the parsing if bitstream not byte-aligned */
126    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
127  } while (m_pcBitstream->getNumBitsLeft() > 8);
128
129  UInt rbspTrailingBits;
130  READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
131  assert(rbspTrailingBits == 0x80);
132}
133
134Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
135{
136#if ENC_DEC_TRACE
137  xTraceSEIHeader();
138#endif
139  Int payloadType = 0;
140  UInt val = 0;
141
142  do
143  {
144    READ_CODE (8, val, "payload_type");
145    payloadType += val;
146  } while (val==0xFF);
147
148  UInt payloadSize = 0;
149  do
150  {
151    READ_CODE (8, val, "payload_size");
152    payloadSize += val;
153  } while (val==0xFF);
154
155#if ENC_DEC_TRACE
156  xTraceSEIMessageType((SEI::PayloadType)payloadType);
157#endif
158
159  /* extract the payload for this single SEI message.
160   * This allows greater safety in erroneous parsing of an SEI message
161   * from affecting subsequent messages.
162   * After parsing the payload, bs needs to be restored as the primary
163   * bitstream.
164   */
165  TComInputBitstream *bs = getBitstream();
166  setBitstream(bs->extractSubstream(payloadSize * 8));
167
168  SEI *sei = NULL;
169
170  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
171  {
172    switch (payloadType)
173    {
174    case SEI::USER_DATA_UNREGISTERED:
175      sei = new SEIuserDataUnregistered;
176      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
177      break;
178    case SEI::ACTIVE_PARAMETER_SETS:
179      sei = new SEIActiveParameterSets; 
180      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); 
181      break; 
182    case SEI::DECODING_UNIT_INFO:
183      if (!sps)
184      {
185        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
186      }
187      else
188      {
189        sei = new SEIDecodingUnitInfo; 
190        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
191      }
192      break; 
193    case SEI::BUFFERING_PERIOD:
194      if (!sps)
195      {
196        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
197      }
198      else
199      {
200        sei = new SEIBufferingPeriod;
201        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
202      }
203      break;
204    case SEI::PICTURE_TIMING:
205      if (!sps)
206      {
207        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
208      }
209      else
210      {
211        sei = new SEIPictureTiming;
212        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
213      }
214      break;
215    case SEI::RECOVERY_POINT:
216      sei = new SEIRecoveryPoint;
217      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
218      break;
219    case SEI::FRAME_PACKING:
220      sei = new SEIFramePacking;
221      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
222      break;
223    case SEI::DISPLAY_ORIENTATION:
224      sei = new SEIDisplayOrientation;
225      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
226      break;
227    case SEI::TEMPORAL_LEVEL0_INDEX:
228      sei = new SEITemporalLevel0Index;
229      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
230      break;
231    case SEI::REGION_REFRESH_INFO:
232      sei = new SEIGradualDecodingRefreshInfo;
233      xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
234      break;
235    case SEI::TONE_MAPPING_INFO:
236      sei = new SEIToneMappingInfo;
237      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
238      break;
239    case SEI::SOP_DESCRIPTION:
240      sei = new SEISOPDescription;
241      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
242      break;
243    case SEI::SCALABLE_NESTING:
244      sei = new SEIScalableNesting;
245      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
246      break;
247#if H_MV
248     case SEI::SUB_BITSTREAM_PROPERTY:
249       sei = new SEISubBitstreamProperty;
250       xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
251       break;
252#endif
253    default:
254      for (UInt i = 0; i < payloadSize; i++)
255      {
256        UInt seiByte;
257        READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
258      }
259      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
260    }
261  }
262  else
263  {
264    switch (payloadType)
265    {
266      case SEI::USER_DATA_UNREGISTERED:
267        sei = new SEIuserDataUnregistered;
268        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
269        break;
270      case SEI::DECODED_PICTURE_HASH:
271        sei = new SEIDecodedPictureHash;
272        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
273        break;
274      default:
275        for (UInt i = 0; i < payloadSize; i++)
276        {
277          UInt seiByte;
278          READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
279        }
280        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
281    }
282  }
283  if (sei != NULL)
284  {
285    seis.push_back(sei);
286  }
287
288  /* By definition the underlying bitstream terminates in a byte-aligned manner.
289   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
290   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
291   * 3. Extract the remainingreserved_payload_extension_data bits.
292   *
293   * If there are fewer than 9 bits available, extract them.
294   */
295  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
296  if (payloadBitsRemaining) /* more_data_in_payload() */
297  {
298    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
299    {
300      UInt reservedPayloadExtensionData;
301      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
302    }
303
304    /* 2 */
305    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
306    Int finalPayloadBits = 0;
307    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
308    {
309      continue;
310    }
311
312    /* 3 */
313    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
314    {
315      UInt reservedPayloadExtensionData;
316      READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
317    }
318
319    UInt dummy;
320    READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
321    while (payloadBitsRemaining)
322    {
323      READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
324    }
325  }
326
327  /* restore primary bitstream for sei_message */
328  getBitstream()->deleteFifo();
329  delete getBitstream();
330  setBitstream(bs);
331}
332
333/**
334 * parse bitstream bs and unpack a user_data_unregistered SEI message
335 * of payloasSize bytes into sei.
336 */
337Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
338{
339  assert(payloadSize >= 16);
340  UInt val;
341
342  for (UInt i = 0; i < 16; i++)
343  {
344    READ_CODE (8, val, "uuid_iso_iec_11578");
345    sei.uuid_iso_iec_11578[i] = val;
346  }
347
348  sei.userDataLength = payloadSize - 16;
349  if (!sei.userDataLength)
350  {
351    sei.userData = 0;
352    return;
353  }
354
355  sei.userData = new UChar[sei.userDataLength];
356  for (UInt i = 0; i < sei.userDataLength; i++)
357  {
358    READ_CODE (8, val, "user_data" );
359    sei.userData[i] = val;
360  }
361}
362
363/**
364 * parse bitstream bs and unpack a decoded picture hash SEI message
365 * of payloadSize bytes into sei.
366 */
367Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
368{
369  UInt val;
370  READ_CODE (8, val, "hash_type");
371  sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
372  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
373  {
374    if(SEIDecodedPictureHash::MD5 == sei.method)
375    {
376      for (UInt i = 0; i < 16; i++)
377      {
378        READ_CODE(8, val, "picture_md5");
379        sei.digest[yuvIdx][i] = val;
380      }
381    }
382    else if(SEIDecodedPictureHash::CRC == sei.method)
383    {
384      READ_CODE(16, val, "picture_crc");
385      sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
386      sei.digest[yuvIdx][1] = val & 0xFF;
387    }
388    else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
389    {
390      READ_CODE(32, val, "picture_checksum");
391      sei.digest[yuvIdx][0] = (val>>24) & 0xff;
392      sei.digest[yuvIdx][1] = (val>>16) & 0xff;
393      sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
394      sei.digest[yuvIdx][3] =  val      & 0xff;
395    }
396  }
397}
398Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
399{
400  UInt val; 
401  READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val; 
402  READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
403  READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
404  READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
405
406  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
407  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
408  {
409    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
410  }
411
412  xParseByteAlign();
413}
414
415Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
416{
417  UInt val;
418  READ_UVLC(val, "decoding_unit_idx");
419  sei.m_decodingUnitIdx = val;
420
421  TComVUI *vui = sps->getVuiParameters();
422  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
423  {
424    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
425    sei.m_duSptCpbRemovalDelay = val;
426  }
427  else
428  {
429    sei.m_duSptCpbRemovalDelay = 0;
430  }
431  READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
432  if(sei.m_dpbOutputDuDelayPresentFlag)
433  {
434    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
435    sei.m_picSptDpbOutputDuDelay = val;
436  }
437  xParseByteAlign();
438}
439
440Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
441{
442  Int i, nalOrVcl;
443  UInt code;
444
445  TComVUI *pVUI = sps->getVuiParameters();
446  TComHRD *pHRD = pVUI->getHrdParameters();
447
448  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
449  if( !pHRD->getSubPicCpbParamsPresentFlag() )
450  {
451    READ_FLAG( code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
452  }
453  if( sei.m_rapCpbParamsPresentFlag )
454  {
455    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
456    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
457  }
458  //read splicing flag and cpb_removal_delay_delta
459  READ_FLAG( code, "concatenation_flag"); 
460  sei.m_concatenationFlag = code;
461  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
462  sei.m_auCpbRemovalDelayDelta = code + 1;
463  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
464  {
465    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
466        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
467    {
468      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
469      {
470        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
471        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
472        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
473        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
474        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
475        {
476          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
477          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
478          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
479          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
480        }
481      }
482    }
483  }
484  xParseByteAlign();
485}
486Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
487{
488  Int i;
489  UInt code;
490
491  TComVUI *vui = sps->getVuiParameters();
492  TComHRD *hrd = vui->getHrdParameters();
493
494  if( vui->getFrameFieldInfoPresentFlag() )
495  {
496    READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
497    READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
498    READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
499  }
500
501  if( hrd->getCpbDpbDelaysPresentFlag())
502  {
503    READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
504    sei.m_auCpbRemovalDelay = code + 1;
505    READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
506    sei.m_picDpbOutputDelay = code;
507
508    if(hrd->getSubPicCpbParamsPresentFlag())
509    {
510      READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
511      sei.m_picDpbOutputDuDelay = code;
512    }
513    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
514    {
515      READ_UVLC( code, "num_decoding_units_minus1");
516      sei.m_numDecodingUnitsMinus1 = code;
517      READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
518      sei.m_duCommonCpbRemovalDelayFlag = code;
519      if( sei.m_duCommonCpbRemovalDelayFlag )
520      {
521        READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
522        sei.m_duCommonCpbRemovalDelayMinus1 = code;
523      }
524      if( sei.m_numNalusInDuMinus1 != NULL )
525      {
526        delete sei.m_numNalusInDuMinus1;
527      }
528      sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
529      if( sei.m_duCpbRemovalDelayMinus1  != NULL )
530      {
531        delete sei.m_duCpbRemovalDelayMinus1;
532      }
533      sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
534
535      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
536      {
537        READ_UVLC( code, "num_nalus_in_du_minus1");
538        sei.m_numNalusInDuMinus1[ i ] = code;
539        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
540        {
541          READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
542          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
543        }
544      }
545    }
546  }
547  xParseByteAlign();
548}
549Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
550{
551  Int  iCode;
552  UInt uiCode;
553  READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
554  READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
555  READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
556  xParseByteAlign();
557}
558Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
559{
560  UInt val;
561  READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
562  READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
563
564  if ( !sei.m_arrangementCancelFlag )
565  {
566    READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
567    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
568    READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
569
570    READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
571    READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
572    READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
573    READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
574    READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
575    READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
576    READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
577
578    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
579    {
580      READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
581      READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
582      READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
583      READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
584    }
585
586    READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
587    READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
588  }
589  READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
590
591  xParseByteAlign();
592}
593
594Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
595{
596  UInt val;
597  READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
598  if( !sei.cancelFlag ) 
599  {
600    READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
601    READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
602    READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
603    READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
604  }
605  xParseByteAlign();
606}
607
608Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
609{
610  UInt val;
611  READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
612  READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
613  xParseByteAlign();
614}
615
616Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
617{
618  UInt val;
619  READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
620  xParseByteAlign();
621}
622
623Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
624{
625  Int i;
626  UInt val;
627  READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
628  READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
629
630  if ( !sei.m_toneMapCancelFlag )
631  {
632    READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val; 
633    READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
634    READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
635    READ_UVLC( val, "model_id" );                          sei.m_modelId = val; 
636    switch(sei.m_modelId)
637    {
638    case 0:
639      {
640        READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
641        READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
642        break;
643      }
644    case 1:
645      {
646        READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
647        READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
648        break;
649      }
650    case 2:
651      {
652        UInt num = 1u << sei.m_targetBitDepth;
653        sei.m_startOfCodedInterval.resize(num+1);
654        for(i = 0; i < num; i++)
655        {
656          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
657          sei.m_startOfCodedInterval[i] = val;
658        }
659        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
660        break;
661      }
662    case 3:
663      {
664        READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
665        sei.m_codedPivotValue.resize(sei.m_numPivots);
666        sei.m_targetPivotValue.resize(sei.m_numPivots);
667        for(i = 0; i < sei.m_numPivots; i++ )
668        {
669          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
670          sei.m_codedPivotValue[i] = val;
671          READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
672          sei.m_targetPivotValue[i] = val;
673        }
674        break;
675      }
676    case 4:
677      {
678        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
679        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
680        {
681          READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
682        }
683        READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
684        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
685        {
686          READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
687        }
688        READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
689        READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
690        READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
691        READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
692        READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
693        READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
694        READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
695        READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
696        break;
697      }
698    default:
699      {
700        assert(!"Undefined SEIToneMapModelId");
701        break;
702      }
703    }//switch model id
704  }// if(!sei.m_toneMapCancelFlag)
705
706  xParseByteAlign();
707}
708
709Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
710{
711  Int iCode;
712  UInt uiCode;
713
714  READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
715  READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
716  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
717  {
718    READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
719    READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
720    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
721    {
722      READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
723    }
724    if (i > 0)
725    {
726      READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
727    }
728  }
729
730  xParseByteAlign();
731}
732
733Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
734{
735  UInt uiCode;
736  SEIMessages seis;
737
738  READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
739  READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
740  if (sei.m_nestingOpFlag)
741  {
742    READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
743    READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
744    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
745    {
746      READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
747      READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
748    }
749  }
750  else
751  {
752    READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
753    if (!sei.m_allLayersFlag)
754    {
755      READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
756      READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
757      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
758      {
759        READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
760      }
761    }
762  }
763
764  // byte alignment
765  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
766  {
767    UInt code;
768    READ_FLAG( code, "nesting_zero_bit" );
769  }
770
771  sei.m_callerOwnsSEIs = false;
772
773  // read nested SEI messages
774  do {
775    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
776  } while (m_pcBitstream->getNumBitsLeft() > 8);
777
778}
779#if H_MV
780Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
781{
782  UInt uiCode;
783  READ_CODE( 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
784  READ_UVLC(    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
785
786  xResizeSubBitstreamPropertySeiArrays(sei);
787  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
788  {
789    READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
790    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
791    READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
792    READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
793    READ_CODE( 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
794  }
795  xParseByteAlign();
796}
797Void SEIReader::xResizeSubBitstreamPropertySeiArrays(SEISubBitstreamProperty &sei)
798{
799  sei.m_subBitstreamMode.resize( sei.m_numAdditionalSubStreams );
800  sei.m_outputLayerSetIdxToVps.resize( sei.m_numAdditionalSubStreams );
801  sei.m_highestSublayerId.resize( sei.m_numAdditionalSubStreams );
802  sei.m_avgBitRate.resize( sei.m_numAdditionalSubStreams );
803  sei.m_maxBitRate.resize( sei.m_numAdditionalSubStreams );
804}
805#endif
806
807Void SEIReader::xParseByteAlign()
808{
809  UInt code;
810  if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
811  {
812    READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
813  }
814  while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
815  {
816    READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
817  }
818}
819//! \}
Note: See TracBrowser for help on using the repository browser.