7 #include "../exceptions.h" 9 #include <c++utilities/io/binaryreader.h> 10 #include <c++utilities/io/binarywriter.h> 28 Mp4Atom::Mp4Atom(GenericFileElement::containerType &container, uint64 startOffset) :
29 GenericFileElement<Mp4Atom>(container, startOffset)
36 GenericFileElement<Mp4Atom>(container, startOffset, maxSize)
43 GenericFileElement<Mp4Atom>(parent, startOffset)
49 string Mp4Atom::parsingContext()
const 51 return "parsing " + idToString() +
" atom at " + numberToString(startOffset());
60 static const string context(
"parsing MP4 atom");
61 if(maxTotalSize() < minimumElementSize()) {
62 addNotification(
NotificationType::Critical,
"Atom is smaller then 8 byte and hence invalid. The remaining size within the parent atom is " + numberToString(maxTotalSize()) +
".", context);
65 stream().seekg(startOffset());
66 m_dataSize = reader().readUInt32BE();
69 m_dataSize = maxTotalSize();
75 if(m_dataSize < 8 && m_dataSize != 1) {
79 m_id = reader().readUInt32BE();
82 m_dataSize = reader().readUInt64BE();
84 if(dataSize() < 16 && m_dataSize != 1) {
85 addNotification(
NotificationType::Critical,
"Atom denoting 64-bit size is smaller then 16 byte and hence invalid.", parsingContext());
91 if(maxTotalSize() < m_dataSize) {
92 addNotification(
NotificationType::Warning,
"The atom seems to be truncated; unable to parse siblings of that ", parsingContext());
93 m_dataSize = maxTotalSize();
96 m_dataSize -= headerSize();
98 if(uint64 firstChildOffset = this->firstChildOffset()) {
99 if(firstChildOffset + minimumElementSize() <= totalSize()) {
100 child =
new Mp4Atom(static_cast<Mp4Atom &>(*
this), startOffset() + firstChildOffset);
103 m_firstChild.reset(child);
105 if(totalSize() < maxTotalSize()) {
107 sibling =
new Mp4Atom(*(parent()), startOffset() + totalSize());
109 sibling =
new Mp4Atom(container(), startOffset() + totalSize(), maxTotalSize() - totalSize());
112 m_nextSibling.reset(sibling);
126 ostream::pos_type currentOffset = stream.tellp();
127 stream.seekp(startOffset);
128 BinaryWriter writer(&stream);
129 writer.writeUInt32BE(currentOffset - startOffset);
130 stream.seekp(currentOffset);
144 ostream::pos_type currentOffset = stream.tellp();
145 stream.seekp(startOffset);
146 BinaryWriter writer(&stream);
147 writer.writeUInt32BE(1);
148 stream.seekp(4, ios_base::cur);
149 writer.writeUInt64BE(currentOffset - startOffset);
150 stream.seekp(currentOffset);
158 if(size < 0xFFFFFFFF) {
159 writer.writeUInt32BE(static_cast<uint32>(size));
160 writer.writeUInt32BE(
id);
162 writer.writeUInt32BE(1);
163 writer.writeUInt32BE(
id);
164 writer.writeUInt64BE(size);
177 using namespace Mp4AtomIds;
191 switch(parent()->
id()) {
209 using namespace Mp4AtomIds;
228 using namespace Mp4AtomIds;
229 using namespace FourccIds;
232 case Meta:
return headerSize() + 0x4u;
234 default:
return headerSize();
239 default:
return 0x00u;
Contains utility classes helping to read and write streams.