1 | |
---|
2 | |
---|
3 | #include "../TLibCommon/TComBitStream.h" |
---|
4 | #include "../TLibCommon/SEI.h" |
---|
5 | #include "SEIread.h" |
---|
6 | |
---|
7 | static void parseSEIuserDataUnregistered(TComBitstream& bs, SEIuserDataUnregistered &sei, unsigned payloadSize); |
---|
8 | static void parseSEIpictureDigest(TComBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize); |
---|
9 | |
---|
10 | /** |
---|
11 | * unmarshal a single SEI message from bitstream @bs |
---|
12 | */ |
---|
13 | void parseSEImessage(TComBitstream& bs, SEImessages& seis) |
---|
14 | { |
---|
15 | unsigned payloadType = 0; |
---|
16 | for (unsigned char byte = 0xff; 0xff == byte; ) |
---|
17 | { |
---|
18 | payloadType += byte = bs.read(8); |
---|
19 | } |
---|
20 | |
---|
21 | unsigned payloadSize = 0; |
---|
22 | for (unsigned char byte = 0xff; 0xff == byte; ) |
---|
23 | { |
---|
24 | payloadSize += byte = bs.read(8); |
---|
25 | } |
---|
26 | |
---|
27 | switch (payloadType) |
---|
28 | { |
---|
29 | case SEI::USER_DATA_UNREGISTERED: |
---|
30 | seis.user_data_unregistered = new SEIuserDataUnregistered; |
---|
31 | parseSEIuserDataUnregistered(bs, *seis.user_data_unregistered, payloadSize); |
---|
32 | break; |
---|
33 | case SEI::PICTURE_DIGEST: |
---|
34 | seis.picture_digest = new SEIpictureDigest; |
---|
35 | parseSEIpictureDigest(bs, *seis.picture_digest, payloadSize); |
---|
36 | break; |
---|
37 | default: |
---|
38 | assert(!"Unhandled SEI message"); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * parse bitstream @bs and unpack a user_data_unregistered SEI message |
---|
44 | * of @payloasSize bytes into @sei. |
---|
45 | */ |
---|
46 | static void parseSEIuserDataUnregistered(TComBitstream& bs, SEIuserDataUnregistered &sei, unsigned payloadSize) |
---|
47 | { |
---|
48 | assert(payloadSize >= 16); |
---|
49 | for (unsigned i = 0; i < 16; i++) |
---|
50 | { |
---|
51 | sei.uuid_iso_iec_11578[i] = bs.read(8); |
---|
52 | } |
---|
53 | |
---|
54 | sei.userDataLength = payloadSize - 16; |
---|
55 | if (!sei.userDataLength) |
---|
56 | { |
---|
57 | sei.userData = 0; |
---|
58 | return; |
---|
59 | } |
---|
60 | |
---|
61 | sei.userData = new unsigned char[sei.userDataLength]; |
---|
62 | for (unsigned i = 0; i < sei.userDataLength; i++) |
---|
63 | { |
---|
64 | sei.userData[i] = bs.read(8); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * parse bitstream @bs and unpack a picture_digest SEI message |
---|
70 | * of @payloadSize bytes into @sei. |
---|
71 | */ |
---|
72 | static void parseSEIpictureDigest(TComBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize) |
---|
73 | { |
---|
74 | assert(payloadSize >= 17); |
---|
75 | sei.method = static_cast<SEIpictureDigest::Method>(bs.read(8)); |
---|
76 | assert(SEIpictureDigest::MD5 == sei.method); |
---|
77 | for (unsigned i = 0; i < 16; i++) |
---|
78 | { |
---|
79 | sei.digest[i] = bs.read(8); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|