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

Last change on this file since 1497 was 1475, checked in by seregin, 9 years ago

port rev 4600, remove macro Q0074_COLOUR_REMAPPING_SEI

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