Coverage Report

Created: 2025-12-14 06:57

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
   */
32
  explicit RiffVideo(std::unique_ptr<BasicIo> io);
33
  //@}
34
35
  //! @name Manipulators
36
  //@{
37
  void readMetadata() override;
38
  void writeMetadata() override;
39
  //@}
40
41
  //! @name Accessors
42
  //@{
43
  [[nodiscard]] std::string mimeType() const override;
44
  //@}
45
46
 protected:
47
  class HeaderReader {
48
    std::string id_;
49
    uint64_t size_ = 0;
50
51
   public:
52
    explicit HeaderReader(const std::unique_ptr<BasicIo>& io);
53
54
4.91k
    [[nodiscard]] uint64_t getSize() const {
55
4.91k
      return size_;
56
4.91k
    }
57
58
42.5k
    [[nodiscard]] const std::string& getId() const {
59
42.5k
      return id_;
60
42.5k
    }
61
  };
62
63
  void readList(const HeaderReader& header_);
64
65
  void readChunk(const HeaderReader& header_);
66
67
  void decodeBlocks();
68
69
 private:
70
  static bool equal(const std::string& str1, const std::string& str2);
71
72
  /*!
73
  @brief Interpret MainAVIHeader (avih) structure, and save it in the respective XMP container.
74
  */
75
  void readAviHeader();
76
77
  /*!
78
  @brief Interpret stream header list element (strh), and save it in the respective XMP container.
79
  */
80
  void readStreamHeader();
81
82
  /*!
83
  @brief Interpret stream header list element (strf), and save it in the respective XMP container.
84
  @param size_ Size of the data block used to store Tag Information.
85
  */
86
  void readStreamFormat(uint64_t size_);
87
88
  /*!
89
  @brief Interpret Additional header data (strd), and save it in the respective XMP container.
90
  @param size_ Size of the data block used to store Tag Information.
91
 */
92
  void readStreamData(uint64_t size_) const;
93
94
  /*!
95
  @brief Interpret stream header list element (strn) , and save it in the respective XMP container.
96
  @param size_ Size of the data block used to store Tag Information.
97
 */
98
  void StreamName(uint64_t size_) const;
99
  /*!
100
  @brief Interpret INFO List Chunk, and save it in the respective XMP container.
101
  @param size_ Size of the data block used to store Tag Information.
102
 */
103
  void readInfoListChunk(uint64_t size_);
104
105
  /*!
106
  @brief Interpret Riff Stream Data tag information, and save it in the respective XMP container.
107
  The Movi - Lists contain Video, Audio, Subtitle and (secondary) index data. Those can be grouped into rec - Lists.
108
  @param size_ Size of the data block used to store Tag Information.
109
 */
110
  void readMoviList(uint64_t size_) const;
111
  /*!
112
  @brief Interpret Video Properties Header chunk, and save it in the respective XMP container.
113
  The video properties header identifies video signal properties associated with a digital video stream in an AVI file
114
  @param size_ Size of the data block used to store Tag Information.
115
 */
116
  void readVPRPChunk(uint64_t size_) const;
117
  /*!
118
  @brief Interpret Riff INdex Chunk, and save it in the respective XMP container.
119
  @param size_ Size of the data block used to store Tag Information.
120
 */
121
  void readIndexChunk(uint64_t size_) const;
122
  /*!
123
  @brief Interpret Riff Stream Chunk, and save it in the respective XMP container.
124
  @param size_ Size of the data block used to store Tag Information.
125
 */
126
  void readDataChunk(uint64_t size_) const;
127
  /*!
128
  @brief Interpret Junk Chunk and save it in the respective XMP container.
129
  @param size_ Size of the data block used to store Tag Information.
130
 */
131
  void readJunk(uint64_t size_) const;
132
133
  static std::string getStreamType(uint32_t stream);
134
  /*!
135
   @brief Calculates Duration of a video, and stores it in the respective XMP container.
136
   @param frame_rate Frame rate of the video.
137
   @param frame_count Total number of frames present in the video.
138
  */
139
  void fillDuration(double frame_rate, size_t frame_count);
140
141
  /*!
142
   @brief Calculates Aspect Ratio of a video, and stores it in the respective XMP container.
143
   @param width Width of the video.
144
   @param height Height of the video.
145
  */
146
  void fillAspectRatio(size_t width, size_t height);
147
148
  static constexpr auto CHUNK_HEADER_ICCP = "ICCP";
149
  static constexpr auto CHUNK_HEADER_EXIF = "EXIF";
150
  static constexpr auto CHUNK_HEADER_XMP = "XMP ";
151
152
  /* Chunk header names */
153
  static constexpr auto CHUNK_ID_MOVI = "MOVI";
154
  static constexpr auto CHUNK_ID_DATA = "DATA";
155
  static constexpr auto CHUNK_ID_HDRL = "HDRL";
156
  static constexpr auto CHUNK_ID_STRL = "STRL";
157
  static constexpr auto CHUNK_ID_LIST = "LIST";
158
  static constexpr auto CHUNK_ID_JUNK = "JUNK";
159
  static constexpr auto CHUNK_ID_AVIH = "AVIH";
160
  static constexpr auto CHUNK_ID_STRH = "STRH";
161
  static constexpr auto CHUNK_ID_STRF = "STRF";
162
  static constexpr auto CHUNK_ID_FMT = "FMT ";
163
  static constexpr auto CHUNK_ID_STRN = "STRN";
164
  static constexpr auto CHUNK_ID_STRD = "STRD";
165
  static constexpr auto CHUNK_ID_IDIT = "IDIT";
166
  static constexpr auto CHUNK_ID_INFO = "INFO";
167
  static constexpr auto CHUNK_ID_NCDT = "NCDT";
168
  static constexpr auto CHUNK_ID_ODML = "ODML";
169
  static constexpr auto CHUNK_ID_VPRP = "VPRP";
170
  static constexpr auto CHUNK_ID_IDX1 = "IDX1";
171
172
  int streamType_{};
173
174
};  // Class RiffVideo
175
176
/*
177
  @brief Create a new RiffVideo 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 newRiffInstance(std::unique_ptr<BasicIo> io, bool create);
182
183
//! Check if the file iIo is a Riff Video.
184
EXIV2API bool isRiffType(BasicIo& iIo, bool advance);
185
186
}  // namespace Exiv2
187
188
#endif  // EXIV2_RIFFVIDEO_HPP