7 #include "../mediafileinfo.h" 8 #include "../exceptions.h" 10 #include <c++utilities/conversion/stringbuilder.h> 11 #include <c++utilities/io/binaryreader.h> 12 #include <c++utilities/io/binarywriter.h> 30 Mp4Atom::Mp4Atom(GenericFileElement::containerType &container, uint64 startOffset) :
31 GenericFileElement<Mp4Atom>(container, startOffset)
38 GenericFileElement<Mp4Atom>(container, startOffset, maxSize)
45 GenericFileElement<Mp4Atom>(parent, startOffset)
51 string Mp4Atom::parsingContext()
const 53 return "parsing " % idToString() %
" atom at " + startOffset();
62 static const string context(
"parsing MP4 atom");
63 if(maxTotalSize() < minimumElementSize()) {
64 addNotification(
NotificationType::Critical,
"Atom is smaller than 8 byte and hence invalid. The remaining size within the parent atom is " % numberToString(maxTotalSize()) +
".", context);
67 stream().seekg(startOffset());
68 m_dataSize = reader().readUInt32BE();
71 m_dataSize = maxTotalSize();
77 if(m_dataSize < 8 && m_dataSize != 1) {
81 m_id = reader().readUInt32BE();
84 m_dataSize = reader().readUInt64BE();
86 if(dataSize() < 16 && m_dataSize != 1) {
87 addNotification(
NotificationType::Critical,
"Atom denoting 64-bit size is smaller than 16 byte and hence invalid.", parsingContext());
93 if(maxTotalSize() < m_dataSize) {
94 addNotification(
NotificationType::Warning,
"The atom seems to be truncated; unable to parse siblings of that ", parsingContext());
95 m_dataSize = maxTotalSize();
98 m_dataSize -= headerSize();
100 if(uint64 firstChildOffset = this->firstChildOffset()) {
101 if(firstChildOffset + minimumElementSize() <= totalSize()) {
102 child =
new Mp4Atom(static_cast<Mp4Atom &>(*
this), startOffset() + firstChildOffset);
105 m_firstChild.reset(child);
107 if(totalSize() < maxTotalSize()) {
109 sibling =
new Mp4Atom(*(parent()), startOffset() + totalSize());
111 sibling =
new Mp4Atom(container(), startOffset() + totalSize(), maxTotalSize() - totalSize());
114 m_nextSibling.reset(sibling);
128 ostream::pos_type currentOffset = stream.tellp();
129 stream.seekp(startOffset);
130 BinaryWriter writer(&stream);
131 writer.writeUInt32BE(currentOffset - startOffset);
132 stream.seekp(currentOffset);
146 ostream::pos_type currentOffset = stream.tellp();
147 stream.seekp(startOffset);
148 BinaryWriter writer(&stream);
149 writer.writeUInt32BE(1);
150 stream.seekp(4, ios_base::cur);
151 writer.writeUInt64BE(currentOffset - startOffset);
152 stream.seekp(currentOffset);
160 if(size < 0xFFFFFFFF) {
161 writer.writeUInt32BE(static_cast<uint32>(size));
162 writer.writeUInt32BE(
id);
164 writer.writeUInt32BE(1);
165 writer.writeUInt32BE(
id);
166 writer.writeUInt64BE(size);
179 using namespace Mp4AtomIds;
193 switch(parent()->
id()) {
211 using namespace Mp4AtomIds;
230 using namespace Mp4AtomIds;
231 using namespace FourccIds;
234 case Meta:
return headerSize() + 0x4u;
236 default:
return headerSize();
241 default:
return 0x00u;
Contains utility classes helping to read and write streams.