source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibDecoder/SEIread.cpp @ 297

Last change on this file since 297 was 292, checked in by vidyo, 11 years ago

Implementation of M0043 - Layers Present SEI.
This is disabled by default. Enable this by setting M0043_LAYERS_PRESENT_SEI to 1

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