Tag Parser  8.2.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 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 <sstream>
10 #include <vector>
11 
12 namespace TagParser {
13 
17 namespace RawDataType {
18 enum KnownValue : uint32 {
19  Reserved = 0,
20  Utf8 = 1,
21  Utf16 = 2,
22  Sjis = 3,
23  Utf8Sort = 4,
24  Utf16Sort = 5,
25  Html = 6,
26  Xml = 7,
27  Uuid = 8,
28  Isrc = 9,
29  Mi3p = 10,
30  Gif = 12,
31  Jpeg = 13,
32  Png = 14,
33  Url = 15,
34  Duration = 16,
35  DateTime = 17,
36  Genred = 18,
37  BeSignedInt = 21,
39  BeFloat32 = 23,
40  BeFloat64 = 24,
41  Upc = 25,
42  Bmp = 27,
44  Undefined = 255
45 };
46 }
47 
48 class Mp4TagField;
49 class Diagnostics;
50 
55 public:
56  using IdentifierType = uint32;
57  using TypeInfoType = uint32;
58 };
59 
60 class Mp4Atom;
61 
63  friend class Mp4TagField;
64 
65 public:
66  void make(std::ostream &stream);
67  const Mp4TagField &field() const;
68  uint64 requiredSize() const;
69 
70 private:
72 
73  Mp4TagField &m_field;
74  std::stringstream m_convertedData;
75  IoUtilities::BinaryWriter m_writer;
76  uint32 m_rawDataType;
77  uint64 m_dataSize;
78  uint64 m_totalSize;
79 };
80 
84 inline const Mp4TagField &Mp4TagFieldMaker::field() const
85 {
86  return m_field;
87 }
88 
92 inline uint64 Mp4TagFieldMaker::requiredSize() const
93 {
94  return m_totalSize;
95 }
96 
97 class TAG_PARSER_EXPORT Mp4TagField : public TagField<Mp4TagField> {
98  friend class TagField<Mp4TagField>;
99 
100 public:
101  Mp4TagField();
102  Mp4TagField(IdentifierType id, const TagValue &value);
103  Mp4TagField(const std::string &mean, const std::string &name, const TagValue &value);
104 
105  void reparse(Mp4Atom &ilstChild, Diagnostics &diag);
106  Mp4TagFieldMaker prepareMaking(Diagnostics &diag);
107  void make(std::ostream &stream, Diagnostics &diag);
108 
109  bool isAdditionalTypeInfoUsed() const;
110  const std::string &name() const;
111  void setName(const std::string &name);
112  const std::string &mean() const;
113  void setMean(const std::string &mean);
114  uint32 parsedRawDataType() const;
115  uint16 countryIndicator() const;
116  uint16 languageIndicator() const;
117  bool supportsNestedFields() const;
118  std::vector<uint32> expectedRawDataTypes() const;
119  uint32 appropriateRawDataType() const;
120 
121  static IdentifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
122  static std::string fieldIdToString(IdentifierType id);
123 
124 private:
125  void reset();
126  std::string m_name;
127  std::string m_mean;
128  uint32 m_parsedRawDataType;
129  uint16 m_countryIndicator;
130  uint16 m_langIndicator;
131 };
132 
137 {
138  return false;
139 }
140 
144 inline const std::string &Mp4TagField::name() const
145 {
146  return m_name;
147 }
148 
152 inline void Mp4TagField::setName(const std::string &name)
153 {
154  m_name = name;
155 }
156 
160 inline const std::string &Mp4TagField::mean() const
161 {
162  return m_mean;
163 }
164 
168 inline void Mp4TagField::setMean(const std::string &mean)
169 {
170  m_mean = mean;
171 }
172 
176 inline uint32 Mp4TagField::parsedRawDataType() const
177 {
178  return m_parsedRawDataType;
179 }
180 
184 inline uint16 Mp4TagField::countryIndicator() const
185 {
186  return m_countryIndicator;
187 }
188 
192 inline uint16 Mp4TagField::languageIndicator() const
193 {
194  return m_langIndicator;
195 }
196 
201 {
202  return false;
203 }
204 
210 inline Mp4TagField::IdentifierType Mp4TagField::fieldIdFromString(const char *idString, std::size_t idStringSize)
211 {
212  const auto latin1 = ConversionUtilities::convertUtf8ToLatin1(idString, idStringSize != std::string::npos ? idStringSize : std::strlen(idString));
213  switch (latin1.second) {
214  case 4:
215  return ConversionUtilities::BE::toUInt32(latin1.first.get());
216  default:
217  throw ConversionUtilities::ConversionException("MP4 ID must be exactly 4 chars");
218  }
219 }
220 
227 {
228  const auto utf8 = ConversionUtilities::convertLatin1ToUtf8(ConversionUtilities::interpretIntegerAsString<uint32>(id).data(), 4);
229  return std::string(utf8.first.get(), utf8.second);
230 }
231 
232 } // namespace TagParser
233 
234 #endif // TAG_PARSER_MP4TAGATOM_H
bool supportsNestedFields() const
Returns whether nested fields are supported.
Definition: mp4tagfield.h:200
const std::string & name() const
Returns the "name" for "extended" fields.
Definition: mp4tagfield.h:144
uint32 parsedRawDataType() const
Returns the raw data type which has been determined when parsing.
Definition: mp4tagfield.h:176
uint16 languageIndicator() const
Returns the language indicator.
Definition: mp4tagfield.h:192
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition: mp4tagfield.h:97
Defines traits for the specified ImplementationType.
const Mp4TagField & field() const
Returns the associated field.
Definition: mp4tagfield.h:84
static std::string fieldIdToString(IdentifierType id)
Returns the string representation for the specified id.
Definition: mp4tagfield.h:226
uint16 countryIndicator() const
Returns the country indicator.
Definition: mp4tagfield.h:184
The Mp4TagFieldMaker class helps making tag fields.
Definition: mp4tagfield.h:62
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:38
uint64 requiredSize() const
Returns number of bytes which will be written when making the field.
Definition: mp4tagfield.h:92
void setMean(const std::string &mean)
Sets the "mean" for the "extended" field.
Definition: mp4tagfield.h:168
The TagField class is used by FieldMapBasedTag to store the fields.
typename TagFieldTraits< Mp4TagField >::IdentifierType IdentifierType
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:210
void setName(const std::string &name)
Sets the "name" for the "extended" field.
Definition: mp4tagfield.h:152
bool isAdditionalTypeInfoUsed() const
Returns whether the additional type info is used.
Definition: mp4tagfield.h:136
The TagValue class wraps values of different types.
Definition: tagvalue.h:65
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition: mp4tagfield.h:160