| Exiv2

Loading...
Searching...
No Matches
matroskavideo.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20#ifndef MATROSKAVIDEO_HPP_
21#define MATROSKAVIDEO_HPP_
22
23// *****************************************************************************
24#include "exiv2lib_export.h"
25
26// included header files
27#include "image.hpp"
28
29// *****************************************************************************
30// namespace extensions
31 namespace Exiv2 {
32
36
37// *****************************************************************************
38// class definitions
39 namespace Internal {
40
41 enum matroskaTypeEnum : char {
42 String = 's',
43 Integer = 'i',
44 UInteger = 'u',
45 Date = 'd',
46 InternalField = 'n',
47 Boolean = 'o',
48 Binary = 'b',
49 Master = 'm',
50 Float = 'f',
51 Utf8 = '8',
52 UndefinedType = 'z',
53};
54
55 enum matroskaProcessEnum : char {
56 Process = 'p',
57 Skip = 's',
58 Composite = 'c',
59 Undefined = 'u',
60};
61
62 struct MatroskaTag {
63 uint64_t _id;
64 std::string _label;
65 matroskaTypeEnum _type;
66 matroskaProcessEnum _process;
67
68 MatroskaTag(uint64_t id, std::string label, matroskaTypeEnum type, matroskaProcessEnum process) :
69 _id(id), _label(std::move(label)), _type(type), _process(process) {
70 }
71
72 MatroskaTag(uint64_t id, std::string label) :
73 _id(id),
74 _label(std::move(label)),
75 _type(matroskaTypeEnum::UndefinedType),
76 _process(matroskaProcessEnum::Undefined) {
77 }
78
79 bool operator==(uint64_t id) const {
80 return id == _id;
81 }
82
83 [[nodiscard]] bool isSkipped() const {
84 return _process == Skip;
85 }
86 [[nodiscard]] bool isComposite() const {
87 return _process == Composite;
88 }
89 void dump(std::ostream& os) const {
90 os << " MatroskaTag "
91 << " id: [0x" << std::hex << _id << "] label:[" << _label << "] type:[" << _type << "] process :[" << _process
92 << "]\n";
93 }
94};
95} // namespace Internal
96
100 class EXIV2API MatroskaVideo : public Image {
101 public:
103
104
115 explicit MatroskaVideo(BasicIo::UniquePtr io);
117
119
120 void readMetadata() override;
121 void writeMetadata() override;
123
125
126 [[nodiscard]] std::string mimeType() const override;
128
129 protected:
139 [[nodiscard]] static uint32_t findBlockSize(byte b);
144 void decodeBlock();
151
152 void decodeInternalTags(const Internal::MatroskaTag* tag, const byte* buf);
153 void decodeStringTags(const Internal::MatroskaTag* tag, const byte* buf);
154 void decodeIntegerTags(const Internal::MatroskaTag* tag, const byte* buf);
155 void decodeBooleanTags(const Internal::MatroskaTag* tag, const byte* buf);
156 void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
157 void decodeFloatTags(const Internal::MatroskaTag* tag, const byte* buf);
158
159 private:
161 bool continueTraversing_{};
163 uint64_t height_{};
164 uint64_t width_{};
165 uint32_t track_count_{};
166 double time_code_scale_ = 1.0;
167 uint64_t stream_{};
168
169 static constexpr double bytesMB = 1048576;
170
171}; // class MatroskaVideo
172
173// *****************************************************************************
174// template, inline and free functions
175
176// These could be static private functions on Image subclasses but then
177// ImageFactory needs to be made a friend.
183EXIV2API Image::UniquePtr newMkvInstance(BasicIo::UniquePtr io, bool create);
184
186EXIV2API bool isMkvType(BasicIo& iIo, bool advance);
187
188} // namespace Exiv2
189
190#endif // #ifndef MATROSKAVIDEO_HPP_
Exiv2::BasicIo
An interface for simple binary IO.
Definition basicio.hpp:35
Exiv2::BasicIo::UniquePtr
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition basicio.hpp:38
Exiv2::Image::Image
Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io)
Constructor taking the image type, a bitmap of the supported metadata types and an auto-pointer that ...
Definition image.cpp:132
Exiv2::Image::io
virtual BasicIo & io() const
Return a reference to the BasicIo instance being used for Io.
Definition image.cpp:696
Exiv2::Image::UniquePtr
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition image.hpp:53
Exiv2::MatroskaVideo::mimeType
std::string mimeType() const override
Return the MIME type of the image.
Definition matroskavideo.cpp:607
Exiv2::MatroskaVideo::readMetadata
void readMetadata() override
Read all metadata supported by a specific image format from the image. Before this method is called,...
Definition matroskavideo.cpp:614
Exiv2::MatroskaVideo::decodeBlock
void decodeBlock()
Check for a valid tag and decode the block at the current IO position. Calls contentManagement() or s...
Definition matroskavideo.cpp:639
Exiv2::MatroskaVideo::decodeInternalTags
void decodeInternalTags(const Internal::MatroskaTag *tag, const byte *buf)
Interpret tag information, and save it in the respective XMP container.
Definition matroskavideo.cpp:722
Exiv2::MatroskaVideo::writeMetadata
void writeMetadata() override
Write metadata back to the image.
Definition matroskavideo.cpp:611
Exiv2::MatroskaVideo::findBlockSize
static uint32_t findBlockSize(byte b)
Function used to calculate the size of a block. This information is only stored in one byte....
Definition matroskavideo.cpp:902
Exiv2::MatroskaVideo::MatroskaVideo
MatroskaVideo(BasicIo::UniquePtr io)
Constructor for a Matroska video. Since the constructor can not return a result, callers should check...
Definition matroskavideo.cpp:604
Exiv2::Internal
Helper structure for the Matroska tags lookup table.
Definition matroskavideo.hpp:39
Exiv2
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
Exiv2::newMkvInstance
EXIV2API Image::UniquePtr newMkvInstance(BasicIo::UniquePtr io, bool create)
Create a new MatroskaVideo instance and return an auto-pointer to it. Caller owns the returned object...
Definition matroskavideo.cpp:922
Exiv2::isMkvType
EXIV2API bool isMkvType(BasicIo &iIo, bool advance)
Check if the file iIo is a Matroska Video.
Definition matroskavideo.cpp:930
Exiv2::Internal::MatroskaTag
Definition matroskavideo.hpp:62