1 | |
---|
2 | |
---|
3 | #include "../TLibCommon/TComBitCounter.h" |
---|
4 | #include "../TLibCommon/TComBitStream.h" |
---|
5 | #include "../TLibCommon/SEI.h" |
---|
6 | #include "SEIwrite.h" |
---|
7 | |
---|
8 | static void writeSEIuserDataUnregistered(TComBitIf& bs, const SEIuserDataUnregistered &sei); |
---|
9 | static void writeSEIpictureDigest(TComBitIf& bs, const SEIpictureDigest& sei); |
---|
10 | |
---|
11 | void writeSEIpayloadData(TComBitIf& bs, const SEI& sei) |
---|
12 | { |
---|
13 | switch (sei.payloadType()) |
---|
14 | { |
---|
15 | case SEI::USER_DATA_UNREGISTERED: |
---|
16 | writeSEIuserDataUnregistered(bs, *static_cast<const SEIuserDataUnregistered*>(&sei)); |
---|
17 | break; |
---|
18 | case SEI::PICTURE_DIGEST: |
---|
19 | writeSEIpictureDigest(bs, *static_cast<const SEIpictureDigest*>(&sei)); |
---|
20 | break; |
---|
21 | default: |
---|
22 | assert(!"Unhandled SEI message"); |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * marshal a single SEI message @sei, storing the marshalled representation |
---|
28 | * in bitstream @bs. |
---|
29 | */ |
---|
30 | void writeSEImessage(TComBitIf& bs, const SEI& sei) |
---|
31 | { |
---|
32 | /* calculate how large the payload data is */ |
---|
33 | /* TODO: this would be far nicer if it used vectored buffers */ |
---|
34 | TComBitCounter bs_count; |
---|
35 | bs_count.resetBits(); |
---|
36 | writeSEIpayloadData(bs_count, sei); |
---|
37 | unsigned payload_data_num_bits = bs_count.getNumberOfWrittenBits(); |
---|
38 | assert(0 == payload_data_num_bits % 8); |
---|
39 | |
---|
40 | unsigned payloadType = sei.payloadType(); |
---|
41 | for (; payloadType >= 0xff; payloadType -= 0xff) |
---|
42 | bs.write(0xff, 8); |
---|
43 | bs.write(payloadType, 8); |
---|
44 | |
---|
45 | unsigned payloadSize = payload_data_num_bits/8; |
---|
46 | for (; payloadSize >= 0xff; payloadSize -= 0xff) |
---|
47 | bs.write(0xff, 8); |
---|
48 | bs.write(payloadSize, 8); |
---|
49 | |
---|
50 | /* payloadData */ |
---|
51 | writeSEIpayloadData(bs, sei); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * marshal a user_data_unregistered SEI message @sei, storing the marshalled |
---|
56 | * representation in bitstream @bs. |
---|
57 | */ |
---|
58 | static void writeSEIuserDataUnregistered(TComBitIf& bs, const SEIuserDataUnregistered &sei) |
---|
59 | { |
---|
60 | for (unsigned i = 0; i < 16; i++) |
---|
61 | { |
---|
62 | bs.write(sei.uuid_iso_iec_11578[i], 8); |
---|
63 | } |
---|
64 | |
---|
65 | for (unsigned i = 0; i < sei.userDataLength; i++) |
---|
66 | { |
---|
67 | bs.write(sei.userData[i], 8); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * marshal a picture_digest SEI message, storing the marshalled |
---|
73 | * representation in bitstream @bs. |
---|
74 | */ |
---|
75 | static void writeSEIpictureDigest(TComBitIf& bs, const SEIpictureDigest& sei) |
---|
76 | { |
---|
77 | bs.write(sei.method, 8); |
---|
78 | for (unsigned i = 0; i < 16; i++) |
---|
79 | { |
---|
80 | bs.write(sei.digest[i], 8); |
---|
81 | } |
---|
82 | } |
---|