source: SHVCSoftware/trunk/source/Lib/TLibEncoder/SEIwrite.cpp @ 594

Last change on this file since 594 was 588, checked in by seregin, 11 years ago

merge with SHM-5.0-dev

  • Property svn:eol-style set to native
File size: 26.3 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include "TLibCommon/TComBitCounter.h"
35#include "TLibCommon/TComBitStream.h"
36#include "TLibCommon/SEI.h"
37#include "TLibCommon/TComSlice.h"
38#include "SEIwrite.h"
39
40//! \ingroup TLibEncoder
41//! \{
42
43#if ENC_DEC_TRACE
44Void  xTraceSEIHeader()
45{
46  fprintf( g_hTrace, "=========== SEI message ===========\n");
47}
48
49Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
50{
51  switch (payloadType)
52  {
53  case SEI::DECODED_PICTURE_HASH:
54    fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n");
55    break;
56  case SEI::USER_DATA_UNREGISTERED:
57    fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n");
58    break;
59  case SEI::ACTIVE_PARAMETER_SETS:
60    fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n");
61    break;
62  case SEI::BUFFERING_PERIOD:
63    fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n");
64    break;
65  case SEI::PICTURE_TIMING:
66    fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n");
67    break;
68  case SEI::RECOVERY_POINT:
69    fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n");
70    break;
71  case SEI::FRAME_PACKING:
72    fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n");
73    break;
74  case SEI::DISPLAY_ORIENTATION:
75    fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n");
76    break;
77  case SEI::TEMPORAL_LEVEL0_INDEX:
78    fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n");
79    break;
80  case SEI::REGION_REFRESH_INFO:
81    fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n");
82    break;
83  case SEI::DECODING_UNIT_INFO:
84    fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
85    break;
86  case SEI::TONE_MAPPING_INFO:
87    fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
88    break;
89#if LAYERS_NOT_PRESENT_SEI
90  case SEI::LAYERS_NOT_PRESENT:
91    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
92    break;
93#endif
94  case SEI::SOP_DESCRIPTION:
95    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
96    break;
97#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
98  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
99    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
100    break;
101#endif
102#if SUB_BITSTREAM_PROPERTY_SEI
103    case SEI::SUB_BITSTREAM_PROPERTY:
104      fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
105      break;
106#endif
107  case SEI::SCALABLE_NESTING:
108    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
109    break;
110  default:
111    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
112    break;
113  }
114}
115#endif
116
117void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
118{
119  switch (sei.payloadType())
120  {
121  case SEI::USER_DATA_UNREGISTERED:
122    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
123    break;
124  case SEI::ACTIVE_PARAMETER_SETS:
125    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei)); 
126    break; 
127  case SEI::DECODING_UNIT_INFO:
128    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
129    break;
130  case SEI::DECODED_PICTURE_HASH:
131    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
132    break;
133  case SEI::BUFFERING_PERIOD:
134    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
135    break;
136  case SEI::PICTURE_TIMING:
137    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
138    break;
139  case SEI::RECOVERY_POINT:
140    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
141    break;
142  case SEI::FRAME_PACKING:
143    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
144    break;
145  case SEI::DISPLAY_ORIENTATION:
146    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
147    break;
148  case SEI::TEMPORAL_LEVEL0_INDEX:
149    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
150    break;
151  case SEI::REGION_REFRESH_INFO:
152    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
153    break;
154  case SEI::TONE_MAPPING_INFO:
155    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
156    break;
157#if LAYERS_NOT_PRESENT_SEI
158  case SEI::LAYERS_NOT_PRESENT:
159    xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
160    break;
161#endif
162  case SEI::SOP_DESCRIPTION:
163    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
164    break;
165#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
166  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
167    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
168    break;
169#endif
170#if SUB_BITSTREAM_PROPERTY_SEI
171   case SEI::SUB_BITSTREAM_PROPERTY:
172     xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
173     break;
174#endif
175  case SEI::SCALABLE_NESTING:
176    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
177    break;
178  default:
179    assert(!"Unhandled SEI message");
180  }
181}
182
183/**
184 * marshal a single SEI message sei, storing the marshalled representation
185 * in bitstream bs.
186 */
187Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
188{
189  /* calculate how large the payload data is */
190  /* TODO: this would be far nicer if it used vectored buffers */
191  TComBitCounter bs_count;
192  bs_count.resetBits();
193  setBitstream(&bs_count);
194
195
196#if ENC_DEC_TRACE
197  Bool traceEnable = g_HLSTraceEnable;
198  g_HLSTraceEnable = false;
199#endif
200  xWriteSEIpayloadData(bs_count, sei, sps);
201#if ENC_DEC_TRACE
202  g_HLSTraceEnable = traceEnable;
203#endif
204
205  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
206  assert(0 == payload_data_num_bits % 8);
207
208  setBitstream(&bs);
209
210#if ENC_DEC_TRACE
211  if (g_HLSTraceEnable)
212  xTraceSEIHeader();
213#endif
214
215  UInt payloadType = sei.payloadType();
216  for (; payloadType >= 0xff; payloadType -= 0xff)
217  {
218    WRITE_CODE(0xff, 8, "payload_type");
219  }
220  WRITE_CODE(payloadType, 8, "payload_type");
221
222  UInt payloadSize = payload_data_num_bits/8;
223  for (; payloadSize >= 0xff; payloadSize -= 0xff)
224  {
225    WRITE_CODE(0xff, 8, "payload_size");
226  }
227  WRITE_CODE(payloadSize, 8, "payload_size");
228
229  /* payloadData */
230#if ENC_DEC_TRACE
231  if (g_HLSTraceEnable)
232  xTraceSEIMessageType(sei.payloadType());
233#endif
234
235  xWriteSEIpayloadData(bs, sei, sps);
236}
237
238/**
239 * marshal a user_data_unregistered SEI message sei, storing the marshalled
240 * representation in bitstream bs.
241 */
242Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
243{
244  for (UInt i = 0; i < 16; i++)
245  {
246    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
247  }
248
249  for (UInt i = 0; i < sei.userDataLength; i++)
250  {
251    WRITE_CODE(sei.userData[i], 8 , "user_data");
252  }
253}
254
255/**
256 * marshal a decoded picture hash SEI message, storing the marshalled
257 * representation in bitstream bs.
258 */
259Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
260{
261  UInt val;
262
263  WRITE_CODE(sei.method, 8, "hash_type");
264
265  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
266  {
267    if(sei.method == SEIDecodedPictureHash::MD5)
268    {
269      for (UInt i = 0; i < 16; i++)
270      {
271        WRITE_CODE(sei.digest[yuvIdx][i], 8, "picture_md5");
272      }
273    }
274    else if(sei.method == SEIDecodedPictureHash::CRC)
275    {
276      val = (sei.digest[yuvIdx][0] << 8)  + sei.digest[yuvIdx][1];
277      WRITE_CODE(val, 16, "picture_crc");
278    }
279    else if(sei.method == SEIDecodedPictureHash::CHECKSUM)
280    {
281      val = (sei.digest[yuvIdx][0] << 24)  + (sei.digest[yuvIdx][1] << 16) + (sei.digest[yuvIdx][2] << 8) + sei.digest[yuvIdx][3];
282      WRITE_CODE(val, 32, "picture_checksum");
283    }
284  }
285}
286
287Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
288{
289  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
290  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
291  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
292  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
293
294  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));
295
296  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
297  {
298    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
299  }
300
301  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
302  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8; 
303  if(uiAlignedBits) 
304  {
305    WRITE_FLAG(1, "alignment_bit" );
306    uiAlignedBits--; 
307    while(uiAlignedBits--)
308    {
309      WRITE_FLAG(0, "alignment_bit" );
310    }
311  }
312}
313
314Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps)
315{
316  TComVUI *vui = sps->getVuiParameters();
317  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
318  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
319  {
320    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
321  }
322  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
323  if(sei.m_dpbOutputDuDelayPresentFlag)
324  {
325    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
326  }
327  xWriteByteAlign();
328}
329
330Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
331{
332  Int i, nalOrVcl;
333  TComVUI *vui = sps->getVuiParameters();
334  TComHRD *hrd = vui->getHrdParameters();
335
336  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
337  if( !hrd->getSubPicCpbParamsPresentFlag() )
338  {
339    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
340  }
341  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
342  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
343  if( sei.m_rapCpbParamsPresentFlag )
344  {
345    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
346    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
347  }
348  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
349  {
350    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
351        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
352    {
353      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
354      {
355        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
356        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
357        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
358        {
359          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
360          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
361        }
362      }
363    }
364  }
365  xWriteByteAlign();
366}
367Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
368{
369  Int i;
370  TComVUI *vui = sps->getVuiParameters();
371  TComHRD *hrd = vui->getHrdParameters();
372
373  if( vui->getFrameFieldInfoPresentFlag() )
374  {
375    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
376    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
377    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
378  }
379
380  if( hrd->getCpbDpbDelaysPresentFlag() )
381  {
382    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
383    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
384    if(hrd->getSubPicCpbParamsPresentFlag())
385    {
386      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
387    }
388    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
389    {
390      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
391      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
392      if( sei.m_duCommonCpbRemovalDelayFlag )
393      {
394        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
395      }
396      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
397      {
398        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
399        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
400        {
401          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
402        }
403      }
404    }
405  }
406  xWriteByteAlign();
407}
408Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
409{
410  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
411  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
412  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
413  xWriteByteAlign();
414}
415Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
416{
417  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
418  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
419
420  if( sei.m_arrangementCancelFlag == 0 ) {
421    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
422
423    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
424    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
425    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
426    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
427    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
428    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
429
430    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
431    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
432
433    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
434    {
435      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
436      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
437      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
438      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
439    }
440
441    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
442    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
443  }
444
445  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
446
447  xWriteByteAlign();
448}
449
450Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
451{
452  Int i;
453  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
454  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
455  if( !sei.m_toneMapCancelFlag ) 
456  {
457    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
458    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
459    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
460    WRITE_UVLC( sei.m_modelId,                    "model_id" );
461    switch(sei.m_modelId)
462    {
463    case 0:
464      {
465        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
466        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
467        break;
468      }
469    case 1:
470      {
471        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
472        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
473        break;
474      }
475    case 2:
476      {
477        UInt num = 1u << sei.m_targetBitDepth;
478        for(i = 0; i < num; i++)
479        {
480          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
481        }
482        break;
483      }
484    case 3:
485      {
486        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
487        for(i = 0; i < sei.m_numPivots; i++ )
488        {
489          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
490          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
491        }
492        break;
493      }
494    case 4:
495      {
496        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
497        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
498        {
499          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
500        }
501        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
502        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
503        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
504        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
505        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
506        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
507        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
508        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
509        break;
510      }
511    default:
512      {
513        assert(!"Undefined SEIToneMapModelId");
514        break;
515      }
516    }//switch m_modelId
517  }//if(!sei.m_toneMapCancelFlag)
518
519  xWriteByteAlign();
520}
521
522Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
523{
524  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
525  if( !sei.cancelFlag )
526  {
527    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
528    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
529    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
530    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
531  }
532  xWriteByteAlign();
533}
534
535Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
536{
537  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
538  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
539  xWriteByteAlign();
540}
541
542Void SEIWriter::xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei)
543{
544  WRITE_FLAG( sei.m_gdrForegroundFlag, "gdr_foreground_flag");
545  xWriteByteAlign();
546}
547
548#if LAYERS_NOT_PRESENT_SEI
549Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
550{
551  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
552  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
553  {
554    WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
555  }
556  xWriteByteAlign();
557}
558#endif
559
560Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
561{
562  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
563  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
564  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
565  {
566    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
567    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
568    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
569    {
570      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
571    }
572    if (i > 0)
573    {
574      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
575    }
576  }
577
578  xWriteByteAlign();
579}
580
581#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
582Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
583{
584  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
585  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
586  if( !sei.m_ilOneTilePerTileSetFlag )
587  {
588    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
589    if( sei.m_ilNumSetsInMessageMinus1 )
590    {
591      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
592    }
593    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
594    for( UInt i = 0; i < numSignificantSets; i++ )
595    {
596      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
597      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
598      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
599      {
600        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
601        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
602      }
603      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
604      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
605      {
606        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
607      }
608    }
609  }
610  else
611  {
612    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
613  }
614
615  xWriteByteAlign();
616}
617#endif
618#if SUB_BITSTREAM_PROPERTY_SEI
619Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
620{
621  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
622  assert( sei.m_numAdditionalSubStreams >= 1 );
623  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
624
625  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
626  {
627    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
628    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
629    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
630    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
631    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
632  }
633  xWriteByteAlign();
634}
635#endif
636Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
637{
638  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
639  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
640  if (sei.m_nestingOpFlag)
641  {
642    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
643    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
644    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
645    {
646      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
647      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
648      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
649    }
650  }
651  else
652  {
653    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
654    if (!sei.m_allLayersFlag)
655    {
656      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
657      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
658      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
659      {
660        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
661      }
662    }
663  }
664 
665  // byte alignment
666  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
667  {
668    WRITE_FLAG( 0, "nesting_zero_bit" );
669  }
670
671  // write nested SEI messages
672  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
673  {
674    writeSEImessage(bs, *(*it), sps);
675  }
676}
677
678Void SEIWriter::xWriteByteAlign()
679{
680  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
681  {
682    WRITE_FLAG( 1, "bit_equal_to_one" );
683    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
684    {
685      WRITE_FLAG( 0, "bit_equal_to_zero" );
686    }
687  }
688};
689
690//! \}
Note: See TracBrowser for help on using the repository browser.