source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp @ 794

Last change on this file since 794 was 780, checked in by nokia, 11 years ago

software implementation for JCTVC-Q0247

  • Property svn:eol-style set to native
File size: 41.6 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#if P0050_KNEE_FUNCTION_SEI
90  case SEI::KNEE_FUNCTION_INFO:
91    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
92    break;
93#endif
94#if Q0074_SEI_COLOR_MAPPING
95  case SEI::COLOR_MAPPING_INFO:
96    fprintf( g_hTrace, "=========== Color Mapping Info SEI message ===========\n");
97    break;
98#endif
99  case SEI::SOP_DESCRIPTION:
100    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
101    break;
102  case SEI::SCALABLE_NESTING:
103    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
104    break;
105#if SVC_EXTENSION
106#if LAYERS_NOT_PRESENT_SEI
107  case SEI::LAYERS_NOT_PRESENT:
108    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
109    break;
110#endif
111#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
112  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
113    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
114    break;
115#endif
116#if SUB_BITSTREAM_PROPERTY_SEI
117  case SEI::SUB_BITSTREAM_PROPERTY:
118    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
119    break;
120#endif
121#if O0164_MULTI_LAYER_HRD
122  case SEI::BSP_NESTING:
123    fprintf( g_hTrace, "=========== Bitstream partition nesting SEI message ===========\n");
124    break;
125  case SEI::BSP_INITIAL_ARRIVAL_TIME:
126    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
127    break;
128  case SEI::BSP_HRD:
129    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
130    break;
131#endif
132#if Q0078_ADD_LAYER_SETS
133  case SEI::OUTPUT_LAYER_SET_NESTING:
134    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
135    break;
136  case SEI::VPS_REWRITING:
137    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
138    break;
139#endif
140#endif //SVC_EXTENSION
141  default:
142    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
143    break;
144  }
145}
146#endif
147
148#if O0164_MULTI_LAYER_HRD
149void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei)
150#else
151void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
152#endif
153{
154  switch (sei.payloadType())
155  {
156  case SEI::USER_DATA_UNREGISTERED:
157    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
158    break;
159  case SEI::ACTIVE_PARAMETER_SETS:
160    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei)); 
161    break; 
162  case SEI::DECODING_UNIT_INFO:
163    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
164    break;
165  case SEI::DECODED_PICTURE_HASH:
166    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
167    break;
168  case SEI::BUFFERING_PERIOD:
169    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
170    break;
171  case SEI::PICTURE_TIMING:
172    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
173    break;
174  case SEI::RECOVERY_POINT:
175    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
176    break;
177  case SEI::FRAME_PACKING:
178    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
179    break;
180  case SEI::DISPLAY_ORIENTATION:
181    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
182    break;
183  case SEI::TEMPORAL_LEVEL0_INDEX:
184    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
185    break;
186  case SEI::REGION_REFRESH_INFO:
187    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
188    break;
189  case SEI::TONE_MAPPING_INFO:
190    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
191    break;
192#if P0050_KNEE_FUNCTION_SEI
193  case SEI::KNEE_FUNCTION_INFO:
194    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
195    break;
196#endif
197#if Q0074_SEI_COLOR_MAPPING
198  case SEI::COLOR_MAPPING_INFO:
199    xWriteSEIColorMappingInfo(*static_cast<const SEIColorMappingInfo*>(&sei));
200    break;
201#endif
202  case SEI::SOP_DESCRIPTION:
203    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
204    break;
205  case SEI::SCALABLE_NESTING:
206#if O0164_MULTI_LAYER_HRD
207    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), vps, sps);
208#else
209    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
210#endif
211    break;
212#if SVC_EXTENSION
213#if LAYERS_NOT_PRESENT_SEI
214  case SEI::LAYERS_NOT_PRESENT:
215    xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
216    break;
217#endif
218#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
219  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
220    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
221    break;
222#endif
223#if SUB_BITSTREAM_PROPERTY_SEI
224   case SEI::SUB_BITSTREAM_PROPERTY:
225     xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
226     break;
227#endif
228#if O0164_MULTI_LAYER_HRD
229   case SEI::BSP_NESTING:
230     xWriteSEIBspNesting(bs, *static_cast<const SEIBspNesting*>(&sei), vps, sps, nestingSei);
231     break;
232   case SEI::BSP_INITIAL_ARRIVAL_TIME:
233     xWriteSEIBspInitialArrivalTime(*static_cast<const SEIBspInitialArrivalTime*>(&sei), vps, sps, nestingSei, bspNestingSei);
234     break;
235   case SEI::BSP_HRD:
236     xWriteSEIBspHrd(*static_cast<const SEIBspHrd*>(&sei), sps, nestingSei);
237     break;
238#endif
239#if Q0078_ADD_LAYER_SETS
240   case SEI::OUTPUT_LAYER_SET_NESTING:
241     xWriteSEIOutputLayerSetNesting(bs, *static_cast<const SEIOutputLayerSetNesting*>(&sei), vps, sps);
242     break;
243   case SEI::VPS_REWRITING:
244     xWriteSEIVPSRewriting(*static_cast<const SEIVPSRewriting*>(&sei));
245     break;
246#endif
247#if Q0189_TMVP_CONSTRAINTS
248   case SEI::TMVP_CONSTRAINTS:
249     xWriteSEITMVPConstraints(*static_cast<const SEITMVPConstrains*>(&sei));
250     break;
251#endif
252#if Q0247_FRAME_FIELD_INFO
253   case SEI::FRAME_FIELD_INFO:
254     xWriteSEIFrameFieldInfo(*static_cast<const SEIFrameFieldInfo*>(&sei));
255     break;
256#endif
257#endif //SVC_EXTENSION
258  default:
259    assert(!"Unhandled SEI message");
260  }
261}
262
263/**
264 * marshal a single SEI message sei, storing the marshalled representation
265 * in bitstream bs.
266 */
267#if O0164_MULTI_LAYER_HRD
268Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei)
269#else
270Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
271#endif
272{
273  /* calculate how large the payload data is */
274  /* TODO: this would be far nicer if it used vectored buffers */
275  TComBitCounter bs_count;
276  bs_count.resetBits();
277  setBitstream(&bs_count);
278
279
280#if ENC_DEC_TRACE
281  Bool traceEnable = g_HLSTraceEnable;
282  g_HLSTraceEnable = false;
283#endif
284#if O0164_MULTI_LAYER_HRD
285  xWriteSEIpayloadData(bs_count, sei, vps, sps, *nestingSei, *bspNestingSei);
286#else
287  xWriteSEIpayloadData(bs_count, sei, sps);
288#endif
289#if ENC_DEC_TRACE
290  g_HLSTraceEnable = traceEnable;
291#endif
292
293  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
294  assert(0 == payload_data_num_bits % 8);
295
296  setBitstream(&bs);
297
298#if ENC_DEC_TRACE
299  if (g_HLSTraceEnable)
300  xTraceSEIHeader();
301#endif
302
303  UInt payloadType = sei.payloadType();
304  for (; payloadType >= 0xff; payloadType -= 0xff)
305  {
306    WRITE_CODE(0xff, 8, "payload_type");
307  }
308  WRITE_CODE(payloadType, 8, "payload_type");
309
310  UInt payloadSize = payload_data_num_bits/8;
311  for (; payloadSize >= 0xff; payloadSize -= 0xff)
312  {
313    WRITE_CODE(0xff, 8, "payload_size");
314  }
315  WRITE_CODE(payloadSize, 8, "payload_size");
316
317  /* payloadData */
318#if ENC_DEC_TRACE
319  if (g_HLSTraceEnable)
320  xTraceSEIMessageType(sei.payloadType());
321#endif
322
323#if O0164_MULTI_LAYER_HRD
324  xWriteSEIpayloadData(bs, sei, vps, sps, *nestingSei, *bspNestingSei);
325#else
326  xWriteSEIpayloadData(bs, sei, sps);
327#endif
328}
329
330/**
331 * marshal a user_data_unregistered SEI message sei, storing the marshalled
332 * representation in bitstream bs.
333 */
334Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
335{
336  for (UInt i = 0; i < 16; i++)
337  {
338    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
339  }
340
341  for (UInt i = 0; i < sei.userDataLength; i++)
342  {
343    WRITE_CODE(sei.userData[i], 8 , "user_data");
344  }
345}
346
347/**
348 * marshal a decoded picture hash SEI message, storing the marshalled
349 * representation in bitstream bs.
350 */
351Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
352{
353  UInt val;
354
355  WRITE_CODE(sei.method, 8, "hash_type");
356
357  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
358  {
359    if(sei.method == SEIDecodedPictureHash::MD5)
360    {
361      for (UInt i = 0; i < 16; i++)
362      {
363        WRITE_CODE(sei.digest[yuvIdx][i], 8, "picture_md5");
364      }
365    }
366    else if(sei.method == SEIDecodedPictureHash::CRC)
367    {
368      val = (sei.digest[yuvIdx][0] << 8)  + sei.digest[yuvIdx][1];
369      WRITE_CODE(val, 16, "picture_crc");
370    }
371    else if(sei.method == SEIDecodedPictureHash::CHECKSUM)
372    {
373      val = (sei.digest[yuvIdx][0] << 24)  + (sei.digest[yuvIdx][1] << 16) + (sei.digest[yuvIdx][2] << 8) + sei.digest[yuvIdx][3];
374      WRITE_CODE(val, 32, "picture_checksum");
375    }
376  }
377}
378
379Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
380{
381  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
382  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
383  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
384  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
385
386  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
387
388  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
389  {
390    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
391  }
392  xWriteByteAlign();
393}
394
395Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps)
396{
397  TComVUI *vui = sps->getVuiParameters();
398  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
399  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
400  {
401    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
402  }
403  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
404  if(sei.m_dpbOutputDuDelayPresentFlag)
405  {
406    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
407  }
408  xWriteByteAlign();
409}
410
411Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
412{
413  Int i, nalOrVcl;
414  TComVUI *vui = sps->getVuiParameters();
415  TComHRD *hrd = vui->getHrdParameters();
416
417  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
418  if( !hrd->getSubPicCpbParamsPresentFlag() )
419  {
420    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
421  }
422  if( sei.m_rapCpbParamsPresentFlag )
423  {
424    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
425    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
426  }
427  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
428  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
429  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
430  {
431    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
432        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
433    {
434      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
435      {
436        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
437        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
438        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
439        {
440          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
441          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
442        }
443      }
444    }
445  }
446#if P0138_USE_ALT_CPB_PARAMS_FLAG
447  if (sei.m_useAltCpbParamsFlagPresent)
448  {
449    WRITE_FLAG( sei.m_useAltCpbParamsFlag, "use_alt_cpb_params_flag");
450  }
451#endif
452  xWriteByteAlign();
453}
454Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
455{
456  Int i;
457  TComVUI *vui = sps->getVuiParameters();
458  TComHRD *hrd = vui->getHrdParameters();
459
460  if( vui->getFrameFieldInfoPresentFlag() )
461  {
462    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
463    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
464    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
465  }
466
467  if( hrd->getCpbDpbDelaysPresentFlag() )
468  {
469    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
470    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
471    if(hrd->getSubPicCpbParamsPresentFlag())
472    {
473      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
474    }
475    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
476    {
477      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
478      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
479      if( sei.m_duCommonCpbRemovalDelayFlag )
480      {
481        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
482      }
483      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
484      {
485        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
486        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
487        {
488          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
489        }
490      }
491    }
492  }
493  xWriteByteAlign();
494}
495Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
496{
497  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
498  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
499  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
500  xWriteByteAlign();
501}
502Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
503{
504  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
505  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
506
507  if( sei.m_arrangementCancelFlag == 0 ) {
508    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
509
510    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
511    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
512    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
513    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
514    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
515    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
516
517    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
518    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
519
520    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
521    {
522      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
523      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
524      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
525      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
526    }
527
528    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
529    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
530  }
531
532  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
533
534  xWriteByteAlign();
535}
536
537Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
538{
539  Int i;
540  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
541  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
542  if( !sei.m_toneMapCancelFlag ) 
543  {
544    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
545    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
546    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
547    WRITE_UVLC( sei.m_modelId,                    "model_id" );
548    switch(sei.m_modelId)
549    {
550    case 0:
551      {
552        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
553        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
554        break;
555      }
556    case 1:
557      {
558        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
559        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
560        break;
561      }
562    case 2:
563      {
564        UInt num = 1u << sei.m_targetBitDepth;
565        for(i = 0; i < num; i++)
566        {
567          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
568        }
569        break;
570      }
571    case 3:
572      {
573        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
574        for(i = 0; i < sei.m_numPivots; i++ )
575        {
576          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
577          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
578        }
579        break;
580      }
581    case 4:
582      {
583        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
584        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
585        {
586          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
587        }
588        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
589        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
590        {
591          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
592        }
593        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
594        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
595        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
596        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
597        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
598        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
599        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
600        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
601        break;
602      }
603    default:
604      {
605        assert(!"Undefined SEIToneMapModelId");
606        break;
607      }
608    }//switch m_modelId
609  }//if(!sei.m_toneMapCancelFlag)
610
611  xWriteByteAlign();
612}
613#if P0050_KNEE_FUNCTION_SEI
614Void SEIWriter::xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei)
615{
616  WRITE_UVLC( sei.m_kneeId, "knee_function_id" );
617  WRITE_FLAG( sei.m_kneeCancelFlag, "knee_function_cancel_flag" ); 
618  if ( !sei.m_kneeCancelFlag )
619  {
620    WRITE_FLAG( sei.m_kneePersistenceFlag, "knee_function_persistence_flag" );
621    WRITE_FLAG( sei.m_kneeMappingFlag, "mapping_flag" );
622    WRITE_CODE( (UInt)sei.m_kneeInputDrange , 32,  "input_d_range" );
623    WRITE_CODE( (UInt)sei.m_kneeInputDispLuminance, 32,  "input_disp_luminance" );
624    WRITE_CODE( (UInt)sei.m_kneeOutputDrange, 32,  "output_d_range" );
625    WRITE_CODE( (UInt)sei.m_kneeOutputDispLuminance, 32,  "output_disp_luminance" );
626    WRITE_UVLC( sei.m_kneeNumKneePointsMinus1, "num_knee_points_minus1" );
627    for(Int i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
628    {
629      WRITE_CODE( (UInt)sei.m_kneeInputKneePoint[i], 10,"input_knee_point" );
630      WRITE_CODE( (UInt)sei.m_kneeOutputKneePoint[i], 10, "output_knee_point" );
631    }
632  }
633  xWriteByteAlign();
634}
635#endif
636#if Q0074_SEI_COLOR_MAPPING
637Void SEIWriter::xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei)
638{
639  WRITE_UVLC( sei.m_colorMapId,                    "colour_map_id" );
640  WRITE_FLAG( sei.m_colorMapCancelFlag,            "colour_map_cancel_flag" );
641  if( !sei.m_colorMapCancelFlag ) 
642  {
643    WRITE_FLAG( sei.m_colorMapPersistenceFlag,            "colour_map_persistence_flag" );
644    WRITE_FLAG( sei.m_colorMap_video_signal_type_present_flag,            "colour_map_video_signal_type_present_flag" );
645    if ( sei.m_colorMap_video_signal_type_present_flag )
646    {
647      WRITE_FLAG( sei.m_colorMap_video_full_range_flag,       "colour_map_video_full_range_flag" );
648      WRITE_CODE( sei.m_colorMap_primaries,                 8,      "colour_map_primaries" );
649      WRITE_CODE( sei.m_colorMap_transfer_characteristics,  8,      "colour_map_transfer_characteristics" );
650      WRITE_CODE( sei.m_colorMap_matrix_coeffs,             8,      "colour_map_matrix_coeffs" );
651    }
652  }
653
654  WRITE_CODE( sei.m_colour_map_coded_data_bit_depth,  5,  "colour_map_coded_data_bit_depth" );
655  WRITE_CODE( sei.m_colour_map_target_bit_depth,  5,      "colour_map_target_bit_depth" );
656  WRITE_UVLC( sei.m_colorMapModelId,                      "colour_map_model_id" );
657
658  assert( sei.m_colorMapModelId == 0 );
659 
660  for( Int i=0 ; i<3 ; i++ )
661  {
662    WRITE_CODE( sei.m_num_input_pivots[i] - 1,         8,      "num_input_pivots_minus1[i]" );
663    for( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
664    {
665      WRITE_CODE( sei.m_coded_input_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_input_pivot_value[i][j]" );
666      WRITE_CODE( sei.m_target_input_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_input_pivot_value[i][j]" );
667    }
668  }
669
670  WRITE_FLAG( sei.m_matrix_flag,            "matrix_flag" );
671  if( sei.m_matrix_flag )
672  {
673    WRITE_CODE( sei.m_log2_matrix_denom, 4, "log2_matrix_denom" );
674    for( Int i=0 ; i<3 ; i++ )
675    {
676      for( Int j=0 ; j<3 ; j++ )
677      {
678        WRITE_SVLC( sei.m_matrix_coef[i][j],  "matrix_coef[i][j]" );
679      }
680    }
681  }
682
683  for( Int i=0 ; i<3 ; i++ )
684  {
685    WRITE_CODE( sei.m_num_output_pivots[i] - 1,         8,      "num_output_pivots_minus1[i]" );
686    for( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
687    {
688      WRITE_CODE( sei.m_coded_output_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_output_pivot_value[i][j]" );
689      WRITE_CODE( sei.m_target_output_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_output_pivot_value[i][j]" );
690    }
691  }
692
693  xWriteByteAlign();
694}
695#endif
696
697Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
698{
699  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
700  if( !sei.cancelFlag )
701  {
702    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
703    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
704    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
705    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
706  }
707  xWriteByteAlign();
708}
709
710Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
711{
712  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
713  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
714  xWriteByteAlign();
715}
716
717Void SEIWriter::xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei)
718{
719  WRITE_FLAG( sei.m_gdrForegroundFlag, "gdr_foreground_flag");
720  xWriteByteAlign();
721}
722
723Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
724{
725  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
726  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
727  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
728  {
729    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
730    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
731    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
732    {
733      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
734    }
735    if (i > 0)
736    {
737      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
738    }
739  }
740
741  xWriteByteAlign();
742}
743
744#if O0164_MULTI_LAYER_HRD
745Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComVPS *vps, TComSPS *sps)
746#else
747Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
748#endif
749{
750  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
751  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
752  if (sei.m_nestingOpFlag)
753  {
754    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
755    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
756    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
757    {
758      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
759      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
760      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
761    }
762  }
763  else
764  {
765    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
766    if (!sei.m_allLayersFlag)
767    {
768      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
769      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
770      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
771      {
772        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
773      }
774    }
775  }
776 
777  // byte alignment
778  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
779  {
780    WRITE_FLAG( 0, "nesting_zero_bit" );
781  }
782
783  // write nested SEI messages
784  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
785  {
786#if O0164_MULTI_LAYER_HRD
787    writeSEImessage(bs, *(*it), vps, sps, &sei);
788#else
789    writeSEImessage(bs, *(*it), sps);
790#endif
791  }
792}
793
794Void SEIWriter::xWriteByteAlign()
795{
796  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
797  {
798    WRITE_FLAG( 1, "bit_equal_to_one" );
799    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
800    {
801      WRITE_FLAG( 0, "bit_equal_to_zero" );
802    }
803  }
804};
805
806#if SVC_EXTENSION
807#if LAYERS_NOT_PRESENT_SEI
808Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
809{
810  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
811  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
812  {
813    WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
814  }
815  xWriteByteAlign();
816}
817#endif
818
819#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
820Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
821{
822  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
823  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
824  if( !sei.m_ilOneTilePerTileSetFlag )
825  {
826    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
827    if( sei.m_ilNumSetsInMessageMinus1 )
828    {
829      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
830    }
831    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
832    for( UInt i = 0; i < numSignificantSets; i++ )
833    {
834      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
835      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
836      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
837      {
838        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
839        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
840      }
841      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
842      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
843      {
844        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
845      }
846    }
847  }
848  else
849  {
850    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
851  }
852
853  xWriteByteAlign();
854}
855#endif
856#if SUB_BITSTREAM_PROPERTY_SEI
857Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
858{
859  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
860  assert( sei.m_numAdditionalSubStreams >= 1 );
861  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
862
863  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
864  {
865    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
866    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
867    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
868    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
869    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
870  }
871  xWriteByteAlign();
872}
873#endif
874
875#if Q0189_TMVP_CONSTRAINTS
876Void SEIWriter::xWriteSEITMVPConstraints (const SEITMVPConstrains &sei)
877{
878  WRITE_UVLC( sei.prev_pics_not_used_flag ,    "prev_pics_not_used_flag"  );
879  WRITE_UVLC( sei.no_intra_layer_col_pic_flag ,    "no_intra_layer_col_pic_flag"  ); 
880  xWriteByteAlign();
881}
882#endif
883
884#if Q0247_FRAME_FIELD_INFO
885Void SEIWriter::xWriteSEIFrameFieldInfo  (const SEIFrameFieldInfo &sei)
886{
887  WRITE_CODE( sei.m_ffinfo_picStruct , 4,             "ffinfo_pic_struct" );
888  WRITE_CODE( sei.m_ffinfo_sourceScanType, 2,         "ffinfo_source_scan_type" );
889  WRITE_FLAG( sei.m_ffinfo_duplicateFlag ? 1 : 0,     "ffinfo_duplicate_flag" );
890  xWriteByteAlign();
891}
892#endif
893
894#if O0164_MULTI_LAYER_HRD
895Void SEIWriter::xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
896{
897  WRITE_UVLC( sei.m_bspIdx, "bsp_idx" );
898
899  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
900  {
901    WRITE_FLAG( 0, "bsp_nesting_zero_bit" );
902  }
903
904  // write nested SEI messages
905  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
906  {
907    writeSEImessage(bs, *(*it), vps, sps, &nestingSei, &sei);
908  }
909}
910
911Void SEIWriter::xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
912{
913  assert(vps->getVpsVuiPresentFlag());
914
915  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
916  UInt len;
917  UInt hrdIdx;
918
919  if (schedCombCnt > 0)
920  {
921    hrdIdx = vps->getBspCombHrdIdx(nestingSei.m_nestingOpIdx[0], 0, bspNestingSei.m_bspIdx);
922  }
923  else
924  {
925    hrdIdx = 0;
926  }
927
928  TComHRD *hrd = vps->getBspHrd(hrdIdx);
929
930  if (hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag())
931  {
932    len = hrd->getInitialCpbRemovalDelayLengthMinus1() + 1;
933  }
934  else
935  {
936    len = 23 + 1;
937  }
938
939  if (hrd->getNalHrdParametersPresentFlag())
940  {
941    for(UInt i = 0; i < schedCombCnt; i++)
942    {
943      WRITE_CODE( sei.m_nalInitialArrivalDelay[i], len, "nal_initial_arrival_delay" );
944    }
945  }
946  else
947  {
948    for(UInt i = 0; i < schedCombCnt; i++)
949    {
950      WRITE_CODE( sei.m_vclInitialArrivalDelay[i], len, "vcl_initial_arrival_delay" );
951    }
952  }
953}
954
955Void SEIWriter::xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
956{
957  WRITE_UVLC( sei.m_seiNumBspHrdParametersMinus1, "sei_num_bsp_hrd_parameters_minus1" );
958  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
959  {
960    if (i > 0)
961    {
962      WRITE_FLAG( sei.m_seiBspCprmsPresentFlag[i], "sei_bsp_cprms_present_flag" );
963    }
964    xCodeHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1);
965  }
966  for (UInt h = 0; h <= nestingSei.m_nestingNumOpsMinus1; h++)
967  {
968    UInt lsIdx = nestingSei.m_nestingOpIdx[h];
969    WRITE_UVLC( sei.m_seiNumBitstreamPartitionsMinus1[lsIdx], "num_sei_bitstream_partitions_minus1[i]");
970    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
971    {
972#if HRD_BPB
973      UInt nl=0;
974      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
975      {
976        if (sei.m_layerIdIncludedFlag[lsIdx][j])
977        {
978          nl++;
979        }
980      }
981      for (UInt j = 0; j < nl; j++)
982      {
983#else
984      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
985      {
986        if (sei.m_layerIdIncludedFlag[lsIdx][j])
987        {
988#endif
989          WRITE_FLAG( sei.m_seiLayerInBspFlag[lsIdx][i][j], "sei_layer_in_bsp_flag[lsIdx][i][j]" );
990        }
991#if !HRD_BPB
992      }
993#endif
994    }
995    WRITE_UVLC( sei.m_seiNumBspSchedCombinationsMinus1[lsIdx], "sei_num_bsp_sched_combinations_minus1[i]");
996    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
997    {
998      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
999      {
1000        WRITE_UVLC( sei.m_seiBspCombHrdIdx[lsIdx][i][j], "sei_bsp_comb_hrd_idx[lsIdx][i][j]");
1001        WRITE_UVLC( sei.m_seiBspCombScheddx[lsIdx][i][j], "sei_bsp_comb_sched_idx[lsIdx][i][j]");
1002      }
1003    }
1004  }
1005}
1006
1007Void SEIWriter::xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
1008{
1009  if( commonInfPresentFlag )
1010  {
1011    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
1012    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
1013    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
1014    {
1015      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
1016      if( hrd->getSubPicCpbParamsPresentFlag() )
1017      {
1018        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
1019        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
1020        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
1021        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
1022      }
1023      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
1024      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
1025      if( hrd->getSubPicCpbParamsPresentFlag() )
1026      {
1027        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" ); 
1028      }
1029      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
1030      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
1031      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
1032    }
1033  }
1034  Int i, j, nalOrVcl;
1035  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1036  {
1037    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
1038    if( !hrd->getFixedPicRateFlag( i ) )
1039    {
1040      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
1041    }
1042    else
1043    {
1044      hrd->setFixedPicRateWithinCvsFlag( i, true );
1045    }
1046    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1047    {
1048      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
1049    }
1050    else
1051    {
1052      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
1053    }
1054    if (!hrd->getLowDelayHrdFlag( i ))
1055    {
1056      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
1057    }
1058   
1059    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1060    {
1061      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1062          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1063      {
1064        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1065        {
1066          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
1067          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
1068          if( hrd->getSubPicCpbParamsPresentFlag() )
1069          {
1070            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
1071            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
1072          }
1073          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
1074        }
1075      }
1076    }
1077  }
1078}
1079
1080#endif
1081
1082#if Q0078_ADD_LAYER_SETS
1083
1084Void SEIWriter::xWriteSEIOutputLayerSetNesting(TComBitIf& bs, const SEIOutputLayerSetNesting &sei, TComVPS *vps, TComSPS *sps)
1085{
1086  WRITE_FLAG(sei.m_olsFlag, "ols_flag");
1087  WRITE_UVLC(sei.m_numOlsIndicesMinus1, "num_ols_indices_minus1");
1088
1089  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
1090  {
1091    WRITE_UVLC(sei.m_olsIdx[i], "ols_idx[i]");
1092  }
1093
1094  while (m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
1095  {
1096    WRITE_FLAG(0, "ols_nesting_zero_bit");
1097  }
1098
1099  // write nested SEI messages
1100  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
1101  {
1102    writeSEImessage(bs, *(*it), vps, sps);
1103  }
1104}
1105
1106Void SEIWriter::xWriteSEIVPSRewriting(const SEIVPSRewriting &sei)
1107{
1108  //sei.nalu->
1109}
1110
1111#endif
1112
1113#endif //SVC_EXTENSION
1114
1115//! \}
Note: See TracBrowser for help on using the repository browser.