Tag Parser 12.4.0
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
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
18namespace RawDataType {
19enum KnownValue : std::uint32_t {
21 Utf8 = 1,
22 Utf16 = 2,
23 Sjis = 3,
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,
40 BeFloat32 = 23,
41 BeFloat64 = 24,
42 Upc = 25,
43 Bmp = 27,
45 Undefined = 255
46};
47}
48
49class Mp4TagField;
50class Diagnostics;
51
56public:
57 using IdentifierType = std::uint32_t;
58 using TypeInfoType = std::uint32_t;
59};
60
61class Mp4Atom;
62
64 friend class Mp4TagField;
65
66public:
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
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
100{
101 return m_field;
102}
103
107inline std::uint64_t Mp4TagFieldMaker::requiredSize() const
108{
109 return m_totalSize;
110}
111
112class TAG_PARSER_EXPORT Mp4TagField : public TagField<Mp4TagField> {
113 friend class TagField<Mp4TagField>;
114
115public:
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
164inline const std::vector<Mp4TagField::AdditionalData> &Mp4TagField::additionalData() const
165{
166 return m_additionalData;
167}
168
173inline std::vector<Mp4TagField::AdditionalData> &Mp4TagField::additionalData()
174{
175 return m_additionalData;
176}
177
182{
183 return false;
184}
185
189inline const std::string &Mp4TagField::name() const
190{
191 return m_name;
192}
193
197inline void Mp4TagField::setName(const std::string &name)
198{
199 m_name = name;
200}
201
205inline const std::string &Mp4TagField::mean() const
206{
207 return m_mean;
208}
209
213inline void Mp4TagField::setMean(const std::string &mean)
214{
215 m_mean = mean;
216}
217
221inline std::uint32_t Mp4TagField::parsedRawDataType() const
222{
223 return m_parsedRawDataType;
224}
225
229inline std::uint16_t Mp4TagField::countryIndicator() const
230{
231 return m_countryIndicator;
232}
233
237inline std::uint16_t Mp4TagField::languageIndicator() const
238{
239 return m_langIndicator;
240}
241
246{
247 return false;
248}
249
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
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
The Diagnostics class is a container for DiagMessage.
The Mp4Atom class helps to parse MP4 files.
The Mp4TagFieldMaker class helps making tag fields.
Mp4TagFieldMaker(Mp4TagFieldMaker &&)=default
std::uint64_t requiredSize() const
Returns number of bytes which will be written when making the field.
const Mp4TagField & field() const
Returns the associated field.
Definition mp4tagfield.h:99
The Mp4TagField class is used by Mp4Tag to store the fields.
bool supportsNestedFields() const
Returns whether nested fields are supported.
const std::vector< AdditionalData > & additionalData() const
Returns additional data (and the corresponding raw data type, country and language).
const std::string & name() const
Returns the "name" for "extended" fields.
void setName(const std::string &name)
Sets the "name" for the "extended" field.
bool isAdditionalTypeInfoUsed() const
Returns whether the additional type info is used.
const std::string & mean() const
Returns the "mean" for "extended" fields.
static IdentifierType fieldIdFromString(std::string_view idString)
Converts the specified ID string representation to an actual ID.
std::uint32_t parsedRawDataType() const
Returns the raw data type which has been determined when parsing.
void setMean(const std::string &mean)
Sets the "mean" for the "extended" field.
std::uint16_t languageIndicator() const
Returns the language indicator.
std::uint16_t countryIndicator() const
Returns the country indicator.
static std::string fieldIdToString(IdentifierType id)
Returns the string representation for the specified id.
Defines traits for the specified ImplementationType.
The TagField class is used by FieldMapBasedTag to store the fields.
typename TagFieldTraits< Mp4TagField >::IdentifierType IdentifierType
The TagValue class wraps values of different types.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10