/src/exiv2/include/exiv2/asfvideo.hpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | // Spec : Advanced Systems Format (ASF) Specification : Revision 01.20.05 : |
3 | | // https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf |
4 | | |
5 | | #ifndef EXIV2_ASFVIDEO_HPP |
6 | | #define EXIV2_ASFVIDEO_HPP |
7 | | |
8 | | // ***************************************************************************** |
9 | | #include "exiv2lib_export.h" |
10 | | |
11 | | // included header files |
12 | | #include "image.hpp" |
13 | | |
14 | | #include <array> |
15 | | |
16 | | // ***************************************************************************** |
17 | | // namespace extensions |
18 | | namespace Exiv2 { |
19 | | |
20 | | // ***************************************************************************** |
21 | | // class definitions |
22 | | |
23 | | /*! |
24 | | @brief Class to access ASF video files. |
25 | | */ |
26 | | class EXIV2API AsfVideo : public Image { |
27 | | public: |
28 | | //! @name Creators |
29 | | //@{ |
30 | | /*! |
31 | | @brief Constructor for a ASF video. Since the constructor |
32 | | can not return a result, callers should check the good() method |
33 | | after object construction to determine success or failure. |
34 | | @param io An auto-pointer that owns a BasicIo instance used for |
35 | | reading and writing image metadata. \b Important: The constructor |
36 | | takes ownership of the passed in BasicIo instance through the |
37 | | auto-pointer. Callers should not continue to use the BasicIo |
38 | | instance after it is passed to this method. Use the Image::io() |
39 | | method to get a temporary reference. |
40 | | @param params Parameters that are passed through to Image's constructor. |
41 | | */ |
42 | | |
43 | | explicit AsfVideo(std::unique_ptr<BasicIo> io, const ImageCtorParams& params); |
44 | | //@} |
45 | | |
46 | | //! @name Manipulators |
47 | | //@{ |
48 | | void readMetadata() override; |
49 | | void writeMetadata() override; |
50 | | //@} |
51 | | |
52 | | //! @name Accessors |
53 | | //@{ |
54 | | [[nodiscard]] std::string mimeType() const override; |
55 | | //@} |
56 | | |
57 | | /* @class GUID_struct |
58 | | * |
59 | | * @brief A class to represent a globally unique identifier (GUID) structure |
60 | | * |
61 | | * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a |
62 | | * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to |
63 | | * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an |
64 | | * array of 8 bytes. |
65 | | * |
66 | | * @note The byte order of the GUID structure is in little endian. |
67 | | * |
68 | | * @see https://en.wikipedia.org/wiki/Globally_unique_identifier |
69 | | * |
70 | | */ |
71 | | class GUIDTag { |
72 | | uint32_t data1_; |
73 | | uint16_t data2_; |
74 | | uint16_t data3_; |
75 | | std::array<byte, 8> data4_; |
76 | | |
77 | | public: |
78 | | bool operator==(const GUIDTag& other) const; |
79 | | |
80 | | // Constructor to create a GUID object by passing individual values for each attribute |
81 | | constexpr GUIDTag(unsigned int data1, unsigned short data2, unsigned short data3, std::array<byte, 8> data4) : |
82 | 124 | data1_(data1), data2_(data2), data3_(data3), data4_(data4) { |
83 | 124 | } |
84 | | |
85 | | // Constructor to create a GUID object from a byte array |
86 | | explicit GUIDTag(const uint8_t* bytes); |
87 | | |
88 | | [[nodiscard]] std::string to_string() const; |
89 | | |
90 | | bool operator<(const GUIDTag& other) const; |
91 | | }; |
92 | | |
93 | | private: |
94 | | static constexpr size_t CODEC_TYPE_VIDEO = 1; |
95 | | static constexpr size_t CODEC_TYPE_AUDIO = 2; |
96 | | |
97 | | class HeaderReader { |
98 | | DataBuf IdBuf_; |
99 | | uint64_t size_{}; |
100 | | uint64_t remaining_size_{}; |
101 | | |
102 | | public: |
103 | | explicit HeaderReader(const std::unique_ptr<BasicIo>& io); |
104 | | |
105 | 2.53k | [[nodiscard]] uint64_t getSize() const { |
106 | 2.53k | return size_; |
107 | 2.53k | } |
108 | | |
109 | 471 | [[nodiscard]] uint64_t getRemainingSize() const { |
110 | 471 | return remaining_size_; |
111 | 471 | } |
112 | | |
113 | 2.34k | [[nodiscard]] DataBuf& getId() { |
114 | 2.34k | return IdBuf_; |
115 | 2.34k | } |
116 | | }; |
117 | | |
118 | | protected: |
119 | | /*! |
120 | | @brief Check for a valid tag and decode the block at the current IO |
121 | | position. Calls tagDecoder() or skips to next tag, if required. |
122 | | @param depth Current recursion depth, to detect files with excessive nesting. |
123 | | */ |
124 | | void decodeBlock(size_t depth); |
125 | | |
126 | | /*! |
127 | | @brief Parse the header |
128 | | @param depth Current recursion depth, to detect files with excessive nesting. |
129 | | */ |
130 | | void decodeHeader(size_t depth); |
131 | | /*! |
132 | | @brief Interpret File_Properties tag information, and save it in |
133 | | the respective XMP container. |
134 | | */ |
135 | | void fileProperties(); |
136 | | /*! |
137 | | @brief Interpret Stream_Properties tag information, and save it |
138 | | in the respective XMP container. |
139 | | */ |
140 | | void streamProperties(); |
141 | | /*! |
142 | | @brief Interpret Codec_List tag information, and save it in |
143 | | the respective XMP container. |
144 | | */ |
145 | | void codecList(); |
146 | | /*! |
147 | | @brief Interpret Content_Description tag information, and save it |
148 | | in the respective XMP container. |
149 | | */ |
150 | | void contentDescription(); |
151 | | /*! |
152 | | @brief Interpret Extended_Stream_Properties tag information, and |
153 | | save it in the respective XMP container. |
154 | | */ |
155 | | void extendedStreamProperties(); |
156 | | /*! |
157 | | @brief Interpret Header_Extension tag information, and save it in |
158 | | the respective XMP container. |
159 | | */ |
160 | | void headerExtension() const; |
161 | | /*! |
162 | | @brief Interpret Metadata, Extended_Content_Description, |
163 | | Metadata_Library tag information, and save it in the respective |
164 | | XMP container. |
165 | | */ |
166 | | void extendedContentDescription(); |
167 | | |
168 | | void DegradableJPEGMedia(); |
169 | | |
170 | | private: |
171 | | //! Variable to store height and width of a video frame. |
172 | | uint64_t height_{}; |
173 | | uint64_t width_{}; |
174 | | }; // Class AsfVideo |
175 | | |
176 | | // ***************************************************************************** |
177 | | // template, inline and free functions |
178 | | |
179 | | // These could be static private functions on Image subclasses but then |
180 | | // ImageFactory needs to be made a friend. |
181 | | /*! |
182 | | @brief Create a new AsfVideo instance and return an auto-pointer to it. |
183 | | Caller owns the returned object and the auto-pointer ensures that |
184 | | it will be deleted. |
185 | | */ |
186 | | EXIV2API Image::UniquePtr newAsfInstance(std::unique_ptr<BasicIo> io, const ImageCtorParams& params); |
187 | | |
188 | | //! Check if the file iIo is a Windows Asf Video. |
189 | | EXIV2API bool isAsfType(BasicIo& iIo, bool advance); |
190 | | } // namespace Exiv2 |
191 | | |
192 | | #endif // EXIV2_ASFVIDEO_HPP |