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

Last change on this file since 873 was 871, checked in by qualcomm, 10 years ago

JCTVC-R0231: Make signalling of vcl_initial_arrival_delay independent of NalHrdBpPresentFlag (Macro: BSP_INIT_ARRIVAL_SEI))

From: Adarsh K. Ramasubramonian <aramasub@…>

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