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

Last change on this file since 225 was 191, checked in by seregin, 12 years ago

unix2dos for *.cpp and *.h

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