|
10 | 10 | #include "helper_functions.hpp" |
11 | 11 | #include "image_int.hpp" |
12 | 12 |
|
13 | | -// ***************************************************************************** |
14 | | -// class member definitions |
15 | | -namespace Exiv2 { |
16 | | - |
17 | | -/*! |
18 | | - Look-up list for ASF Type Video Files |
19 | | - Associates the GUID with its Name(i.e. Human Readable Form) |
20 | | - Tags have been differentiated into Various Categories. |
21 | | - The categories have been listed above Groups |
22 | | - see : |
23 | | - - https://fr.wikipedia.org/wiki/Advanced_Systems_Format |
24 | | - - https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf |
25 | | - */ |
26 | | -/* |
27 | | - * @class GUID_struct |
28 | | - * |
29 | | - * @brief A class to represent a globally unique identifier (GUID) structure |
30 | | - * |
31 | | - * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a |
32 | | - * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to |
33 | | - * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an |
34 | | - * array of 8 bytes. |
35 | | - * |
36 | | - * @note The byte order of the GUID structure is in little endian. |
37 | | - * |
38 | | - * @see https://en.wikipedia.org/wiki/Globally_unique_identifier |
39 | | - * |
40 | | - */ |
41 | | - |
42 | | -bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const { |
43 | | - return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_; |
44 | | -} |
| 13 | +namespace { |
| 14 | +constexpr Exiv2::AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}); |
45 | 15 |
|
46 | | -AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { |
47 | | - data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian); |
48 | | - data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian); |
49 | | - data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian); |
50 | | - std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin()); |
51 | | -} |
| 16 | +constexpr struct tags { |
| 17 | + Exiv2::AsfVideo::GUIDTag first; |
| 18 | + std::string_view second; |
52 | 19 |
|
53 | | -std::string AsfVideo::GUIDTag::to_string() const { |
54 | | - // Concatenate all strings into a single string |
55 | | - // Convert the string to uppercase |
56 | | - // Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E |
57 | | - return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_, |
58 | | - data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]); |
59 | | -} |
60 | | - |
61 | | -bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const { |
62 | | - if (data1_ != other.data1_) |
63 | | - return data1_ < other.data1_; |
64 | | - if (data2_ != other.data2_) |
65 | | - return data2_ < other.data2_; |
66 | | - if (data3_ != other.data3_) |
67 | | - return data3_ < other.data3_; |
68 | | - return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end()); |
69 | | -} |
70 | | - |
71 | | -constexpr AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}); |
72 | | - |
73 | | -const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = { |
| 20 | + bool operator==(const Exiv2::DataBuf& tag) const { |
| 21 | + return Exiv2::AsfVideo::GUIDTag(tag.c_data()) == first; |
| 22 | + }; |
| 23 | +} GUIDReferenceTags[] = { |
74 | 24 | //!< Top-level ASF object GUIDS |
75 | 25 | {Header, "Header"}, |
76 | 26 | {{0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}}, "Data"}, |
@@ -175,8 +125,68 @@ const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = { |
175 | 125 | @param buf Exiv2 byte buffer |
176 | 126 | @return Returns true if the buffer data is equivalent to Header GUID. |
177 | 127 | */ |
178 | | -static bool isASFType(const byte buf[]) { |
179 | | - return Header == AsfVideo::GUIDTag(buf); |
| 128 | +bool isASFType(const Exiv2::byte buf[]) { |
| 129 | + return Header == Exiv2::AsfVideo::GUIDTag(buf); |
| 130 | +} |
| 131 | + |
| 132 | +} // namespace |
| 133 | + |
| 134 | +// ***************************************************************************** |
| 135 | +// class member definitions |
| 136 | +namespace Exiv2 { |
| 137 | + |
| 138 | +/*! |
| 139 | + Look-up list for ASF Type Video Files |
| 140 | + Associates the GUID with its Name(i.e. Human Readable Form) |
| 141 | + Tags have been differentiated into Various Categories. |
| 142 | + The categories have been listed above Groups |
| 143 | + see : |
| 144 | + - https://fr.wikipedia.org/wiki/Advanced_Systems_Format |
| 145 | + - https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf |
| 146 | + */ |
| 147 | +/* |
| 148 | + * @class GUID_struct |
| 149 | + * |
| 150 | + * @brief A class to represent a globally unique identifier (GUID) structure |
| 151 | + * |
| 152 | + * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a |
| 153 | + * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to |
| 154 | + * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an |
| 155 | + * array of 8 bytes. |
| 156 | + * |
| 157 | + * @note The byte order of the GUID structure is in little endian. |
| 158 | + * |
| 159 | + * @see https://en.wikipedia.org/wiki/Globally_unique_identifier |
| 160 | + * |
| 161 | + */ |
| 162 | + |
| 163 | +bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const { |
| 164 | + return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_; |
| 165 | +} |
| 166 | + |
| 167 | +AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { |
| 168 | + data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian); |
| 169 | + data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian); |
| 170 | + data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian); |
| 171 | + std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin()); |
| 172 | +} |
| 173 | + |
| 174 | +std::string AsfVideo::GUIDTag::to_string() const { |
| 175 | + // Concatenate all strings into a single string |
| 176 | + // Convert the string to uppercase |
| 177 | + // Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E |
| 178 | + return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_, |
| 179 | + data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]); |
| 180 | +} |
| 181 | + |
| 182 | +bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const { |
| 183 | + if (data1_ != other.data1_) |
| 184 | + return data1_ < other.data1_; |
| 185 | + if (data2_ != other.data2_) |
| 186 | + return data2_ < other.data2_; |
| 187 | + if (data3_ != other.data3_) |
| 188 | + return data3_ < other.data3_; |
| 189 | + return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end()); |
180 | 190 | } |
181 | 191 |
|
182 | 192 | AsfVideo::AsfVideo(BasicIo::UniquePtr io) : Image(ImageType::asf, mdNone, std::move(io)) { |
@@ -231,9 +241,8 @@ void AsfVideo::decodeBlock() { |
231 | 241 | << "\tsize= " << objectHeader.getSize() << "\t " << io_->tell() << "/" << io_->size() << '\n'; |
232 | 242 | #endif |
233 | 243 | Internal::enforce(objectHeader.getSize() <= io_->size() - io_->tell(), Exiv2::ErrorCode::kerCorruptedMetadata); |
234 | | - auto tag = GUIDReferenceTags.find(GUIDTag(objectHeader.getId().data())); |
235 | 244 |
|
236 | | - if (tag != GUIDReferenceTags.end()) { |
| 245 | + if (auto tag = Exiv2::find(GUIDReferenceTags, objectHeader.getId())) { |
237 | 246 | if (tag->second == "Header") |
238 | 247 | decodeHeader(); |
239 | 248 | else if (tag->second == "File_Properties") |
@@ -339,8 +348,7 @@ void AsfVideo::streamProperties() { |
339 | 348 | enum class streamTypeInfo { Audio = 1, Video = 2 }; |
340 | 349 | auto stream = streamTypeInfo{0}; |
341 | 350 |
|
342 | | - auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data())); |
343 | | - if (tag_stream_type != GUIDReferenceTags.end()) { |
| 351 | + if (auto tag_stream_type = Exiv2::find(GUIDReferenceTags, streamTypedBuf)) { |
344 | 352 | if (tag_stream_type->second == "Audio_Media") |
345 | 353 | stream = streamTypeInfo::Audio; |
346 | 354 | else if (tag_stream_type->second == "Video_Media") |
|
0 commit comments