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

Last change on this file since 1242 was 1235, checked in by seregin, 9 years ago

port rev 4219 and rev 4246

  • Property svn:eol-style set to native
File size: 56.4 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 "TLibCommon/TComPicYuv.h"
39#include "SEIwrite.h"
40
41//! \ingroup TLibEncoder
42//! \{
43
44#if ENC_DEC_TRACE
45Void  xTraceSEIHeader()
46{
47  fprintf( g_hTrace, "=========== SEI message ===========\n");
48}
49
50Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
51{
52  fprintf( g_hTrace, "=========== %s SEI message ===========\n", SEI::getSEIMessageString(payloadType));
53}
54#endif
55
56#if O0164_MULTI_LAYER_HRD
57Void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSeiPtr, const SEIBspNesting* bspNestingSeiPtr)
58#else
59Void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, const TComSPS *sps)
60#endif
61{
62#if SVC_EXTENSION
63  SEIScalableNesting nestingSei;
64  SEIBspNesting      bspNestingSei;
65  if( nestingSeiPtr )
66  {
67    nestingSei = *nestingSeiPtr;
68  }
69  if( bspNestingSeiPtr )
70  {
71    bspNestingSei = *bspNestingSeiPtr;
72  }
73#endif
74  switch (sei.payloadType())
75  {
76  case SEI::USER_DATA_UNREGISTERED:
77    xWriteSEIuserDataUnregistered(*static_cast<const SEIuserDataUnregistered*>(&sei));
78    break;
79  case SEI::ACTIVE_PARAMETER_SETS:
80    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei));
81    break; 
82  case SEI::DECODED_PICTURE_HASH:
83    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
84    break;
85#if SVC_EXTENSION
86  case SEI::DECODING_UNIT_INFO:
87    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
88    break;
89  case SEI::BUFFERING_PERIOD:
90    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
91    break;
92  case SEI::PICTURE_TIMING:
93    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
94    break;
95#else
96  case SEI::DECODING_UNIT_INFO:
97    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
98    break;
99  case SEI::BUFFERING_PERIOD:
100    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
101    break;
102  case SEI::PICTURE_TIMING:
103    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
104    break;
105#endif
106  case SEI::RECOVERY_POINT:
107    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
108    break;
109  case SEI::FRAME_PACKING:
110    xWriteSEIFramePacking(*static_cast<const SEIFramePacking*>(&sei));
111    break;
112  case SEI::SEGM_RECT_FRAME_PACKING:
113    xWriteSEISegmentedRectFramePacking(*static_cast<const SEISegmentedRectFramePacking*>(&sei));
114    break;
115  case SEI::DISPLAY_ORIENTATION:
116    xWriteSEIDisplayOrientation(*static_cast<const SEIDisplayOrientation*>(&sei));
117    break;
118  case SEI::TEMPORAL_LEVEL0_INDEX:
119    xWriteSEITemporalLevel0Index(*static_cast<const SEITemporalLevel0Index*>(&sei));
120    break;
121  case SEI::REGION_REFRESH_INFO:
122    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
123    break;
124  case SEI::NO_DISPLAY:
125    xWriteSEINoDisplay(*static_cast<const SEINoDisplay*>(&sei));
126    break;
127  case SEI::TONE_MAPPING_INFO:
128    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
129    break;
130  case SEI::SOP_DESCRIPTION:
131    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
132    break;
133  case SEI::SCALABLE_NESTING:
134#if O0164_MULTI_LAYER_HRD
135    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), vps, sps);
136#else
137    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
138#endif
139    break;
140  case SEI::CHROMA_SAMPLING_FILTER_HINT:
141    xWriteSEIChromaSamplingFilterHint(*static_cast<const SEIChromaSamplingFilterHint*>(&sei)/*, sps*/);
142    break;
143  case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
144    xWriteSEITempMotionConstrainedTileSets(bs, *static_cast<const SEITempMotionConstrainedTileSets*>(&sei));
145    break;
146  case SEI::TIME_CODE:
147    xWriteSEITimeCode(*static_cast<const SEITimeCode*>(&sei));
148    break;
149  case SEI::KNEE_FUNCTION_INFO:
150    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
151    break;
152  case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
153    xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
154    break;
155#if Q0074_COLOUR_REMAPPING_SEI
156  case SEI::COLOUR_REMAPPING_INFO:
157    xWriteSEIColourRemappingInfo(*static_cast<const SEIColourRemappingInfo*>(&sei));
158    break;
159#endif
160#if SVC_EXTENSION
161#if LAYERS_NOT_PRESENT_SEI
162  case SEI::LAYERS_NOT_PRESENT:
163    xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
164    break;
165#endif
166#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
167  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
168    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
169    break;
170#endif
171#if SUB_BITSTREAM_PROPERTY_SEI
172   case SEI::SUB_BITSTREAM_PROPERTY:
173     xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
174     break;
175#endif
176#if O0164_MULTI_LAYER_HRD
177   case SEI::BSP_NESTING:
178     xWriteSEIBspNesting(bs, *static_cast<const SEIBspNesting*>(&sei), vps, sps, nestingSei);
179     break;
180   case SEI::BSP_INITIAL_ARRIVAL_TIME:
181     xWriteSEIBspInitialArrivalTime(*static_cast<const SEIBspInitialArrivalTime*>(&sei), vps, sps, nestingSei, bspNestingSei);
182     break;
183#endif
184#if Q0189_TMVP_CONSTRAINTS
185   case SEI::TMVP_CONSTRAINTS:
186     xWriteSEITMVPConstraints(*static_cast<const SEITMVPConstrains*>(&sei));
187     break;
188#endif
189#if Q0247_FRAME_FIELD_INFO
190   case SEI::FRAME_FIELD_INFO:
191     xWriteSEIFrameFieldInfo(*static_cast<const SEIFrameFieldInfo*>(&sei));
192     break;
193#endif
194#if P0123_ALPHA_CHANNEL_SEI
195   case SEI::ALPHA_CHANNEL_INFO:
196     xWriteSEIAlphaChannelInfo(*static_cast<const SEIAlphaChannelInfo*>(&sei));
197     break;
198#endif
199#if Q0096_OVERLAY_SEI
200   case SEI::OVERLAY_INFO:
201     xWriteSEIOverlayInfo(*static_cast<const SEIOverlayInfo*>(&sei));
202     break;
203#endif
204#endif //SVC_EXTENSION
205  default:
206    assert(!"Unhandled SEI message");
207    break;
208  }
209  xWriteByteAlign();
210}
211
212/**
213 * marshal a single SEI message sei, storing the marshalled representation
214 * in bitstream bs.
215 */
216#if O0164_MULTI_LAYER_HRD
217Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei)
218#else
219Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, const TComSPS *sps)
220#endif
221{
222  /* calculate how large the payload data is */
223  /* TODO: this would be far nicer if it used vectored buffers */
224  TComBitCounter bs_count;
225  bs_count.resetBits();
226  setBitstream(&bs_count);
227
228
229#if ENC_DEC_TRACE
230  Bool traceEnable = g_HLSTraceEnable;
231  g_HLSTraceEnable = false;
232#endif
233#if O0164_MULTI_LAYER_HRD
234  xWriteSEIpayloadData(bs_count, sei, vps, sps, nestingSei, bspNestingSei);
235#else
236  xWriteSEIpayloadData(bs_count, sei, sps);
237#endif
238#if ENC_DEC_TRACE
239  g_HLSTraceEnable = traceEnable;
240#endif
241
242  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
243  assert(0 == payload_data_num_bits % 8);
244
245  setBitstream(&bs);
246
247#if ENC_DEC_TRACE
248  if (g_HLSTraceEnable)
249  xTraceSEIHeader();
250#endif
251
252  UInt payloadType = sei.payloadType();
253  for (; payloadType >= 0xff; payloadType -= 0xff)
254  {
255    WRITE_CODE(0xff, 8, "payload_type");
256  }
257  WRITE_CODE(payloadType, 8, "payload_type");
258
259  UInt payloadSize = payload_data_num_bits/8;
260  for (; payloadSize >= 0xff; payloadSize -= 0xff)
261  {
262    WRITE_CODE(0xff, 8, "payload_size");
263  }
264  WRITE_CODE(payloadSize, 8, "payload_size");
265
266  /* payloadData */
267#if ENC_DEC_TRACE
268  if (g_HLSTraceEnable)
269  xTraceSEIMessageType(sei.payloadType());
270#endif
271
272#if O0164_MULTI_LAYER_HRD
273  xWriteSEIpayloadData(bs, sei, vps, sps, nestingSei, bspNestingSei);
274#else
275  xWriteSEIpayloadData(bs, sei, sps);
276#endif
277}
278
279/**
280 * marshal a user_data_unregistered SEI message sei, storing the marshalled
281 * representation in bitstream bs.
282 */
283Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
284{
285  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
286  {
287    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
288  }
289
290  for (UInt i = 0; i < sei.userDataLength; i++)
291  {
292    WRITE_CODE(sei.userData[i], 8 , "user_data");
293  }
294}
295
296/**
297 * marshal a decoded picture hash SEI message, storing the marshalled
298 * representation in bitstream bs.
299 */
300Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
301{
302  const Char *traceString="\0";
303  switch (sei.method)
304  {
305    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
306    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
307    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
308    default: assert(false); break;
309  }
310
311  if (traceString != 0) //use of this variable is needed to avoid a compiler error with G++ 4.6.1
312  {
313    WRITE_CODE(sei.method, 8, "hash_type");
314    for(UInt i=0; i<UInt(sei.m_digest.hash.size()); i++)
315    {
316      WRITE_CODE(sei.m_digest.hash[i], 8, traceString);
317    }
318  }
319}
320
321Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
322{
323  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
324  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
325  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
326  WRITE_UVLC(sei.numSpsIdsMinus1,            "num_sps_ids_minus1");
327
328  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
329
330  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
331  {
332    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
333  }
334#if R0247_SEI_ACTIVE
335  for (Int i = 1; i < sei.activeSeqParameterSetId.size(); i++)
336  {
337    WRITE_UVLC(sei.layerSpsIdx[i], "layer_sps_idx"); 
338  }
339#endif
340}
341
342#if SVC_EXTENSION
343Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps)
344{
345  const TComHRD *hrd;
346  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
347  {
348    assert( nestingSei );
349    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
350    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
351    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
352    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
353    std::vector<Int> hrdIdx(maxValues, 0);
354    std::vector<const TComHRD*> hrdVec;
355    std::vector<Int> syntaxElemLen(maxValues, 0);
356    for(Int i = 0; i < maxValues; i++)
357    {
358      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
359      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
360   
361      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
362      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
363      {
364        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
365      }
366      if( i > 0 )
367      {
368        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
369        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
370        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
371        // To be done: Check CpbDpbDelaysPresentFlag
372      }
373    }
374    hrd = hrdVec[0];
375  }
376  else
377  {
378    const TComVUI *vui = sps->getVuiParameters();
379    hrd = vui->getHrdParameters();
380  }
381
382  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
383  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
384  {
385    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (hrd->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
386  }
387  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
388  if(sei.m_dpbOutputDuDelayPresentFlag)
389  {
390    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
391  }
392}
393#else
394Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, const TComSPS *sps)
395{
396  const TComVUI *vui = sps->getVuiParameters();
397  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
398  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
399  {
400    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
401  }
402  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
403  if(sei.m_dpbOutputDuDelayPresentFlag)
404  {
405    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
406  }
407}
408#endif
409
410#if SVC_EXTENSION
411Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps)
412#else
413Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, const TComSPS *sps)
414#endif
415{
416  Int i, nalOrVcl;
417#if SVC_EXTENSION
418  const TComHRD *hrd;
419  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
420  {
421    assert( nestingSei );
422    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
423    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
424    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
425    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
426    std::vector<Int> hrdIdx(maxValues, 0);
427    std::vector<const TComHRD*> hrdVec;
428    std::vector<Int> syntaxElemLen(maxValues, 0);
429    for(i = 0; i < maxValues; i++)
430    {
431      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
432      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
433   
434      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
435      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
436      {
437        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
438      }
439      if( i > 0 )
440      {
441        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
442        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
443        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
444      }
445    }
446    hrd = hrdVec[i];
447  }
448  else
449  {
450    const TComVUI *vui = sps->getVuiParameters();
451    hrd = vui->getHrdParameters();
452  }
453  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
454#else
455  const TComVUI *vui = sps->getVuiParameters();
456  const TComHRD *hrd = vui->getHrdParameters();
457#endif
458
459  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
460  if( !hrd->getSubPicCpbParamsPresentFlag() )
461  {
462    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
463  }
464  if( sei.m_rapCpbParamsPresentFlag )
465  {
466    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
467    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
468  }
469  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
470  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
471  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
472  {
473    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
474        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
475    {
476      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
477      {
478        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
479        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
480        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
481        {
482          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
483          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
484        }
485      }
486    }
487  }
488#if P0138_USE_ALT_CPB_PARAMS_FLAG
489  if (sei.m_useAltCpbParamsFlagPresent)
490  {
491    WRITE_FLAG( sei.m_useAltCpbParamsFlag, "use_alt_cpb_params_flag");
492  }
493#endif
494}
495
496#if SVC_EXTENSION
497Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei, const TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, const TComVPS *vps)
498#else
499Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei, const TComSPS *sps)
500#endif
501{
502  Int i;
503#if SVC_EXTENSION
504  const TComHRD *hrd;   
505  const TComVUI *vui = sps->getVuiParameters(); 
506  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
507  {
508    assert( nestingSei );
509    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
510    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
511    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
512    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
513    std::vector<Int> hrdIdx(maxValues, 0);
514    std::vector<const TComHRD*> hrdVec;
515    std::vector<Int> syntaxElemLen(maxValues, 0);
516    for(i = 0; i < maxValues; i++)
517    {
518      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
519      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
520   
521      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
522      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
523      {
524        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
525      }
526      if( i > 0 )
527      {
528        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
529        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
530        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
531        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
532        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
533        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
534        // To be done: Check CpbDpbDelaysPresentFlag
535      }
536    }
537    hrd = hrdVec[0];
538  }
539  else
540  {
541    hrd = vui->getHrdParameters();
542  }
543  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
544#else
545  const TComVUI *vui = sps->getVuiParameters();
546  const TComHRD *hrd = vui->getHrdParameters();
547#endif
548
549  if( vui->getFrameFieldInfoPresentFlag() )
550  {
551    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
552    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
553    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
554  }
555
556  if( hrd->getCpbDpbDelaysPresentFlag() )
557  {
558    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
559    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
560    if(hrd->getSubPicCpbParamsPresentFlag())
561    {
562      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
563    }
564    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
565    {
566      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
567      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
568      if( sei.m_duCommonCpbRemovalDelayFlag )
569      {
570        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
571      }
572      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
573      {
574        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
575        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
576        {
577          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
578        }
579      }
580    }
581  }
582}
583Void SEIWriter::xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei)
584{
585  WRITE_SVLC( sei.m_recoveryPocCnt,    "recovery_poc_cnt"    );
586  WRITE_FLAG( sei.m_exactMatchingFlag, "exact_matching_flag" );
587  WRITE_FLAG( sei.m_brokenLinkFlag,    "broken_link_flag"    );
588}
589Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
590{
591  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
592  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );
593
594  if( sei.m_arrangementCancelFlag == 0 ) {
595    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );
596
597    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
598    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
599    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
600    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
601    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
602    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );
603
604    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
605    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );
606
607    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
608    {
609      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
610      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
611      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
612      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
613    }
614
615    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
616    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
617  }
618
619  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );
620}
621
622Void SEIWriter::xWriteSEISegmentedRectFramePacking(const SEISegmentedRectFramePacking& sei)
623{
624  WRITE_FLAG( sei.m_arrangementCancelFlag,          "segmented_rect_frame_packing_arrangement_cancel_flag" );
625  if( sei.m_arrangementCancelFlag == 0 ) 
626  {
627    WRITE_CODE( sei.m_contentInterpretationType, 2, "segmented_rect_content_interpretation_type" );
628    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "segmented_rect_frame_packing_arrangement_persistence" );
629  }
630}
631
632Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
633{
634  Int i;
635  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
636  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
637  if( !sei.m_toneMapCancelFlag )
638  {
639    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
640    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
641    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
642    WRITE_UVLC( sei.m_modelId,                    "model_id" );
643    switch(sei.m_modelId)
644    {
645    case 0:
646      {
647        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
648        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
649        break;
650      }
651    case 1:
652      {
653        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
654        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
655        break;
656      }
657    case 2:
658      {
659        UInt num = 1u << sei.m_targetBitDepth;
660        for(i = 0; i < num; i++)
661        {
662          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
663        }
664        break;
665      }
666    case 3:
667      {
668        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
669        for(i = 0; i < sei.m_numPivots; i++ )
670        {
671          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
672          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
673        }
674        break;
675      }
676    case 4:
677      {
678        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
679        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
680        {
681          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
682        }
683        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
684        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
685        {
686          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
687        }
688        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
689        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
690        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
691        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
692        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
693        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
694        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
695        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
696        break;
697      }
698    default:
699      {
700        assert(!"Undefined SEIToneMapModelId");
701        break;
702      }
703    }//switch m_modelId
704  }//if(!sei.m_toneMapCancelFlag)
705}
706
707Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
708{
709  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
710  if( !sei.cancelFlag )
711  {
712    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
713    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
714    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
715    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
716  }
717}
718
719Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
720{
721  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
722  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
723}
724
725Void SEIWriter::xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei)
726{
727  WRITE_FLAG( sei.m_gdrForegroundFlag, "gdr_foreground_flag");
728}
729
730Void SEIWriter::xWriteSEINoDisplay(const SEINoDisplay &sei)
731{
732}
733
734Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
735{
736  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
737  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
738  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
739  {
740    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
741    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
742    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
743    {
744      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
745    }
746    if (i > 0)
747    {
748      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
749    }
750  }
751}
752
753#if O0164_MULTI_LAYER_HRD
754Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, const TComVPS *vps, const TComSPS *sps)
755#else
756Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, const TComSPS *sps)
757#endif
758{
759  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
760  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
761  if (sei.m_nestingOpFlag)
762  {
763    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
764    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops_minus1"        );
765    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
766    {
767      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id_plus1" );
768      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
769    }
770  }
771  else
772  {
773    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
774    if (!sei.m_allLayersFlag)
775    {
776      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id_plus1" );
777      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"                  );
778      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
779      {
780        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
781      }
782    }
783  }
784
785  // byte alignment
786  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
787  {
788    WRITE_FLAG( 0, "nesting_zero_bit" );
789  }
790
791  // write nested SEI messages
792  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
793  {
794#if O0164_MULTI_LAYER_HRD
795    writeSEImessage(bs, *(*it), vps, sps, &sei);
796#else
797    writeSEImessage(bs, *(*it), sps);
798#endif
799  }
800}
801
802Void SEIWriter::xWriteSEITempMotionConstrainedTileSets(TComBitIf& bs, const SEITempMotionConstrainedTileSets& sei)
803{
804  //UInt code;
805  WRITE_FLAG((sei.m_mc_all_tiles_exact_sample_value_match_flag ? 1 : 0), "mc_all_tiles_exact_sample_value_match_flag"); 
806  WRITE_FLAG((sei.m_each_tile_one_tile_set_flag                ? 1 : 0), "each_tile_one_tile_set_flag"               );
807
808  if(!sei.m_each_tile_one_tile_set_flag)
809  {
810    WRITE_FLAG((sei.m_limited_tile_set_display_flag ? 1 : 0), "limited_tile_set_display_flag");
811    WRITE_UVLC((sei.getNumberOfTileSets() - 1),               "num_sets_in_message_minus1"   );
812
813    if(sei.getNumberOfTileSets() > 0)
814    {
815      for(Int i = 0; i < sei.getNumberOfTileSets(); i++)
816      {
817        WRITE_UVLC(sei.tileSetData(i).m_mcts_id, "mcts_id");
818
819        if(sei.m_limited_tile_set_display_flag)
820        { 
821          WRITE_FLAG((sei.tileSetData(i).m_display_tile_set_flag ? 1 : 0), "display_tile_set_flag"); 
822        }
823
824        WRITE_UVLC((sei.tileSetData(i).getNumberOfTileRects() - 1), "num_tile_rects_in_set_minus1"); 
825       
826        for(Int j = 0; j < sei.tileSetData(i).getNumberOfTileRects(); j++)
827        {
828          WRITE_UVLC(sei.tileSetData(i).topLeftTileIndex    (j), "top_left_tile_index"); 
829          WRITE_UVLC(sei.tileSetData(i).bottomRightTileIndex(j), "bottom_right_tile_index"); 
830        }
831
832        if(!sei.m_mc_all_tiles_exact_sample_value_match_flag)
833        {
834          WRITE_FLAG((sei.tileSetData(i).m_exact_sample_value_match_flag ? 1 : 0), "exact_sample_value_match_flag"); 
835        }
836
837        WRITE_FLAG((sei.tileSetData(i).m_mcts_tier_level_idc_present_flag ? 1 : 0), "mcts_tier_level_idc_present_flag");
838
839        if(sei.tileSetData(i).m_mcts_tier_level_idc_present_flag)
840        {
841          WRITE_FLAG((sei.tileSetData(i).m_mcts_tier_flag ? 1 : 0), "mcts_tier_flag");
842          WRITE_CODE( sei.tileSetData(i).m_mcts_level_idc, 8,       "mcts_level_idc"); 
843        }
844      }
845    }
846  }
847  else
848  {
849    WRITE_FLAG((sei.m_max_mcs_tier_level_idc_present_flag ? 1 : 0), "max_mcs_tier_level_idc_present_flag");
850
851    if(sei.m_max_mcs_tier_level_idc_present_flag)
852    {
853      WRITE_FLAG((sei.m_max_mcts_tier_flag ? 1 : 0), "max_mcts_tier_flag"); 
854      WRITE_CODE( sei.m_max_mcts_level_idc, 8,       "max_mcts_level_idc"); 
855    }
856  }
857}
858
859Void SEIWriter::xWriteSEITimeCode(const SEITimeCode& sei)
860{
861  WRITE_CODE(sei.numClockTs, 2, "num_clock_ts");
862  for(Int i = 0; i < sei.numClockTs; i++)
863  {
864    const TComSEITimeSet &currentTimeSet = sei.timeSetArray[i];
865    WRITE_FLAG(currentTimeSet.clockTimeStampFlag, "clock_time_stamp_flag");
866    if(currentTimeSet.clockTimeStampFlag)
867    {
868      WRITE_FLAG(currentTimeSet.numUnitFieldBasedFlag, "units_field_based_flag");
869      WRITE_CODE(currentTimeSet.countingType, 5, "counting_type");
870      WRITE_FLAG(currentTimeSet.fullTimeStampFlag, "full_timestamp_flag");
871      WRITE_FLAG(currentTimeSet.discontinuityFlag, "discontinuity_flag");
872      WRITE_FLAG(currentTimeSet.cntDroppedFlag, "cnt_dropped_flag");
873      WRITE_CODE(currentTimeSet.numberOfFrames, 9, "n_frames");
874      if(currentTimeSet.fullTimeStampFlag)
875      {
876        WRITE_CODE(currentTimeSet.secondsValue, 6, "seconds_value");
877        WRITE_CODE(currentTimeSet.minutesValue, 6, "minutes_value");
878        WRITE_CODE(currentTimeSet.hoursValue, 5, "hours_value");
879      }
880      else
881      {
882        WRITE_FLAG(currentTimeSet.secondsFlag, "seconds_flag");
883        if(currentTimeSet.secondsFlag)
884        {
885          WRITE_CODE(currentTimeSet.secondsValue, 6, "seconds_value");
886          WRITE_FLAG(currentTimeSet.minutesFlag, "minutes_flag");
887          if(currentTimeSet.minutesFlag)
888          {
889            WRITE_CODE(currentTimeSet.minutesValue, 6, "minutes_value");
890            WRITE_FLAG(currentTimeSet.hoursFlag, "hours_flag");
891            if(currentTimeSet.hoursFlag)
892              WRITE_CODE(currentTimeSet.hoursValue, 5, "hours_value");
893          }
894        }
895      }
896      WRITE_CODE(currentTimeSet.timeOffsetLength, 5, "time_offset_length");
897      if(currentTimeSet.timeOffsetLength > 0)
898      {
899        if(currentTimeSet.timeOffsetValue >= 0)
900        {
901          WRITE_CODE((UInt)currentTimeSet.timeOffsetValue, currentTimeSet.timeOffsetLength, "time_offset_value");
902        }
903        else
904        {
905          //  Two's complement conversion
906          UInt offsetValue = ~(currentTimeSet.timeOffsetValue) + 1;
907          offsetValue |= (1 << (currentTimeSet.timeOffsetLength-1));
908          WRITE_CODE(offsetValue, currentTimeSet.timeOffsetLength, "time_offset_value");
909        }
910      }
911    }
912  }
913}
914
915Void SEIWriter::xWriteSEIChromaSamplingFilterHint(const SEIChromaSamplingFilterHint &sei/*, TComSPS* sps*/)
916{
917  WRITE_CODE(sei.m_verChromaFilterIdc, 8, "ver_chroma_filter_idc");
918  WRITE_CODE(sei.m_horChromaFilterIdc, 8, "hor_chroma_filter_idc");
919  WRITE_FLAG(sei.m_verFilteringProcessFlag, "ver_filtering_process_flag");
920  if(sei.m_verChromaFilterIdc == 1 || sei.m_horChromaFilterIdc == 1)
921  {
922    writeUserDefinedCoefficients(sei);
923  }
924}
925
926// write hardcoded chroma filter coefficients in the SEI messages
927Void SEIWriter::writeUserDefinedCoefficients(const SEIChromaSamplingFilterHint &sei)
928{
929  Int const iNumVerticalFilters = 3;
930  Int verticalTapLength_minus1[iNumVerticalFilters] = {5,3,3};
931  Int* userVerticalCoefficients[iNumVerticalFilters];
932  for(Int i = 0; i < iNumVerticalFilters; i ++)
933  {
934    userVerticalCoefficients[i] = (Int*)malloc( (verticalTapLength_minus1[i]+1) * sizeof(Int));
935  }
936  userVerticalCoefficients[0][0] = -3;
937  userVerticalCoefficients[0][1] = 13;
938  userVerticalCoefficients[0][2] = 31;
939  userVerticalCoefficients[0][3] = 23;
940  userVerticalCoefficients[0][4] = 3;
941  userVerticalCoefficients[0][5] = -3;
942
943  userVerticalCoefficients[1][0] = -1;
944  userVerticalCoefficients[1][1] = 25;
945  userVerticalCoefficients[1][2] = 247;
946  userVerticalCoefficients[1][3] = -15;
947
948  userVerticalCoefficients[2][0] = -20;
949  userVerticalCoefficients[2][1] = 186;
950  userVerticalCoefficients[2][2] = 100;
951  userVerticalCoefficients[2][3] = -10;
952 
953  Int const iNumHorizontalFilters = 1;
954  Int horizontalTapLength_minus1[iNumHorizontalFilters] = {3};
955  Int* userHorizontalCoefficients[iNumHorizontalFilters];
956  for(Int i = 0; i < iNumHorizontalFilters; i ++)
957  {
958    userHorizontalCoefficients[i] = (Int*)malloc( (horizontalTapLength_minus1[i]+1) * sizeof(Int));
959  }
960  userHorizontalCoefficients[0][0] = 1;
961  userHorizontalCoefficients[0][1] = 6;
962  userHorizontalCoefficients[0][2] = 1;
963
964  WRITE_UVLC(3, "target_format_idc");
965  if(sei.m_verChromaFilterIdc == 1)
966  {
967    WRITE_UVLC(iNumVerticalFilters, "num_vertical_filters");
968    if(iNumVerticalFilters > 0)
969    {
970      for(Int i = 0; i < iNumVerticalFilters; i ++)
971      {
972        WRITE_UVLC(verticalTapLength_minus1[i], "ver_tap_length_minus_1");
973        for(Int j = 0; j < verticalTapLength_minus1[i]; j ++)
974        {
975          WRITE_SVLC(userVerticalCoefficients[i][j], "ver_filter_coeff");
976        }
977      }
978    }
979  }
980  if(sei.m_horChromaFilterIdc == 1)
981  {
982    WRITE_UVLC(iNumHorizontalFilters, "num_horizontal_filters");
983    if(iNumHorizontalFilters > 0)
984    {
985      for(Int i = 0; i < iNumHorizontalFilters; i ++)
986      {
987        WRITE_UVLC(horizontalTapLength_minus1[i], "hor_tap_length_minus_1");
988        for(Int j = 0; j < horizontalTapLength_minus1[i]; j ++)
989        {
990          WRITE_SVLC(userHorizontalCoefficients[i][j], "hor_filter_coeff");
991        }
992      }
993    }
994  }
995}
996
997Void SEIWriter::xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei)
998{
999  WRITE_UVLC( sei.m_kneeId, "knee_function_id" );
1000  WRITE_FLAG( sei.m_kneeCancelFlag, "knee_function_cancel_flag" ); 
1001  if ( !sei.m_kneeCancelFlag )
1002  {
1003    WRITE_FLAG( sei.m_kneePersistenceFlag, "knee_function_persistence_flag" );
1004    WRITE_CODE( (UInt)sei.m_kneeInputDrange , 32,  "input_d_range" );
1005    WRITE_CODE( (UInt)sei.m_kneeInputDispLuminance, 32,  "input_disp_luminance" );
1006    WRITE_CODE( (UInt)sei.m_kneeOutputDrange, 32,  "output_d_range" );
1007    WRITE_CODE( (UInt)sei.m_kneeOutputDispLuminance, 32,  "output_disp_luminance" );
1008    WRITE_UVLC( sei.m_kneeNumKneePointsMinus1, "num_knee_points_minus1" );
1009    for(Int i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
1010    {
1011      WRITE_CODE( (UInt)sei.m_kneeInputKneePoint[i], 10,"input_knee_point" );
1012      WRITE_CODE( (UInt)sei.m_kneeOutputKneePoint[i], 10, "output_knee_point" );
1013    }
1014  }
1015}
1016
1017
1018Void SEIWriter::xWriteSEIMasteringDisplayColourVolume(const SEIMasteringDisplayColourVolume& sei)
1019{
1020  WRITE_CODE( sei.values.primaries[0][0],  16,  "display_primaries_x[0]" );
1021  WRITE_CODE( sei.values.primaries[0][1],  16,  "display_primaries_y[0]" );
1022
1023  WRITE_CODE( sei.values.primaries[1][0],  16,  "display_primaries_x[1]" );
1024  WRITE_CODE( sei.values.primaries[1][1],  16,  "display_primaries_y[1]" );
1025
1026  WRITE_CODE( sei.values.primaries[2][0],  16,  "display_primaries_x[2]" );
1027  WRITE_CODE( sei.values.primaries[2][1],  16,  "display_primaries_y[2]" );
1028
1029  WRITE_CODE( sei.values.whitePoint[0],    16,  "white_point_x" );
1030  WRITE_CODE( sei.values.whitePoint[1],    16,  "white_point_y" );
1031   
1032  WRITE_CODE( sei.values.maxLuminance,     32,  "max_display_mastering_luminance" );
1033  WRITE_CODE( sei.values.minLuminance,     32,  "min_display_mastering_luminance" );
1034}
1035
1036
1037Void SEIWriter::xWriteByteAlign()
1038{
1039  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
1040  {
1041    WRITE_FLAG( 1, "payload_bit_equal_to_one" );
1042    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
1043    {
1044      WRITE_FLAG( 0, "payload_bit_equal_to_zero" );
1045    }
1046  }
1047}
1048
1049#if SVC_EXTENSION
1050#if LAYERS_NOT_PRESENT_SEI
1051Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
1052{
1053  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
1054  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
1055  {
1056    WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
1057  } 
1058}
1059#endif
1060
1061#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
1062Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
1063{
1064  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
1065  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
1066  if( !sei.m_ilOneTilePerTileSetFlag )
1067  {
1068    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
1069    if( sei.m_ilNumSetsInMessageMinus1 )
1070    {
1071      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
1072    }
1073    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
1074    for( UInt i = 0; i < numSignificantSets; i++ )
1075    {
1076      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
1077      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
1078      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
1079      {
1080        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
1081        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
1082      }
1083      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
1084      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
1085      {
1086        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
1087      }
1088    }
1089  }
1090  else
1091  {
1092    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
1093  }
1094}
1095#endif
1096#if SUB_BITSTREAM_PROPERTY_SEI
1097Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
1098{
1099  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
1100  assert( sei.m_numAdditionalSubStreams >= 1 );
1101  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
1102
1103  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
1104  {
1105    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
1106    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
1107    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
1108    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
1109    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
1110  } 
1111}
1112#endif
1113
1114#if Q0189_TMVP_CONSTRAINTS
1115Void SEIWriter::xWriteSEITMVPConstraints (const SEITMVPConstrains &sei)
1116{
1117  WRITE_UVLC( sei.prev_pics_not_used_flag ,    "prev_pics_not_used_flag"  );
1118  WRITE_UVLC( sei.no_intra_layer_col_pic_flag ,    "no_intra_layer_col_pic_flag"  ); 
1119}
1120#endif
1121
1122#if Q0247_FRAME_FIELD_INFO
1123Void SEIWriter::xWriteSEIFrameFieldInfo  (const SEIFrameFieldInfo &sei)
1124{
1125  WRITE_CODE( sei.m_ffinfo_picStruct , 4,             "ffinfo_pic_struct" );
1126  WRITE_CODE( sei.m_ffinfo_sourceScanType, 2,         "ffinfo_source_scan_type" );
1127  WRITE_FLAG( sei.m_ffinfo_duplicateFlag ? 1 : 0,     "ffinfo_duplicate_flag" );
1128}
1129#endif
1130
1131#if O0164_MULTI_LAYER_HRD
1132Void SEIWriter::xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei)
1133{
1134  WRITE_UVLC( sei.m_bspIdx, "bsp_idx" );
1135
1136  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
1137  {
1138    WRITE_FLAG( 0, "bsp_nesting_zero_bit" );
1139  }
1140
1141  assert( sei.m_nestedSEIs.size() <= MAX_SEIS_IN_BSP_NESTING );
1142  WRITE_UVLC( (UInt)sei.m_nestedSEIs.size(), "num_seis_in_bsp_minus1" );
1143
1144  // write nested SEI messages
1145  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
1146  {
1147    writeSEImessage(bs, *(*it), vps, sps, &nestingSei, &sei);
1148  }
1149}
1150
1151Void SEIWriter::xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
1152{
1153  assert(vps->getVpsVuiPresentFlag());
1154
1155  Int psIdx = bspNestingSei.m_seiPartitioningSchemeIdx;
1156  Int seiOlsIdx = bspNestingSei.m_seiOlsIdx;
1157  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0] - 1;
1158  Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
1159  std::vector<Int> hrdIdx(maxValues, 0);
1160  std::vector<const TComHRD*> hrdVec;
1161  std::vector<Int> syntaxElemLen(maxValues, 0);
1162  for(Int i = 0; i < maxValues; i++)
1163  {
1164    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
1165    hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
1166   
1167    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
1168    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
1169    {
1170      assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
1171    }
1172    if( i > 0 )
1173    {
1174      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
1175      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
1176    }
1177  }
1178  if (hrdVec[0]->getNalHrdParametersPresentFlag())
1179  {
1180    for(UInt i = 0; i < maxValues; i++)
1181    {
1182      WRITE_CODE( sei.m_nalInitialArrivalDelay[i], syntaxElemLen[i], "nal_initial_arrival_delay[i]" );
1183    }
1184  }
1185  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
1186  {
1187    for(UInt i = 0; i < maxValues; i++)
1188    {
1189      WRITE_CODE( sei.m_vclInitialArrivalDelay[i], syntaxElemLen[i], "vcl_initial_arrival_delay[i]" );
1190    }
1191  }
1192}
1193
1194Void SEIWriter::xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
1195{
1196  if( commonInfPresentFlag )
1197  {
1198    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
1199    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
1200    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
1201    {
1202      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
1203      if( hrd->getSubPicCpbParamsPresentFlag() )
1204      {
1205        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
1206        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
1207        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
1208        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
1209      }
1210      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
1211      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
1212      if( hrd->getSubPicCpbParamsPresentFlag() )
1213      {
1214        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" ); 
1215      }
1216      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
1217      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
1218      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
1219    }
1220  }
1221  Int i, j, nalOrVcl;
1222  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
1223  {
1224    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
1225    if( !hrd->getFixedPicRateFlag( i ) )
1226    {
1227      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
1228    }
1229    else
1230    {
1231      hrd->setFixedPicRateWithinCvsFlag( i, true );
1232    }
1233    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
1234    {
1235      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
1236    }
1237    else
1238    {
1239      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
1240    }
1241    if (!hrd->getLowDelayHrdFlag( i ))
1242    {
1243      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
1244    }
1245   
1246    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
1247    {
1248      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
1249          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
1250      {
1251        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
1252        {
1253          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
1254          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
1255          if( hrd->getSubPicCpbParamsPresentFlag() )
1256          {
1257            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
1258            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
1259          }
1260          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
1261        }
1262      }
1263    }
1264  }
1265}
1266
1267#endif
1268
1269#if P0123_ALPHA_CHANNEL_SEI
1270Void SEIWriter::xWriteSEIAlphaChannelInfo(const SEIAlphaChannelInfo &sei)
1271{
1272  WRITE_FLAG(sei.m_alphaChannelCancelFlag, "alpha_channel_cancel_flag");
1273  if(!sei.m_alphaChannelCancelFlag)
1274  {
1275    WRITE_CODE(sei.m_alphaChannelUseIdc, 3, "alpha_channel_use_idc");
1276    WRITE_CODE(sei.m_alphaChannelBitDepthMinus8, 3, "alpha_channel_bit_depth_minus8");
1277    WRITE_CODE(sei.m_alphaTransparentValue, sei.m_alphaChannelBitDepthMinus8 + 9, "alpha_transparent_value");
1278    WRITE_CODE(sei.m_alphaOpaqueValue, sei.m_alphaChannelBitDepthMinus8 + 9, "alpha_opaque_value");
1279    WRITE_FLAG(sei.m_alphaChannelIncrFlag, "alpha_channel_incr_flag");
1280    WRITE_FLAG(sei.m_alphaChannelClipFlag, "alpha_channel_clip_flag");
1281    if(sei.m_alphaChannelClipFlag)
1282    {
1283      WRITE_FLAG(sei.m_alphaChannelClipTypeFlag, "alpha_channel_clip_type_flag");
1284    }
1285  }
1286  xWriteByteAlign();
1287}
1288#endif
1289
1290#if Q0096_OVERLAY_SEI
1291Void SEIWriter::xWriteSEIOverlayInfo(const SEIOverlayInfo &sei)
1292{
1293  Int i,j;
1294  WRITE_FLAG( sei.m_overlayInfoCancelFlag, "overlay_info_cancel_flag" );
1295  if ( !sei.m_overlayInfoCancelFlag )
1296  {
1297    WRITE_UVLC( sei.m_overlayContentAuxIdMinus128, "overlay_content_aux_id_minus128" );
1298    WRITE_UVLC( sei.m_overlayLabelAuxIdMinus128, "overlay_label_aux_id_minus128" );
1299    WRITE_UVLC( sei.m_overlayAlphaAuxIdMinus128, "overlay_alpha_aux_id_minus128" );
1300    WRITE_UVLC( sei.m_overlayElementLabelValueLengthMinus8, "overlay_element_label_value_length_minus8" );
1301    assert( sei.m_numOverlaysMinus1 < MAX_OVERLAYS );
1302    WRITE_UVLC( sei.m_numOverlaysMinus1, "num_overlays_minus1" );
1303    for (i=0 ; i<=sei.m_numOverlaysMinus1 ; i++)
1304    {
1305      WRITE_UVLC( sei.m_overlayIdx[i], "overlay_idx" );
1306      WRITE_FLAG( sei.m_languageOverlayPresentFlag[i], "language_overlay_present_flag" );
1307      WRITE_CODE( sei.m_overlayContentLayerId[i], 6, "overlay_content_layer_id");
1308      WRITE_FLAG( sei.m_overlayLabelPresentFlag[i], "overlay_label_present_flag" );
1309      if ( sei.m_overlayLabelPresentFlag[i] )
1310      {
1311        WRITE_CODE(  sei.m_overlayLabelLayerId[i], 6, "overlay_label_layer_id");
1312      }
1313      WRITE_FLAG( sei.m_overlayAlphaPresentFlag[i], "overlay_alpha_present_flag" );
1314      if ( sei.m_overlayAlphaPresentFlag[i] )
1315      {
1316        WRITE_CODE( sei.m_overlayAlphaLayerId[i], 6, "overlay_alpha_layer_id");
1317      }
1318      if ( sei.m_overlayLabelPresentFlag[i] )
1319      {
1320        assert( sei.m_numOverlayElementsMinus1[i] < MAX_OVERLAY_ELEMENTS );
1321        WRITE_UVLC( sei.m_numOverlayElementsMinus1[i], "num_overlay_elements_minus1");
1322        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++ )
1323        {
1324          WRITE_CODE(sei.m_overlayElementLabelMin[i][j], sei.m_overlayElementLabelValueLengthMinus8 + 8, "overlay_element_label_min");
1325          WRITE_CODE(sei.m_overlayElementLabelMax[i][j], sei.m_overlayElementLabelValueLengthMinus8 + 8, "overlay_element_label_max"); 
1326        }
1327      }
1328    }
1329
1330
1331    // byte alignment
1332    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
1333    {
1334      WRITE_FLAG( 0, "overlay_zero_bit" );
1335    }
1336
1337    for ( i=0 ; i<=sei.m_numOverlaysMinus1 ; i++ )
1338    {
1339      if ( sei.m_languageOverlayPresentFlag[i] )
1340      {
1341        WRITE_STRING( sei.m_overlayLanguage[i], sei.m_overlayLanguageLength[i], "overlay_language" );    //WRITE_STRING adds zero-termination byte
1342      }
1343      WRITE_STRING( sei.m_overlayName[i], sei.m_overlayNameLength[i], "overlay_name" );
1344      if ( sei.m_overlayLabelPresentFlag[i] )
1345      {
1346        for ( j=0 ; j<=sei.m_numOverlayElementsMinus1[i] ; j++)
1347        {
1348          WRITE_STRING( sei.m_overlayElementName[i][j], sei.m_overlayElementNameLength[i][j], "overlay_element_name" );
1349        }
1350      }
1351    }
1352    WRITE_FLAG( sei.m_overlayInfoPersistenceFlag, "overlay_info_persistence_flag" );
1353  }
1354}
1355#endif
1356
1357#endif //SVC_EXTENSION
1358
1359#if Q0074_COLOUR_REMAPPING_SEI
1360Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
1361{
1362  WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
1363  WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
1364  if( !sei.m_colourRemapCancelFlag ) 
1365  {
1366    WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
1367    WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
1368    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
1369    {
1370      WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
1371      WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
1372      WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
1373      WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
1374    }
1375    WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
1376    WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
1377    for( Int c=0 ; c<3 ; c++ )
1378    {
1379      WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
1380      if( sei.m_preLutNumValMinus1[c]>0 )
1381        for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
1382        {
1383          WRITE_CODE( sei.m_preLutCodedValue[c][i], (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
1384          WRITE_CODE( sei.m_preLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
1385        }
1386    }
1387    WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
1388    if( sei.m_colourRemapMatrixPresentFlag )
1389    {
1390      WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
1391      for( Int c=0 ; c<3 ; c++ )
1392        for( Int i=0 ; i<3 ; i++ )
1393          WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
1394    }
1395
1396    for( Int c=0 ; c<3 ; c++ )
1397    {
1398      WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
1399      if( sei.m_postLutNumValMinus1[c]>0 )
1400        for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
1401        {
1402          WRITE_CODE( sei.m_postLutCodedValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );       
1403          WRITE_CODE( sei.m_postLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
1404        }
1405    }
1406  }
1407}
1408#endif
1409
1410//! \}
Note: See TracBrowser for help on using the repository browser.