7 #include "../exceptions.h" 8 #include "../mediafileinfo.h" 10 #include <c++utilities/conversion/stringbuilder.h> 11 #include <c++utilities/io/binaryreader.h> 12 #include <c++utilities/io/binarywriter.h> 54 string Mp4Atom::parsingContext()
const 64 static const string context(
"parsing MP4 atom");
67 argsToString(
"Atom is smaller than 8 byte and hence invalid. The remaining size within the parent atom is ",
maxTotalSize(),
'.'),
82 diag.emplace_back(
DiagLevel::Critical,
"Atom is smaller than 8 byte and hence invalid.", context);
91 diag.emplace_back(
DiagLevel::Critical,
"Atom denoting 64-bit size is smaller than 16 byte and hence invalid.", parsingContext());
98 diag.emplace_back(
DiagLevel::Warning,
"The atom seems to be truncated; unable to parse siblings of that ", parsingContext());
136 ostream::pos_type currentOffset =
stream.tellp();
138 if (atomSize > numeric_limits<uint32>::max()) {
139 diag.emplace_back(
DiagLevel::Fatal, argsToString(atomSize,
" exceeds maximum."),
"write 32-bit atom size");
144 writer.writeUInt32BE(static_cast<uint32>(atomSize));
145 stream.seekp(currentOffset);
160 ostream::pos_type currentOffset =
stream.tellp();
164 stream.seekp(4, ios_base::cur);
166 stream.seekp(currentOffset);
174 if (size < numeric_limits<uint32>::max()) {
175 writer.writeUInt32BE(static_cast<uint32>(size));
180 writer.writeUInt64BE(size);
193 using namespace Mp4AtomIds;
244 using namespace Mp4AtomIds;
264 using namespace Mp4AtomIds;
265 using namespace FourccIds;
bool isParent() const
Returns an indication whether the atom is a parent element.
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Mp4Atom(ContainerType &container, uint64 startOffset)
Constructs a new top level atom with the specified container at the specified startOffset.
std::unique_ptr< ImplementationType > m_firstChild
std::unique_ptr< ImplementationType > m_nextSibling
DataSizeType dataSize() const
Returns the data size of the element in byte.
uint64 startOffset() const
Returns the start offset in the related stream.
The Mp4Atom class helps to parse MP4 files.
bool isPadding() const
Returns an indication whether the atom is a padding element.
uint64 totalSize() const
Returns the total size of the element.
The GenericFileElement class helps to parse binary files which consist of an arboreal element strucut...
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 constexpr byte minimumElementSize()
Returns the mimimum element size.
IoUtilities::BinaryReader & reader()
Returns the related BinaryReader.
Contains utility classes helping to read and write streams.
ContainerType & container()
Returns the related container.
void internalParse(Diagnostics &diag)
Parses the MP4 atom.
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.
The exception that is thrown when the data to be parsed holds no parsable information.
uint64 firstChildOffset() const
Returns the offset of the first child (relative to the start offset of this atom).
uint32 headerSize() const
Returns the header size of the element in byte.
IoUtilities::BinaryWriter & writer()
Returns the related BinaryWriter.
uint64 maxTotalSize() const
Returns maximum total size.
static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer)
Writes an MP4 atom header to the specified stream.
typename FileElementTraits< ImplementationType >::ContainerType ContainerType
Specifies the type of the corresponding container.
std::iostream & stream()
Returns the related stream.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
Contains all classes and functions of the TagInfo library.
std::string idToString() const
Converts the specified atom ID to a printable string.
The Diagnostics class is a container for DiagMessage.
ImplementationType * parent()
Returns the parent of the element.