Tag Parser  6.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mp4tagfield.h
Go to the documentation of this file.
1 #ifndef MP4TAGATOM_H
2 #define MP4TAGATOM_H
3 
4 #include "../generictagfield.h"
5 #include "../statusprovider.h"
6 
7 #include <c++utilities/io/binarywriter.h>
8 #include <c++utilities/conversion/stringconversion.h>
9 
10 #include <vector>
11 #include <sstream>
12 
13 namespace Media
14 {
15 
19 namespace RawDataType {
20 enum KnownValue : uint32
21 {
22  Reserved = 0,
23  Utf8 = 1,
24  Utf16 = 2,
25  Sjis = 3,
26  Utf8Sort = 4,
27  Utf16Sort = 5,
28  Html = 6,
29  Xml = 7,
30  Uuid = 8,
31  Isrc = 9,
32  Mi3p = 10,
33  Gif = 12,
34  Jpeg = 13,
35  Png = 14,
36  Url = 15,
37  Duration = 16,
38  DateTime = 17,
39  Genred = 18,
40  BeSignedInt = 21,
42  BeFloat32 = 23,
43  BeFloat64 = 24,
44  Upc = 25,
45  Bmp = 27,
47  Undefined = 255
48 };
49 }
50 
51 class Mp4TagField;
52 
56 template <>
58 {
59 public:
63  typedef uint32 identifierType;
64 
68  typedef uint32 typeInfoType;
69 
74 };
75 
76 class Mp4Atom;
77 
79 {
80  friend class Mp4TagField;
81 
82 public:
83  void make(std::ostream &stream);
84  const Mp4TagField &field() const;
85  uint64 requiredSize() const;
86 
87 private:
89 
90  Mp4TagField &m_field;
91  std::stringstream m_convertedData;
92  IoUtilities::BinaryWriter m_writer;
93  uint32 m_rawDataType;
94  uint64 m_dataSize;
95  uint64 m_totalSize;
96 };
97 
102 {
103  return m_field;
104 }
105 
109 inline uint64 Mp4TagFieldMaker::requiredSize() const
110 {
111  return m_totalSize;
112 }
113 
114 class TAG_PARSER_EXPORT Mp4TagField : public TagField<Mp4TagField>, public StatusProvider
115 {
116  friend class TagField<Mp4TagField>;
117 
118 public:
119  Mp4TagField();
120  Mp4TagField(identifierType id, const TagValue &value);
121  Mp4TagField(const std::string &mean, const std::string &name, const TagValue &value);
122 
123  void reparse(Mp4Atom &ilstChild);
124  Mp4TagFieldMaker prepareMaking();
125  void make(std::ostream &stream);
126 
127  bool isAdditionalTypeInfoUsed() const;
128  const std::string &name() const;
129  void setName(const std::string &name);
130  const std::string &mean() const;
131  void setMean(const std::string &mean);
132  uint32 parsedRawDataType() const;
133  uint16 countryIndicator() const;
134  uint16 languageIndicator() const;
135  bool supportsNestedFields() const;
136  std::vector<uint32> expectedRawDataTypes() const;
137  uint32 appropriateRawDataType() const;
138 
139  static identifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
140  static std::string fieldIdToString(identifierType id);
141 
142 protected:
143  void cleared();
144 
145 private:
146  std::string m_name;
147  std::string m_mean;
148  uint32 m_parsedRawDataType;
149  uint16 m_countryIndicator;
150  uint16 m_langIndicator;
151 };
152 
157 {
158  return false;
159 }
160 
164 inline const std::string &Mp4TagField::name() const
165 {
166  return m_name;
167 }
168 
172 inline void Mp4TagField::setName(const std::string &name)
173 {
174  m_name = name;
175 }
176 
180 inline const std::string &Mp4TagField::mean() const
181 {
182  return m_mean;
183 }
184 
188 inline void Mp4TagField::setMean(const std::string &mean)
189 {
190  m_mean = mean;
191 }
192 
196 inline uint32 Mp4TagField::parsedRawDataType() const
197 {
198  return m_parsedRawDataType;
199 }
200 
204 inline uint16 Mp4TagField::countryIndicator() const
205 {
206  return m_countryIndicator;
207 }
208 
212 inline uint16 Mp4TagField::languageIndicator() const
213 {
214  return m_langIndicator;
215 }
216 
221 {
222  return false;
223 }
224 
230 inline Mp4TagField::identifierType Mp4TagField::fieldIdFromString(const char *idString, std::size_t idStringSize)
231 {
232  const auto latin1 = ConversionUtilities::convertUtf8ToLatin1(idString, idStringSize != std::string::npos ? idStringSize : std::strlen(idString));
233  switch(latin1.second) {
234  case 4:
235  return ConversionUtilities::BE::toUInt32(latin1.first.get());
236  default:
237  throw ConversionUtilities::ConversionException("MP4 ID must be exactly 4 chars");
238  }
239 }
240 
247 {
248  const auto utf8 = ConversionUtilities::convertLatin1ToUtf8(ConversionUtilities::interpretIntegerAsString<uint32>(id).data(), 4);
249  return std::string(utf8.first.get(), utf8.second);
250 }
251 
252 }
253 
254 #endif // MP4TAGATOM_H
uint64 requiredSize() const
Returns number of bytes which will be written when making the field.
Definition: mp4tagfield.h:109
The TagValue class wraps values of different types.
Definition: tagvalue.h:63
static identifierType fieldIdFromString(const char *idString, std::size_t idStringSize=std::string::npos)
Converts the specified ID string representation to an actual ID.
Definition: mp4tagfield.h:230
TagFieldTraits< Mp4TagField >::identifierType identifierType
void setName(const std::string &name)
Sets the "name" for the "extended" field.
Definition: mp4tagfield.h:172
void setMean(const std::string &mean)
Sets the "mean" for the "extended" field.
Definition: mp4tagfield.h:188
Defines traits for the specified ImplementationType.
The Mp4TagFieldMaker class helps making tag fields.
Definition: mp4tagfield.h:78
const Mp4TagField & field() const
Returns the associated field.
Definition: mp4tagfield.h:101
static std::string fieldIdToString(identifierType id)
Returns the string representation for the specified id.
Definition: mp4tagfield.h:246
bool isAdditionalTypeInfoUsed() const
Returns whether the additional type info is used.
Definition: mp4tagfield.h:156
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition: mp4tagfield.h:180
uint16 languageIndicator() const
Returns the language indicator.
Definition: mp4tagfield.h:212
uint32 typeInfoType
The type info is stored using 32-bit unsigned integers.
Definition: mp4tagfield.h:68
The TagField class is used by FieldMapBasedTag to store the fields.
uint32 identifierType
Fields in a iTunes-style MP4 tag are identified by 32-bit unsigned integers.
Definition: mp4tagfield.h:63
Mp4TagField implementationType
The implementation type is Mp4TagField.
Definition: mp4tagfield.h:73
uint16 countryIndicator() const
Returns the country indicator.
Definition: mp4tagfield.h:204
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:57
const std::string & name() const
Returns the "name" for "extended" fields.
Definition: mp4tagfield.h:164
uint32 parsedRawDataType() const
Returns the raw data type which has been determined when parsing.
Definition: mp4tagfield.h:196
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The StatusProvider class acts as a base class for objects providing status information.
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition: mp4tagfield.h:114
bool supportsNestedFields() const
Returns whether nested fields are supported.
Definition: mp4tagfield.h:220
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.