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

Last change on this file since 776 was 776, checked in by sony, 12 years ago

JCTVC-P0050: Knee Function Information (MACRO: P0050_KNEE_FUNCTION_SEI)
ohji.nakagami@…

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