Tag Parser: mp4/mp4tag.h Source File

Tag Parser 12.5.2 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
mp4tag.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_MP4TAG_H
2#define TAG_PARSER_MP4TAG_H
3
4#include "./mp4tagfield.h"
5
6#include "../fieldbasedtag.h"
7
8namespace TagParser {
9
10class Mp4Atom;
11class Mp4Tag;
12
13 struct TAG_PARSER_EXPORT Mp4ExtendedFieldId {
14 Mp4ExtendedFieldId(std::string_view mean, std::string_view name, bool updateOnly = false);
15 Mp4ExtendedFieldId(KnownField field);
16
17 operator bool() const;
18 bool matches(const Mp4TagField &field) const;
19
21 std::string_view mean;
23 std::string_view name;
25 bool updateOnly = false;
26};
27
31 inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(std::string_view mean, std::string_view name, bool updateOnly)
32 : mean(mean)
33 , name(name)
34 , updateOnly(updateOnly)
35{
36}
37
41 inline Mp4ExtendedFieldId::operator bool() const
42{
43 return !mean.empty() && !name.empty();
44}
45
49 inline bool Mp4ExtendedFieldId::matches(const Mp4TagField &field) const
50{
51 return field.mean() == mean && field.name() == name;
52}
53
54 class TAG_PARSER_EXPORT Mp4TagMaker {
55 friend class Mp4Tag;
56
57public:
58 void make(std::ostream &stream, Diagnostics &diag);
59 const Mp4Tag &tag() const;
60 std::uint64_t requiredSize() const;
61
62private:
63 Mp4TagMaker(Mp4Tag &tag, Diagnostics &diag);
64
65 Mp4Tag &m_tag;
66 std::vector<Mp4TagFieldMaker> m_maker;
67 std::uint64_t m_metaSize;
68 std::uint64_t m_ilstSize;
69 bool m_omitPreDefinedGenre;
70};
71
75 inline const Mp4Tag &Mp4TagMaker::tag() const
76{
77 return m_tag;
78}
79
83 inline std::uint64_t Mp4TagMaker::requiredSize() const
84{
85 return m_metaSize;
86}
87
91 template <> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<Mp4Tag> {
92public:
93 using FieldType = Mp4TagField;
94 using Compare = std::less<typename FieldType::IdentifierType>;
95};
96
97 class TAG_PARSER_EXPORT Mp4Tag final : public FieldMapBasedTag<Mp4Tag> {
98 friend class FieldMapBasedTag<Mp4Tag>;
99
100public:
101 Mp4Tag();
102
103 static constexpr TagType tagType = TagType::Mp4Tag;
104 static constexpr std::string_view tagName = "MP4/iTunes tag";
105 static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
106 bool canEncodingBeUsed(TagTextEncoding encoding) const override;
107
108 bool supportsField(KnownField field) const override;
109 using FieldMapBasedTag<Mp4Tag>::value;
110 const TagValue &value(KnownField value) const override;
111 using FieldMapBasedTag<Mp4Tag>::values;
112 std::vector<const TagValue *> values(KnownField field) const override;
113 const TagValue &value(std::string_view mean, std::string_view name) const;
114 using FieldMapBasedTag<Mp4Tag>::setValue;
115 bool setValue(KnownField field, const TagValue &value) override;
116 using FieldMapBasedTag<Mp4Tag>::setValues;
117 bool setValues(KnownField field, const std::vector<TagValue> &values) override;
118 bool setValue(std::string_view mean, std::string_view name, const TagValue &value);
119 using FieldMapBasedTag<Mp4Tag>::hasField;
120 bool hasField(KnownField value) const override;
121 bool supportsMultipleValues(KnownField) const override;
122
123 void parse(Mp4Atom &metaAtom, Diagnostics &diag);
124 Mp4TagMaker prepareMaking(Diagnostics &diag);
125 void make(std::ostream &stream, Diagnostics &diag);
126
127protected:
128 IdentifierType internallyGetFieldId(KnownField field) const;
129 KnownField internallyGetKnownField(const IdentifierType &id) const;
130 void internallyGetValuesFromField(const FieldType &field, std::vector<const TagValue *> &values) const;
131};
132
136 inline Mp4Tag::Mp4Tag()
137{
138}
139
140 inline bool Mp4Tag::supportsField(KnownField field) const
141{
142 switch (field) {
143 case KnownField::EncoderSettings:
144 return true;
145 default:
146 return FieldMapBasedTag<Mp4Tag>::supportsField(field);
147 }
148}
149
155 inline bool Mp4Tag::supportsMultipleValues(KnownField) const
156{
157 return false;
158}
159
160} // namespace TagParser
161
162#endif // TAG_PARSER_MP4TAG_H
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::FieldMapBasedTagTraits< Mp4Tag >::Compare
std::less< typename FieldType::IdentifierType > Compare
Definition mp4tag.h:94
TagParser::FieldMapBasedTagTraits< Mp4Tag >::FieldType
Mp4TagField FieldType
Definition mp4tag.h:93
TagParser::FieldMapBasedTagTraits
Defines traits for the specified ImplementationType.
Definition fieldbasedtag.h:17
TagParser::FieldMapBasedTag< Mp4Tag >::IdentifierType
typename FieldMapBasedTagTraits< Mp4Tag >::FieldType::IdentifierType IdentifierType
Definition fieldbasedtag.h:35
TagParser::FieldMapBasedTag< Mp4Tag >::FieldMapBasedTag
FieldMapBasedTag()
Definition fieldbasedtag.h:100
TagParser::FieldMapBasedTag< Mp4Tag >::FieldType
typename FieldMapBasedTagTraits< Mp4Tag >::FieldType FieldType
Definition fieldbasedtag.h:34
TagParser::FieldMapBasedTag::supportsField
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
Definition fieldbasedtag.h:370
TagParser::Mp4Atom
The Mp4Atom class helps to parse MP4 files.
Definition mp4atom.h:38
TagParser::Mp4TagField
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition mp4tagfield.h:112
TagParser::Mp4TagField::name
const std::string & name() const
Returns the "name" for "extended" fields.
Definition mp4tagfield.h:189
TagParser::Mp4TagField::mean
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition mp4tagfield.h:205
TagParser::Mp4TagMaker
The Mp4TagMaker class helps writing MP4 tags.
Definition mp4tag.h:54
TagParser::Mp4TagMaker::tag
const Mp4Tag & tag() const
Returns the associated tag.
Definition mp4tag.h:75
TagParser::Mp4TagMaker::requiredSize
std::uint64_t requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition mp4tag.h:83
TagParser::Mp4TagMaker::make
void make(std::ostream &stream, Diagnostics &diag)
Saves the tag (specified when constructing the object) to the specified stream.
Definition mp4tag.cpp:512
TagParser::Mp4TagMaker::Mp4Tag
friend class Mp4Tag
Definition mp4tag.h:55
TagParser::Mp4Tag
Implementation of TagParser::Tag for the MP4 container.
Definition mp4tag.h:97
TagParser::Mp4Tag::values
std::vector< const TagValue * > values(KnownField field) const override
Returns the values of the specified field.
Definition mp4tag.cpp:85
TagParser::Mp4Tag::supportsMultipleValues
bool supportsMultipleValues(KnownField) const override
Returns false for all fields (for now).
Definition mp4tag.h:155
TagParser::Mp4Tag::value
const TagValue & value(KnownField value) const override
Returns the value of the specified field.
Definition mp4tag.cpp:59
TagParser::Mp4Tag::hasField
bool hasField(KnownField value) const override
Returns an indication whether the specified field is present.
Definition mp4tag.cpp:365
TagParser::Mp4Tag::setValue
bool setValue(KnownField field, const TagValue &value) override
Assigns the given value to the specified field.
Definition mp4tag.cpp:287
TagParser::Mp4Tag::internallyGetFieldId
IdentifierType internallyGetFieldId(KnownField field) const
Definition mp4tag.cpp:119
TagParser::Mp4Tag::supportsField
bool supportsField(KnownField field) const override
Returns an indication whether the specified field is supported by the tag.
Definition mp4tag.h:140
TagParser::Mp4Tag::tagName
static constexpr std::string_view tagName
Definition mp4tag.h:104
TagParser::Mp4Tag::prepareMaking
Mp4TagMaker prepareMaking(Diagnostics &diag)
Prepares making.
Definition mp4tag.cpp:448
TagParser::Mp4Tag::setValues
bool setValues(KnownField field, const std::vector< TagValue > &values) override
Assigns the given values to the specified field.
Definition mp4tag.cpp:311
TagParser::Mp4Tag::Mp4Tag
Mp4Tag()
Constructs a new tag.
Definition mp4tag.h:136
TagParser::Mp4Tag::parse
void parse(Mp4Atom &metaAtom, Diagnostics &diag)
Parses tag information from the specified metaAtom.
Definition mp4tag.cpp:382
TagParser::Mp4Tag::make
void make(std::ostream &stream, Diagnostics &diag)
Writes tag information to the specified stream.
Definition mp4tag.cpp:459
TagParser::Mp4Tag::canEncodingBeUsed
bool canEncodingBeUsed(TagTextEncoding encoding) const override
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition mp4tag.cpp:47
TagParser::Mp4Tag::internallyGetKnownField
KnownField internallyGetKnownField(const IdentifierType &id) const
Definition mp4tag.cpp:195
TagParser::Mp4Tag::defaultTextEncoding
static constexpr TagTextEncoding defaultTextEncoding
Definition mp4tag.h:105
TagParser::Mp4Tag::internallyGetValuesFromField
void internallyGetValuesFromField(const FieldType &field, std::vector< const TagValue * > &values) const
Adds values from additional data atoms as well.
Definition mp4tag.cpp:275
TagParser::Mp4Tag::tagType
static constexpr TagType tagType
Definition mp4tag.h:103
TagParser::TagValue
The TagValue class wraps values of different types.
Definition tagvalue.h:147
fieldbasedtag.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
mp4tagfield.h
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::KnownField
KnownField
Specifies the field.
Definition tag.h:37
TagParser::KnownField::EncoderSettings
@ EncoderSettings
Definition tag.h:56
TagParser::TagTextEncoding
TagTextEncoding
Specifies the text encoding.
Definition tagvalue.h:29
TagParser::TagTextEncoding::Utf8
@ Utf8
Definition tagvalue.h:31
TagParser::TagType
TagType
Specifies the tag type.
Definition tagtype.h:11
TagParser::TagType::Mp4Tag
@ Mp4Tag
Definition tagtype.h:15
TagParser::Mp4ExtendedFieldId::matches
bool matches(const Mp4TagField &field) const
Returns whether the current parameter match the specified field.
Definition mp4tag.h:49
TagParser::Mp4ExtendedFieldId::updateOnly
bool updateOnly
Whether only existing fields should be updated but no new extended field should be created.
Definition mp4tag.h:25
TagParser::Mp4ExtendedFieldId::mean
std::string_view mean
mean parameter, usually Mp4TagExtendedMeanIds::iTunes
Definition mp4tag.h:21
TagParser::Mp4ExtendedFieldId::Mp4ExtendedFieldId
Mp4ExtendedFieldId(std::string_view mean, std::string_view name, bool updateOnly=false)
Constructs a new instance with the specified parameter.
Definition mp4tag.h:31
TagParser::Mp4ExtendedFieldId::name
std::string_view name
name parameter
Definition mp4tag.h:23