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

Last change on this file since 363 was 313, checked in by suehring, 11 years ago

set svn:eol-style=native property on all source files to do proper
automatic line break conversion on check-out and check-in

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