source: SHVCSoftware/branches/SHM-2.0avc-dev/source/Lib/TLibDecoder/SEIread.cpp @ 915

Last change on this file since 915 was 191, checked in by seregin, 12 years ago

unix2dos for *.cpp and *.h

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