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

Last change on this file since 1547 was 1538, checked in by seregin, 9 years ago

port rev 4690

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