From 0fff6f8773c799d7fa55ea84b0a148bd70216bc3 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Wed, 2 May 2018 16:26:22 +0200 Subject: [PATCH] Skip at least some corruption in TS --- lib/adts.cpp | 8 ++++---- lib/dtscmeta.cpp | 2 +- lib/ts_stream.cpp | 22 +++++++++++++--------- src/analysers/analyser_ts.cpp | 2 +- src/input/input_ts.cpp | 7 +++++-- src/output/output.cpp | 2 +- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/adts.cpp b/lib/adts.cpp index 047c4010..ae41f04f 100644 --- a/lib/adts.cpp +++ b/lib/adts.cpp @@ -142,15 +142,15 @@ namespace aac { if (syncWord != 0xfff){ res << " Sync word " << std::hex << syncWord << " != fff!" << std::endl; } - if (data[1] & 0x8 == 0x8){ + if ((data[1] & 0x8) == 0x8){ res << " MPEG-2" << std::endl; }else{ res << " MPEG-4" << std::endl; } - if (data[1] & 0x6 != 0){ + if ((data[1] & 0x6) != 0){ res << " Non-zero layer!" << std::endl; } - if (data[1] & 0x1 == 0x0){ + if ((data[1] & 0x1) == 0x0){ res << " CRC present" << std::endl; } res << " MPEG-4 audio object type: " << getAACProfile() << std::endl; @@ -161,7 +161,7 @@ namespace aac { return res.str(); } adts::operator bool() const{ - return hasSync() && len && len >= getHeaderSize() && getFrequency(); + return hasSync() && len && len >= getHeaderSize() && getFrequency() && getChannelCount() && getSampleCount(); } bool adts::hasSync() const{ return len && (((int)data[0] << 4) | ((data[1] >> 4) & 0x0F)) == 0xfff; diff --git a/lib/dtscmeta.cpp b/lib/dtscmeta.cpp index 47302ae5..6ff8c0ad 100644 --- a/lib/dtscmeta.cpp +++ b/lib/dtscmeta.cpp @@ -219,7 +219,7 @@ namespace DTSC { //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) 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; } unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos?15:0) + (isKeyframe?19:0) + packDataSize+11; diff --git a/lib/ts_stream.cpp b/lib/ts_stream.cpp index a278dd4d..b7b22313 100644 --- a/lib/ts_stream.cpp +++ b/lib/ts_stream.cpp @@ -305,7 +305,7 @@ namespace TS{ } std::deque &inStream = pesStreams[tid]; if (inStream.size() <= 1){ - HIGH_MSG("No PES packets to parse"); + FAIL_MSG("No PES packets to parse"); return; } // Find number of packets before unit Start @@ -325,7 +325,7 @@ namespace TS{ } } 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; } @@ -518,14 +518,18 @@ namespace TS{ adtsInfo[tid] = adtsPack; } out.push_back(DTSC::Packet()); - out.back().genericFill(timeStamp + msRead, timeOffset, tid, - adtsPack.getPayload(), adtsPack.getPayloadSize(), bPos, - 0); - msRead += (adtsPack.getSampleCount() * 1000) / adtsPack.getFrequency(); - offsetInPes += adtsPack.getCompleteSize(); + if (adtsPack.getPayloadSize()){ + out.back().genericFill(timeStamp + msRead, timeOffset, tid, + adtsPack.getPayload(), adtsPack.getPayloadSize(), bPos, + 0); + offsetInPes += adtsPack.getCompleteSize(); + msRead += (adtsPack.getSampleCount() * 1000) / adtsPack.getFrequency(); + }else{ + offsetInPes++; + } }else{ /// \todo What about the case that we have an invalid start, going over the PES boundary? - if (!adtsPack.hasSync()){ + if (!adtsPack){ offsetInPes++; }else{ // remainder, keep it, use it next time @@ -815,7 +819,7 @@ namespace TS{ for (std::map >::iterator it = outPackets.begin(); it != outPackets.end(); it++){ - if (it->second.front().getTime() < packTime){ + if (it->second.size() && it->second.front().getTime() < packTime){ packTrack = it->first; packTime = it->second.front().getTime(); } diff --git a/src/analysers/analyser_ts.cpp b/src/analysers/analyser_ts.cpp index 1a1216bb..dbd15cd6 100644 --- a/src/analysers/analyser_ts.cpp +++ b/src/analysers/analyser_ts.cpp @@ -178,8 +178,8 @@ std::string AnalyserTS::printPES(const std::string &d, unsigned long PID){ counter = 0; } res << std::hex << std::setw(2) << std::setfill('0') << (int)(d[i] & 0xff) << " "; - counter++; if ((counter) % 32 == 31){res << std::endl;} + counter++; } res << std::endl; } diff --git a/src/input/input_ts.cpp b/src/input/input_ts.cpp index 0cbbc311..73f6e71d 100755 --- a/src/input/input_ts.cpp +++ b/src/input/input_ts.cpp @@ -273,6 +273,9 @@ namespace Mist { if (packet.getUnitStart()){ while (tsStream.hasPacketOnEachTrack()) { tsStream.getEarliestPacket(headerPack); + if (!headerPack){ + break; + } if (!myMeta.tracks.count(headerPack.getTrackId()) || !myMeta.tracks[headerPack.getTrackId()].codec.size()) { tsStream.initializeMetadata(myMeta, headerPack.getTrackId()); } @@ -302,13 +305,13 @@ namespace Mist { void inputTS::getNext(bool smart) { INSANE_MSG("Getting next"); 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) { tsBuf.FromFile(inFile); if (selectedTracks.count(tsBuf.getPID())) { tsStream.parse(tsBuf, 0);//bPos == 0 if (tsBuf.getUnitStart()){ - hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacketOnEachTrack()); + hasPacket = (selectedTracks.size() == 1 ? tsStream.hasPacket(*selectedTracks.begin()) : tsStream.hasPacket()); } } } diff --git a/src/output/output.cpp b/src/output/output.cpp index 158c63b5..b4af7fff 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -906,7 +906,7 @@ namespace Mist{ stats(); } 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{ return seek(tid, pos, getNextKey); }