source: 3DVCSoftware/branches/HTM-13.1-dev1-Samsung2/source/Lib/TLibEncoder/SEIwrite.cpp @ 1159

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