Tag Parser  6.4.0
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 MP4ATOM_H
2 #define MP4ATOM_H
3 
4 #include "./mp4ids.h"
5 
6 #include "../genericfileelement.h"
7 
8 #include <c++utilities/conversion/types.h>
9 #include <c++utilities/conversion/stringconversion.h>
10 
11 #include <list>
12 #include <iostream>
13 #include <memory>
14 
15 namespace Media
16 {
17 
18 class Mp4Atom;
19 class Mp4Container;
20 
24 template <>
26 {
27 public:
32 
36  typedef uint32 identifierType;
37 
41  typedef uint64 dataSizeType;
42 
47 
51  static constexpr byte minimumElementSize()
52  {
53  return 8;
54  }
55 };
56 
58 {
59  friend class GenericFileElement<Mp4Atom>;
60 
61 public:
62  Mp4Atom(containerType& container, uint64 startOffset);
63 
64  std::string idToString() const;
65  bool isParent() const;
66  bool isPadding() const;
67  uint64 firstChildOffset() const;
68 
69  static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset);
70  static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
71  static void addHeaderSize(uint64 &dataSize);
72  static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer);
73 
74 protected:
75  Mp4Atom(containerType& container, uint64 startOffset, uint64 maxSize);
76  Mp4Atom(implementationType &parent, uint64 startOffset);
77 
78  void internalParse();
79 
80 private:
81  std::string parsingContext() const;
82 };
83 
87 inline std::string Mp4Atom::idToString() const
88 {
89  auto idString = ConversionUtilities::interpretIntegerAsString<identifierType>(id());
90  for(char &c : idString) {
91  if(c < ' ') {
92  c = '?';
93  }
94  }
95  return idString;
96 }
97 
101 inline void Mp4Atom::addHeaderSize(uint64 &dataSize)
102 {
103  dataSize += dataSize < 0xFFFFFFF7 ? 8 : 16;
104 }
105 
106 }
107 
108 #endif // MP4ATOM_H
uint64 dataSizeType
The type used to store element sizes is an unsigned 64-bit integer.
Definition: mp4atom.h:41
static constexpr byte minimumElementSize()
Returns the minimal atom size which is 8 byte.
Definition: mp4atom.h:51
Implementation of GenericContainer<MediaFileInfo, Mp4Tag, Mp4Track, Mp4Atom>.
Definition: mp4container.h:19
Mp4Container containerType
The container type used to store such elements is Mp4Container.
Definition: mp4atom.h:31
The GenericFileElement class helps to parse binary files which consist of an arboreal element strucut...
Mp4Atom implementationType
The implementation type is Mp4Atom.
Definition: mp4atom.h:46
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:57
uint32 identifierType
The type used to store atom IDs is an unsigned 32-bit integer.
Definition: mp4atom.h:36
Defines traits for the specified ImplementationType.
std::string idToString() const
Converts the specified atom ID to a printable string.
Definition: mp4atom.h:87
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
static void addHeaderSize(uint64 &dataSize)
Adds the header size to the specified data size.
Definition: mp4atom.h:101