7 #include "../exceptions.h" 9 #include <c++utilities/conversion/stringbuilder.h> 10 #include <c++utilities/io/binaryreader.h> 11 #include <c++utilities/io/binarywriter.h> 29 Mp4Atom::Mp4Atom(GenericFileElement::containerType &container, uint64 startOffset) :
30 GenericFileElement<Mp4Atom>(container, startOffset)
37 GenericFileElement<Mp4Atom>(container, startOffset, maxSize)
44 GenericFileElement<Mp4Atom>(parent, startOffset)
50 string Mp4Atom::parsingContext()
const 52 return "parsing " % idToString() %
" atom at " + startOffset();
61 static const string context(
"parsing MP4 atom");
62 if(maxTotalSize() < minimumElementSize()) {
63 addNotification(
NotificationType::Critical,
"Atom is smaller then 8 byte and hence invalid. The remaining size within the parent atom is " % numberToString(maxTotalSize()) +
".", context);
66 stream().seekg(startOffset());
67 m_dataSize = reader().readUInt32BE();
70 m_dataSize = maxTotalSize();
76 if(m_dataSize < 8 && m_dataSize != 1) {
80 m_id = reader().readUInt32BE();
83 m_dataSize = reader().readUInt64BE();
85 if(dataSize() < 16 && m_dataSize != 1) {
86 addNotification(
NotificationType::Critical,
"Atom denoting 64-bit size is smaller then 16 byte and hence invalid.", parsingContext());
92 if(maxTotalSize() < m_dataSize) {
93 addNotification(
NotificationType::Warning,
"The atom seems to be truncated; unable to parse siblings of that ", parsingContext());
94 m_dataSize = maxTotalSize();
97 m_dataSize -= headerSize();
99 if(uint64 firstChildOffset = this->firstChildOffset()) {
100 if(firstChildOffset + minimumElementSize() <= totalSize()) {
101 child =
new Mp4Atom(static_cast<Mp4Atom &>(*
this), startOffset() + firstChildOffset);
104 m_firstChild.reset(child);
106 if(totalSize() < maxTotalSize()) {
108 sibling =
new Mp4Atom(*(parent()), startOffset() + totalSize());
110 sibling =
new Mp4Atom(container(), startOffset() + totalSize(), maxTotalSize() - totalSize());
113 m_nextSibling.reset(sibling);
127 ostream::pos_type currentOffset = stream.tellp();
128 stream.seekp(startOffset);
129 BinaryWriter writer(&stream);
130 writer.writeUInt32BE(currentOffset - startOffset);
131 stream.seekp(currentOffset);
145 ostream::pos_type currentOffset = stream.tellp();
146 stream.seekp(startOffset);
147 BinaryWriter writer(&stream);
148 writer.writeUInt32BE(1);
149 stream.seekp(4, ios_base::cur);
150 writer.writeUInt64BE(currentOffset - startOffset);
151 stream.seekp(currentOffset);
159 if(size < 0xFFFFFFFF) {
160 writer.writeUInt32BE(static_cast<uint32>(size));
161 writer.writeUInt32BE(
id);
163 writer.writeUInt32BE(1);
164 writer.writeUInt32BE(
id);
165 writer.writeUInt64BE(size);
178 using namespace Mp4AtomIds;
192 switch(parent()->
id()) {
210 using namespace Mp4AtomIds;
229 using namespace Mp4AtomIds;
230 using namespace FourccIds;
233 case Meta:
return headerSize() + 0x4u;
235 default:
return headerSize();
240 default:
return 0x00u;
Contains utility classes helping to read and write streams.