10#include <c++utilities/conversion/stringbuilder.h>
11#include <c++utilities/io/binaryreader.h>
12#include <c++utilities/io/binarywriter.h>
30 : GenericFileElement<Mp4Atom>(container, startOffset)
37Mp4Atom::Mp4Atom(GenericFileElement::ContainerType &container, std::uint64_t startOffset, std::uint64_t maxSize)
38 : GenericFileElement<Mp4Atom>(container, startOffset, maxSize)
45Mp4Atom::Mp4Atom(
Mp4Atom &parent, std::uint64_t startOffset)
53string Mp4Atom::parsingContext()
const
63 static const string context(
"parsing MP4 atom");
66 argsToString(
"Atom is smaller than 8 byte and hence invalid. The remaining size within the parent atom is ",
maxTotalSize(),
'.'),
81 diag.emplace_back(
DiagLevel::Critical,
"Atom is smaller than 8 byte and hence invalid.", context);
90 diag.emplace_back(
DiagLevel::Critical,
"Atom denoting 64-bit size is smaller than 16 byte and hence invalid.", parsingContext());
97 diag.emplace_back(
DiagLevel::Warning,
"The atom seems to be truncated; unable to parse siblings of that ", parsingContext());
135 ostream::pos_type currentOffset =
stream.tellp();
137 if (atomSize > numeric_limits<std::uint32_t>::max()) {
138 diag.emplace_back(
DiagLevel::Fatal, argsToString(atomSize,
" exceeds maximum."),
"write 32-bit atom size");
143 writer.writeUInt32BE(
static_cast<std::uint32_t
>(atomSize));
144 stream.seekp(currentOffset);
159 ostream::pos_type currentOffset =
stream.tellp();
163 stream.seekp(4, ios_base::cur);
165 stream.seekp(currentOffset);
173 if (size < numeric_limits<std::uint32_t>::max()) {
174 writer.writeUInt32BE(
static_cast<std::uint32_t
>(size));
179 writer.writeUInt64BE(size);
192 using namespace Mp4AtomIds;
199 case MediaInformation:
200 case MediaInformationHeader:
201 case DataInformation:
246 using namespace Mp4AtomIds;
266 using namespace Mp4AtomIds;
267 using namespace FourccIds;
282 case SampleDescription:
The Diagnostics class is a container for DiagMessage.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
The GenericFileElement class helps to parse binary files which consist of an arboreal element structu...
std::uint64_t startOffset() const
std::uint32_t headerSize() const
CppUtilities::BinaryWriter & writer()
typename FileElementTraits< ImplementationType >::ContainerType ContainerType
Specifies the type of the corresponding container.
std::unique_ptr< Mp4Atom > m_nextSibling
static constexpr std::uint8_t minimumElementSize()
std::unique_ptr< Mp4Atom > m_firstChild
DataSizeType dataSize() const
std::uint64_t totalSize() const
ContainerType & container()
CppUtilities::BinaryReader & reader()
std::uint64_t maxTotalSize() const
std::uint32_t m_sizeLength
The Mp4Atom class helps to parse MP4 files.
std::string idToString() const
Converts the specified atom ID to a printable string.
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.
static void makeHeader(std::uint64_t size, std::uint32_t id, CppUtilities::BinaryWriter &writer)
Writes an MP4 atom header to the specified stream.
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.
bool isParent() const
Returns an indication whether the atom is a parent element.
void internalParse(Diagnostics &diag)
Parses the MP4 atom.
std::uint64_t firstChildOffset() const
Returns the offset of the first child (relative to the start offset of this atom).
bool isPadding() const
Returns an indication whether the atom is a padding element.
Mp4Atom(ContainerType &container, std::uint64_t startOffset)
The exception that is thrown when the data to be parsed holds no parsable information (e....
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Contains all classes and functions of the TagInfo library.