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

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

software implementation for JCTVC-Q0189

  • Property svn:eol-style set to native
File size: 41.1 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include "TLibCommon/TComBitCounter.h"
35#include "TLibCommon/TComBitStream.h"
36#include "TLibCommon/SEI.h"
37#include "TLibCommon/TComSlice.h"
38#include "SEIwrite.h"
39
40//! \ingroup TLibEncoder
41//! \{
42
43#if ENC_DEC_TRACE
44Void  xTraceSEIHeader()
45{
46  fprintf( g_hTrace, "=========== SEI message ===========\n");
47}
48
49Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
50{
51  switch (payloadType)
52  {
53  case SEI::DECODED_PICTURE_HASH:
54    fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n");
55    break;
56  case SEI::USER_DATA_UNREGISTERED:
57    fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n");
58    break;
59  case SEI::ACTIVE_PARAMETER_SETS:
60    fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n");
61    break;
62  case SEI::BUFFERING_PERIOD:
63    fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n");
64    break;
65  case SEI::PICTURE_TIMING:
66    fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n");
67    break;
68  case SEI::RECOVERY_POINT:
69    fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n");
70    break;
71  case SEI::FRAME_PACKING:
72    fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n");
73    break;
74  case SEI::DISPLAY_ORIENTATION:
75    fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n");
76    break;
77  case SEI::TEMPORAL_LEVEL0_INDEX:
78    fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n");
79    break;
80  case SEI::REGION_REFRESH_INFO:
81    fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n");
82    break;
83  case SEI::DECODING_UNIT_INFO:
84    fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
85    break;
86  case SEI::TONE_MAPPING_INFO:
87    fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
88    break;
89#if P0050_KNEE_FUNCTION_SEI
90  case SEI::KNEE_FUNCTION_INFO:
91    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
92    break;
93#endif
94#if Q0074_SEI_COLOR_MAPPING
95  case SEI::COLOR_MAPPING_INFO:
96    fprintf( g_hTrace, "=========== Color Mapping Info SEI message ===========\n");
97    break;
98#endif
99  case SEI::SOP_DESCRIPTION:
100    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
101    break;
102  case SEI::SCALABLE_NESTING:
103    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
104    break;
105#if SVC_EXTENSION
106#if LAYERS_NOT_PRESENT_SEI
107  case SEI::LAYERS_NOT_PRESENT:
108    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
109    break;
110#endif
111#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
112  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
113    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
114    break;
115#endif
116#if SUB_BITSTREAM_PROPERTY_SEI
117  case SEI::SUB_BITSTREAM_PROPERTY:
118    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
119    break;
120#endif
121#if O0164_MULTI_LAYER_HRD
122  case SEI::BSP_NESTING:
123    fprintf( g_hTrace, "=========== Bitstream partition nesting SEI message ===========\n");
124    break;
125  case SEI::BSP_INITIAL_ARRIVAL_TIME:
126    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
127    break;
128  case SEI::BSP_HRD:
129    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
130    break;
131#endif
132#if Q0078_ADD_LAYER_SETS
133  case SEI::OUTPUT_LAYER_SET_NESTING:
134    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
135    break;
136  case SEI::VPS_REWRITING:
137    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
138    break;
139#endif
140#endif //SVC_EXTENSION
141  default:
142    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
143    break;
144  }
145}
146#endif
147
148#if O0164_MULTI_LAYER_HRD
149void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei)
150#else
151void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
152#endif
153{
154  switch (sei.payloadType())
155  {
156  case SEI::USER_DATA_UNREGISTERED:
157    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
158    break;
159  case SEI::ACTIVE_PARAMETER_SETS:
160    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei)); 
161    break; 
162  case SEI::DECODING_UNIT_INFO:
163    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
164    break;
165  case SEI::DECODED_PICTURE_HASH:
166    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
167    break;
168  case SEI::BUFFERING_PERIOD:
169    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
170    break;
171  case SEI::PICTURE_TIMING:
172    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
173    break;
174  case SEI::RECOVERY_POINT:
175    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
176    break;
177  case SEI::FRAME_PACKING:
178    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
179    break;
180  case SEI::DISPLAY_ORIENTATION:
181    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
182    break;
183  case SEI::TEMPORAL_LEVEL0_INDEX:
184    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
185    break;
186  case SEI::REGION_REFRESH_INFO:
187    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
188    break;
189  case SEI::TONE_MAPPING_INFO:
190    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
191    break;
192#if P0050_KNEE_FUNCTION_SEI
193  case SEI::KNEE_FUNCTION_INFO:
194    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
195    break;
196#endif
197#if Q0074_SEI_COLOR_MAPPING
198  case SEI::COLOR_MAPPING_INFO:
199    xWriteSEIColorMappingInfo(*static_cast<const SEIColorMappingInfo*>(&sei));
200    break;
201#endif
202  case SEI::SOP_DESCRIPTION:
203    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
204    break;
205  case SEI::SCALABLE_NESTING:
206#if O0164_MULTI_LAYER_HRD
207    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), vps, sps);
208#else
209    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
210#endif
211    break;
212#if SVC_EXTENSION
213#if LAYERS_NOT_PRESENT_SEI
214  case SEI::LAYERS_NOT_PRESENT:
215    xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
216    break;
217#endif
218#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
219  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
220    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
221    break;
222#endif
223#if SUB_BITSTREAM_PROPERTY_SEI
224   case SEI::SUB_BITSTREAM_PROPERTY:
225     xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
226     break;
227#endif
228#if O0164_MULTI_LAYER_HRD
229   case SEI::BSP_NESTING:
230     xWriteSEIBspNesting(bs, *static_cast<const SEIBspNesting*>(&sei), vps, sps, nestingSei);
231     break;
232   case SEI::BSP_INITIAL_ARRIVAL_TIME:
233     xWriteSEIBspInitialArrivalTime(*static_cast<const SEIBspInitialArrivalTime*>(&sei), vps, sps, nestingSei, bspNestingSei);
234     break;
235   case SEI::BSP_HRD:
236     xWriteSEIBspHrd(*static_cast<const SEIBspHrd*>(&sei), sps, nestingSei);
237     break;
238#endif
239#if Q0078_ADD_LAYER_SETS
240   case SEI::OUTPUT_LAYER_SET_NESTING:
241     xWriteSEIOutputLayerSetNesting(bs, *static_cast<const SEIOutputLayerSetNesting*>(&sei), vps, sps);
242     break;
243   case SEI::VPS_REWRITING:
244     xWriteSEIVPSRewriting(*static_cast<const SEIVPSRewriting*>(&sei));
245     break;
246#endif
247#if Q0189_TMVP_CONSTRAINTS
248   case SEI::TMVP_CONSTRAINTS:
249     xWriteSEITMVPConstraints(*static_cast<const SEITMVPConstrains*>(&sei));
250     break;
251#endif
252#endif //SVC_EXTENSION
253  default:
254    assert(!"Unhandled SEI message");
255  }
256}
257
258/**
259 * marshal a single SEI message sei, storing the marshalled representation
260 * in bitstream bs.
261 */
262#if O0164_MULTI_LAYER_HRD
263Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei)
264#else
265Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
266#endif
267{
268  /* calculate how large the payload data is */
269  /* TODO: this would be far nicer if it used vectored buffers */
270  TComBitCounter bs_count;
271  bs_count.resetBits();
272  setBitstream(&bs_count);
273
274
275#if ENC_DEC_TRACE
276  Bool traceEnable = g_HLSTraceEnable;
277  g_HLSTraceEnable = false;
278#endif
279#if O0164_MULTI_LAYER_HRD
280  xWriteSEIpayloadData(bs_count, sei, vps, sps, *nestingSei, *bspNestingSei);
281#else
282  xWriteSEIpayloadData(bs_count, sei, sps);
283#endif
284#if ENC_DEC_TRACE
285  g_HLSTraceEnable = traceEnable;
286#endif
287
288  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
289  assert(0 == payload_data_num_bits % 8);
290
291  setBitstream(&bs);
292
293#if ENC_DEC_TRACE
294  if (g_HLSTraceEnable)
295  xTraceSEIHeader();
296#endif
297
298  UInt payloadType = sei.payloadType();
299  for (; payloadType >= 0xff; payloadType -= 0xff)
300  {
301    WRITE_CODE(0xff, 8, "payload_type");
302  }
303  WRITE_CODE(payloadType, 8, "payload_type");
304
305  UInt payloadSize = payload_data_num_bits/8;
306  for (; payloadSize >= 0xff; payloadSize -= 0xff)
307  {
308    WRITE_CODE(0xff, 8, "payload_size");
309  }
310  WRITE_CODE(payloadSize, 8, "payload_size");
311
312  /* payloadData */
313#if ENC_DEC_TRACE
314  if (g_HLSTraceEnable)
315  xTraceSEIMessageType(sei.payloadType());
316#endif
317
318#if O0164_MULTI_LAYER_HRD
319  xWriteSEIpayloadData(bs, sei, vps, sps, *nestingSei, *bspNestingSei);
320#else
321  xWriteSEIpayloadData(bs, sei, sps);
322#endif
323}
324
325/**
326 * marshal a user_data_unregistered SEI message sei, storing the marshalled
327 * representation in bitstream bs.
328 */
329Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
330{
331  for (UInt i = 0; i < 16; i++)
332  {
333    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
334  }
335
336  for (UInt i = 0; i < sei.userDataLength; i++)
337  {
338    WRITE_CODE(sei.userData[i], 8 , "user_data");
339  }
340}
341
342/**
343 * marshal a decoded picture hash SEI message, storing the marshalled
344 * representation in bitstream bs.
345 */
346Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
347{
348  UInt val;
349
350  WRITE_CODE(sei.method, 8, "hash_type");
351
352  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
353  {
354    if(sei.method == SEIDecodedPictureHash::MD5)
355    {
356      for (UInt i = 0; i < 16; i++)
357      {
358        WRITE_CODE(sei.digest[yuvIdx][i], 8, "picture_md5");
359      }
360    }
361    else if(sei.method == SEIDecodedPictureHash::CRC)
362    {
363      val = (sei.digest[yuvIdx][0] << 8)  + sei.digest[yuvIdx][1];
364      WRITE_CODE(val, 16, "picture_crc");
365    }
366    else if(sei.method == SEIDecodedPictureHash::CHECKSUM)
367    {
368      val = (sei.digest[yuvIdx][0] << 24)  + (sei.digest[yuvIdx][1] << 16) + (sei.digest[yuvIdx][2] << 8) + sei.digest[yuvIdx][3];
369      WRITE_CODE(val, 32, "picture_checksum");
370    }
371  }
372}
373
374Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
375{
376  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
377  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
378  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
379  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
380
381  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
382
383  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
384  {
385    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
386  }
387  xWriteByteAlign();
388}
389
390Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps)
391{
392  TComVUI *vui = sps->getVuiParameters();
393  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
394  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
395  {
396    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
397  }
398  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
399  if(sei.m_dpbOutputDuDelayPresentFlag)
400  {
401    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
402  }
403  xWriteByteAlign();
404}
405
406Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
407{
408  Int i, nalOrVcl;
409  TComVUI *vui = sps->getVuiParameters();
410  TComHRD *hrd = vui->getHrdParameters();
411
412  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
413  if( !hrd->getSubPicCpbParamsPresentFlag() )
414  {
415    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
416  }
417  if( sei.m_rapCpbParamsPresentFlag )
418  {
419    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
420    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
421  }
422  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
423  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
424  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
425  {
426    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
427        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
428    {
429      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
430      {
431        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
432        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
433        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
434        {
435          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
436          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
437        }
438      }
439    }
440  }
441#if P0138_USE_ALT_CPB_PARAMS_FLAG
442  if (sei.m_useAltCpbParamsFlagPresent)
443  {
444    WRITE_FLAG( sei.m_useAltCpbParamsFlag, "use_alt_cpb_params_flag");
445  }
446#endif
447  xWriteByteAlign();
448}
449Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
450{
451  Int i;
452  TComVUI *vui = sps->getVuiParameters();
453  TComHRD *hrd = vui->getHrdParameters();
454
455  if( vui->getFrameFieldInfoPresentFlag() )
456  {
457    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
458    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
459    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
460  }
461
462  if( hrd->getCpbDpbDelaysPresentFlag() )
463  {
464    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
465    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
466    if(hrd->getSubPicCpbParamsPresentFlag())
467    {
468      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
469    }
470    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
471    {
472      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
473      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
474      if( sei.m_duCommonCpbRemovalDelayFlag )
475      {
476        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
477      }
478      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
479      {
480        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
481        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
482        {
483          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
484        }
485      }
486    }
487  }
488  xWriteByteAlign();
489}
490Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
491{
492  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
493  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
494  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
495  xWriteByteAlign();
496}
497Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
498{
499  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
500  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
501
502  if( sei.m_arrangementCancelFlag == 0 ) {
503    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
504
505    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
506    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
507    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
508    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
509    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
510    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
511
512    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
513    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
514
515    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
516    {
517      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
518      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
519      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
520      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
521    }
522
523    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
524    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
525  }
526
527  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
528
529  xWriteByteAlign();
530}
531
532Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
533{
534  Int i;
535  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
536  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
537  if( !sei.m_toneMapCancelFlag ) 
538  {
539    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
540    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
541    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
542    WRITE_UVLC( sei.m_modelId,                    "model_id" );
543    switch(sei.m_modelId)
544    {
545    case 0:
546      {
547        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
548        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
549        break;
550      }
551    case 1:
552      {
553        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
554        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
555        break;
556      }
557    case 2:
558      {
559        UInt num = 1u << sei.m_targetBitDepth;
560        for(i = 0; i < num; i++)
561        {
562          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
563        }
564        break;
565      }
566    case 3:
567      {
568        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
569        for(i = 0; i < sei.m_numPivots; i++ )
570        {
571          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
572          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
573        }
574        break;
575      }
576    case 4:
577      {
578        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
579        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
580        {
581          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
582        }
583        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
584        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
585        {
586          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
587        }
588        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
589        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
590        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
591        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
592        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
593        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
594        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
595        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
596        break;
597      }
598    default:
599      {
600        assert(!"Undefined SEIToneMapModelId");
601        break;
602      }
603    }//switch m_modelId
604  }//if(!sei.m_toneMapCancelFlag)
605
606  xWriteByteAlign();
607}
608#if P0050_KNEE_FUNCTION_SEI
609Void SEIWriter::xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei)
610{
611  WRITE_UVLC( sei.m_kneeId, "knee_function_id" );
612  WRITE_FLAG( sei.m_kneeCancelFlag, "knee_function_cancel_flag" ); 
613  if ( !sei.m_kneeCancelFlag )
614  {
615    WRITE_FLAG( sei.m_kneePersistenceFlag, "knee_function_persistence_flag" );
616    WRITE_FLAG( sei.m_kneeMappingFlag, "mapping_flag" );
617    WRITE_CODE( (UInt)sei.m_kneeInputDrange , 32,  "input_d_range" );
618    WRITE_CODE( (UInt)sei.m_kneeInputDispLuminance, 32,  "input_disp_luminance" );
619    WRITE_CODE( (UInt)sei.m_kneeOutputDrange, 32,  "output_d_range" );
620    WRITE_CODE( (UInt)sei.m_kneeOutputDispLuminance, 32,  "output_disp_luminance" );
621    WRITE_UVLC( sei.m_kneeNumKneePointsMinus1, "num_knee_points_minus1" );
622    for(Int i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
623    {
624      WRITE_CODE( (UInt)sei.m_kneeInputKneePoint[i], 10,"input_knee_point" );
625      WRITE_CODE( (UInt)sei.m_kneeOutputKneePoint[i], 10, "output_knee_point" );
626    }
627  }
628  xWriteByteAlign();
629}
630#endif
631#if Q0074_SEI_COLOR_MAPPING
632Void SEIWriter::xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei)
633{
634  WRITE_UVLC( sei.m_colorMapId,                    "colour_map_id" );
635  WRITE_FLAG( sei.m_colorMapCancelFlag,            "colour_map_cancel_flag" );
636  if( !sei.m_colorMapCancelFlag ) 
637  {
638    WRITE_FLAG( sei.m_colorMapPersistenceFlag,            "colour_map_persistence_flag" );
639    WRITE_FLAG( sei.m_colorMap_video_signal_type_present_flag,            "colour_map_video_signal_type_present_flag" );
640    if ( sei.m_colorMap_video_signal_type_present_flag )
641    {
642      WRITE_FLAG( sei.m_colorMap_video_full_range_flag,       "colour_map_video_full_range_flag" );
643      WRITE_CODE( sei.m_colorMap_primaries,                 8,      "colour_map_primaries" );
644      WRITE_CODE( sei.m_colorMap_transfer_characteristics,  8,      "colour_map_transfer_characteristics" );
645      WRITE_CODE( sei.m_colorMap_matrix_coeffs,             8,      "colour_map_matrix_coeffs" );
646    }
647  }
648
649  WRITE_CODE( sei.m_colour_map_coded_data_bit_depth,  5,  "colour_map_coded_data_bit_depth" );
650  WRITE_CODE( sei.m_colour_map_target_bit_depth,  5,      "colour_map_target_bit_depth" );
651  WRITE_UVLC( sei.m_colorMapModelId,                      "colour_map_model_id" );
652
653  assert( sei.m_colorMapModelId == 0 );
654 
655  for( Int i=0 ; i<3 ; i++ )
656  {
657    WRITE_CODE( sei.m_num_input_pivots[i] - 1,         8,      "num_input_pivots_minus1[i]" );
658    for( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
659    {
660      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]" );
661      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]" );
662    }
663  }
664
665  WRITE_FLAG( sei.m_matrix_flag,            "matrix_flag" );
666  if( sei.m_matrix_flag )
667  {
668    WRITE_CODE( sei.m_log2_matrix_denom, 4, "log2_matrix_denom" );
669    for( Int i=0 ; i<3 ; i++ )
670    {
671      for( Int j=0 ; j<3 ; j++ )
672      {
673        WRITE_SVLC( sei.m_matrix_coef[i][j],  "matrix_coef[i][j]" );
674      }
675    }
676  }
677
678  for( Int i=0 ; i<3 ; i++ )
679  {
680    WRITE_CODE( sei.m_num_output_pivots[i] - 1,         8,      "num_output_pivots_minus1[i]" );
681    for( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
682    {
683      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]" );
684      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]" );
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 O0164_MULTI_LAYER_HRD
880Void SEIWriter::xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
881{
882  WRITE_UVLC( sei.m_bspIdx, "bsp_idx" );
883
884  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
885  {
886    WRITE_FLAG( 0, "bsp_nesting_zero_bit" );
887  }
888
889  // write nested SEI messages
890  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
891  {
892    writeSEImessage(bs, *(*it), vps, sps, &nestingSei, &sei);
893  }
894}
895
896Void SEIWriter::xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
897{
898  assert(vps->getVpsVuiPresentFlag());
899
900  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
901  UInt len;
902  UInt hrdIdx;
903
904  if (schedCombCnt > 0)
905  {
906    hrdIdx = vps->getBspCombHrdIdx(nestingSei.m_nestingOpIdx[0], 0, bspNestingSei.m_bspIdx);
907  }
908  else
909  {
910    hrdIdx = 0;
911  }
912
913  TComHRD *hrd = vps->getBspHrd(hrdIdx);
914
915  if (hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag())
916  {
917    len = hrd->getInitialCpbRemovalDelayLengthMinus1() + 1;
918  }
919  else
920  {
921    len = 23 + 1;
922  }
923
924  if (hrd->getNalHrdParametersPresentFlag())
925  {
926    for(UInt i = 0; i < schedCombCnt; i++)
927    {
928      WRITE_CODE( sei.m_nalInitialArrivalDelay[i], len, "nal_initial_arrival_delay" );
929    }
930  }
931  else
932  {
933    for(UInt i = 0; i < schedCombCnt; i++)
934    {
935      WRITE_CODE( sei.m_vclInitialArrivalDelay[i], len, "vcl_initial_arrival_delay" );
936    }
937  }
938}
939
940Void SEIWriter::xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
941{
942  WRITE_UVLC( sei.m_seiNumBspHrdParametersMinus1, "sei_num_bsp_hrd_parameters_minus1" );
943  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
944  {
945    if (i > 0)
946    {
947      WRITE_FLAG( sei.m_seiBspCprmsPresentFlag[i], "sei_bsp_cprms_present_flag" );
948    }
949    xCodeHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1);
950  }
951  for (UInt h = 0; h <= nestingSei.m_nestingNumOpsMinus1; h++)
952  {
953    UInt lsIdx = nestingSei.m_nestingOpIdx[h];
954    WRITE_UVLC( sei.m_seiNumBitstreamPartitionsMinus1[lsIdx], "num_sei_bitstream_partitions_minus1[i]");
955    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
956    {
957#if HRD_BPB
958      UInt nl=0;
959      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
960      {
961        if (sei.m_layerIdIncludedFlag[lsIdx][j])
962        {
963          nl++;
964        }
965      }
966      for (UInt j = 0; j < nl; j++)
967      {
968#else
969      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
970      {
971        if (sei.m_layerIdIncludedFlag[lsIdx][j])
972        {
973#endif
974          WRITE_FLAG( sei.m_seiLayerInBspFlag[lsIdx][i][j], "sei_layer_in_bsp_flag[lsIdx][i][j]" );
975        }
976#if !HRD_BPB
977      }
978#endif
979    }
980    WRITE_UVLC( sei.m_seiNumBspSchedCombinationsMinus1[lsIdx], "sei_num_bsp_sched_combinations_minus1[i]");
981    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
982    {
983      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
984      {
985        WRITE_UVLC( sei.m_seiBspCombHrdIdx[lsIdx][i][j], "sei_bsp_comb_hrd_idx[lsIdx][i][j]");
986        WRITE_UVLC( sei.m_seiBspCombScheddx[lsIdx][i][j], "sei_bsp_comb_sched_idx[lsIdx][i][j]");
987      }
988    }
989  }
990}
991
992Void SEIWriter::xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
993{
994  if( commonInfPresentFlag )
995  {
996    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
997    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
998    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
999    {
1000      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
1001      if( hrd->getSubPicCpbParamsPresentFlag() )
1002      {
1003        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
1004        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
1005        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
1006        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
1007      }
1008      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
1009      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
1010      if( hrd->getSubPicCpbParamsPresentFlag() )
1011      {
1012        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" ); 
1013      }
1014      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
1015      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
1016      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
1017    }
1018  }
1019  Int i, j, nalOrVcl;
1020  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1021  {
1022    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
1023    if( !hrd->getFixedPicRateFlag( i ) )
1024    {
1025      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
1026    }
1027    else
1028    {
1029      hrd->setFixedPicRateWithinCvsFlag( i, true );
1030    }
1031    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1032    {
1033      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
1034    }
1035    else
1036    {
1037      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
1038    }
1039    if (!hrd->getLowDelayHrdFlag( i ))
1040    {
1041      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
1042    }
1043   
1044    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1045    {
1046      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1047          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1048      {
1049        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1050        {
1051          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
1052          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
1053          if( hrd->getSubPicCpbParamsPresentFlag() )
1054          {
1055            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
1056            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
1057          }
1058          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
1059        }
1060      }
1061    }
1062  }
1063}
1064
1065#endif
1066
1067#if Q0078_ADD_LAYER_SETS
1068
1069Void SEIWriter::xWriteSEIOutputLayerSetNesting(TComBitIf& bs, const SEIOutputLayerSetNesting &sei, TComVPS *vps, TComSPS *sps)
1070{
1071  WRITE_FLAG(sei.m_olsFlag, "ols_flag");
1072  WRITE_UVLC(sei.m_numOlsIndicesMinus1, "num_ols_indices_minus1");
1073
1074  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
1075  {
1076    WRITE_UVLC(sei.m_olsIdx[i], "ols_idx[i]");
1077  }
1078
1079  while (m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
1080  {
1081    WRITE_FLAG(0, "ols_nesting_zero_bit");
1082  }
1083
1084  // write nested SEI messages
1085  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
1086  {
1087    writeSEImessage(bs, *(*it), vps, sps);
1088  }
1089}
1090
1091Void SEIWriter::xWriteSEIVPSRewriting(const SEIVPSRewriting &sei)
1092{
1093  //sei.nalu->
1094}
1095
1096#endif
1097
1098#endif //SVC_EXTENSION
1099
1100//! \}
Note: See TracBrowser for help on using the repository browser.