source: SHVCSoftware/branches/SHM-5.1-dev/source/Lib/TLibDecoder/SEIread.cpp @ 622

Last change on this file since 622 was 616, checked in by nokia, 12 years ago

JCTVC-P0138: Implementation of use_alt_cpb_params_flag

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