Tag Parser  6.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mp4tag.h
Go to the documentation of this file.
1 #ifndef MP4TAG_H
2 #define MP4TAG_H
3 
4 #include "./mp4tagfield.h"
5 
6 #include "../fieldbasedtag.h"
7 
8 namespace Media
9 {
10 
11 class Mp4Atom;
12 class Mp4Tag;
13 
15 {
16  Mp4ExtendedFieldId(const char *mean = nullptr, const char *name = nullptr, bool updateOnly = false);
18 
19  operator bool() const;
20  bool matches(const Mp4TagField &field) const;
21 
23  const char *mean;
25  const char *name;
27  bool updateOnly;
28 };
29 
33 inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(const char *mean, const char *name, bool updateOnly) :
34  mean(mean),
35  name(name),
36  updateOnly(updateOnly)
37 {}
38 
42 inline Mp4ExtendedFieldId::operator bool() const
43 {
44  return mean && name;
45 }
46 
50 inline bool Mp4ExtendedFieldId::matches(const Mp4TagField &field) const
51 {
52  return field.mean() == mean && field.name() == name;
53 }
54 
56 {
57  friend class Mp4Tag;
58 
59 public:
60  void make(std::ostream &stream);
61  const Mp4Tag &tag() const;
62  uint64 requiredSize() const;
63 
64 private:
65  Mp4TagMaker(Mp4Tag &tag);
66 
67  Mp4Tag &m_tag;
68  std::vector<Mp4TagFieldMaker> m_maker;
69  uint64 m_metaSize;
70  uint64 m_ilstSize;
71  bool m_omitPreDefinedGenre;
72 };
73 
77 inline const Mp4Tag &Mp4TagMaker::tag() const
78 {
79  return m_tag;
80 }
81 
85 inline uint64 Mp4TagMaker::requiredSize() const
86 {
87  return m_metaSize;
88 }
89 
90 class TAG_PARSER_EXPORT Mp4Tag : public FieldMapBasedTag<Mp4TagField>
91 {
92 public:
93  Mp4Tag();
94 
95  static constexpr TagType tagType = TagType::Mp4Tag;
96  TagType type() const;
97  const char *typeName() const;
98  TagTextEncoding proposedTextEncoding() const;
99  bool canEncodingBeUsed(TagTextEncoding encoding) const;
100 
101  uint32 fieldId(KnownField field) const;
102  KnownField knownField(const uint32 &id) const;
103  bool supportsField(KnownField field) const;
105  const TagValue &value(KnownField value) const;
107  std::vector<const TagValue *> values(KnownField field) const;
108 #ifdef LEGACY_API
109  const TagValue &value(const std::string mean, const std::string name) const;
110 #endif
111  const TagValue &value(const std::string &mean, const std::string &name) const;
112  const TagValue &value(const char *mean, const char *name) const;
114  bool setValue(KnownField field, const TagValue &value);
116  bool setValues(KnownField field, const std::vector<TagValue> &values);
117 #ifdef LEGACY_API
118  bool setValue(const std::string mean, const std::string name, const TagValue &value);
119 #endif
120  bool setValue(const std::string &mean, const std::string &name, const TagValue &value);
121  bool setValue(const char *mean, const char *name, const TagValue &value);
123  bool hasField(KnownField value) const;
124 
125  void parse(Mp4Atom &metaAtom);
126  Mp4TagMaker prepareMaking();
127  void make(std::ostream &stream);
128 };
129 
134 {}
135 
136 inline TagType Mp4Tag::type() const
137 {
138  return TagType::Mp4Tag;
139 }
140 
141 inline const char *Mp4Tag::typeName() const
142 {
143  return "MP4/iTunes tag";
144 }
145 
147 {
148  return TagTextEncoding::Utf8;
149 }
150 
151 inline bool Mp4Tag::supportsField(KnownField field) const
152 {
153  switch(field) {
155  return true;
156  default:
158  }
159 }
160 
164 inline const TagValue &Mp4Tag::value(const std::string &mean, const std::string &name) const
165 {
166  return value(mean.data(), name.data());
167 }
168 
172 inline bool Mp4Tag::setValue(const std::string &mean, const std::string &name, const TagValue &value)
173 {
174  return setValue(mean.data(), name.data(), value);
175 }
176 
177 }
178 
179 #endif // MP4TAG_H
The TagValue class wraps values of different types.
Definition: tagvalue.h:64
The Mp4ExtendedFieldId specifies parameter for an extended field denoted via Mp4TagAtomIds::Extended...
Definition: mp4tag.h:14
bool matches(const Mp4TagField &field) const
Returns whether the current parameter match the specified field.
Definition: mp4tag.h:50
bool updateOnly
Whether only existing fields should be updated but no new extended field should be created...
Definition: mp4tag.h:27
The Mp4TagMaker class helps writing MP4 tags.
Definition: mp4tag.h:55
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition: mp4tag.h:146
const char * typeName() const
Returns the type name of the tag as C-style string.
Definition: mp4tag.h:141
KnownField
Specifies the field.
Definition: tag.h:42
TagType type() const
Returns the type of the tag as Media::TagType.
Definition: mp4tag.h:136
Mp4Tag()
Constructs a new tag.
Definition: mp4tag.h:133
Mp4ExtendedFieldId(const char *mean=nullptr, const char *name=nullptr, bool updateOnly=false)
Constructs a new instance with the specified parameter.
Definition: mp4tag.h:33
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:22
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition: mp4tagfield.h:180
Implementation of Media::Tag for the MP4 container.
Definition: mp4tag.h:90
const Mp4Tag & tag() const
Returns the associated tag.
Definition: mp4tag.h:77
const TagValue & value(KnownField value) const
Returns the value of the specified field.
Definition: mp4tag.cpp:58
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
Definition: fieldbasedtag.h:25
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:57
const char * mean
mean parameter, usually Mp4TagExtendedMeanIds::iTunes
Definition: mp4tag.h:23
TagType
Specifies the tag type.
Definition: tag.h:21
const std::string & name() const
Returns the "name" for "extended" fields.
Definition: mp4tagfield.h:164
uint64 requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition: mp4tag.h:85
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
const char * name
name parameter
Definition: mp4tag.h:25
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition: mp4tagfield.h:114
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
bool setValue(KnownField field, const TagValue &value)
Assigns the given value to the specified field.
Definition: mp4tag.cpp:176
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
Definition: mp4tag.h:151