source: 3DVCSoftware/branches/HTM-15.1-dev0/source/Lib/TLibEncoder/SEIwrite.cpp @ 1327

Last change on this file since 1327 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

  • Property svn:eol-style set to native
File size: 31.8 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-2015, 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 "TLibCommon/TComPicYuv.h"
39#include "SEIwrite.h"
40
41//! \ingroup TLibEncoder
42//! \{
43
44#if ENC_DEC_TRACE
45Void  xTraceSEIHeader()
46{
47  fprintf( g_hTrace, "=========== SEI message ===========\n");
48}
49
50Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
51{
52  fprintf( g_hTrace, "=========== %s SEI message ===========\n", SEI::getSEIMessageString(payloadType));
53}
54#endif
55
56Void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, const TComSPS *sps)
57{
58  switch (sei.payloadType())
59  {
60  case SEI::USER_DATA_UNREGISTERED:
61    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
62    break;
63  case SEI::ACTIVE_PARAMETER_SETS:
64    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei));
65    break;
66  case SEI::DECODING_UNIT_INFO:
67    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
68    break;
69  case SEI::DECODED_PICTURE_HASH:
70    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
71    break;
72  case SEI::BUFFERING_PERIOD:
73    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
74    break;
75  case SEI::PICTURE_TIMING:
76    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
77    break;
78  case SEI::RECOVERY_POINT:
79    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
80    break;
81  case SEI::FRAME_PACKING:
82    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
83    break;
84  case SEI::SEGM_RECT_FRAME_PACKING:
85    xWriteSEISegmentedRectFramePacking(*static_cast<const SEISegmentedRectFramePacking*>(&sei));
86    break;
87  case SEI::DISPLAY_ORIENTATION:
88    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
89    break;
90  case SEI::TEMPORAL_LEVEL0_INDEX:
91    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
92    break;
93  case SEI::REGION_REFRESH_INFO:
94    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
95    break;
96  case SEI::NO_DISPLAY:
97    xWriteSEINoDisplay(*static_cast<const SEINoDisplay*>(&sei));
98    break;
99  case SEI::TONE_MAPPING_INFO:
100    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
101    break;
102  case SEI::SOP_DESCRIPTION:
103    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
104    break;
105  case SEI::SCALABLE_NESTING:
106    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
107    break;
108  case SEI::CHROMA_SAMPLING_FILTER_HINT:
109    xWriteSEIChromaSamplingFilterHint(*static_cast<const SEIChromaSamplingFilterHint*>(&sei)/*, sps*/);
110    break;
111  case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
112    xWriteSEITempMotionConstrainedTileSets(*static_cast<const SEITempMotionConstrainedTileSets*>(&sei));
113    break;
114  case SEI::TIME_CODE:
115    xWriteSEITimeCode(*static_cast<const SEITimeCode*>(&sei));
116    break;
117  case SEI::KNEE_FUNCTION_INFO:
118    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
119    break;
120  case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
121    xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
122    break;
123#if NH_MV
124   case SEI::SUB_BITSTREAM_PROPERTY:
125   xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
126   break;
127#endif
128
129  default:
130    assert(!"Unhandled SEI message");
131    break;
132  }
133  xWriteByteAlign();
134}
135
136/**
137 * marshal all SEI messages in provided list into one bitstream bs
138 */
139Void SEIWriter::writeSEImessages(TComBitIf& bs, const SEIMessages &seiList, const TComSPS *sps, Bool isNested)
140{
141#if ENC_DEC_TRACE
142  if (g_HLSTraceEnable)
143    xTraceSEIHeader();
144#endif
145
146  TComBitCounter bs_count;
147
148  for (SEIMessages::const_iterator sei=seiList.begin(); sei!=seiList.end(); sei++)
149  {
150    // calculate how large the payload data is
151    // TODO: this would be far nicer if it used vectored buffers
152    bs_count.resetBits();
153    setBitstream(&bs_count);
154
155#if ENC_DEC_TRACE
156    Bool traceEnable = g_HLSTraceEnable;
157    g_HLSTraceEnable = false;
158#endif
159    xWriteSEIpayloadData(bs_count, **sei, sps);
160#if ENC_DEC_TRACE
161    g_HLSTraceEnable = traceEnable;
162#endif
163    UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
164    assert(0 == payload_data_num_bits % 8);
165
166    setBitstream(&bs);
167    UInt payloadType = (*sei)->payloadType();
168    for (; payloadType >= 0xff; payloadType -= 0xff)
169    {
170      WRITE_CODE(0xff, 8, "payload_type");
171    }
172    WRITE_CODE(payloadType, 8, "payload_type");
173
174    UInt payloadSize = payload_data_num_bits/8;
175    for (; payloadSize >= 0xff; payloadSize -= 0xff)
176    {
177      WRITE_CODE(0xff, 8, "payload_size");
178    }
179    WRITE_CODE(payloadSize, 8, "payload_size");
180
181    /* payloadData */
182#if ENC_DEC_TRACE
183    if (g_HLSTraceEnable)
184      xTraceSEIMessageType((*sei)->payloadType());
185#endif
186
187    xWriteSEIpayloadData(bs, **sei, sps);
188  }
189  if (!isNested)
190  {
191    xWriteRbspTrailingBits();
192  }
193}
194
195/**
196 * marshal a user_data_unregistered SEI message sei, storing the marshalled
197 * representation in bitstream bs.
198 */
199Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
200{
201  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
202  {
203    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
204  }
205
206  for (UInt i = 0; i < sei.userDataLength; i++)
207  {
208    WRITE_CODE(sei.userData[i], 8 , "user_data");
209  }
210}
211
212/**
213 * marshal a decoded picture hash SEI message, storing the marshalled
214 * representation in bitstream bs.
215 */
216Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
217{
218  const Char *traceString="\0";
219  switch (sei.method)
220  {
221    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
222    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
223    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
224    default: assert(false); break;
225  }
226
227  if (traceString != 0) //use of this variable is needed to avoid a compiler error with G++ 4.6.1
228  {
229    WRITE_CODE(sei.method, 8, "hash_type");
230    for(UInt i=0; i<UInt(sei.m_pictureHash.hash.size()); i++)
231    {
232      WRITE_CODE(sei.m_pictureHash.hash[i], 8, traceString);
233    }
234  }
235}
236
237Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
238{
239  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
240  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
241  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
242  WRITE_UVLC(sei.numSpsIdsMinus1,            "num_sps_ids_minus1");
243
244  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
245
246  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
247  {
248    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
249  }
250}
251
252Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, const TComSPS *sps)
253{
254  const TComVUI *vui = sps->getVuiParameters();
255  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
256  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
257  {
258    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay_increment");
259  }
260  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
261  if(sei.m_dpbOutputDuDelayPresentFlag)
262  {
263    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
264  }
265}
266
267Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, const TComSPS *sps)
268{
269  Int i, nalOrVcl;
270  const TComVUI *vui = sps->getVuiParameters();
271  const TComHRD *hrd = vui->getHrdParameters();
272
273  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
274  if( !hrd->getSubPicCpbParamsPresentFlag() )
275  {
276    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
277  }
278  if( sei.m_rapCpbParamsPresentFlag )
279  {
280    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
281    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
282  }
283  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
284  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
285  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
286  {
287    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
288        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
289    {
290      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
291      {
292        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
293        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
294        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
295        {
296          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
297          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
298        }
299      }
300    }
301  }
302}
303Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei, const TComSPS *sps)
304{
305  Int i;
306  const TComVUI *vui = sps->getVuiParameters();
307  const TComHRD *hrd = vui->getHrdParameters();
308
309  if( vui->getFrameFieldInfoPresentFlag() )
310  {
311    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
312    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
313    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
314  }
315
316  if( hrd->getCpbDpbDelaysPresentFlag() )
317  {
318    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
319    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
320    if(hrd->getSubPicCpbParamsPresentFlag())
321    {
322      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
323    }
324    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
325    {
326      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
327      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
328      if( sei.m_duCommonCpbRemovalDelayFlag )
329      {
330        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
331      }
332      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
333      {
334        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
335        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
336        {
337          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
338        }
339      }
340    }
341  }
342}
343Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
344{
345  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
346  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
347  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
348}
349Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
350{
351  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
352  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
353
354  if( sei.m_arrangementCancelFlag == 0 )
355  {
356    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
357
358    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
359    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
360    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
361    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
362    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
363    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
364
365    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
366    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
367
368    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
369    {
370      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
371      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
372      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
373      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
374    }
375
376    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
377    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
378  }
379
380  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
381}
382
383Void SEIWriter::xWriteSEISegmentedRectFramePacking(const SEISegmentedRectFramePacking& sei)
384{
385  WRITE_FLAG( sei.m_arrangementCancelFlag,          "segmented_rect_frame_packing_arrangement_cancel_flag" );
386  if( sei.m_arrangementCancelFlag == 0 ) 
387  {
388    WRITE_CODE( sei.m_contentInterpretationType, 2, "segmented_rect_content_interpretation_type" );
389    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "segmented_rect_frame_packing_arrangement_persistence" );
390  }
391}
392
393Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
394{
395  Int i;
396  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
397  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
398  if( !sei.m_toneMapCancelFlag )
399  {
400    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
401    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
402    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
403    WRITE_UVLC( sei.m_modelId,                    "model_id" );
404    switch(sei.m_modelId)
405    {
406    case 0:
407      {
408        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
409        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
410        break;
411      }
412    case 1:
413      {
414        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
415        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
416        break;
417      }
418    case 2:
419      {
420        UInt num = 1u << sei.m_targetBitDepth;
421        for(i = 0; i < num; i++)
422        {
423          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
424        }
425        break;
426      }
427    case 3:
428      {
429        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
430        for(i = 0; i < sei.m_numPivots; i++ )
431        {
432          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
433          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
434        }
435        break;
436      }
437    case 4:
438      {
439        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
440        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
441        {
442          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
443        }
444        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
445        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
446        {
447          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
448        }
449        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
450        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
451        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
452        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
453        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
454        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
455        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
456        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
457        break;
458      }
459    default:
460      {
461        assert(!"Undefined SEIToneMapModelId");
462        break;
463      }
464    }//switch m_modelId
465  }//if(!sei.m_toneMapCancelFlag)
466}
467
468Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
469{
470  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
471  if( !sei.cancelFlag )
472  {
473    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
474    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
475    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
476    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
477  }
478}
479
480Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
481{
482  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
483  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
484}
485
486Void SEIWriter::xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei)
487{
488  WRITE_FLAG( sei.m_gdrForegroundFlag, "gdr_foreground_flag");
489}
490
491Void SEIWriter::xWriteSEINoDisplay(const SEINoDisplay& /*sei*/)
492{
493}
494
495Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
496{
497  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
498  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
499  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
500  {
501    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
502    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
503    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
504    {
505      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
506    }
507    if (i > 0)
508    {
509      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
510    }
511  }
512}
513
514Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, const TComSPS *sps)
515{
516  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
517  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
518  if (sei.m_nestingOpFlag)
519  {
520    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
521    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops_minus1"        );
522    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
523    {
524      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id_plus1" );
525      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
526    }
527  }
528  else
529  {
530    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
531    if (!sei.m_allLayersFlag)
532    {
533      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id_plus1" );
534      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"                  );
535      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
536      {
537        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
538      }
539    }
540  }
541
542  // byte alignment
543  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
544  {
545    WRITE_FLAG( 0, "nesting_zero_bit" );
546  }
547
548  // write nested SEI messages
549  writeSEImessages(bs, sei.m_nestedSEIs, sps, true);
550}
551
552Void SEIWriter::xWriteSEITempMotionConstrainedTileSets(const SEITempMotionConstrainedTileSets& sei)
553{
554  //UInt code;
555  WRITE_FLAG((sei.m_mc_all_tiles_exact_sample_value_match_flag ? 1 : 0), "mc_all_tiles_exact_sample_value_match_flag"); 
556  WRITE_FLAG((sei.m_each_tile_one_tile_set_flag                ? 1 : 0), "each_tile_one_tile_set_flag"               );
557
558  if(!sei.m_each_tile_one_tile_set_flag)
559  {
560    WRITE_FLAG((sei.m_limited_tile_set_display_flag ? 1 : 0), "limited_tile_set_display_flag");
561    WRITE_UVLC((sei.getNumberOfTileSets() - 1),               "num_sets_in_message_minus1"   );
562
563    if(sei.getNumberOfTileSets() > 0)
564    {
565      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
566      {
567        WRITE_UVLC(sei.tileSetData(i).m_mcts_id, "mcts_id");
568
569        if(sei.m_limited_tile_set_display_flag)
570        { 
571          WRITE_FLAG((sei.tileSetData(i).m_display_tile_set_flag ? 1 : 0), "display_tile_set_flag"); 
572        }
573
574        WRITE_UVLC((sei.tileSetData(i).getNumberOfTileRects() - 1), "num_tile_rects_in_set_minus1"); 
575       
576        for(Int j = 0; j < sei.tileSetData(i).getNumberOfTileRects(); j++)
577        {
578          WRITE_UVLC(sei.tileSetData(i).topLeftTileIndex    (j), "top_left_tile_index"); 
579          WRITE_UVLC(sei.tileSetData(i).bottomRightTileIndex(j), "bottom_right_tile_index"); 
580        }
581
582        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
583        {
584          WRITE_FLAG((sei.tileSetData(i).m_exact_sample_value_match_flag ? 1 : 0), "exact_sample_value_match_flag"); 
585        }
586
587        WRITE_FLAG((sei.tileSetData(i).m_mcts_tier_level_idc_present_flag ? 1 : 0), "mcts_tier_level_idc_present_flag");
588
589        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
590        {
591          WRITE_FLAG((sei.tileSetData(i).m_mcts_tier_flag ? 1 : 0), "mcts_tier_flag");
592          WRITE_CODE( sei.tileSetData(i).m_mcts_level_idc, 8,       "mcts_level_idc"); 
593        }
594      }
595    }
596  }
597  else
598  {
599    WRITE_FLAG((sei.m_max_mcs_tier_level_idc_present_flag ? 1 : 0), "max_mcs_tier_level_idc_present_flag");
600
601    if(sei.m_max_mcs_tier_level_idc_present_flag)
602    {
603      WRITE_FLAG((sei.m_max_mcts_tier_flag ? 1 : 0), "max_mcts_tier_flag"); 
604      WRITE_CODE( sei.m_max_mcts_level_idc, 8,       "max_mcts_level_idc"); 
605    }
606  }
607}
608
609Void SEIWriter::xWriteSEITimeCode(const SEITimeCode& sei)
610{
611  WRITE_CODE(sei.numClockTs, 2, "num_clock_ts");
612  for(Int i = 0; i < sei.numClockTs; i++)
613  {
614    const TComSEITimeSet &currentTimeSet = sei.timeSetArray[i];
615    WRITE_FLAG(currentTimeSet.clockTimeStampFlag, "clock_time_stamp_flag");
616    if(currentTimeSet.clockTimeStampFlag)
617    {
618      WRITE_FLAG(currentTimeSet.numUnitFieldBasedFlag, "units_field_based_flag");
619      WRITE_CODE(currentTimeSet.countingType, 5, "counting_type");
620      WRITE_FLAG(currentTimeSet.fullTimeStampFlag, "full_timestamp_flag");
621      WRITE_FLAG(currentTimeSet.discontinuityFlag, "discontinuity_flag");
622      WRITE_FLAG(currentTimeSet.cntDroppedFlag, "cnt_dropped_flag");
623      WRITE_CODE(currentTimeSet.numberOfFrames, 9, "n_frames");
624      if(currentTimeSet.fullTimeStampFlag)
625      {
626        WRITE_CODE(currentTimeSet.secondsValue, 6, "seconds_value");
627        WRITE_CODE(currentTimeSet.minutesValue, 6, "minutes_value");
628        WRITE_CODE(currentTimeSet.hoursValue, 5, "hours_value");
629      }
630      else
631      {
632        WRITE_FLAG(currentTimeSet.secondsFlag, "seconds_flag");
633        if(currentTimeSet.secondsFlag)
634        {
635          WRITE_CODE(currentTimeSet.secondsValue, 6, "seconds_value");
636          WRITE_FLAG(currentTimeSet.minutesFlag, "minutes_flag");
637          if(currentTimeSet.minutesFlag)
638          {
639            WRITE_CODE(currentTimeSet.minutesValue, 6, "minutes_value");
640            WRITE_FLAG(currentTimeSet.hoursFlag, "hours_flag");
641            if(currentTimeSet.hoursFlag)
642            {
643              WRITE_CODE(currentTimeSet.hoursValue, 5, "hours_value");
644            }
645          }
646        }
647      }
648      WRITE_CODE(currentTimeSet.timeOffsetLength, 5, "time_offset_length");
649      if(currentTimeSet.timeOffsetLength > 0)
650      {
651        if(currentTimeSet.timeOffsetValue >= 0)
652        {
653          WRITE_CODE((UInt)currentTimeSet.timeOffsetValue, currentTimeSet.timeOffsetLength, "time_offset_value");
654        }
655        else
656        {
657          //  Two's complement conversion
658          UInt offsetValue = ~(currentTimeSet.timeOffsetValue) + 1;
659          offsetValue |= (1 << (currentTimeSet.timeOffsetLength-1));
660          WRITE_CODE(offsetValue, currentTimeSet.timeOffsetLength, "time_offset_value");
661        }
662      }
663    }
664  }
665}
666
667Void SEIWriter::xWriteSEIChromaSamplingFilterHint(const SEIChromaSamplingFilterHint &sei/*, TComSPS* sps*/)
668{
669  WRITE_CODE(sei.m_verChromaFilterIdc, 8, "ver_chroma_filter_idc");
670  WRITE_CODE(sei.m_horChromaFilterIdc, 8, "hor_chroma_filter_idc");
671  WRITE_FLAG(sei.m_verFilteringProcessFlag, "ver_filtering_process_flag");
672  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
673  {
674    writeUserDefinedCoefficients(sei);
675  }
676}
677
678// write hardcoded chroma filter coefficients in the SEI messages
679Void SEIWriter::writeUserDefinedCoefficients(const SEIChromaSamplingFilterHint &sei)
680{
681  Int const iNumVerticalFilters = 3;
682  Int verticalTapLength_minus1[iNumVerticalFilters] = {5,3,3};
683  Int* userVerticalCoefficients[iNumVerticalFilters];
684  for(Int i = 0; i < iNumVerticalFilters; i ++)
685  {
686    userVerticalCoefficients[i] = (Int*)malloc( (verticalTapLength_minus1[i]+1) * sizeof(Int));
687  }
688  userVerticalCoefficients[0][0] = -3;
689  userVerticalCoefficients[0][1] = 13;
690  userVerticalCoefficients[0][2] = 31;
691  userVerticalCoefficients[0][3] = 23;
692  userVerticalCoefficients[0][4] = 3;
693  userVerticalCoefficients[0][5] = -3;
694
695  userVerticalCoefficients[1][0] = -1;
696  userVerticalCoefficients[1][1] = 25;
697  userVerticalCoefficients[1][2] = 247;
698  userVerticalCoefficients[1][3] = -15;
699
700  userVerticalCoefficients[2][0] = -20;
701  userVerticalCoefficients[2][1] = 186;
702  userVerticalCoefficients[2][2] = 100;
703  userVerticalCoefficients[2][3] = -10;
704 
705  Int const iNumHorizontalFilters = 1;
706  Int horizontalTapLength_minus1[iNumHorizontalFilters] = {3};
707  Int* userHorizontalCoefficients[iNumHorizontalFilters];
708  for(Int i = 0; i < iNumHorizontalFilters; i ++)
709  {
710    userHorizontalCoefficients[i] = (Int*)malloc( (horizontalTapLength_minus1[i]+1) * sizeof(Int));
711  }
712  userHorizontalCoefficients[0][0] = 1;
713  userHorizontalCoefficients[0][1] = 6;
714  userHorizontalCoefficients[0][2] = 1;
715
716  WRITE_UVLC(3, "target_format_idc");
717  if(sei.m_verChromaFilterIdc == 1)
718  {
719    WRITE_UVLC(iNumVerticalFilters, "num_vertical_filters");
720    if(iNumVerticalFilters > 0)
721    {
722      for(Int i = 0; i < iNumVerticalFilters; i ++)
723      {
724        WRITE_UVLC(verticalTapLength_minus1[i], "ver_tap_length_minus_1");
725        for(Int j = 0; j < verticalTapLength_minus1[i]; j ++)
726        {
727          WRITE_SVLC(userVerticalCoefficients[i][j], "ver_filter_coeff");
728        }
729      }
730    }
731  }
732  if(sei.m_horChromaFilterIdc == 1)
733  {
734    WRITE_UVLC(iNumHorizontalFilters, "num_horizontal_filters");
735    if(iNumHorizontalFilters > 0)
736    {
737      for(Int i = 0; i < iNumHorizontalFilters; i ++)
738      {
739        WRITE_UVLC(horizontalTapLength_minus1[i], "hor_tap_length_minus_1");
740        for(Int j = 0; j < horizontalTapLength_minus1[i]; j ++)
741        {
742          WRITE_SVLC(userHorizontalCoefficients[i][j], "hor_filter_coeff");
743        }
744      }
745    }
746  }
747}
748
749#if NH_MV
750Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
751{
752  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
753  assert( sei.m_numAdditionalSubStreams >= 1 );
754  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
755
756  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
757  {
758    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
759    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
760    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
761    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
762    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
763  }
764  xWriteByteAlign();
765}
766#endif
767
768Void SEIWriter::xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei)
769{
770  WRITE_UVLC( sei.m_kneeId, "knee_function_id" );
771  WRITE_FLAG( sei.m_kneeCancelFlag, "knee_function_cancel_flag" ); 
772  if ( !sei.m_kneeCancelFlag )
773  {
774    WRITE_FLAG( sei.m_kneePersistenceFlag, "knee_function_persistence_flag" );
775    WRITE_CODE( (UInt)sei.m_kneeInputDrange , 32,  "input_d_range" );
776    WRITE_CODE( (UInt)sei.m_kneeInputDispLuminance, 32,  "input_disp_luminance" );
777    WRITE_CODE( (UInt)sei.m_kneeOutputDrange, 32,  "output_d_range" );
778    WRITE_CODE( (UInt)sei.m_kneeOutputDispLuminance, 32,  "output_disp_luminance" );
779    WRITE_UVLC( sei.m_kneeNumKneePointsMinus1, "num_knee_points_minus1" );
780    for(Int i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
781    {
782      WRITE_CODE( (UInt)sei.m_kneeInputKneePoint[i], 10,"input_knee_point" );
783      WRITE_CODE( (UInt)sei.m_kneeOutputKneePoint[i], 10, "output_knee_point" );
784    }
785  }
786}
787
788
789Void SEIWriter::xWriteSEIMasteringDisplayColourVolume(const SEIMasteringDisplayColourVolume& sei)
790{
791  WRITE_CODE( sei.values.primaries[0][0],  16,  "display_primaries_x[0]" );
792  WRITE_CODE( sei.values.primaries[0][1],  16,  "display_primaries_y[0]" );
793
794  WRITE_CODE( sei.values.primaries[1][0],  16,  "display_primaries_x[1]" );
795  WRITE_CODE( sei.values.primaries[1][1],  16,  "display_primaries_y[1]" );
796
797  WRITE_CODE( sei.values.primaries[2][0],  16,  "display_primaries_x[2]" );
798  WRITE_CODE( sei.values.primaries[2][1],  16,  "display_primaries_y[2]" );
799
800  WRITE_CODE( sei.values.whitePoint[0],    16,  "white_point_x" );
801  WRITE_CODE( sei.values.whitePoint[1],    16,  "white_point_y" );
802   
803  WRITE_CODE( sei.values.maxLuminance,     32,  "max_display_mastering_luminance" );
804  WRITE_CODE( sei.values.minLuminance,     32,  "min_display_mastering_luminance" );
805}
806
807
808Void SEIWriter::xWriteByteAlign()
809{
810  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
811  {
812    WRITE_FLAG( 1, "payload_bit_equal_to_one" );
813    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
814    {
815      WRITE_FLAG( 0, "payload_bit_equal_to_zero" );
816    }
817  }
818}
819
820//! \}
Note: See TracBrowser for help on using the repository browser.