Coverage Report

Created: 2026-02-26 07:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
  */
41
42
  explicit AsfVideo(std::unique_ptr<BasicIo> io);
43
  //@}
44
45
  //! @name Manipulators
46
  //@{
47
  void readMetadata() override;
48
  void writeMetadata() override;
49
  //@}
50
51
  //! @name Accessors
52
  //@{
53
  [[nodiscard]] std::string mimeType() const override;
54
  //@}
55
56
  /* @class GUID_struct
57
   *
58
   * @brief A class to represent a globally unique identifier (GUID) structure
59
   *
60
   * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a
61
   * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to
62
   * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an
63
   * array of 8 bytes.
64
   *
65
   * @note The byte order of the GUID structure is in little endian.
66
   *
67
   * @see https://en.wikipedia.org/wiki/Globally_unique_identifier
68
   *
69
   */
70
  class GUIDTag {
71
    uint32_t data1_;
72
    uint16_t data2_;
73
    uint16_t data3_;
74
    std::array<byte, 8> data4_;
75
76
   public:
77
    bool operator==(const GUIDTag& other) const;
78
79
    // Constructor to create a GUID object by passing individual values for each attribute
80
    constexpr GUIDTag(unsigned int data1, unsigned short data2, unsigned short data3, std::array<byte, 8> data4) :
81
248
        data1_(data1), data2_(data2), data3_(data3), data4_(data4) {
82
248
    }
83
84
    // Constructor to create a GUID object from a byte array
85
    explicit GUIDTag(const uint8_t* bytes);
86
87
    [[nodiscard]] std::string to_string() const;
88
89
    bool operator<(const GUIDTag& other) const;
90
  };
91
92
 private:
93
  static constexpr size_t CODEC_TYPE_VIDEO = 1;
94
  static constexpr size_t CODEC_TYPE_AUDIO = 2;
95
96
  class HeaderReader {
97
    DataBuf IdBuf_;
98
    uint64_t size_{};
99
    uint64_t remaining_size_{};
100
101
   public:
102
    explicit HeaderReader(const std::unique_ptr<BasicIo>& io);
103
104
2.75k
    [[nodiscard]] uint64_t getSize() const {
105
2.75k
      return size_;
106
2.75k
    }
107
108
466
    [[nodiscard]] uint64_t getRemainingSize() const {
109
466
      return remaining_size_;
110
466
    }
111
112
2.43k
    [[nodiscard]] DataBuf& getId() {
113
2.43k
      return IdBuf_;
114
2.43k
    }
115
  };
116
117
 protected:
118
  /*!
119
    @brief Check for a valid tag and decode the block at the current IO
120
    position. Calls tagDecoder() or skips to next tag, if required.
121
   */
122
  void decodeBlock();
123
124
  void decodeHeader();
125
  /*!
126
    @brief Interpret File_Properties tag information, and save it in
127
        the respective XMP container.
128
   */
129
  void fileProperties();
130
  /*!
131
    @brief Interpret Stream_Properties tag information, and save it
132
        in the respective XMP container.
133
   */
134
  void streamProperties();
135
  /*!
136
    @brief Interpret Codec_List tag information, and save it in
137
        the respective XMP container.
138
   */
139
  void codecList();
140
  /*!
141
    @brief Interpret Content_Description tag information, and save it
142
        in the respective XMP container.
143
   */
144
  void contentDescription();
145
  /*!
146
    @brief Interpret Extended_Stream_Properties tag information, and
147
        save it in the respective XMP container.
148
   */
149
  void extendedStreamProperties();
150
  /*!
151
    @brief Interpret Header_Extension tag information, and save it in
152
        the respective XMP container.
153
   */
154
  void headerExtension() const;
155
  /*!
156
    @brief Interpret Metadata, Extended_Content_Description,
157
        Metadata_Library tag information, and save it in the respective
158
        XMP container.
159
   */
160
  void extendedContentDescription();
161
162
  void DegradableJPEGMedia();
163
164
 private:
165
  //! Variable to store height and width of a video frame.
166
  uint64_t height_{};
167
  uint64_t width_{};
168
169
};  // Class AsfVideo
170
171
// *****************************************************************************
172
// template, inline and free functions
173
174
// These could be static private functions on Image subclasses but then
175
// ImageFactory needs to be made a friend.
176
/*!
177
  @brief Create a new AsfVideo instance and return an auto-pointer to it.
178
      Caller owns the returned object and the auto-pointer ensures that
179
      it will be deleted.
180
 */
181
EXIV2API Image::UniquePtr newAsfInstance(std::unique_ptr<BasicIo> io, bool create);
182
183
//! Check if the file iIo is a Windows Asf Video.
184
EXIV2API bool isAsfType(BasicIo& iIo, bool advance);
185
}  // namespace Exiv2
186
187
#endif  // EXIV2_ASFVIDEO_HPP