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

Last change on this file since 851 was 847, checked in by qualcomm, 11 years ago

JCTVC-R0221: Changes to BSP nesting SEI (Macro: NESTING_SEI_EXTENSIBILITY)

Include signalling the number of SEI messages in bitstream partition nesting SEI message.

From: Adarsh K. Ramasubramonian <aramasub@…>

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