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

Last change on this file since 891 was 884, checked in by nokia, 11 years ago

implementation of jct-vc R0247
(1) Only the base layer creates the Active Parameter Sets SEI message.
(2) Active Parameter Sets SEI message can active more than 1 sps.

  • Property svn:eol-style set to native
File size: 55.9 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#if P0050_KNEE_FUNCTION_SEI
96  case SEI::KNEE_FUNCTION_INFO:
97    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
98    break;
99#endif
100#if Q0074_COLOUR_REMAPPING_SEI
101  case SEI::COLOUR_REMAPPING_INFO:
102    fprintf( g_hTrace, "===========Colour Remapping Information SEI message ===========\n");
103    break;
104#endif
105  case SEI::SOP_DESCRIPTION:
106    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
107    break;
108  case SEI::SCALABLE_NESTING:
109    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
110    break;
111#if SVC_EXTENSION
112#if LAYERS_NOT_PRESENT_SEI
113  case SEI::LAYERS_NOT_PRESENT:
114    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
115    break;
116#endif
117#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
118  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
119    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
120    break;
121#endif
122#if SUB_BITSTREAM_PROPERTY_SEI
123  case SEI::SUB_BITSTREAM_PROPERTY:
124    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
125    break;
126#endif
127#if O0164_MULTI_LAYER_HRD
128  case SEI::BSP_NESTING:
129    fprintf( g_hTrace, "=========== Bitstream parition nesting SEI message ===========\n");
130    break;
131  case SEI::BSP_INITIAL_ARRIVAL_TIME:
132    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
133    break;
134#if !REMOVE_BSP_HRD_SEI
135  case SEI::BSP_HRD:
136    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
137    break;
138#endif
139#endif
140#if Q0078_ADD_LAYER_SETS
141  case SEI::OUTPUT_LAYER_SET_NESTING:
142    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
143    break;
144  case SEI::VPS_REWRITING:
145    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
146    break;
147#endif
148#endif //SVC_EXTENSION
149  default:
150    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
151    break;
152  }
153}
154#endif
155
156/**
157 * unmarshal a single SEI message from bitstream bs
158 */
159#if LAYERS_NOT_PRESENT_SEI
160void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
161#else
162void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
163#endif
164{
165  setBitstream(bs);
166
167  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
168  do
169  {
170#if LAYERS_NOT_PRESENT_SEI
171    xReadSEImessage(seis, nalUnitType, vps, sps);
172#else
173    xReadSEImessage(seis, nalUnitType, sps);
174#endif
175    /* SEI messages are an integer number of bytes, something has failed
176    * in the parsing if bitstream not byte-aligned */
177    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
178  } while (m_pcBitstream->getNumBitsLeft() > 8);
179
180  UInt rbspTrailingBits;
181  READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
182  assert(rbspTrailingBits == 0x80);
183}
184
185#if O0164_MULTI_LAYER_HRD
186#if LAYERS_NOT_PRESENT_SEI
187Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei)
188#else
189Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei)
190#endif
191#else
192#if LAYERS_NOT_PRESENT_SEI
193Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
194#else
195Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
196#endif
197#endif
198{
199#if ENC_DEC_TRACE
200  xTraceSEIHeader();
201#endif
202  Int payloadType = 0;
203  UInt val = 0;
204
205  do
206  {
207    READ_CODE (8, val, "payload_type");
208    payloadType += val;
209  } while (val==0xFF);
210
211  UInt payloadSize = 0;
212  do
213  {
214    READ_CODE (8, val, "payload_size");
215    payloadSize += val;
216  } while (val==0xFF);
217
218#if ENC_DEC_TRACE
219  xTraceSEIMessageType((SEI::PayloadType)payloadType);
220#endif
221
222  /* extract the payload for this single SEI message.
223   * This allows greater safety in erroneous parsing of an SEI message
224   * from affecting subsequent messages.
225   * After parsing the payload, bs needs to be restored as the primary
226   * bitstream.
227   */
228  TComInputBitstream *bs = getBitstream();
229  setBitstream(bs->extractSubstream(payloadSize * 8));
230
231  SEI *sei = NULL;
232
233  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
234  {
235    switch (payloadType)
236    {
237    case SEI::USER_DATA_UNREGISTERED:
238      sei = new SEIuserDataUnregistered;
239      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
240      break;
241    case SEI::ACTIVE_PARAMETER_SETS:
242      sei = new SEIActiveParameterSets; 
243      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); 
244      break; 
245    case SEI::DECODING_UNIT_INFO:
246      if (!sps)
247      {
248        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
249      }
250      else
251      {
252        sei = new SEIDecodingUnitInfo; 
253        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
254      }
255      break; 
256    case SEI::BUFFERING_PERIOD:
257      if (!sps)
258      {
259        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
260      }
261      else
262      {
263        sei = new SEIBufferingPeriod;
264        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
265      }
266      break;
267    case SEI::PICTURE_TIMING:
268      if (!sps)
269      {
270        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
271      }
272      else
273      {
274        sei = new SEIPictureTiming;
275        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
276      }
277      break;
278    case SEI::RECOVERY_POINT:
279      sei = new SEIRecoveryPoint;
280      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
281      break;
282    case SEI::FRAME_PACKING:
283      sei = new SEIFramePacking;
284      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
285      break;
286    case SEI::DISPLAY_ORIENTATION:
287      sei = new SEIDisplayOrientation;
288      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
289      break;
290    case SEI::TEMPORAL_LEVEL0_INDEX:
291      sei = new SEITemporalLevel0Index;
292      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
293      break;
294    case SEI::REGION_REFRESH_INFO:
295      sei = new SEIGradualDecodingRefreshInfo;
296      xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
297      break;
298    case SEI::TONE_MAPPING_INFO:
299      sei = new SEIToneMappingInfo;
300      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
301      break;
302#if P0050_KNEE_FUNCTION_SEI
303    case SEI::KNEE_FUNCTION_INFO:
304      sei = new SEIKneeFunctionInfo;
305      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize);
306      break;
307#endif
308#if Q0074_COLOUR_REMAPPING_SEI
309    case SEI::COLOUR_REMAPPING_INFO:
310      sei = new SEIColourRemappingInfo;
311      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize);
312      break;
313#endif
314    case SEI::SOP_DESCRIPTION:
315      sei = new SEISOPDescription;
316      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
317      break;
318    case SEI::SCALABLE_NESTING:
319      sei = new SEIScalableNesting;
320#if LAYERS_NOT_PRESENT_SEI
321      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps);
322#else
323      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
324#endif
325      break;
326#if SVC_EXTENSION
327#if LAYERS_NOT_PRESENT_SEI
328    case SEI::LAYERS_NOT_PRESENT:
329      if (!vps)
330      {
331        printf ("Warning: Found Layers not present SEI message, but no active VPS is available. Ignoring.");
332      }
333      else
334      {
335        sei = new SEILayersNotPresent;
336        xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps);
337      }
338      break;
339#endif
340#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
341    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
342      sei = new SEIInterLayerConstrainedTileSets;
343      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize);
344      break;
345#endif
346#if SUB_BITSTREAM_PROPERTY_SEI
347   case SEI::SUB_BITSTREAM_PROPERTY:
348     sei = new SEISubBitstreamProperty;
349     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
350     break;
351#endif
352#if O0164_MULTI_LAYER_HRD
353   case SEI::BSP_NESTING:
354     sei = new SEIBspNesting;
355#if LAYERS_NOT_PRESENT_SEI
356     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei);
357#else
358     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei);
359#endif
360     break;
361   case SEI::BSP_INITIAL_ARRIVAL_TIME:
362     sei = new SEIBspInitialArrivalTime;
363     xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei);
364     break;
365#if !REMOVE_BSP_HRD_SEI
366   case SEI::BSP_HRD:
367     sei = new SEIBspHrd;
368     xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
369     break;
370#endif
371#endif
372#if Q0078_ADD_LAYER_SETS
373   case SEI::OUTPUT_LAYER_SET_NESTING:
374     sei = new SEIOutputLayerSetNesting;
375#if LAYERS_NOT_PRESENT_SEI
376     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps);
377#else
378     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps);
379#endif
380     break;
381   case SEI::VPS_REWRITING:
382     sei = new SEIVPSRewriting;
383     xParseSEIVPSRewriting((SEIVPSRewriting&)*sei);
384     break;
385#endif
386#if Q0189_TMVP_CONSTRAINTS
387   case SEI::TMVP_CONSTRAINTS:
388     sei =  new SEITMVPConstrains;
389     xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize);
390     break;
391#endif
392#if Q0247_FRAME_FIELD_INFO
393   case SEI::FRAME_FIELD_INFO:
394     sei =  new SEIFrameFieldInfo;
395     xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize); 
396     break;
397#endif
398#endif //SVC_EXTENSION
399      break;
400    default:
401      for (UInt i = 0; i < payloadSize; i++)
402      {
403        UInt seiByte;
404        READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
405      }
406      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
407    }
408  }
409  else
410  {
411    switch (payloadType)
412    {
413      case SEI::USER_DATA_UNREGISTERED:
414        sei = new SEIuserDataUnregistered;
415        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
416        break;
417      case SEI::DECODED_PICTURE_HASH:
418        sei = new SEIDecodedPictureHash;
419        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
420        break;
421      default:
422        for (UInt i = 0; i < payloadSize; i++)
423        {
424          UInt seiByte;
425          READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
426        }
427        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
428    }
429  }
430  if (sei != NULL)
431  {
432    seis.push_back(sei);
433  }
434
435  /* By definition the underlying bitstream terminates in a byte-aligned manner.
436   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
437   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
438   * 3. Extract the remainingreserved_payload_extension_data bits.
439   *
440   * If there are fewer than 9 bits available, extract them.
441   */
442  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
443  if (payloadBitsRemaining) /* more_data_in_payload() */
444  {
445    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
446    {
447      UInt reservedPayloadExtensionData;
448      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
449    }
450
451    /* 2 */
452    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
453    Int finalPayloadBits = 0;
454    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
455    {
456      continue;
457    }
458
459    /* 3 */
460    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
461    {
462      UInt reservedPayloadExtensionData;
463      READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
464    }
465
466    UInt dummy;
467    READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
468    while (payloadBitsRemaining)
469    {
470      READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
471    }
472  }
473
474  /* restore primary bitstream for sei_message */
475  getBitstream()->deleteFifo();
476  delete getBitstream();
477  setBitstream(bs);
478}
479
480#if P0138_USE_ALT_CPB_PARAMS_FLAG
481/**
482 * Check if SEI message contains payload extension
483 */
484Bool SEIReader::xPayloadExtensionPresent()
485{
486  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
487  Bool payloadExtensionPresent = false;
488
489  if (payloadBitsRemaining > 8)
490  {
491    payloadExtensionPresent = true;
492  }
493  else
494  {
495    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
496    while (payloadBitsRemaining && (finalBits & 1) == 0)
497    {
498      payloadBitsRemaining--;
499      finalBits >>= 1;
500    }
501    payloadBitsRemaining--;
502    if (payloadBitsRemaining > 0)
503    {
504      payloadExtensionPresent = true;
505    }
506  }
507
508  return payloadExtensionPresent;
509}
510#endif
511
512/**
513 * parse bitstream bs and unpack a user_data_unregistered SEI message
514 * of payloasSize bytes into sei.
515 */
516Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
517{
518  assert(payloadSize >= 16);
519  UInt val;
520
521  for (UInt i = 0; i < 16; i++)
522  {
523    READ_CODE (8, val, "uuid_iso_iec_11578");
524    sei.uuid_iso_iec_11578[i] = val;
525  }
526
527  sei.userDataLength = payloadSize - 16;
528  if (!sei.userDataLength)
529  {
530    sei.userData = 0;
531    return;
532  }
533
534  sei.userData = new UChar[sei.userDataLength];
535  for (UInt i = 0; i < sei.userDataLength; i++)
536  {
537    READ_CODE (8, val, "user_data" );
538    sei.userData[i] = val;
539  }
540}
541
542/**
543 * parse bitstream bs and unpack a decoded picture hash SEI message
544 * of payloadSize bytes into sei.
545 */
546Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
547{
548  UInt val;
549  READ_CODE (8, val, "hash_type");
550  sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
551  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
552  {
553    if(SEIDecodedPictureHash::MD5 == sei.method)
554    {
555      for (UInt i = 0; i < 16; i++)
556      {
557        READ_CODE(8, val, "picture_md5");
558        sei.digest[yuvIdx][i] = val;
559      }
560    }
561    else if(SEIDecodedPictureHash::CRC == sei.method)
562    {
563      READ_CODE(16, val, "picture_crc");
564      sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
565      sei.digest[yuvIdx][1] = val & 0xFF;
566    }
567    else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
568    {
569      READ_CODE(32, val, "picture_checksum");
570      sei.digest[yuvIdx][0] = (val>>24) & 0xff;
571      sei.digest[yuvIdx][1] = (val>>16) & 0xff;
572      sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
573      sei.digest[yuvIdx][3] =  val      & 0xff;
574    }
575  }
576}
577Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
578{
579  UInt val; 
580  READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val; 
581  READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
582  READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
583  READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
584
585  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
586#if R0247_SEI_ACTIVE
587  sei.layerSpsIdx.resize(sei.numSpsIdsMinus1 + 1);
588#endif
589  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
590  {
591    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
592  }
593#if R0247_SEI_ACTIVE
594  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
595  {
596    READ_UVLC(val, "layer_sps_idx"); sei.layerSpsIdx[i] = val; 
597  }
598#endif
599  xParseByteAlign();
600}
601
602Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
603{
604  UInt val;
605  READ_UVLC(val, "decoding_unit_idx");
606  sei.m_decodingUnitIdx = val;
607
608  TComVUI *vui = sps->getVuiParameters();
609  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
610  {
611    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
612    sei.m_duSptCpbRemovalDelay = val;
613  }
614  else
615  {
616    sei.m_duSptCpbRemovalDelay = 0;
617  }
618  READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
619  if(sei.m_dpbOutputDuDelayPresentFlag)
620  {
621    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
622    sei.m_picSptDpbOutputDuDelay = val;
623  }
624  xParseByteAlign();
625}
626
627Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
628{
629  Int i, nalOrVcl;
630  UInt code;
631
632  TComVUI *pVUI = sps->getVuiParameters();
633  TComHRD *pHRD = pVUI->getHrdParameters();
634
635  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
636  if( !pHRD->getSubPicCpbParamsPresentFlag() )
637  {
638    READ_FLAG( code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
639  }
640  if( sei.m_rapCpbParamsPresentFlag )
641  {
642    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
643    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
644  }
645  //read splicing flag and cpb_removal_delay_delta
646  READ_FLAG( code, "concatenation_flag"); 
647  sei.m_concatenationFlag = code;
648  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
649  sei.m_auCpbRemovalDelayDelta = code + 1;
650  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
651  {
652    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
653        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
654    {
655      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
656      {
657        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
658        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
659        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
660        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
661        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
662        {
663          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
664          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
665          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
666          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
667        }
668      }
669    }
670  }
671
672#if P0138_USE_ALT_CPB_PARAMS_FLAG
673  sei.m_useAltCpbParamsFlag = false;
674  sei.m_useAltCpbParamsFlagPresent = false;
675  if (xPayloadExtensionPresent())
676  {
677    READ_FLAG (code, "use_alt_cpb_params_flag");
678    sei.m_useAltCpbParamsFlag = code;
679    sei.m_useAltCpbParamsFlagPresent = true;
680  }
681#endif
682
683  xParseByteAlign();
684}
685Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
686{
687  Int i;
688  UInt code;
689
690  TComVUI *vui = sps->getVuiParameters();
691  TComHRD *hrd = vui->getHrdParameters();
692
693  if( vui->getFrameFieldInfoPresentFlag() )
694  {
695    READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
696    READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
697    READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
698  }
699
700  if( hrd->getCpbDpbDelaysPresentFlag())
701  {
702    READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
703    sei.m_auCpbRemovalDelay = code + 1;
704    READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
705    sei.m_picDpbOutputDelay = code;
706
707    if(hrd->getSubPicCpbParamsPresentFlag())
708    {
709      READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
710      sei.m_picDpbOutputDuDelay = code;
711    }
712    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
713    {
714      READ_UVLC( code, "num_decoding_units_minus1");
715      sei.m_numDecodingUnitsMinus1 = code;
716      READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
717      sei.m_duCommonCpbRemovalDelayFlag = code;
718      if( sei.m_duCommonCpbRemovalDelayFlag )
719      {
720        READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
721        sei.m_duCommonCpbRemovalDelayMinus1 = code;
722      }
723      if( sei.m_numNalusInDuMinus1 != NULL )
724      {
725        delete sei.m_numNalusInDuMinus1;
726      }
727      sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
728      if( sei.m_duCpbRemovalDelayMinus1  != NULL )
729      {
730        delete sei.m_duCpbRemovalDelayMinus1;
731      }
732      sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
733
734      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
735      {
736        READ_UVLC( code, "num_nalus_in_du_minus1");
737        sei.m_numNalusInDuMinus1[ i ] = code;
738        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
739        {
740          READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
741          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
742        }
743      }
744    }
745  }
746  xParseByteAlign();
747}
748Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
749{
750  Int  iCode;
751  UInt uiCode;
752  READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
753  READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
754  READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
755  xParseByteAlign();
756}
757Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
758{
759  UInt val;
760  READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
761  READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
762
763  if ( !sei.m_arrangementCancelFlag )
764  {
765    READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
766    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
767    READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
768
769    READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
770    READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
771    READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
772    READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
773    READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
774    READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
775    READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
776
777    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
778    {
779      READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
780      READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
781      READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
782      READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
783    }
784
785    READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
786    READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
787  }
788  READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
789
790  xParseByteAlign();
791}
792
793Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
794{
795  UInt val;
796  READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
797  if( !sei.cancelFlag ) 
798  {
799    READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
800    READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
801    READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
802    READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
803  }
804  xParseByteAlign();
805}
806
807Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
808{
809  UInt val;
810  READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
811  READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
812  xParseByteAlign();
813}
814
815Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
816{
817  UInt val;
818  READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
819  xParseByteAlign();
820}
821
822Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
823{
824  Int i;
825  UInt val;
826  READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
827  READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
828
829  if ( !sei.m_toneMapCancelFlag )
830  {
831    READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val; 
832    READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
833    READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
834    READ_UVLC( val, "model_id" );                          sei.m_modelId = val; 
835    switch(sei.m_modelId)
836    {
837    case 0:
838      {
839        READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
840        READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
841        break;
842      }
843    case 1:
844      {
845        READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
846        READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
847        break;
848      }
849    case 2:
850      {
851        UInt num = 1u << sei.m_targetBitDepth;
852        sei.m_startOfCodedInterval.resize(num+1);
853        for(i = 0; i < num; i++)
854        {
855          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
856          sei.m_startOfCodedInterval[i] = val;
857        }
858        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
859        break;
860      }
861    case 3:
862      {
863        READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
864        sei.m_codedPivotValue.resize(sei.m_numPivots);
865        sei.m_targetPivotValue.resize(sei.m_numPivots);
866        for(i = 0; i < sei.m_numPivots; i++ )
867        {
868          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
869          sei.m_codedPivotValue[i] = val;
870          READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
871          sei.m_targetPivotValue[i] = val;
872        }
873        break;
874      }
875    case 4:
876      {
877        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
878        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
879        {
880          READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
881        }
882        READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
883        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
884        {
885          READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
886        }
887        READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
888        READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
889        READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
890        READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
891        READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
892        READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
893        READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
894        READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
895        break;
896      }
897    default:
898      {
899        assert(!"Undefined SEIToneMapModelId");
900        break;
901      }
902    }//switch model id
903  }// if(!sei.m_toneMapCancelFlag)
904
905  xParseByteAlign();
906}
907
908#if P0050_KNEE_FUNCTION_SEI
909Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt /*payloadSize*/){
910  Int i;
911  UInt val;
912  READ_UVLC( val, "knee_function_id" );                   sei.m_kneeId = val;
913  READ_FLAG( val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
914  if ( !sei.m_kneeCancelFlag )
915  {
916    READ_FLAG( val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
917    READ_FLAG( val, "mapping_flag" );                     sei.m_kneeMappingFlag = val;
918    READ_CODE( 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
919    READ_CODE( 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
920    READ_CODE( 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
921    READ_CODE( 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
922    READ_UVLC( val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
923    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
924    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
925    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
926    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
927    {
928      READ_CODE( 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
929      READ_CODE( 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
930    }
931  }
932}
933#endif
934
935#if Q0074_COLOUR_REMAPPING_SEI
936Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/)
937{
938  UInt  uiVal;
939  Int   iVal;
940
941  READ_UVLC( uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
942  READ_FLAG( uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
943  if( !sei.m_colourRemapCancelFlag ) 
944  {
945    READ_FLAG( uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
946    READ_FLAG( uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
947    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
948    {
949      READ_FLAG( uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
950      READ_CODE( 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
951      READ_CODE( 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
952      READ_CODE( 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
953    }
954    READ_CODE( 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
955    READ_CODE( 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
956 
957    for( Int c=0 ; c<3 ; c++ )
958    {
959      READ_CODE( 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
960      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
961      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
962      if( uiVal> 0 )
963        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
964        {
965          READ_CODE( (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
966          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
967        }
968      else // pre_lut_num_val_minus1[c] == 0
969      {
970        sei.m_preLutCodedValue[c][0]  = 0;
971        sei.m_preLutTargetValue[c][0] = 0;
972        sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
973        sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
974      }
975    }
976
977    READ_FLAG( uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
978    if( sei.m_colourRemapMatrixPresentFlag )
979    {
980      READ_CODE( 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
981      for ( Int c=0 ; c<3 ; c++ )
982        for ( Int i=0 ; i<3 ; i++ )
983        {
984          READ_SVLC( iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
985        }
986    }
987    else // setting default matrix (I3)
988    {
989      sei.m_log2MatrixDenom = 0;
990      for ( Int c=0 ; c<3 ; c++ )
991        for ( Int i=0 ; i<3 ; i++ )
992          sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
993    }
994    for( Int c=0 ; c<3 ; c++ )
995    {
996      READ_CODE( 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
997      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
998      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
999      if( uiVal > 0 )
1000        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
1001        {
1002          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
1003          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
1004        }
1005      else
1006      {
1007        sei.m_postLutCodedValue[c][0]  = 0;
1008        sei.m_postLutTargetValue[c][0] = 0;
1009        sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
1010        sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
1011      }
1012    }
1013  }
1014
1015  xParseByteAlign();
1016}
1017#endif
1018
1019Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
1020{
1021  Int iCode;
1022  UInt uiCode;
1023
1024  READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
1025  READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
1026  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
1027  {
1028    READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
1029    READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
1030    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
1031    {
1032      READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
1033    }
1034    if (i > 0)
1035    {
1036      READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
1037    }
1038  }
1039
1040  xParseByteAlign();
1041}
1042
1043#if Q0189_TMVP_CONSTRAINTS
1044Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize)
1045{
1046  UInt uiCode;
1047  READ_UVLC( uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
1048  READ_UVLC( uiCode,           "no_intra_layer_col_pic_flag"            ); sei.no_intra_layer_col_pic_flag = uiCode;
1049  xParseByteAlign();
1050}
1051#endif
1052
1053#if Q0247_FRAME_FIELD_INFO
1054Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize)
1055{
1056  UInt code;
1057  READ_CODE( 4, code, "ffinfo_pic_struct" );             sei.m_ffinfo_picStruct            = code;
1058  READ_CODE( 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
1059  READ_FLAG(    code, "ffinfo_duplicate_flag" );         sei.m_ffinfo_duplicateFlag    = ( code == 1 ? true : false );
1060  xParseByteAlign();
1061}
1062#endif
1063
1064#if LAYERS_NOT_PRESENT_SEI
1065Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
1066#else
1067Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
1068#endif
1069{
1070  UInt uiCode;
1071  SEIMessages seis;
1072
1073  READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
1074  READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
1075  if (sei.m_nestingOpFlag)
1076  {
1077    READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
1078    READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
1079    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
1080    {
1081      READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
1082      READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
1083    }
1084  }
1085  else
1086  {
1087    READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
1088    if (!sei.m_allLayersFlag)
1089    {
1090      READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
1091      READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
1092      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
1093      {
1094        READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
1095      }
1096    }
1097  }
1098
1099  // byte alignment
1100  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1101  {
1102    UInt code;
1103    READ_FLAG( code, "nesting_zero_bit" );
1104  }
1105
1106  sei.m_callerOwnsSEIs = false;
1107
1108  // read nested SEI messages
1109  do {
1110#if O0164_MULTI_LAYER_HRD
1111#if LAYERS_NOT_PRESENT_SEI
1112    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &sei);
1113#else
1114    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &sei);
1115#endif
1116#else
1117#if LAYERS_NOT_PRESENT_SEI
1118    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
1119#else
1120    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
1121#endif
1122#endif
1123  } while (m_pcBitstream->getNumBitsLeft() > 8);
1124
1125}
1126
1127Void SEIReader::xParseByteAlign()
1128{
1129  UInt code;
1130  if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1131  {
1132    READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
1133  }
1134  while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1135  {
1136    READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
1137  }
1138}
1139
1140#if SVC_EXTENSION
1141#if LAYERS_NOT_PRESENT_SEI
1142Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps)
1143{
1144  UInt uiCode;
1145  UInt i = 0;
1146
1147  READ_UVLC( uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
1148  assert(vps->getVPSId() == sei.m_activeVpsId);
1149  sei.m_vpsMaxLayers = vps->getMaxLayers();
1150  for (; i < sei.m_vpsMaxLayers; i++)
1151  {
1152    READ_FLAG( uiCode,         "layer_not_present_flag"   ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false;
1153  }
1154  for (; i < MAX_LAYERS; i++)
1155  {
1156    sei.m_layerNotPresentFlag[i] = false;
1157  }
1158  xParseByteAlign();
1159}
1160#endif
1161#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
1162Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize)
1163{
1164  UInt uiCode;
1165
1166  READ_FLAG( uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
1167  READ_FLAG( uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
1168  if( !sei.m_ilOneTilePerTileSetFlag )
1169  {
1170    READ_UVLC( uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
1171    if( sei.m_ilNumSetsInMessageMinus1 )
1172    {
1173      READ_FLAG( uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
1174    }
1175    else
1176    {
1177      sei.m_skippedTileSetPresentFlag = false;
1178    }
1179    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
1180    for( UInt i = 0; i < numSignificantSets; i++ )
1181    {
1182      READ_UVLC( uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
1183      READ_UVLC( uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
1184      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
1185      {
1186        READ_UVLC( uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
1187        READ_UVLC( uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
1188      }
1189      READ_CODE( 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
1190      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
1191      {
1192        READ_FLAG( uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
1193      }
1194    }
1195  }
1196  else
1197  {
1198    READ_CODE( 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
1199  }
1200
1201  xParseByteAlign();
1202}
1203#endif
1204#if SUB_BITSTREAM_PROPERTY_SEI
1205Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
1206{
1207  UInt uiCode;
1208  READ_CODE( 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
1209  READ_UVLC(    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
1210
1211  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
1212  {
1213    READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
1214    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
1215    READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
1216    READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
1217    READ_CODE( 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
1218  }
1219  xParseByteAlign();
1220}
1221#endif
1222
1223#if O0164_MULTI_LAYER_HRD
1224#if LAYERS_NOT_PRESENT_SEI
1225Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
1226#else
1227Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei)
1228#endif
1229{
1230  UInt uiCode;
1231  READ_UVLC( uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
1232
1233  // byte alignment
1234  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1235  {
1236    UInt code;
1237    READ_FLAG( code, "bsp_nesting_zero_bit" );
1238  }
1239
1240  sei.m_callerOwnsSEIs = false;
1241
1242  // read nested SEI messages
1243#if NESTING_SEI_EXTENSIBILITY
1244  Int numSeiMessages = 0;
1245  READ_UVLC( uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
1246  numSeiMessages = uiCode;
1247  for(Int i = 0; i < numSeiMessages; i++)
1248  {
1249    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
1250  }
1251#else
1252  do {
1253#if LAYERS_NOT_PRESENT_SEI
1254    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
1255#else
1256    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &nestingSei);
1257#endif
1258  } while (m_pcBitstream->getNumBitsLeft() > 8);
1259#endif
1260}
1261
1262Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
1263{
1264  assert(vps->getVpsVuiPresentFlag());
1265
1266  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
1267  UInt len;
1268  UInt hrdIdx;
1269  UInt uiCode;
1270
1271  if (schedCombCnt > 0)
1272  {
1273    hrdIdx = vps->getBspCombHrdIdx(nestingSei.m_nestingOpIdx[0], 0, bspNestingSei.m_bspIdx);
1274  }
1275  else
1276  {
1277    hrdIdx = 0;
1278  }
1279
1280  TComHRD *hrd = vps->getBspHrd(hrdIdx);
1281
1282  if (hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag())
1283  {
1284    len = hrd->getInitialCpbRemovalDelayLengthMinus1() + 1;
1285  }
1286  else
1287  {
1288    len = 23 + 1;
1289  }
1290
1291  if (hrd->getNalHrdParametersPresentFlag())
1292  {
1293    for(UInt i = 0; i < schedCombCnt; i++)
1294    {
1295      READ_CODE( len, uiCode, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
1296    }
1297  }
1298#if BSP_INIT_ARRIVAL_SEI
1299  if( hrd->getVclHrdParametersPresentFlag() )
1300#else
1301  else
1302#endif
1303  {
1304    for(UInt i = 0; i < schedCombCnt; i++)
1305    {
1306      READ_CODE( len, uiCode, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
1307    }
1308  }
1309}
1310
1311#if !REMOVE_BSP_HRD_SEI
1312Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
1313{
1314  UInt uiCode;
1315  READ_UVLC( uiCode, "sei_num_bsp_hrd_parameters_minus1" ); sei.m_seiNumBspHrdParametersMinus1 = uiCode;
1316  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
1317  {
1318    if (i > 0)
1319    {
1320      READ_FLAG( uiCode, "sei_bsp_cprms_present_flag" ); sei.m_seiBspCprmsPresentFlag[i] = uiCode;
1321    }
1322    xParseHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1);
1323  }
1324  for (UInt h = 0; h <= nestingSei.m_nestingNumOpsMinus1; h++)
1325  {
1326    UInt lsIdx = nestingSei.m_nestingOpIdx[h];
1327    READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
1328#if HRD_BPB
1329    Int chkPart=0;
1330#endif
1331    UInt i;
1332    for(i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
1333    {
1334#if HRD_BPB
1335      UInt nl=0; UInt j;
1336      for(j = 0; j < sei.m_vpsMaxLayers; j++)
1337      {
1338        if (sei.m_layerIdIncludedFlag[lsIdx][j])
1339        {
1340          nl++;
1341        }
1342      }
1343      for (j = 0; j < nl; j++)
1344      {
1345#else
1346      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
1347      {
1348        if (sei.m_layerIdIncludedFlag[lsIdx][j])
1349        {
1350#endif
1351          READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
1352        }
1353#if !HRD_BPB
1354      }
1355#endif
1356#if HRD_BPB
1357      chkPart+=sei.m_seiLayerInBspFlag[lsIdx][i][j];
1358#endif
1359    }
1360#if HRD_BPB
1361    assert(chkPart<=1);
1362#endif
1363#if HRD_BPB
1364    if(sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]==0)
1365    {
1366      Int chkPartition1=0; Int chkPartition2=0;
1367      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
1368      {
1369        if( sei.m_layerIdIncludedFlag[lsIdx][j] )
1370        {
1371          chkPartition1+=sei.m_seiLayerInBspFlag[lsIdx][0][j];
1372          chkPartition2++;
1373        }
1374      }
1375      assert(chkPartition1!=chkPartition2);
1376    }
1377#endif
1378     
1379    READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
1380    for (i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
1381    {
1382      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
1383      {
1384        READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
1385#if HRD_BPB
1386        assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1);
1387#endif
1388        READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
1389#if HRD_BPB
1390        assert(uiCode <= sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 ));
1391#endif
1392
1393      }
1394    }
1395  }
1396}
1397#endif
1398
1399Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
1400{
1401  UInt  uiCode;
1402  if( commonInfPresentFlag )
1403  {
1404    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
1405    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
1406    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
1407    {
1408      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
1409      if( hrd->getSubPicCpbParamsPresentFlag() )
1410      {
1411        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
1412        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
1413        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
1414        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
1415      }
1416      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
1417      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
1418      if( hrd->getSubPicCpbParamsPresentFlag() )
1419      {
1420        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
1421      }
1422      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
1423      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
1424      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
1425    }
1426  }
1427  Int i, j, nalOrVcl;
1428  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1429  {
1430    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
1431    if( !hrd->getFixedPicRateFlag( i ) )
1432    {
1433      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
1434    }
1435    else
1436    {
1437      hrd->setFixedPicRateWithinCvsFlag( i, true );
1438    }
1439    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
1440    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
1441    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1442    {
1443      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
1444    }
1445    else
1446    {
1447      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
1448    }
1449    if (!hrd->getLowDelayHrdFlag( i ))
1450    {
1451      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
1452    }
1453    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1454    {
1455      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1456          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1457      {
1458        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1459        {
1460          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
1461          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
1462          if( hrd->getSubPicCpbParamsPresentFlag() )
1463          {
1464            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
1465            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
1466          }
1467          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
1468        }
1469      }
1470    }
1471  }
1472}
1473#endif
1474
1475#if Q0078_ADD_LAYER_SETS
1476
1477#if LAYERS_NOT_PRESENT_SEI
1478Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
1479#else
1480Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps)
1481#endif
1482{
1483  UInt uiCode;
1484  SEIMessages seis;
1485
1486  READ_FLAG(uiCode, "ols_flag"); sei.m_olsFlag = uiCode;
1487  READ_UVLC(uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode;
1488
1489  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
1490  {
1491    READ_UVLC(uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode;
1492  }
1493
1494  // byte alignment
1495  while (m_pcBitstream->getNumBitsRead() % 8 != 0)
1496  {
1497    UInt code;
1498    READ_FLAG(code, "ols_nesting_zero_bit");
1499  }
1500
1501  sei.m_callerOwnsSEIs = false;
1502
1503  // read nested SEI messages
1504  do {
1505#if O0164_MULTI_LAYER_HRD
1506#if LAYERS_NOT_PRESENT_SEI
1507    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
1508#else
1509    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
1510#endif
1511#else
1512#if LAYERS_NOT_PRESENT_SEI
1513    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
1514#else
1515    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
1516#endif
1517#endif
1518  } while (m_pcBitstream->getNumBitsLeft() > 8);
1519
1520}
1521
1522Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei)
1523{
1524}
1525
1526#endif
1527
1528#endif //SVC_EXTENSION
1529
1530//! \}
Note: See TracBrowser for help on using the repository browser.