From 7bc14161ef164b8140d90059e618492d99099560 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 13 Jan 2022 16:21:55 +0000 Subject: [PATCH] Fix subs running during pause - after a jump then quick pause --- audio.cc | 2 +- dvbsubtitles.cc | 59 ++++++++++++++++++++++++++++++------------------- dvbsubtitles.h | 1 + 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/audio.cc b/audio.cc index e0808c6..0904050 100644 --- a/audio.cc +++ b/audio.cc @@ -106,7 +106,7 @@ int Audio::systemMuteOff() int Audio::doMuting() { - LogNT::getInstance()->debug("Audio", "doMuting: user=%i sys=%i", userMute, systemMute); + LogNT::getInstance()->debug("Audio", "doMuting: user={} sys={}", userMute, systemMute); if (userMute || systemMute) { diff --git a/dvbsubtitles.cc b/dvbsubtitles.cc index 03b52bf..23efef2 100644 --- a/dvbsubtitles.cc +++ b/dvbsubtitles.cc @@ -793,6 +793,7 @@ void DVBSubtitles::start() dds=DVBSubtitleDisplayDefinition(); running = true; + paused = false; dvbsThread = std::thread([this] { threadMethod(); }); @@ -812,6 +813,7 @@ void DVBSubtitles::stop() } running = false; // disables put() + paused = false; signalStop = true; dvbsCond.notify_one(); input_mutex.unlock(); @@ -881,6 +883,7 @@ void DVBSubtitles::pause() return; } + paused = true; signalPause = true; dvbsCond.notify_one(); input_mutex.unlock(); @@ -898,6 +901,7 @@ void DVBSubtitles::unPause() return; } + paused = false; signalRecalcWLTO = true; dvbsCond.notify_one(); input_mutex.unlock(); @@ -952,38 +956,47 @@ void DVBSubtitles::threadMethod() else if (signalRecalcWLTO) // once per incoming packet, and other times { signalRecalcWLTO = false; -#ifndef DVBSDEBUG - ULLONG nowPTS = Video::getInstance()->getCurrentTimestamp(); -#endif - if (nowPTS == 0) + if (paused) { - // Video is not started yet. DVBSub packet has come in. Don't set worklistTimeoutPoint, - // just store the packet and allow next signal to start things off - LogNT::getInstance()->debug(TAG, "signalRecalcWLTO but Video PTS == 0"); + subtitleTimeoutPointActive = false; + worklistTimeoutPointActive = false; } - else if (worklist.size()) // It is possible to be called to recalc when there are no packets + else { - worklistTimeoutPointActive = true; - LogNT::getInstance()->debug(TAG, "Calc: Num packets available: {}", worklist.size()); + #ifndef DVBSDEBUG + ULLONG nowPTS = Video::getInstance()->getCurrentTimestamp(); + #endif - ULLONG pktPTS = worklist.front().getPTS(); - ULLONG diff = PTSDifference(pktPTS, nowPTS); - diff /= 90; // convert diff to ms (PTS difference is in 1/90000s) - if (diff < 60 * 1000) + if (nowPTS == 0) { - worklistTimeoutPoint = std::chrono::system_clock::now() + std::chrono::milliseconds(diff); - LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint"); + // Video is not started yet. DVBSub packet has come in. Don't set worklistTimeoutPoint, + // just store the packet and allow next signal to start things off + LogNT::getInstance()->debug(TAG, "signalRecalcWLTO but Video PTS == 0"); } - else + else if (worklist.size()) // It is possible to be called to recalc when there are no packets { - // We have a problem. An action so far in the future should have - // been culled. Probably the action is already due and PTSDifference - // wrapped around. Therefore we sleep for a minimal time instead. + worklistTimeoutPointActive = true; + LogNT::getInstance()->debug(TAG, "Calc: Num packets available: {}", worklist.size()); - // FIXME check if this still works - worklistTimeoutPoint = std::chrono::system_clock::now(); - LogNT::getInstance()->debug(TAG, "Problem packet"); + ULLONG pktPTS = worklist.front().getPTS(); + ULLONG diff = PTSDifference(pktPTS, nowPTS); + diff /= 90; // convert diff to ms (PTS difference is in 1/90000s) + if (diff < 60 * 1000) + { + worklistTimeoutPoint = std::chrono::system_clock::now() + std::chrono::milliseconds(diff); + LogNT::getInstance()->debug(TAG, "Calc'd new worklistTimeoutPoint"); + } + else + { + // We have a problem. An action so far in the future should have + // been culled. Probably the action is already due and PTSDifference + // wrapped around. Therefore we sleep for a minimal time instead. + + // FIXME check if this still works + worklistTimeoutPoint = std::chrono::system_clock::now(); + LogNT::getInstance()->debug(TAG, "Problem packet"); + } } } } diff --git a/dvbsubtitles.h b/dvbsubtitles.h index 55bef11..ad65ac3 100644 --- a/dvbsubtitles.h +++ b/dvbsubtitles.h @@ -136,6 +136,7 @@ class DVBSubtitles bool osdMenuShowing; bool running; bool showing; + bool paused{}; std::chrono::time_point subtitleTimeoutPoint; bool subtitleTimeoutPointActive{}; void threadMethod(); -- 2.39.5