Some fixes to MP4 live output

This commit is contained in:
Thulinma 2017-07-25 17:04:46 +02:00
parent 8f4ddf14d9
commit 410b99d1cf
2 changed files with 18 additions and 11 deletions

View file

@ -124,7 +124,7 @@ namespace Mist {
res += 8; //mdat beginning res += 8; //mdat beginning
} }
fileSize += res; fileSize += res;
INFO_MSG("H size %llu, file: %llu", res, fileSize); MEDIUM_MSG("H size %llu, file: %llu", res, fileSize);
return res; return res;
} }
@ -396,10 +396,12 @@ namespace Mist {
//Current values are actual byte offset without header-sized offset //Current values are actual byte offset without header-sized offset
std::set <keyPart> sortSet;//filling sortset for interleaving parts std::set <keyPart> sortSet;//filling sortset for interleaving parts
for (std::set<long unsigned int>::iterator subIt = selectedTracks.begin(); subIt != selectedTracks.end(); subIt++) { for (std::set<long unsigned int>::iterator subIt = selectedTracks.begin(); subIt != selectedTracks.end(); subIt++) {
DTSC::Track & thisTrack = myMeta.tracks[*subIt];
keyPart temp; keyPart temp;
temp.trackID = *subIt; temp.trackID = *subIt;
temp.time = myMeta.tracks[*subIt].firstms;//timeplace of frame temp.time = thisTrack.firstms;//timeplace of frame
temp.index = 0; temp.index = 0;
temp.size = thisTrack.parts[0].getDuration();
INFO_MSG("adding to sortSet: tid %lu time %lu", temp.trackID, temp.time); INFO_MSG("adding to sortSet: tid %lu time %lu", temp.trackID, temp.time);
sortSet.insert(temp); sortSet.insert(temp);
} }
@ -422,6 +424,7 @@ namespace Mist {
if (temp.index + 1< thisTrack.parts.size()) {//Only create new element, when there are new elements to be added if (temp.index + 1< thisTrack.parts.size()) {//Only create new element, when there are new elements to be added
temp.time += thisTrack.parts[temp.index].getDuration(); temp.time += thisTrack.parts[temp.index].getDuration();
++temp.index; ++temp.index;
temp.size = thisTrack.parts[temp.index].getSize();
sortSet.insert(temp); sortSet.insert(temp);
} }
} }
@ -442,7 +445,7 @@ namespace Mist {
header << (char)(0); header << (char)(0);
} }
size += header.str().size(); size += header.str().size();
INFO_MSG("Header %llu, file: %llu", header.str().size(), size); MEDIUM_MSG("Header %llu, file: %llu", header.str().size(), size);
if (fragmented) { if (fragmented) {
realBaseOffset = header.str().size(); realBaseOffset = header.str().size();
} }
@ -485,6 +488,7 @@ namespace Mist {
if (temp.index + 1 < myMeta.tracks[temp.trackID].parts.size()){ //only insert when there are parts left if (temp.index + 1 < myMeta.tracks[temp.trackID].parts.size()){ //only insert when there are parts left
temp.time += thisTrack.parts[temp.index].getDuration(); temp.time += thisTrack.parts[temp.index].getDuration();
++temp.index; ++temp.index;
temp.size = thisTrack.parts[temp.index].getSize();
sortSet.insert(temp); sortSet.insert(temp);
} }
//Remove just-parsed element //Remove just-parsed element
@ -587,6 +591,7 @@ namespace Mist {
temp.trackID = it->first; temp.trackID = it->first;
temp.time = timeStamp; temp.time = timeStamp;
temp.index = i; temp.index = i;
temp.size = thisTrack.parts[temp.index].getSize();
timeStamp += thisTrack.parts[temp.index].getDuration(); timeStamp += thisTrack.parts[temp.index].getDuration();
trunOrder.insert(temp); trunOrder.insert(temp);
} }
@ -596,12 +601,11 @@ namespace Mist {
uint64_t relativeOffset = 0; uint64_t relativeOffset = 0;
for (std::set<keyPart>::iterator it = trunOrder.begin(); it != trunOrder.end(); it++) { for (std::set<keyPart>::iterator it = trunOrder.begin(); it != trunOrder.end(); it++) {
DTSC::Track & thisTrack = myMeta.tracks[it->trackID]; DTSC::Track & thisTrack = myMeta.tracks[it->trackID];
uint64_t partSize = thisTrack.parts[it->index].getSize();
//We have to make a copy, because altering the element inside the set would invalidate the iterators //We have to make a copy, because altering the element inside the set would invalidate the iterators
keyPart temp = *it; keyPart temp = *it;
temp.byteOffset = relativeOffset; temp.byteOffset = relativeOffset;
relativeOffset += partSize; relativeOffset += temp.size;
DONTEVEN_MSG("Anticipating tid: %lu size: %lu", it->trackID, partSize); DONTEVEN_MSG("Anticipating tid: %lu size: %lu", it->trackID, temp.size);
sortSet.insert(temp); sortSet.insert(temp);
} }
trunOrder.clear();//erase the trunOrder set, to keep memory usage down trunOrder.clear();//erase the trunOrder set, to keep memory usage down
@ -780,10 +784,12 @@ namespace Mist {
currPos = 0; currPos = 0;
sortSet.clear(); sortSet.clear();
for (std::set<long unsigned int>::iterator subIt = selectedTracks.begin(); subIt != selectedTracks.end(); subIt++) { for (std::set<long unsigned int>::iterator subIt = selectedTracks.begin(); subIt != selectedTracks.end(); subIt++) {
DTSC::Track & thisTrack = myMeta.tracks[*subIt];
keyPart temp; keyPart temp;
temp.trackID = *subIt; temp.trackID = *subIt;
temp.time = myMeta.tracks[*subIt].firstms;//timeplace of frame temp.time = thisTrack.firstms;//timeplace of frame
temp.index = 0; temp.index = 0;
temp.size = thisTrack.parts[temp.index].getSize();
sortSet.insert(temp); sortSet.insert(temp);
} }
if (!myMeta.live) { if (!myMeta.live) {
@ -894,7 +900,7 @@ namespace Mist {
} }
if (first){ if (first){
endms = thisTrack.lastms; endms = thisTrack.lastms;
if (needsLookAhead != endms - startms){ if (endms > startms && needsLookAhead < endms - startms){
needsLookAhead = endms - startms; needsLookAhead = endms - startms;
INFO_MSG("False start! Increasing lookAhead to %ums", needsLookAhead); INFO_MSG("False start! Increasing lookAhead to %ums", needsLookAhead);
missingSome = true; missingSome = true;
@ -946,8 +952,7 @@ namespace Mist {
} }
keyPart thisPart = *sortSet.begin(); keyPart thisPart = *sortSet.begin();
uint64_t thisSize = myMeta.tracks[thisPart.trackID].parts[thisPart.index].getSize(); if ((unsigned long)thisPacket.getTrackId() != thisPart.trackID || thisPacket.getTime() != thisPart.time || len != thisPart.size){
if ((unsigned long)thisPacket.getTrackId() != thisPart.trackID || thisPacket.getTime() != thisPart.time || len != thisSize){
if (thisPacket.getTime() > sortSet.begin()->time || thisPacket.getTrackId() > sortSet.begin()->trackID) { if (thisPacket.getTime() > sortSet.begin()->time || thisPacket.getTrackId() > sortSet.begin()->trackID) {
if (perfect) { if (perfect) {
WARN_MSG("Warning: input is inconsistent. Expected %lu:%lu but got %ld:%llu - cancelling playback", thisPart.trackID, thisPart.time, thisPacket.getTrackId(), thisPacket.getTime()); WARN_MSG("Warning: input is inconsistent. Expected %lu:%lu but got %ld:%llu - cancelling playback", thisPart.trackID, thisPart.time, thisPacket.getTrackId(), thisPacket.getTime());
@ -955,7 +960,7 @@ namespace Mist {
myConn.close(); myConn.close();
} }
} else { } else {
WARN_MSG("Did not receive expected %lu:%lu (%lub) but got %ld:%llu (%ub) - throwing it away", thisPart.trackID, thisPart.time, thisSize, thisPacket.getTrackId(), thisPacket.getTime(), len); WARN_MSG("Did not receive expected %lu:%lu (%lub) but got %ld:%llu (%ub) - throwing it away", thisPart.trackID, thisPart.time, thisPart.size, thisPacket.getTrackId(), thisPacket.getTime(), len);
} }
return; return;
} }
@ -989,6 +994,7 @@ namespace Mist {
if (temp.index + 1 < thisTrack.parts.size()) { //only insert when there are parts left if (temp.index + 1 < thisTrack.parts.size()) { //only insert when there are parts left
temp.time += thisTrack.parts[temp.index].getDuration(); temp.time += thisTrack.parts[temp.index].getDuration();
++temp.index; ++temp.index;
temp.size = thisTrack.parts[temp.index].getSize();
sortSet.insert(temp); sortSet.insert(temp);
} }

View file

@ -21,6 +21,7 @@ namespace Mist {
uint64_t time; uint64_t time;
uint64_t byteOffset;//Stores relative bpos for fragmented MP4 uint64_t byteOffset;//Stores relative bpos for fragmented MP4
uint64_t index; uint64_t index;
uint32_t size;
}; };
struct fragSet{ struct fragSet{