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

Last change on this file since 594 was 588, checked in by seregin, 11 years ago

merge with SHM-5.0-dev

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