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

Last change on this file since 1005 was 912, checked in by seregin, 10 years ago

Overlay SEI with macro Q0096_OVERLAY_SEI, patch was provided by Nikolce Stefanoski <stefanos@…>

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