fixed wrong end position in updateChunkOffsets()

This commit is contained in:
Martchus 2015-07-08 01:15:45 +02:00
parent b3d1d07f1a
commit 78c23779a6
3 changed files with 9 additions and 12 deletions

View File

@ -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);
}

View File

@ -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<int64> origMdatOffsets; // used when simply copying mdat
vector<int64> 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<int64> &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;

View File

@ -812,7 +812,7 @@ void Mp4Track::updateChunkOffsets(const vector<int64> &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<int64>::size_type i;