#ifdef DVBSDEBUG
#include <stdio.h>
+#include "util.h"
#endif
#include "defines.h"
return (1LL<<33) + pts1 - pts2;
}
+static i8 PTSDifference2(u8 now, u8 next)
+{
+ // If next is a bit in the future, return value is small positive
+ // If next is a bit in the past, return value is small negative
+ // If PTS has wrapped then now will be massive, next will be very small
+ // The return value will be very large negative
+
+ return (i8)next - (i8)now;
+}
+
DVBSubtitles::DVBSubtitles(OSDReceiver* tosd)
: osd(tosd),
pageOnDisplay(65536),
LogNT::getInstance()->debug(TAG, "PUT DROPPING INVALID PACKET: PTS: {}, size: {}, type: {}", packet.getPTS(), packet.getSize(), packet.getPacketType());
}
}
+
+ #ifdef DVBSDEBUG
+
+ // FIXME dvbsubsdebug
+ u8 nowPTS = Video::getInstance()->getCurrentTimestamp();
+ fprintf(DBG, "\033[H\033[2J");
+ fprintf(DBG, "Now: %s %llu\n", tp2str(std::chrono::system_clock::now()).c_str(), nowPTS);
+ for (auto p : worklist)
+ {
+ i8 diff = PTSDifference2(nowPTS, p.getPTS());
+ fprintf(DBG, "packet PTS %llu SIZE %i\tTIME %s \tDIFF %lli\n", p.getPTS(), p.getSize(),
+ tp2str(std::chrono::system_clock::now() + std::chrono::milliseconds(diff / 90)).c_str(), diff);
+ }
+ fflush(DBG);
+#endif
+
input_mutex.unlock();
}
while(1)
{
#ifdef DVBSDEBUG
-
// FIXME dvbsubsdebug
- // TEMP DEBUG - re-enable nowPTS below when this goes
u8 nowPTS = Video::getInstance()->getCurrentTimestamp();
fprintf(DBG, "\033[H\033[2J");
- fprintf(DBG, "Now: %s %llu\n", tp2str(std::chrono::system_clock::now()).c_str(), Video::getInstance()->getCurrentTimestamp());
+ fprintf(DBG, "Now: %s %llu\n", tp2str(std::chrono::system_clock::now()).c_str(), nowPTS);
for (auto p : worklist)
{
- fprintf(DBG, "packet PTS %llu SIZE %i\tTIME %s\n", p.getPTS(), p.getSize(),
- tp2str(std::chrono::system_clock::now() + std::chrono::milliseconds(PTSDifference(p.getPTS(), nowPTS) / 90)).c_str());
+ i8 diff = PTSDifference2(nowPTS, p.getPTS());
+ fprintf(DBG, "packet PTS %llu SIZE %i\tTIME %s \tDIFF %lli\n", p.getPTS(), p.getSize(),
+ tp2str(std::chrono::system_clock::now() + std::chrono::milliseconds(diff / 90)).c_str(), diff);
}
fflush(DBG);
-
#endif
-
if (signalStop)
{
LogNT::getInstance()->info(TAG, "Thread exiting");
}
else
{
- #ifndef DVBSDEBUG
+ //#ifndef DVBSDEBUG
u8 nowPTS = Video::getInstance()->getCurrentTimestamp();
- #endif
+ //#endif
if (nowPTS == 0)
{
LogNT::getInstance()->debug(TAG, "Calc: Num packets available: {}", worklist.size());
u8 pktPTS = worklist.front().getPTS();
- u8 diff = PTSDifference(pktPTS, nowPTS);
+ i8 diff = PTSDifference2(nowPTS, pktPTS);
+ LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint. pktPTS {} nowPTS {} diff {}", pktPTS, nowPTS, diff);
diff /= 90; // convert diff to ms (PTS difference is in 1/90000s)
- if (diff < 60 * 1000)
+
+ if ((diff > 0) && (diff < (60 * 1000))) // Packet is in the next minute
{
worklistTimeoutPoint = std::chrono::system_clock::now() + std::chrono::milliseconds(diff);
- LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint");
+ LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint 1 {}", tp2str(worklistTimeoutPoint));
+ }
+ else if ((diff <= 0) && (diff > -(60 * 1000))) // Packet is in the past minute
+ {
+ worklistTimeoutPoint = std::chrono::system_clock::now();
+ LogNT::getInstance()->debug(TAG, "Problem packet 1");
+
+ // try this
+ waitExpireWL = true;
+ continue;
+ }
+ else if (diff < 95300000)
+ {
+ // PTS has wrapped
+
+ u8 newDelay = (1LL<<33) - pktPTS + nowPTS;
+ newDelay /= 90;
+
+ worklistTimeoutPoint = std::chrono::system_clock::now() + std::chrono::milliseconds(newDelay);
+ LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint 2 {}", tp2str(worklistTimeoutPoint));
}
else
{
// FIXME check if this still works
worklistTimeoutPoint = std::chrono::system_clock::now();
LogNT::getInstance()->debug(TAG, "Problem packet");
+
+ // try this
+ waitExpireWL = true;
+ continue;
}
}
}
//#endif
// Guaranteed to be at least one packet in the worklist
PESPacket packet = worklist.front();
- u8 pktPTS = worklist.front().getPTS();
+ //u8 pktPTS = worklist.front().getPTS();
+ u8 pktPTS = packet.getPTS();
while(1)
{
worklist.pop_front();
+ LogNT::getInstance()->debug(TAG, "Consumed packet with PTS {}", pktPTS);
+
output_mutex.lock();
if (showing) decodePacket(packet);