From 225130a3bc6115b5db1cb4b82ebf6b054726ce04 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 25 Feb 2020 16:19:21 +0000 Subject: [PATCH] Simplify VFeed. Switch to std::thread --- playerlivetv.cc | 2 -- playervideorec.cc | 4 +--- playervideorec.h | 6 +++--- vfeed.cc | 50 +++++++++++++++++++---------------------------- vfeed.h | 31 +++++++++-------------------- 5 files changed, 33 insertions(+), 60 deletions(-) diff --git a/playerlivetv.cc b/playerlivetv.cc index d055dca..156db58 100644 --- a/playerlivetv.cc +++ b/playerlivetv.cc @@ -97,7 +97,6 @@ int PlayerLiveTV::init() return 0; } - vfeed.init(); afeed.init(); tfeed.init(); @@ -427,7 +426,6 @@ void PlayerLiveTV::switchState(UCHAR newState) case S_PREBUFFERING: { pendingAudioPlay=false; - vfeed.release(); state = newState; return; } diff --git a/playervideorec.cc b/playervideorec.cc index 0d138bf..8b57532 100644 --- a/playervideorec.cc +++ b/playervideorec.cc @@ -86,7 +86,6 @@ int PlayerVideoRec::init(bool p_isPesRecording, double framespersecond) return 0; } - vfeed.init(); afeed.init(); tfeed.init(); @@ -544,7 +543,7 @@ void PlayerVideoRec::switchState(UCHAR toState, ULONG jumpFrame) audio->unPause(); #ifdef VOMP_PLATFORM_RASPBERRY - vfeed.start(false); + vfeed.start(); #endif state = S_PLAY; @@ -1006,7 +1005,6 @@ void PlayerVideoRec::call(void* caller) video->reset(); video->play(); video->sync(); - vfeed.release(); stateMutex.unlock(); } diff --git a/playervideorec.h b/playervideorec.h index 05e47b8..f55169e 100644 --- a/playervideorec.h +++ b/playervideorec.h @@ -136,8 +136,6 @@ class PlayerVideoRec : public Thread_TYPE, public Callback void restartAtFramePI(ULONG newFrame); bool subtitlesShowing{}; - MessageQueue* messageQueue; - void* messageReceiver; OSDReceiver* osdReceiver; Log* logger; Audio* audio; @@ -149,7 +147,9 @@ class PlayerVideoRec : public Thread_TYPE, public Callback AFeed afeed; TFeed tfeed; TeletextDecoderVBIEBU *teletext; - + MessageQueue* messageQueue; + void* messageReceiver; + bool initted{}; bool startup; bool videoStartup{}; diff --git a/vfeed.cc b/vfeed.cc index c3823a5..0bc69dd 100644 --- a/vfeed.cc +++ b/vfeed.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,48 +14,40 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vfeed.h" - #include "log.h" #include "demuxer.h" #include "callback.h" +#include "vfeed.h" + VFeed::VFeed(Callback* tcb) : cb(*tcb) { } -int VFeed::init() -{ - return 1; -} - -int VFeed::shutdown() +void VFeed::start() { - // FIXME - return 1; -} - -int VFeed::start(bool tWaitForSignal) -{ - waitForSignal = tWaitForSignal; - return threadStart(); + threadStartProtect.lock(); + feedThread = std::thread( [this] + { + threadStartProtect.lock(); + threadStartProtect.unlock(); + threadMethod(); + }); + threadStartProtect.unlock(); } void VFeed::stop() { - Log::getInstance()->log("VFeed", Log::DEBUG, "Stop1"); - threadCancel(); - Log::getInstance()->log("VFeed", Log::DEBUG, "Stop2"); -} - -void VFeed::release() -{ - threadSignal(); + Log::getInstance()->log("VFeed", Log::DEBUG, "Stop1"); + if (!feedThread.joinable()) return; + stopThread = true; + feedThread.join(); + stopThread = false; + Log::getInstance()->log("VFeed", Log::DEBUG, "Stop2"); } void VFeed::threadMethod() @@ -63,12 +55,10 @@ void VFeed::threadMethod() bool vlen; Log::getInstance()->log("VFeed", Log::DEBUG, "Started"); - if (waitForSignal) threadWaitForSignal(); // Don't feed video until audio has started - Log::getInstance()->log("VFeed", Log::DEBUG, "Released"); while(1) { - threadCheckExit(); + if (stopThread) return; vlen = Demuxer::getInstance()->writeVideo(); if (vlen) diff --git a/vfeed.h b/vfeed.h index 18acf38..e911048 100644 --- a/vfeed.h +++ b/vfeed.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,44 +14,31 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VFEED_H #define VFEED_H -#include -#include - -#ifndef WIN32 -#ifdef __ANDROID__ -#include "threadpandroid.h" -#else -#include "threadp.h" -#endif -#else -#include "threadwin.h" -#endif +#include +#include class Callback; -class VFeed : public Thread_TYPE +class VFeed { public: VFeed(Callback* tcb); - int init(); - - int shutdown(); - int start(bool tWaitForSignal = true); + void start(); void stop(); - void release(); private: + std::thread feedThread; + std::mutex threadStartProtect; void threadMethod(); Callback& cb; - bool waitForSignal; + bool stopThread{}; }; #endif -- 2.39.5