From 578d08d586f3e7001705892d5b1ed4a2d2ce0095 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 25 Feb 2020 17:13:47 +0000 Subject: [PATCH] Convert AFeed and TFeed to std::thread --- afeed.cc | 42 +++++++++++++++++++-------------------- afeed.h | 23 ++++++++++------------ playerliveradio.cc | 1 - playerlivetv.cc | 2 -- playerradio.cc | 1 - playervideorec.cc | 3 --- tfeed.cc | 49 ++++++++++++++++++++++------------------------ tfeed.h | 44 +++++++++++++++++++---------------------- vfeed.h | 2 +- 9 files changed, 74 insertions(+), 93 deletions(-) diff --git a/afeed.cc b/afeed.cc index c841f45..2541718 100644 --- a/afeed.cc +++ b/afeed.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,16 +14,14 @@ 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 "afeed.h" - #include "log.h" #include "demuxer.h" #include "callback.h" +#include "afeed.h" AFeed::AFeed(Callback* tcb) : cb(*tcb) @@ -31,17 +29,6 @@ AFeed::AFeed(Callback* tcb) audioEnabled = 1; } -int AFeed::init() -{ - return 1; -} - -int AFeed::shutdown() -{ - // FIXME - return 1; -} - void AFeed::disable() { audioEnabled = 0; @@ -52,17 +39,28 @@ void AFeed::enable() audioEnabled = 1; } -int AFeed::start() +void AFeed::start() { audioEnabled = 1; - return threadStart(); + + threadStartProtect.lock(); + feedThread = std::thread( [this] + { + threadStartProtect.lock(); + threadStartProtect.unlock(); + threadMethod(); + }); + threadStartProtect.unlock(); } void AFeed::stop() { - Log::getInstance()->log("AFeed", Log::DEBUG, "Stop1"); - threadCancel(); - Log::getInstance()->log("AFeed", Log::DEBUG, "Stop2"); + Log::getInstance()->log("AFeed", Log::DEBUG, "Stop1"); + if (!feedThread.joinable()) return; + stopThread = true; + feedThread.join(); + stopThread = false; + Log::getInstance()->log("AFeed", Log::DEBUG, "Stop2"); } void AFeed::threadMethod() @@ -71,7 +69,7 @@ void AFeed::threadMethod() while(1) { - threadCheckExit(); + if (stopThread) return; if (audioEnabled) { diff --git a/afeed.h b/afeed.h index aafb6e9..d2ea550 100644 --- a/afeed.h +++ b/afeed.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,36 +14,33 @@ 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 AFEED_H #define AFEED_H -#include -#include - - -#include "threadsystem.h" +#include +#include class Callback; -class AFeed : public Thread_TYPE +class AFeed { public: AFeed(Callback* tcb); - int init(); - int shutdown(); - - int start(); + void start(); void stop(); void enable(); void disable(); private: + std::thread feedThread; + std::mutex threadStartProtect; void threadMethod(); + bool stopThread{}; + int audioEnabled; bool callbacksend; Callback& cb; diff --git a/playerliveradio.cc b/playerliveradio.cc index 585be83..648dab8 100644 --- a/playerliveradio.cc +++ b/playerliveradio.cc @@ -68,7 +68,6 @@ int PlayerLiveRadio::init() return 0; } - afeed.init(); audio->stop(); initted = true; diff --git a/playerlivetv.cc b/playerlivetv.cc index 156db58..4e2e3f7 100644 --- a/playerlivetv.cc +++ b/playerlivetv.cc @@ -97,8 +97,6 @@ int PlayerLiveTV::init() return 0; } - afeed.init(); - tfeed.init(); video->stop(); video->blank(); diff --git a/playerradio.cc b/playerradio.cc index b291a28..a1f9c1f 100644 --- a/playerradio.cc +++ b/playerradio.cc @@ -62,7 +62,6 @@ bool PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthFrames, bool isPesRecor return false; } - afeed.init(); audio->stop(); lengthBytes = tlengthBytes; diff --git a/playervideorec.cc b/playervideorec.cc index 8b57532..83a02ea 100644 --- a/playervideorec.cc +++ b/playervideorec.cc @@ -86,9 +86,6 @@ int PlayerVideoRec::init(bool p_isPesRecording, double framespersecond) return 0; } - afeed.init(); - tfeed.init(); - video->stop(); video->blank(); audio->stop(); diff --git a/tfeed.cc b/tfeed.cc index b1289e1..97e5284 100644 --- a/tfeed.cc +++ b/tfeed.cc @@ -1,5 +1,4 @@ /* - Copyright 2008 Marten Richter This file is part of VOMP. @@ -14,61 +13,60 @@ 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 "tfeed.h" #include "log.h" #include "demuxer.h" #include "callback.h" +#include "tfeed.h" TFeed::TFeed(Callback* tcb): cb(*tcb) { teletextEnabled = 1; } - -int TFeed::init() -{ - return 1; -} - -int TFeed::shutdown() -{ - // FIXME - return 1; -} - void TFeed::disable() { - teletextEnabled = 0; + teletextEnabled = 0; } void TFeed::enable() { - teletextEnabled = 1; + teletextEnabled = 1; } -int TFeed::start() +void TFeed::start() { teletextEnabled = 1; - return threadStart(); + + threadStartProtect.lock(); + feedThread = std::thread( [this] + { + threadStartProtect.lock(); + threadStartProtect.unlock(); + threadMethod(); + }); + threadStartProtect.unlock(); } void TFeed::stop() { - threadCancel(); + if (!feedThread.joinable()) return; + stopThread = true; + feedThread.join(); + stopThread = false; } void TFeed::threadMethod() { bool tlen; - while(1){ - threadCheckExit(); + while(1) + { + if (stopThread) return; + tlen = Demuxer::getInstance()->writeTeletext(); if (tlen) @@ -83,4 +81,3 @@ void TFeed::threadMethod() } } } - diff --git a/tfeed.h b/tfeed.h index 255ce17..4cb26a0 100644 --- a/tfeed.h +++ b/tfeed.h @@ -14,39 +14,35 @@ 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 TFEED_H #define TFEED_H +#include +#include -#include -#include +class Callback; -#include "threadsystem.h" +class TFeed +{ + public: + TFeed(Callback* tcb); -class Callback; + void start(); + void stop(); + void enable(); + void disable(); -class TFeed: public Thread_TYPE { -public: - TFeed(Callback* tcb); - int init(); - int shutdown(); - int start(); - void stop(); - void enable(); - void disable(); - -private: - - void threadMethod(); - int teletextEnabled; - Callback& cb; + private: + std::thread feedThread; + std::mutex threadStartProtect; + void threadMethod(); + bool stopThread{}; + + int teletextEnabled; + Callback& cb; }; #endif - - diff --git a/vfeed.h b/vfeed.h index e911048..098538c 100644 --- a/vfeed.h +++ b/vfeed.h @@ -37,8 +37,8 @@ class VFeed std::thread feedThread; std::mutex threadStartProtect; void threadMethod(); - Callback& cb; bool stopThread{}; + Callback& cb; }; #endif -- 2.39.5