Tag Parser: mp4/mp4atom.h Source File

Tag Parser 12.5.3 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
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
10#include <cstdint>
11#include <iostream>
12#include <list>
13#include <memory>
14
15namespace TagParser {
16
17class Mp4Atom;
18class Mp4Container;
19
23 template <> class TAG_PARSER_EXPORT FileElementTraits<Mp4Atom> {
24public:
25 using ContainerType = Mp4Container;
26 using IdentifierType = std::uint32_t;
27 using DataSizeType = std::uint64_t;
28
32 static constexpr std::uint8_t minimumElementSize()
33 {
34 return 8;
35 }
36};
37
38 class TAG_PARSER_EXPORT Mp4Atom : public GenericFileElement<Mp4Atom> {
39 friend class GenericFileElement<Mp4Atom>;
40
41public:
42 Mp4Atom(ContainerType &container, std::uint64_t startOffset);
43
44 std::string idToString() const;
45 bool isParent() const;
46 bool isPadding() const;
47 std::uint64_t firstChildOffset() const;
48
49 static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset, Diagnostics &diag);
50 static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
51 static constexpr void addHeaderSize(std::uint64_t &dataSize);
52 static void makeHeader(std::uint64_t size, std::uint32_t id, CppUtilities::BinaryWriter &writer);
53
54protected:
55 Mp4Atom(ContainerType &container, std::uint64_t startOffset, std::uint64_t maxSize);
56 Mp4Atom(Mp4Atom &parent, std::uint64_t startOffset);
57
58 void internalParse(Diagnostics &diag);
59
60private:
61 std::string parsingContext() const;
62};
63
67 inline std::string Mp4Atom::idToString() const
68{
69 auto idString = CppUtilities::interpretIntegerAsString<IdentifierType>(id());
70 for (char &c : idString) {
71 if (c < ' ') {
72 c = '?';
73 }
74 }
75 return idString;
76}
77
81 constexpr void Mp4Atom::addHeaderSize(std::uint64_t &dataSize)
82{
83 dataSize += (dataSize < 0xFFFFFFF7 ? 8 : 16);
84}
85
86} // namespace TagParser
87
88#endif // TAG_PARSER_MP4ATOM_H
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::FileElementTraits< Mp4Atom >::ContainerType
Mp4Container ContainerType
Definition mp4atom.h:25
TagParser::FileElementTraits< Mp4Atom >::DataSizeType
std::uint64_t DataSizeType
Definition mp4atom.h:27
TagParser::FileElementTraits< Mp4Atom >::IdentifierType
std::uint32_t IdentifierType
Definition mp4atom.h:26
TagParser::FileElementTraits
Defines traits for the specified ImplementationType.
Definition genericfileelement.h:34
TagParser::GenericFileElement< Mp4Atom >::GenericFileElement
GenericFileElement(ContainerType &container, std::uint64_t startOffset)
TagParser::GenericFileElement< Mp4Atom >::startOffset
std::uint64_t startOffset() const
Definition genericfileelement.h:266
TagParser::GenericFileElement< Mp4Atom >::writer
CppUtilities::BinaryWriter & writer()
Definition genericfileelement.h:258
TagParser::GenericFileElement< Mp4Atom >::ContainerType
typename FileElementTraits< Mp4Atom >::ContainerType ContainerType
Definition genericfileelement.h:51
TagParser::GenericFileElement< Mp4Atom >::stream
std::iostream & stream()
Definition genericfileelement.h:242
TagParser::GenericFileElement< Mp4Atom >::parent
Mp4Atom * parent()
Definition genericfileelement.h:390
TagParser::GenericFileElement< Mp4Atom >::minimumElementSize
static constexpr std::uint8_t minimumElementSize()
Definition genericfileelement.h:996
TagParser::GenericFileElement< Mp4Atom >::dataSize
DataSizeType dataSize() const
Definition genericfileelement.h:320
TagParser::GenericFileElement< Mp4Atom >::container
ContainerType & container()
Definition genericfileelement.h:225
TagParser::Mp4Atom
The Mp4Atom class helps to parse MP4 files.
Definition mp4atom.h:38
TagParser::Mp4Atom::addHeaderSize
static constexpr void addHeaderSize(std::uint64_t &dataSize)
Adds the header size to the specified data size.
Definition mp4atom.h:81
TagParser::Mp4Atom::Mp4Atom
Mp4Atom(ContainerType &container, std::uint64_t startOffset, std::uint64_t maxSize)
TagParser::Mp4Atom::idToString
std::string idToString() const
Converts the specified atom ID to a printable string.
Definition mp4atom.h:67
TagParser::Mp4Atom::seekBackAndWriteAtomSize
static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset, Diagnostics &diag)
This function helps to write the atom size after writing an atom to a stream.
Definition mp4atom.cpp:133
TagParser::Mp4Atom::makeHeader
static void makeHeader(std::uint64_t size, std::uint32_t id, CppUtilities::BinaryWriter &writer)
Writes an MP4 atom header to the specified stream.
Definition mp4atom.cpp:171
TagParser::Mp4Atom::seekBackAndWriteAtomSize64
static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset)
This function helps to write the atom size after writing an atom to a stream.
Definition mp4atom.cpp:157
TagParser::Mp4Atom::isParent
bool isParent() const
Returns an indication whether the atom is a parent element.
Definition mp4atom.cpp:190
TagParser::Mp4Atom::internalParse
void internalParse(Diagnostics &diag)
Parses the MP4 atom.
Definition mp4atom.cpp:61
TagParser::Mp4Atom::firstChildOffset
std::uint64_t firstChildOffset() const
Returns the offset of the first child (relative to the start offset of this atom).
Definition mp4atom.cpp:264
TagParser::Mp4Atom::isPadding
bool isPadding() const
Returns an indication whether the atom is a padding element.
Definition mp4atom.cpp:244
TagParser::Mp4Atom::Mp4Atom
Mp4Atom(ContainerType &container, std::uint64_t startOffset)
TagParser::Mp4Container
Implementation of GenericContainer<MediaFileInfo, Mp4Tag, Mp4Track, Mp4Atom>.
Definition mp4container.h:18
genericfileelement.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
mp4ids.h
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10