Fix for handling negative h264 offsets in mp4

This commit is contained in:
Erik Zandvliet 2016-04-06 11:38:49 +02:00
parent 3b9911df71
commit 4c2eeb96c8
5 changed files with 14 additions and 12 deletions

View file

@ -2575,7 +2575,8 @@ namespace MP4 {
setEntryCount(no + 1); setEntryCount(no + 1);
} }
setInt32(newCTTSEntry.sampleCount, 8 + no * 8); setInt32(newCTTSEntry.sampleCount, 8 + no * 8);
setInt32(newCTTSEntry.sampleOffset, 8 + (no * 8) + 4); setInt32(*(reinterpret_cast<uint32_t*>(&newCTTSEntry.sampleOffset)), 8 + (no * 8) + 4);
} }
CTTSEntry CTTS::getCTTSEntry(uint32_t no) { CTTSEntry CTTS::getCTTSEntry(uint32_t no) {
@ -2585,7 +2586,8 @@ namespace MP4 {
return inval; return inval;
} }
retval.sampleCount = getInt32(8 + (no * 8)); retval.sampleCount = getInt32(8 + (no * 8));
retval.sampleOffset = getInt32(8 + (no * 8) + 4); uint32_t tmp = getInt32(8 + (no * 8) + 4);
retval.sampleOffset = *(reinterpret_cast<int32_t*>(&tmp));
return retval; return retval;
} }

View file

@ -538,7 +538,7 @@ namespace MP4 {
struct CTTSEntry { struct CTTSEntry {
uint32_t sampleCount; uint32_t sampleCount;
uint32_t sampleOffset; int32_t sampleOffset;
}; };
class CTTS: public fullBox { class CTTS: public fullBox {

View file

@ -100,7 +100,7 @@ namespace Mist {
}//rof trak }//rof trak
} }
void mp4TrackHeader::getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, long long unsigned int & timeOffset){ void mp4TrackHeader::getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, int32_t & timeOffset){
if (index < sampleIndex){ if (index < sampleIndex){
@ -171,7 +171,7 @@ namespace Mist {
while (offsetIndex < cttsBox.getEntryCount()){ while (offsetIndex < cttsBox.getEntryCount()){
tmpCTTS = cttsBox.getCTTSEntry(offsetIndex); tmpCTTS = cttsBox.getCTTSEntry(offsetIndex);
if ((index - offsetPos) < tmpCTTS.sampleCount){ if ((index - offsetPos) < tmpCTTS.sampleCount){
timeOffset = (tmpCTTS.sampleOffset*1000)/timeScale; timeOffset = (tmpCTTS.sampleOffset*1000)/(int32_t)timeScale;
break; break;
} }
offsetPos += tmpCTTS.sampleCount; offsetPos += tmpCTTS.sampleCount;
@ -518,7 +518,7 @@ namespace Mist {
cttsIndex++; cttsIndex++;
cttsEntryRead = 0; cttsEntryRead = 0;
} }
BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000)/timeScale; BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000)/(int32_t)timeScale;
}else{ }else{
BsetPart.timeOffset = 0; BsetPart.timeOffset = 0;
} }
@ -529,9 +529,9 @@ namespace Mist {
/// \todo Fix this. This makes no sense whatsoever. This isn't frame per kilosecond, but milli-STCO-entries per second. /// \todo Fix this. This makes no sense whatsoever. This isn't frame per kilosecond, but milli-STCO-entries per second.
// (A single STCO entry may be more than 1 part, and 1 part may be a partial frame or multiple frames) // (A single STCO entry may be more than 1 part, and 1 part may be a partial frame or multiple frames)
if (stcoIs64){ if (stcoIs64){
myMeta.tracks[trackNo].fpks = (((double)(((MP4::CO64*)&stcoBox)->getEntryCount()*1000))/((totaldur*1000)/timeScale))*1000; myMeta.tracks[trackNo].fpks = (((double)(((MP4::CO64*)&stcoBox)->getEntryCount()*1000))/((totaldur*1000)))*1000;
}else{ }else{
myMeta.tracks[trackNo].fpks = (((double)(stcoBox.getEntryCount()*1000))/((totaldur*1000)/timeScale))*1000; myMeta.tracks[trackNo].fpks = (((double)(stcoBox.getEntryCount()*1000))/((totaldur*1000)))*1000;
} }
} }
}//fi stbl }//fi stbl

View file

@ -23,7 +23,7 @@ namespace Mist {
return false; return false;
} }
long long unsigned int time; long long unsigned int time;
long long unsigned int offset; int32_t offset;
unsigned int trackID; unsigned int trackID;
long long unsigned int bpos; long long unsigned int bpos;
unsigned int size; unsigned int size;
@ -52,7 +52,7 @@ namespace Mist {
long long unsigned int bpos; long long unsigned int bpos;
long long unsigned int size; long long unsigned int size;
long long unsigned int stcoNr; long long unsigned int stcoNr;
long unsigned int timeOffset; int32_t timeOffset;
bool keyframe; bool keyframe;
}; };
@ -67,7 +67,7 @@ namespace Mist {
MP4::CTTS cttsBox; MP4::CTTS cttsBox;
MP4::STSC stscBox; MP4::STSC stscBox;
long unsigned int timeScale; long unsigned int timeScale;
void getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, long long unsigned int & timeOffset); void getPart(long unsigned int index, long long unsigned int & offset,unsigned int& size, long long unsigned int & timestamp, int32_t & timeOffset);
long unsigned int size(); long unsigned int size();
private: private:
bool initialised; bool initialised;

View file

@ -7,7 +7,7 @@
namespace Mist { namespace Mist {
OutProgressiveMP4::OutProgressiveMP4(Socket::Connection & conn) : HTTPOutput(conn) { OutProgressiveMP4::OutProgressiveMP4(Socket::Connection & conn) : HTTPOutput(conn) {
completeKeysOnly = true; completeKeysOnly = false;
} }
OutProgressiveMP4::~OutProgressiveMP4() {} OutProgressiveMP4::~OutProgressiveMP4() {}