Coverage Report

Created: 2026-08-13 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/exiv2/include/exiv2/riffvideo.hpp
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
#ifndef EXIV2_RIFFVIDEO_HPP
3
#define EXIV2_RIFFVIDEO_HPP
4
5
#include "exiv2lib_export.h"
6
7
#include "image.hpp"
8
9
namespace Exiv2 {
10
11
// *****************************************************************************
12
// class definitions
13
14
/*!
15
  @brief Class to access RIFF video files.
16
 */
17
class EXIV2API RiffVideo : public Image {
18
 public:
19
  //! @name Creators
20
  //@{
21
  /*!
22
    @brief Constructor for a Riff video. Since the constructor
23
        can not return a result, callers should check the good() method
24
        after object construction to determine success or failure.
25
    @param io An auto-pointer that owns a BasicIo instance used for
26
        reading and writing image metadata. \b Important: The constructor
27
        takes ownership of the passed in BasicIo instance through the
28
        auto-pointer. Callers should not continue to use the BasicIo
29
        instance after it is passed to this method. Use the Image::io()
30
        method to get a temporary reference.
31
      @param params Parameters that are passed through to Image's constructor.
32
   */
33
  explicit RiffVideo(std::unique_ptr<BasicIo> io, const ImageCtorParams& params);
34
  //@}
35
36
  //! @name Manipulators
37
  //@{
38
  void readMetadata() override;
39
  void writeMetadata() override;
40
  //@}
41
42
  //! @name Accessors
43
  //@{
44
  [[nodiscard]] std::string mimeType() const override;
45
  //@}
46
47
 protected:
48
  class HeaderReader {
49
    std::string id_;
50
    uint64_t size_ = 0;
51
52
   public:
53
    explicit HeaderReader(const std::unique_ptr<BasicIo>& io);
54
55
63.2k
    [[nodiscard]] uint64_t getSize() const {
56
63.2k
      return size_;
57
63.2k
    }
58
59
654k
    [[nodiscard]] const std::string& getId() const {
60
654k
      return id_;
61
654k
    }
62
  };
63
64
  void readList(const HeaderReader& header_);
65
66
  void readChunk(const HeaderReader& header_);
67
68
  void decodeBlocks();
69
70
 private:
71
  static bool equal(const std::string& str1, const std::string& str2);
72
73
  /*!
74
  @brief Interpret MainAVIHeader (avih) structure, and save it in the respective XMP container.
75
  */
76
  void readAviHeader();
77
78
  /*!
79
  @brief Interpret stream header list element (strh), and save it in the respective XMP container.
80
  */
81
  void readStreamHeader();
82
83
  /*!
84
  @brief Interpret stream header list element (strf), and save it in the respective XMP container.
85
  @param size_ Size of the data block used to store Tag Information.
86
  */
87
  void readStreamFormat(uint64_t size_);
88
89
  /*!
90
  @brief Interpret Additional header data (strd), and save it in the respective XMP container.
91
  @param size_ Size of the data block used to store Tag Information.
92
 */
93
  void readStreamData(uint64_t size_) const;
94
95
  /*!
96
  @brief Interpret stream header list element (strn) , and save it in the respective XMP container.
97
  @param size_ Size of the data block used to store Tag Information.
98
 */
99
  void StreamName(uint64_t size_) const;
100
  /*!
101
  @brief Interpret INFO List Chunk, and save it in the respective XMP container.
102
  @param size_ Size of the data block used to store Tag Information.
103
 */
104
  void readInfoListChunk(uint64_t size_);
105
106
  /*!
107
  @brief Interpret Riff Stream Data tag information, and save it in the respective XMP container.
108
  The Movi - Lists contain Video, Audio, Subtitle and (secondary) index data. Those can be grouped into rec - Lists.
109
  @param size_ Size of the data block used to store Tag Information.
110
 */
111
  void readMoviList(uint64_t size_) const;
112
  /*!
113
  @brief Interpret Video Properties Header chunk, and save it in the respective XMP container.
114
  The video properties header identifies video signal properties associated with a digital video stream in an AVI file
115
  @param size_ Size of the data block used to store Tag Information.
116
 */
117
  void readVPRPChunk(uint64_t size_) const;
118
  /*!
119
  @brief Interpret Riff INdex Chunk, and save it in the respective XMP container.
120
  @param size_ Size of the data block used to store Tag Information.
121
 */
122
  void readIndexChunk(uint64_t size_) const;
123
  /*!
124
  @brief Interpret Riff Stream Chunk, and save it in the respective XMP container.
125
  @param size_ Size of the data block used to store Tag Information.
126
 */
127
  void readDataChunk(uint64_t size_) const;
128
  /*!
129
  @brief Interpret Junk Chunk and save it in the respective XMP container.
130
  @param size_ Size of the data block used to store Tag Information.
131
 */
132
  void readJunk(uint64_t size_) const;
133
134
  static std::string getStreamType(uint32_t stream);
135
  /*!
136
   @brief Calculates Duration of a video, and stores it in the respective XMP container.
137
   @param frame_rate Frame rate of the video.
138
   @param frame_count Total number of frames present in the video.
139
  */
140
  void fillDuration(double frame_rate, size_t frame_count);
141
142
  /*!
143
   @brief Calculates Aspect Ratio of a video, and stores it in the respective XMP container.
144
   @param width Width of the video.
145
   @param height Height of the video.
146
  */
147
  void fillAspectRatio(size_t width, size_t height);
148
149
  static constexpr auto CHUNK_HEADER_ICCP = "ICCP";
150
  static constexpr auto CHUNK_HEADER_EXIF = "EXIF";
151
  static constexpr auto CHUNK_HEADER_XMP = "XMP ";
152
153
  /* Chunk header names */
154
  static constexpr auto CHUNK_ID_MOVI = "MOVI";
155
  static constexpr auto CHUNK_ID_DATA = "DATA";
156
  static constexpr auto CHUNK_ID_HDRL = "HDRL";
157
  static constexpr auto CHUNK_ID_STRL = "STRL";
158
  static constexpr auto CHUNK_ID_LIST = "LIST";
159
  static constexpr auto CHUNK_ID_JUNK = "JUNK";
160
  static constexpr auto CHUNK_ID_AVIH = "AVIH";
161
  static constexpr auto CHUNK_ID_STRH = "STRH";
162
  static constexpr auto CHUNK_ID_STRF = "STRF";
163
  static constexpr auto CHUNK_ID_FMT = "FMT ";
164
  static constexpr auto CHUNK_ID_STRN = "STRN";
165
  static constexpr auto CHUNK_ID_STRD = "STRD";
166
  static constexpr auto CHUNK_ID_IDIT = "IDIT";
167
  static constexpr auto CHUNK_ID_INFO = "INFO";
168
  static constexpr auto CHUNK_ID_NCDT = "NCDT";
169
  static constexpr auto CHUNK_ID_ODML = "ODML";
170
  static constexpr auto CHUNK_ID_VPRP = "VPRP";
171
  static constexpr auto CHUNK_ID_IDX1 = "IDX1";
172
173
  int streamType_{};
174
175
};  // Class RiffVideo
176
177
/*
178
  @brief Create a new RiffVideo instance and return an auto-pointer to it.
179
      Caller owns the returned object and the auto-pointer ensures that
180
      it will be deleted.
181
 */
182
EXIV2API Image::UniquePtr newRiffInstance(std::unique_ptr<BasicIo> io, const ImageCtorParams& params);
183
184
//! Check if the file iIo is a Riff Video.
185
EXIV2API bool isRiffType(BasicIo& iIo, bool advance);
186
187
}  // namespace Exiv2
188
189
#endif  // EXIV2_RIFFVIDEO_HPP