Skip at least some corruption in TS

This commit is contained in:
Erik Zandvliet 2018-05-02 16:26:22 +02:00 committed by Thulinma
parent 98c50762e8
commit 0fff6f8773
6 changed files with 25 additions and 18 deletions

View file

@ -142,15 +142,15 @@ namespace aac {
if (syncWord != 0xfff){ if (syncWord != 0xfff){
res << " Sync word " << std::hex << syncWord << " != fff!" << std::endl; res << " Sync word " << std::hex << syncWord << " != fff!" << std::endl;
} }
if (data[1] & 0x8 == 0x8){ if ((data[1] & 0x8) == 0x8){
res << " MPEG-2" << std::endl; res << " MPEG-2" << std::endl;
}else{ }else{
res << " MPEG-4" << std::endl; res << " MPEG-4" << std::endl;
} }
if (data[1] & 0x6 != 0){ if ((data[1] & 0x6) != 0){
res << " Non-zero layer!" << std::endl; res << " Non-zero layer!" << std::endl;
} }
if (data[1] & 0x1 == 0x0){ if ((data[1] & 0x1) == 0x0){
res << " CRC present" << std::endl; res << " CRC present" << std::endl;
} }
res << " MPEG-4 audio object type: " << getAACProfile() << std::endl; res << " MPEG-4 audio object type: " << getAACProfile() << std::endl;
@ -161,7 +161,7 @@ namespace aac {
return res.str(); return res.str();
} }
adts::operator bool() const{ adts::operator bool() const{
return hasSync() && len && len >= getHeaderSize() && getFrequency(); return hasSync() && len && len >= getHeaderSize() && getFrequency() && getChannelCount() && getSampleCount();
} }
bool adts::hasSync() const{ bool adts::hasSync() const{
return len && (((int)data[0] << 4) | ((data[1] >> 4) & 0x0F)) == 0xfff; return len && (((int)data[0] << 4) | ((data[1] >> 4) & 0x0F)) == 0xfff;

View file

@ -219,7 +219,7 @@ namespace DTSC {
//keyframe, if true, adds 9 bytes (integer type) and 10 bytes (2+namelen) //keyframe, if true, adds 9 bytes (integer type) and 10 bytes (2+namelen)
//data adds packDataSize+5 bytes (string type) and 6 bytes (2+namelen) //data adds packDataSize+5 bytes (string type) and 6 bytes (2+namelen)
if (packData && packDataSize < 1){ if (packData && packDataSize < 1){
FAIL_MSG("Attempted to fill a packet with %lli bytes!", packDataSize); FAIL_MSG("Attempted to fill a packet with %lli bytes for timestamp %llu, track %llu!", packDataSize, packTime, packTrack);
return; return;
} }
unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos?15:0) + (isKeyframe?19:0) + packDataSize+11; unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos?15:0) + (isKeyframe?19:0) + packDataSize+11;

View file

@ -305,7 +305,7 @@ namespace TS{
} }
std::deque<Packet> &inStream = pesStreams[tid]; std::deque<Packet> &inStream = pesStreams[tid];
if (inStream.size() <= 1){ if (inStream.size() <= 1){
HIGH_MSG("No PES packets to parse"); FAIL_MSG("No PES packets to parse");
return; return;
} }
// Find number of packets before unit Start // Find number of packets before unit Start
@ -325,7 +325,7 @@ namespace TS{
} }
} }
if (!finished && curPack == inStream.end()){ if (!finished && curPack == inStream.end()){
INFO_MSG("No PES packets to parse (%lu)", seenUnitStart[tid]); FAIL_MSG("No PES packets to parse (%lu)", seenUnitStart[tid]);
return; return;
} }
@ -518,14 +518,18 @@ namespace TS{
adtsInfo[tid] = adtsPack; adtsInfo[tid] = adtsPack;
} }
out.push_back(DTSC::Packet()); out.push_back(DTSC::Packet());
out.back().genericFill(timeStamp + msRead, timeOffset, tid, if (adtsPack.getPayloadSize()){
adtsPack.getPayload(), adtsPack.getPayloadSize(), bPos, out.back().genericFill(timeStamp + msRead, timeOffset, tid,
0); adtsPack.getPayload(), adtsPack.getPayloadSize(), bPos,
msRead += (adtsPack.getSampleCount() * 1000) / adtsPack.getFrequency(); 0);
offsetInPes += adtsPack.getCompleteSize(); offsetInPes += adtsPack.getCompleteSize();
msRead += (adtsPack.getSampleCount() * 1000) / adtsPack.getFrequency();
}else{
offsetInPes++;
}
}else{ }else{
/// \todo What about the case that we have an invalid start, going over the PES boundary? /// \todo What about the case that we have an invalid start, going over the PES boundary?
if (!adtsPack.hasSync()){ if (!adtsPack){
offsetInPes++; offsetInPes++;
}else{ }else{
// remainder, keep it, use it next time // remainder, keep it, use it next time
@ -815,7 +819,7 @@ namespace TS{
for (std::map<unsigned long, std::deque<DTSC::Packet> >::iterator it = outPackets.begin(); for (std::map<unsigned long, std::deque<DTSC::Packet> >::iterator it = outPackets.begin();
it != outPackets.end(); it++){ it != outPackets.end(); it++){
if (it->second.front().getTime() < packTime){ if (it->second.size() && it->second.front().getTime() < packTime){
packTrack = it->first; packTrack = it->first;
packTime = it->second.front().getTime(); packTime = it->second.front().getTime();
} }

View file

@ -178,8 +178,8 @@ std::string AnalyserTS::printPES(const std::string &d, unsigned long PID){
counter = 0; counter = 0;
} }
res << std::hex << std::setw(2) << std::setfill('0') << (int)(d[i] & 0xff) << " "; res << std::hex << std::setw(2) << std::setfill('0') << (int)(d[i] & 0xff) << " ";
counter++;
if ((counter) % 32 == 31){res << std::endl;} if ((counter) % 32 == 31){res << std::endl;}
counter++;
} }
res << std::endl; res << std::endl;
} }

View file

@ -273,6 +273,9 @@ namespace Mist {
if (packet.getUnitStart()){ if (packet.getUnitStart()){
while (tsStream.hasPacketOnEachTrack()) { while (tsStream.hasPacketOnEachTrack()) {
tsStream.getEarliestPacket(headerPack); tsStream.getEarliestPacket(headerPack);
if (!headerPack){
break;
}
if (!myMeta.tracks.count(headerPack.getTrackId()) || !myMeta.tracks[headerPack.getTrackId()].codec.size()) { if (!myMeta.tracks.count(headerPack.getTrackId()) || !myMeta.tracks[headerPack.getTrackId()].codec.size()) {
tsStream.initializeMetadata(myMeta, headerPack.getTrackId()); tsStream.initializeMetadata(myMeta, headerPack.getTrackId());
} }
@ -302,13 +305,13 @@ namespace Mist {
void inputTS::getNext(bool smart) { void inputTS::getNext(bool smart) {
INSANE_MSG("Getting next"); INSANE_MSG("Getting next");
thisPacket.null(); thisPacket.null();
bool hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacketOnEachTrack()); bool hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacket());
while (!hasPacket && !feof(inFile) && (inputProcess == 0 || Util::Procs::childRunning(inputProcess)) && config->is_active) { while (!hasPacket && !feof(inFile) && (inputProcess == 0 || Util::Procs::childRunning(inputProcess)) && config->is_active) {
tsBuf.FromFile(inFile); tsBuf.FromFile(inFile);
if (selectedTracks.count(tsBuf.getPID())) { if (selectedTracks.count(tsBuf.getPID())) {
tsStream.parse(tsBuf, 0);//bPos == 0 tsStream.parse(tsBuf, 0);//bPos == 0
if (tsBuf.getUnitStart()){ if (tsBuf.getUnitStart()){
hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacketOnEachTrack()); hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacket());
} }
} }
} }

View file

@ -906,7 +906,7 @@ namespace Mist{
stats(); stats();
} }
if (nProxy.curPage[tid].mapped[tmp.offset] == 0){ if (nProxy.curPage[tid].mapped[tmp.offset] == 0){
FAIL_MSG("Track %d no data (key %u@%llu) - timeout", tid, getKeyForTime(tid, pos) + (getNextKey?1:0), tmp.offset); FAIL_MSG("Track %d no data (key %u@%u) - timeout", tid, getKeyForTime(tid, pos) + (getNextKey?1:0), tmp.offset);
}else{ }else{
return seek(tid, pos, getNextKey); return seek(tid, pos, getNextKey);
} }