Tag Parser: mp4/mp4tagfield.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
mp4tagfield.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_MP4TAGATOM_H
2#define TAG_PARSER_MP4TAGATOM_H
3
4#include "../generictagfield.h"
5
6#include <c++utilities/conversion/stringconversion.h>
7#include <c++utilities/io/binarywriter.h>
8
9#include <cstdint>
10#include <sstream>
11#include <vector>
12
13namespace TagParser {
14
18 namespace RawDataType {
19 enum KnownValue : std::uint32_t {
20 Reserved = 0,
21 Utf8 = 1,
22 Utf16 = 2,
23 Sjis = 3,
24 Utf8Sort = 4,
25 Utf16Sort = 5,
26 Html = 6,
27 Xml = 7,
28 Uuid = 8,
29 Isrc = 9,
30 Mi3p = 10,
31 Gif = 12,
32 Jpeg = 13,
33 Png = 14,
34 Url = 15,
35 Duration = 16,
36 DateTime = 17,
37 Genred = 18,
38 BeSignedInt = 21,
39 BeUnsignedInt = 22,
40 BeFloat32 = 23,
41 BeFloat64 = 24,
42 Upc = 25,
43 Bmp = 27,
44 QuickTimeMetadataAtom = 28,
45 Undefined = 255
46};
47}
48
49class Mp4TagField;
50class Diagnostics;
51
55 template <> class TAG_PARSER_EXPORT TagFieldTraits<Mp4TagField> {
56public:
57 using IdentifierType = std::uint32_t;
58 using TypeInfoType = std::uint32_t;
59};
60
61class Mp4Atom;
62
63 class TAG_PARSER_EXPORT Mp4TagFieldMaker {
64 friend class Mp4TagField;
65
66public:
67 Mp4TagFieldMaker(Mp4TagFieldMaker &&) = default;
68 void make(std::ostream &stream);
69 const Mp4TagField &field() const;
70 std::uint64_t requiredSize() const;
71
72private:
74 struct Data {
75 Data();
76 Data(Data &&) = default;
77 std::string_view rawData;
78 std::stringstream convertedData;
79 std::uint64_t size = 0;
80 std::uint32_t rawType = 0;
81 std::uint16_t countryIndicator = 0;
82 std::uint16_t languageIndicator = 0;
83 };
85
86 Mp4TagFieldMaker(Mp4TagField &field, Diagnostics &diag);
87 std::uint64_t prepareDataAtom(
88 const TagValue &value, std::uint16_t countryIndicator, std::uint16_t languageIndicator, const std::string &context, Diagnostics &diag);
89
90 Mp4TagField &m_field;
91 CppUtilities::BinaryWriter m_writer;
92 std::vector<Data> m_data;
93 std::uint64_t m_totalSize;
94};
95
99 inline const Mp4TagField &Mp4TagFieldMaker::field() const
100{
101 return m_field;
102}
103
107 inline std::uint64_t Mp4TagFieldMaker::requiredSize() const
108{
109 return m_totalSize;
110}
111
112 class TAG_PARSER_EXPORT Mp4TagField : public TagField<Mp4TagField> {
113 friend class TagField<Mp4TagField>;
114
115public:
116 struct AdditionalData {
117 TagValue value;
118 std::uint32_t rawDataType = 0;
119 std::uint16_t countryIndicator = 0;
120 std::uint16_t languageIndicator = 0;
121 };
122
123 Mp4TagField();
124 Mp4TagField(IdentifierType id, const TagValue &value);
125 Mp4TagField(std::string_view mean, std::string_view name, const TagValue &value);
126
127 void reparse(Mp4Atom &ilstChild, Diagnostics &diag);
128 Mp4TagFieldMaker prepareMaking(Diagnostics &diag);
129 void make(std::ostream &stream, Diagnostics &diag);
130
131 const std::vector<AdditionalData> &additionalData() const;
132 std::vector<AdditionalData> &additionalData();
133 bool isAdditionalTypeInfoUsed() const;
134 const std::string &name() const;
135 void setName(const std::string &name);
136 const std::string &mean() const;
137 void setMean(const std::string &mean);
138 std::uint32_t parsedRawDataType() const;
139 std::uint16_t countryIndicator() const;
140 std::uint16_t languageIndicator() const;
141 bool supportsNestedFields() const;
142 std::vector<std::uint32_t> expectedRawDataTypes() const;
143 std::uint32_t appropriateRawDataType() const;
144 std::uint32_t appropriateRawDataTypeForValue(const TagValue &value) const;
145
146 static IdentifierType fieldIdFromString(std::string_view idString);
147 static std::string fieldIdToString(IdentifierType id);
148
149private:
150 void internallyClearValue();
151 void internallyClearFurtherData();
152 std::string m_name;
153 std::string m_mean;
154 std::vector<AdditionalData> m_additionalData;
155 std::uint32_t m_parsedRawDataType;
156 std::uint16_t m_countryIndicator;
157 std::uint16_t m_langIndicator;
158};
159
164 inline const std::vector<Mp4TagField::AdditionalData> &Mp4TagField::additionalData() const
165{
166 return m_additionalData;
167}
168
173 inline std::vector<Mp4TagField::AdditionalData> &Mp4TagField::additionalData()
174{
175 return m_additionalData;
176}
177
181 inline bool Mp4TagField::isAdditionalTypeInfoUsed() const
182{
183 return false;
184}
185
189 inline const std::string &Mp4TagField::name() const
190{
191 return m_name;
192}
193
197 inline void Mp4TagField::setName(const std::string &name)
198{
199 m_name = name;
200}
201
205 inline const std::string &Mp4TagField::mean() const
206{
207 return m_mean;
208}
209
213 inline void Mp4TagField::setMean(const std::string &mean)
214{
215 m_mean = mean;
216}
217
221 inline std::uint32_t Mp4TagField::parsedRawDataType() const
222{
223 return m_parsedRawDataType;
224}
225
229 inline std::uint16_t Mp4TagField::countryIndicator() const
230{
231 return m_countryIndicator;
232}
233
237 inline std::uint16_t Mp4TagField::languageIndicator() const
238{
239 return m_langIndicator;
240}
241
245 inline bool Mp4TagField::supportsNestedFields() const
246{
247 return false;
248}
249
255 inline Mp4TagField::IdentifierType Mp4TagField::fieldIdFromString(std::string_view idString)
256{
257 const auto latin1 = CppUtilities::convertUtf8ToLatin1(idString.data(), idString.size());
258 switch (latin1.second) {
259 case 4:
260 return CppUtilities::BE::toInt<std::uint32_t>(latin1.first.get());
261 default:
262 throw CppUtilities::ConversionException("MP4 ID must be exactly 4 chars");
263 }
264}
265
271 inline std::string Mp4TagField::fieldIdToString(Mp4TagField::IdentifierType id)
272{
273 const auto utf8 = CppUtilities::convertLatin1ToUtf8(CppUtilities::interpretIntegerAsString<std::uint32_t>(id).data(), 4);
274 return std::string(utf8.first.get(), utf8.second);
275}
276
277} // namespace TagParser
278
279#endif // TAG_PARSER_MP4TAGATOM_H
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::Mp4Atom
The Mp4Atom class helps to parse MP4 files.
Definition mp4atom.h:38
TagParser::Mp4TagFieldMaker
The Mp4TagFieldMaker class helps making tag fields.
Definition mp4tagfield.h:63
TagParser::Mp4TagFieldMaker::make
void make(std::ostream &stream)
Saves the field (specified when constructing the object) to the specified stream.
Definition mp4tagfield.cpp:722
TagParser::Mp4TagFieldMaker::Mp4TagFieldMaker
Mp4TagFieldMaker(Mp4TagFieldMaker &&)=default
TagParser::Mp4TagFieldMaker::requiredSize
std::uint64_t requiredSize() const
Returns number of bytes which will be written when making the field.
Definition mp4tagfield.h:107
TagParser::Mp4TagFieldMaker::field
const Mp4TagField & field() const
Returns the associated field.
Definition mp4tagfield.h:99
TagParser::Mp4TagFieldMaker::Mp4TagField
friend class Mp4TagField
Definition mp4tagfield.h:64
TagParser::Mp4TagField
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition mp4tagfield.h:112
TagParser::Mp4TagField::prepareMaking
Mp4TagFieldMaker prepareMaking(Diagnostics &diag)
Prepares making.
Definition mp4tagfield.cpp:328
TagParser::Mp4TagField::supportsNestedFields
bool supportsNestedFields() const
Returns whether nested fields are supported.
Definition mp4tagfield.h:245
TagParser::Mp4TagField::additionalData
const std::vector< AdditionalData > & additionalData() const
Returns additional data (and the corresponding raw data type, country and language).
Definition mp4tagfield.h:164
TagParser::Mp4TagField::reparse
void reparse(Mp4Atom &ilstChild, Diagnostics &diag)
Parses field information from the specified Mp4Atom.
Definition mp4tagfield.cpp:104
TagParser::Mp4TagField::name
const std::string & name() const
Returns the "name" for "extended" fields.
Definition mp4tagfield.h:189
TagParser::Mp4TagField::setName
void setName(const std::string &name)
Sets the "name" for the "extended" field.
Definition mp4tagfield.h:197
TagParser::Mp4TagField::Mp4TagField
Mp4TagField()
Constructs a new Mp4TagField.
Definition mp4tagfield.cpp:29
TagParser::Mp4TagField::isAdditionalTypeInfoUsed
bool isAdditionalTypeInfoUsed() const
Returns whether the additional type info is used.
Definition mp4tagfield.h:181
TagParser::Mp4TagField::appropriateRawDataTypeForValue
std::uint32_t appropriateRawDataTypeForValue(const TagValue &value) const
Returns an appropriate raw data type.
Definition mp4tagfield.cpp:429
TagParser::Mp4TagField::mean
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition mp4tagfield.h:205
TagParser::Mp4TagField::appropriateRawDataType
std::uint32_t appropriateRawDataType() const
Returns an appropriate raw data type.
Definition mp4tagfield.cpp:408
TagParser::Mp4TagField::fieldIdFromString
static IdentifierType fieldIdFromString(std::string_view idString)
Converts the specified ID string representation to an actual ID.
Definition mp4tagfield.h:255
TagParser::Mp4TagField::parsedRawDataType
std::uint32_t parsedRawDataType() const
Returns the raw data type which has been determined when parsing.
Definition mp4tagfield.h:221
TagParser::Mp4TagField::setMean
void setMean(const std::string &mean)
Sets the "mean" for the "extended" field.
Definition mp4tagfield.h:213
TagParser::Mp4TagField::languageIndicator
std::uint16_t languageIndicator() const
Returns the language indicator.
Definition mp4tagfield.h:237
TagParser::Mp4TagField::expectedRawDataTypes
std::vector< std::uint32_t > expectedRawDataTypes() const
Returns the expected raw data types for the ID of the field.
Definition mp4tagfield.cpp:348
TagParser::Mp4TagField::countryIndicator
std::uint16_t countryIndicator() const
Returns the country indicator.
Definition mp4tagfield.h:229
TagParser::Mp4TagField::make
void make(std::ostream &stream, Diagnostics &diag)
Saves the field to the specified stream.
Definition mp4tagfield.cpp:340
TagParser::Mp4TagField::fieldIdToString
static std::string fieldIdToString(IdentifierType id)
Returns the string representation for the specified id.
Definition mp4tagfield.h:271
TagParser::TagFieldTraits< Mp4TagField >::TypeInfoType
std::uint32_t TypeInfoType
Definition mp4tagfield.h:58
TagParser::TagFieldTraits< Mp4TagField >::IdentifierType
std::uint32_t IdentifierType
Definition mp4tagfield.h:57
TagParser::TagFieldTraits
Defines traits for the specified ImplementationType.
Definition generictagfield.h:16
TagParser::TagField< Mp4TagField >::TagField
TagField()
Definition generictagfield.h:84
TagParser::TagField< Mp4TagField >::IdentifierType
typename TagFieldTraits< Mp4TagField >::IdentifierType IdentifierType
Definition generictagfield.h:33
TagParser::TagField< Mp4TagField >::value
TagValue & value()
Definition generictagfield.h:156
TagParser::TagValue
The TagValue class wraps values of different types.
Definition tagvalue.h:147
generictagfield.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser::RawDataType
Encapsulates the most common data type IDs of MP4 tag fields.
Definition mp4tagfield.h:18
TagParser::RawDataType::KnownValue
KnownValue
Definition mp4tagfield.h:19
TagParser::RawDataType::Utf8
@ Utf8
Definition mp4tagfield.h:21
TagParser::RawDataType::Upc
@ Upc
Definition mp4tagfield.h:42
TagParser::RawDataType::Gif
@ Gif
Definition mp4tagfield.h:31
TagParser::RawDataType::Xml
@ Xml
Definition mp4tagfield.h:27
TagParser::RawDataType::BeSignedInt
@ BeSignedInt
Definition mp4tagfield.h:38
TagParser::RawDataType::BeFloat64
@ BeFloat64
Definition mp4tagfield.h:41
TagParser::RawDataType::Uuid
@ Uuid
Definition mp4tagfield.h:28
TagParser::RawDataType::Utf16Sort
@ Utf16Sort
Definition mp4tagfield.h:25
TagParser::RawDataType::Utf8Sort
@ Utf8Sort
Definition mp4tagfield.h:24
TagParser::RawDataType::Utf16
@ Utf16
Definition mp4tagfield.h:22
TagParser::RawDataType::Png
@ Png
Definition mp4tagfield.h:33
TagParser::RawDataType::Sjis
@ Sjis
Definition mp4tagfield.h:23
TagParser::RawDataType::Duration
@ Duration
Definition mp4tagfield.h:35
TagParser::RawDataType::Mi3p
@ Mi3p
Definition mp4tagfield.h:30
TagParser::RawDataType::Url
@ Url
Definition mp4tagfield.h:34
TagParser::RawDataType::Bmp
@ Bmp
Definition mp4tagfield.h:43
TagParser::RawDataType::Genred
@ Genred
Definition mp4tagfield.h:37
TagParser::RawDataType::BeFloat32
@ BeFloat32
Definition mp4tagfield.h:40
TagParser::RawDataType::Reserved
@ Reserved
Definition mp4tagfield.h:20
TagParser::RawDataType::Isrc
@ Isrc
Definition mp4tagfield.h:29
TagParser::RawDataType::QuickTimeMetadataAtom
@ QuickTimeMetadataAtom
Definition mp4tagfield.h:44
TagParser::RawDataType::DateTime
@ DateTime
Definition mp4tagfield.h:36
TagParser::RawDataType::BeUnsignedInt
@ BeUnsignedInt
Definition mp4tagfield.h:39
TagParser::RawDataType::Html
@ Html
Definition mp4tagfield.h:26
TagParser::RawDataType::Undefined
@ Undefined
Definition mp4tagfield.h:45
TagParser::RawDataType::Jpeg
@ Jpeg
Definition mp4tagfield.h:32
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::Mp4TagField::AdditionalData
Definition mp4tagfield.h:116
TagParser::Mp4TagField::AdditionalData::value
TagValue value
Definition mp4tagfield.h:117
TagParser::Mp4TagField::AdditionalData::countryIndicator
std::uint16_t countryIndicator
Definition mp4tagfield.h:119
TagParser::Mp4TagField::AdditionalData::rawDataType
std::uint32_t rawDataType
Definition mp4tagfield.h:118
TagParser::Mp4TagField::AdditionalData::languageIndicator
std::uint16_t languageIndicator
Definition mp4tagfield.h:120