source: SHVCSoftware/branches/SHM-5.0-dev/source/Lib/TLibEncoder/SEIwrite.cpp @ 1348

Last change on this file since 1348 was 593, checked in by seregin, 11 years ago

update to HM-13.0

  • Property svn:eol-style set to native
File size: 26.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#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  case SEI::SOP_DESCRIPTION:
90    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
91    break;
92  case SEI::SCALABLE_NESTING:
93    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
94    break;
95#if SVC_EXTENSION
96#if LAYERS_NOT_PRESENT_SEI
97  case SEI::LAYERS_NOT_PRESENT:
98    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
99    break;
100#endif
101#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
102  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
103    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
104    break;
105#endif
106#if SUB_BITSTREAM_PROPERTY_SEI
107    case SEI::SUB_BITSTREAM_PROPERTY:
108      fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
109      break;
110#endif
111#endif //SVC_EXTENSION
112  default:
113    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
114    break;
115  }
116}
117#endif
118
119void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
120{
121  switch (sei.payloadType())
122  {
123  case SEI::USER_DATA_UNREGISTERED:
124    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
125    break;
126  case SEI::ACTIVE_PARAMETER_SETS:
127    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei)); 
128    break; 
129  case SEI::DECODING_UNIT_INFO:
130    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
131    break;
132  case SEI::DECODED_PICTURE_HASH:
133    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
134    break;
135  case SEI::BUFFERING_PERIOD:
136    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
137    break;
138  case SEI::PICTURE_TIMING:
139    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
140    break;
141  case SEI::RECOVERY_POINT:
142    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
143    break;
144  case SEI::FRAME_PACKING:
145    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
146    break;
147  case SEI::DISPLAY_ORIENTATION:
148    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
149    break;
150  case SEI::TEMPORAL_LEVEL0_INDEX:
151    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
152    break;
153  case SEI::REGION_REFRESH_INFO:
154    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
155    break;
156  case SEI::TONE_MAPPING_INFO:
157    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
158    break;
159  case SEI::SOP_DESCRIPTION:
160    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
161    break;
162  case SEI::SCALABLE_NESTING:
163    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
164    break;
165#if SVC_EXTENSION
166#if LAYERS_NOT_PRESENT_SEI
167  case SEI::LAYERS_NOT_PRESENT:
168    xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
169    break;
170#endif
171#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
172  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
173    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
174    break;
175#endif
176#if SUB_BITSTREAM_PROPERTY_SEI
177   case SEI::SUB_BITSTREAM_PROPERTY:
178     xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
179     break;
180#endif
181#endif //SVC_EXTENSION
182  default:
183    assert(!"Unhandled SEI message");
184  }
185}
186
187/**
188 * marshal a single SEI message sei, storing the marshalled representation
189 * in bitstream bs.
190 */
191Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
192{
193  /* calculate how large the payload data is */
194  /* TODO: this would be far nicer if it used vectored buffers */
195  TComBitCounter bs_count;
196  bs_count.resetBits();
197  setBitstream(&bs_count);
198
199
200#if ENC_DEC_TRACE
201  Bool traceEnable = g_HLSTraceEnable;
202  g_HLSTraceEnable = false;
203#endif
204  xWriteSEIpayloadData(bs_count, sei, sps);
205#if ENC_DEC_TRACE
206  g_HLSTraceEnable = traceEnable;
207#endif
208
209  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
210  assert(0 == payload_data_num_bits % 8);
211
212  setBitstream(&bs);
213
214#if ENC_DEC_TRACE
215  if (g_HLSTraceEnable)
216  xTraceSEIHeader();
217#endif
218
219  UInt payloadType = sei.payloadType();
220  for (; payloadType >= 0xff; payloadType -= 0xff)
221  {
222    WRITE_CODE(0xff, 8, "payload_type");
223  }
224  WRITE_CODE(payloadType, 8, "payload_type");
225
226  UInt payloadSize = payload_data_num_bits/8;
227  for (; payloadSize >= 0xff; payloadSize -= 0xff)
228  {
229    WRITE_CODE(0xff, 8, "payload_size");
230  }
231  WRITE_CODE(payloadSize, 8, "payload_size");
232
233  /* payloadData */
234#if ENC_DEC_TRACE
235  if (g_HLSTraceEnable)
236  xTraceSEIMessageType(sei.payloadType());
237#endif
238
239  xWriteSEIpayloadData(bs, sei, sps);
240}
241
242/**
243 * marshal a user_data_unregistered SEI message sei, storing the marshalled
244 * representation in bitstream bs.
245 */
246Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
247{
248  for (UInt i = 0; i < 16; i++)
249  {
250    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
251  }
252
253  for (UInt i = 0; i < sei.userDataLength; i++)
254  {
255    WRITE_CODE(sei.userData[i], 8 , "user_data");
256  }
257}
258
259/**
260 * marshal a decoded picture hash SEI message, storing the marshalled
261 * representation in bitstream bs.
262 */
263Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
264{
265  UInt val;
266
267  WRITE_CODE(sei.method, 8, "hash_type");
268
269  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
270  {
271    if(sei.method == SEIDecodedPictureHash::MD5)
272    {
273      for (UInt i = 0; i < 16; i++)
274      {
275        WRITE_CODE(sei.digest[yuvIdx][i], 8, "picture_md5");
276      }
277    }
278    else if(sei.method == SEIDecodedPictureHash::CRC)
279    {
280      val = (sei.digest[yuvIdx][0] << 8)  + sei.digest[yuvIdx][1];
281      WRITE_CODE(val, 16, "picture_crc");
282    }
283    else if(sei.method == SEIDecodedPictureHash::CHECKSUM)
284    {
285      val = (sei.digest[yuvIdx][0] << 24)  + (sei.digest[yuvIdx][1] << 16) + (sei.digest[yuvIdx][2] << 8) + sei.digest[yuvIdx][3];
286      WRITE_CODE(val, 32, "picture_checksum");
287    }
288  }
289}
290
291Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
292{
293  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
294  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
295  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
296  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
297
298  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));
299
300  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
301  {
302    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
303  }
304
305  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
306  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8; 
307  if(uiAlignedBits) 
308  {
309    WRITE_FLAG(1, "alignment_bit" );
310    uiAlignedBits--; 
311    while(uiAlignedBits--)
312    {
313      WRITE_FLAG(0, "alignment_bit" );
314    }
315  }
316}
317
318Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps)
319{
320  TComVUI *vui = sps->getVuiParameters();
321  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
322  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
323  {
324    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
325  }
326  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
327  if(sei.m_dpbOutputDuDelayPresentFlag)
328  {
329    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
330  }
331  xWriteByteAlign();
332}
333
334Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
335{
336  Int i, nalOrVcl;
337  TComVUI *vui = sps->getVuiParameters();
338  TComHRD *hrd = vui->getHrdParameters();
339
340  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
341  if( !hrd->getSubPicCpbParamsPresentFlag() )
342  {
343    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
344  }
345  if( sei.m_rapCpbParamsPresentFlag )
346  {
347    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
348    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
349  }
350  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
351  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
352  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
353  {
354    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
355        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
356    {
357      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
358      {
359        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
360        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
361        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
362        {
363          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
364          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
365        }
366      }
367    }
368  }
369  xWriteByteAlign();
370}
371Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
372{
373  Int i;
374  TComVUI *vui = sps->getVuiParameters();
375  TComHRD *hrd = vui->getHrdParameters();
376
377  if( vui->getFrameFieldInfoPresentFlag() )
378  {
379    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
380    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
381    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
382  }
383
384  if( hrd->getCpbDpbDelaysPresentFlag() )
385  {
386    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
387    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
388    if(hrd->getSubPicCpbParamsPresentFlag())
389    {
390      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
391    }
392    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
393    {
394      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
395      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
396      if( sei.m_duCommonCpbRemovalDelayFlag )
397      {
398        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
399      }
400      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
401      {
402        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
403        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
404        {
405          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
406        }
407      }
408    }
409  }
410  xWriteByteAlign();
411}
412Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
413{
414  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
415  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
416  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
417  xWriteByteAlign();
418}
419Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
420{
421  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
422  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
423
424  if( sei.m_arrangementCancelFlag == 0 ) {
425    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
426
427    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
428    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
429    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
430    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
431    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
432    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
433
434    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
435    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
436
437    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
438    {
439      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
440      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
441      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
442      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
443    }
444
445    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
446    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
447  }
448
449  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
450
451  xWriteByteAlign();
452}
453
454Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
455{
456  Int i;
457  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
458  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
459  if( !sei.m_toneMapCancelFlag ) 
460  {
461    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
462    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
463    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
464    WRITE_UVLC( sei.m_modelId,                    "model_id" );
465    switch(sei.m_modelId)
466    {
467    case 0:
468      {
469        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
470        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
471        break;
472      }
473    case 1:
474      {
475        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
476        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
477        break;
478      }
479    case 2:
480      {
481        UInt num = 1u << sei.m_targetBitDepth;
482        for(i = 0; i < num; i++)
483        {
484          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
485        }
486        break;
487      }
488    case 3:
489      {
490        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
491        for(i = 0; i < sei.m_numPivots; i++ )
492        {
493          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
494          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
495        }
496        break;
497      }
498    case 4:
499      {
500        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
501        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
502        {
503          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
504        }
505        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
506        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
507        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
508        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
509        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
510        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
511        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
512        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
513        break;
514      }
515    default:
516      {
517        assert(!"Undefined SEIToneMapModelId");
518        break;
519      }
520    }//switch m_modelId
521  }//if(!sei.m_toneMapCancelFlag)
522
523  xWriteByteAlign();
524}
525
526Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
527{
528  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
529  if( !sei.cancelFlag )
530  {
531    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
532    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
533    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
534    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
535  }
536  xWriteByteAlign();
537}
538
539Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
540{
541  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
542  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
543  xWriteByteAlign();
544}
545
546Void SEIWriter::xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei)
547{
548  WRITE_FLAG( sei.m_gdrForegroundFlag, "gdr_foreground_flag");
549  xWriteByteAlign();
550}
551
552Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
553{
554  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
555  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
556  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
557  {
558    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
559    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
560    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
561    {
562      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
563    }
564    if (i > 0)
565    {
566      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
567    }
568  }
569
570  xWriteByteAlign();
571}
572
573Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
574{
575  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
576  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
577  if (sei.m_nestingOpFlag)
578  {
579    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
580    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
581    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
582    {
583      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
584      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
585      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
586    }
587  }
588  else
589  {
590    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
591    if (!sei.m_allLayersFlag)
592    {
593      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
594      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
595      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
596      {
597        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
598      }
599    }
600  }
601 
602  // byte alignment
603  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
604  {
605    WRITE_FLAG( 0, "nesting_zero_bit" );
606  }
607
608  // write nested SEI messages
609  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
610  {
611    writeSEImessage(bs, *(*it), sps);
612  }
613}
614
615Void SEIWriter::xWriteByteAlign()
616{
617  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
618  {
619    WRITE_FLAG( 1, "bit_equal_to_one" );
620    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
621    {
622      WRITE_FLAG( 0, "bit_equal_to_zero" );
623    }
624  }
625};
626
627#if SVC_EXTENSION
628#if LAYERS_NOT_PRESENT_SEI
629Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
630{
631  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
632  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
633  {
634    WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
635  }
636  xWriteByteAlign();
637}
638#endif
639
640#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
641Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
642{
643  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
644  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
645  if( !sei.m_ilOneTilePerTileSetFlag )
646  {
647    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
648    if( sei.m_ilNumSetsInMessageMinus1 )
649    {
650      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
651    }
652    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
653    for( UInt i = 0; i < numSignificantSets; i++ )
654    {
655      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
656      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
657      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
658      {
659        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
660        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
661      }
662      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
663      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
664      {
665        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
666      }
667    }
668  }
669  else
670  {
671    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
672  }
673
674  xWriteByteAlign();
675}
676#endif
677#if SUB_BITSTREAM_PROPERTY_SEI
678Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
679{
680  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
681  assert( sei.m_numAdditionalSubStreams >= 1 );
682  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
683
684  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
685  {
686    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
687    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
688    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
689    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
690    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
691  }
692  xWriteByteAlign();
693}
694#endif
695#endif //SVC_EXTENSION
696
697//! \}
Note: See TracBrowser for help on using the repository browser.