From 78c23779a6c9c4b748ca5df58a8c77e69caae8d7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 8 Jul 2015 01:15:45 +0200 Subject: [PATCH] fixed wrong end position in updateChunkOffsets() --- mp4/mp4atom.cpp | 5 ++--- mp4/mp4container.cpp | 14 ++++++-------- mp4/mp4track.cpp | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/mp4/mp4atom.cpp b/mp4/mp4atom.cpp index 0739513..184aefe 100644 --- a/mp4/mp4atom.cpp +++ b/mp4/mp4atom.cpp @@ -124,15 +124,14 @@ void Mp4Atom::internalParse() void Mp4Atom::seekBackAndWriteAtomSize(std::ostream &stream, const ostream::pos_type &startOffset, bool denote64BitSize) { ostream::pos_type currentOffset = stream.tellp(); - uint64 newSize = currentOffset - startOffset; stream.seekp(startOffset); BinaryWriter writer(&stream); if(denote64BitSize) { writer.writeUInt32BE(0); stream.seekp(4, ios_base::cur); - writer.writeUInt64BE(newSize); + writer.writeUInt64BE(currentOffset - startOffset); } else { - writer.writeUInt32BE(newSize); + writer.writeUInt32BE(currentOffset - startOffset); } stream.seekp(currentOffset); } diff --git a/mp4/mp4container.cpp b/mp4/mp4container.cpp index c2a3369..661d162 100644 --- a/mp4/mp4container.cpp +++ b/mp4/mp4container.cpp @@ -231,7 +231,7 @@ void Mp4Container::internalMakeFile() pdinAtom->copyEntirely(outputStream); } ostream::pos_type newMoovOffset = outputStream.tellp(); - Mp4Atom *udtaAtom = nullptr, *udtaChildAtom = nullptr; + Mp4Atom *udtaAtom = nullptr; uint64 newUdtaOffset = 0u; if(isAborted()) { throw OperationAbortedException(); @@ -251,14 +251,13 @@ void Mp4Container::internalMakeFile() // check if the udta atom needs to be written bool writeUdtaAtom = !m_tags.empty(); // it has to be written only when a MP4 tag is assigned if(!writeUdtaAtom) { // or when there is at least one child except the meta atom in the original file - udtaChildAtom = udtaAtom->firstChild(); try { - while(!writeUdtaAtom && udtaChildAtom) { + for(Mp4Atom *udtaChildAtom = udtaAtom->firstChild(); udtaChildAtom; udtaChildAtom = udtaChildAtom->nextSibling()) { udtaChildAtom->parse(); if(udtaChildAtom->id() != Mp4AtomIds::Meta) { writeUdtaAtom = true; + break; } - udtaChildAtom = udtaChildAtom->nextSibling(); } } catch(Failure &) { addNotification(NotificationType::Warning, @@ -280,7 +279,7 @@ void Mp4Container::internalMakeFile() } // write rest of the child atoms of udta atom try { - for(udtaChildAtom = udtaAtom->firstChild(); udtaChildAtom; udtaChildAtom = udtaChildAtom->nextSibling()) { + for(Mp4Atom *udtaChildAtom = udtaAtom->firstChild(); udtaChildAtom; udtaChildAtom = udtaChildAtom->nextSibling()) { udtaChildAtom->parse(); if(udtaChildAtom->id() != Mp4AtomIds::Meta) { // skip meta atoms here of course udtaChildAtom->copyEntirely(outputStream); @@ -335,8 +334,7 @@ void Mp4Container::internalMakeFile() vector origMdatOffsets; // used when simply copying mdat vector newMdatOffsets; // used when simply copying mdat // write other atoms - Mp4Atom *firstOtherTopLevelAtom = firstElement()->nextSibling(); - for(Mp4Atom *otherTopLevelAtom = firstOtherTopLevelAtom; otherTopLevelAtom; otherTopLevelAtom = otherTopLevelAtom->nextSibling()) { + for(Mp4Atom *otherTopLevelAtom = firstElement(); otherTopLevelAtom; otherTopLevelAtom = otherTopLevelAtom->nextSibling()) { if(isAborted()) { throw OperationAbortedException(); } @@ -512,7 +510,7 @@ void Mp4Container::updateOffsets(const std::vector &oldMdatOffsets, const moofAtom->parse(); try { for(Mp4Atom *trafAtom = moofAtom->childById(Mp4AtomIds::TrackFragment); trafAtom; - trafAtom->siblingById(Mp4AtomIds::TrackFragment, false)) { + trafAtom = trafAtom->siblingById(Mp4AtomIds::TrackFragment, false)) { trafAtom->parse(); int tfhdAtomCount = 0; for(Mp4Atom *tfhdAtom = trafAtom->childById(Mp4AtomIds::TrackFragmentHeader); tfhdAtom; diff --git a/mp4/mp4track.cpp b/mp4/mp4track.cpp index 63b4ec6..b75105b 100644 --- a/mp4/mp4track.cpp +++ b/mp4/mp4track.cpp @@ -812,7 +812,7 @@ void Mp4Track::updateChunkOffsets(const vector &oldMdatOffsets, const vec } static const unsigned int stcoDataBegin = 8; uint64 startPos = m_stcoAtom->dataOffset() + stcoDataBegin; - uint64 endPos = startPos + m_stcoAtom->totalSize() - stcoDataBegin; + uint64 endPos = startPos + m_stcoAtom->dataSize() - stcoDataBegin; m_istream->seekg(startPos); m_ostream->seekp(startPos); vector::size_type i;