source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibEncoder/SEIwrite.cpp @ 292

Last change on this file since 292 was 292, checked in by vidyo, 11 years ago

Implementation of M0043 - Layers Present SEI.
This is disabled by default. Enable this by setting M0043_LAYERS_PRESENT_SEI to 1

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