Tag Parser  7.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mp4atom.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_MP4ATOM_H
2 #define TAG_PARSER_MP4ATOM_H
3 
4 #include "./mp4ids.h"
5 
6 #include "../genericfileelement.h"
7 
8 #include <c++utilities/conversion/stringconversion.h>
9 #include <c++utilities/conversion/types.h>
10 
11 #include <iostream>
12 #include <list>
13 #include <memory>
14 
15 namespace TagParser {
16 
17 class Mp4Atom;
18 class Mp4Container;
19 
24 public:
26  typedef uint32 IdentifierType;
27  typedef uint64 DataSizeType;
28 
32  static constexpr byte minimumElementSize()
33  {
34  return 8;
35  }
36 };
37 
38 class TAG_PARSER_EXPORT Mp4Atom : public GenericFileElement<Mp4Atom> {
39  friend class GenericFileElement<Mp4Atom>;
40 
41 public:
42  Mp4Atom(ContainerType &container, uint64 startOffset);
43 
44  std::string idToString() const;
45  bool isParent() const;
46  bool isPadding() const;
47  uint64 firstChildOffset() const;
48 
49  static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset);
50  static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
51  static void addHeaderSize(uint64 &dataSize);
52  static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer);
53 
54 protected:
55  Mp4Atom(ContainerType &container, uint64 startOffset, uint64 maxSize);
56  Mp4Atom(Mp4Atom &parent, uint64 startOffset);
57 
58  void internalParse(Diagnostics &diag);
59 
60 private:
61  std::string parsingContext() const;
62 };
63 
67 inline std::string Mp4Atom::idToString() const
68 {
69  auto idString = ConversionUtilities::interpretIntegerAsString<IdentifierType>(id());
70  for (char &c : idString) {
71  if (c < ' ') {
72  c = '?';
73  }
74  }
75  return idString;
76 }
77 
81 inline void Mp4Atom::addHeaderSize(uint64 &dataSize)
82 {
83  dataSize += (dataSize < 0xFFFFFFF7 ? 8 : 16);
84 }
85 
86 } // namespace TagParser
87 
88 #endif // TAG_PARSER_MP4ATOM_H
FileElementTraits< ImplementationType >::ContainerType ContainerType
Specifies the type of the corresponding container.
static void addHeaderSize(uint64 &dataSize)
Adds the header size to the specified data size.
Definition: mp4atom.h:81
DataSizeType dataSize() const
Returns the data size of the element in byte.
static constexpr byte minimumElementSize()
Returns the minimal atom size which is 8 byte.
Definition: mp4atom.h:32
const IdentifierType & id() const
Returns the element ID.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
std::string idToString() const
Converts the specified atom ID to a printable string.
Definition: mp4atom.h:67