source: 3DVCSoftware/branches/HTM-3.0-Qualcomm/source/Lib/TLibEncoder/SEIwrite.cpp @ 69

Last change on this file since 69 was 56, checked in by hschwarz, 13 years ago

updated trunk (move to HM6.1)

  • Property svn:eol-style set to native
File size: 4.0 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-2012, 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 "SEIwrite.h"
38
39//! \ingroup TLibEncoder
40//! \{
41
42static void writeSEIuserDataUnregistered(TComBitIf& bs, const SEIuserDataUnregistered &sei);
43static void writeSEIpictureDigest(TComBitIf& bs, const SEIpictureDigest& sei);
44
45void writeSEIpayloadData(TComBitIf& bs, const SEI& sei)
46{
47  switch (sei.payloadType())
48  {
49  case SEI::USER_DATA_UNREGISTERED:
50    writeSEIuserDataUnregistered(bs, *static_cast<const SEIuserDataUnregistered*>(&sei));
51    break;
52  case SEI::PICTURE_DIGEST:
53    writeSEIpictureDigest(bs, *static_cast<const SEIpictureDigest*>(&sei));
54    break;
55  default:
56    assert(!"Unhandled SEI message");
57  }
58}
59
60/**
61 * marshal a single SEI message sei, storing the marshalled representation
62 * in bitstream bs.
63 */
64void writeSEImessage(TComBitIf& bs, const SEI& sei)
65{
66  /* calculate how large the payload data is */
67  /* TODO: this would be far nicer if it used vectored buffers */
68  TComBitCounter bs_count;
69  bs_count.resetBits();
70  writeSEIpayloadData(bs_count, sei);
71  unsigned payload_data_num_bits = bs_count.getNumberOfWrittenBits();
72  assert(0 == payload_data_num_bits % 8);
73
74  unsigned payloadType = sei.payloadType();
75  for (; payloadType >= 0xff; payloadType -= 0xff)
76    bs.write(0xff, 8);
77  bs.write(payloadType, 8);
78
79  unsigned payloadSize = payload_data_num_bits/8;
80  for (; payloadSize >= 0xff; payloadSize -= 0xff)
81    bs.write(0xff, 8);
82  bs.write(payloadSize, 8);
83
84  /* payloadData */
85  writeSEIpayloadData(bs, sei);
86}
87
88/**
89 * marshal a user_data_unregistered SEI message sei, storing the marshalled
90 * representation in bitstream bs.
91 */
92static void writeSEIuserDataUnregistered(TComBitIf& bs, const SEIuserDataUnregistered &sei)
93{
94  for (unsigned i = 0; i < 16; i++)
95  {
96    bs.write(sei.uuid_iso_iec_11578[i], 8);
97  }
98
99  for (unsigned i = 0; i < sei.userDataLength; i++)
100  {
101    bs.write(sei.userData[i], 8);
102  }
103}
104
105/**
106 * marshal a picture_digest SEI message, storing the marshalled
107 * representation in bitstream bs.
108 */
109static void writeSEIpictureDigest(TComBitIf& bs, const SEIpictureDigest& sei)
110{
111  bs.write(sei.method, 8);
112  for (unsigned i = 0; i < 16; i++)
113  {
114    bs.write(sei.digest[i], 8);
115  }
116}
117//! \}
Note: See TracBrowser for help on using the repository browser.