]> git.vomp.tv Git - vompclient.git/commitdiff
Convert AFeed and TFeed to std::thread
authorChris Tallon <chris@vomp.tv>
Tue, 25 Feb 2020 17:13:47 +0000 (17:13 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 25 Feb 2020 17:13:47 +0000 (17:13 +0000)
afeed.cc
afeed.h
playerliveradio.cc
playerlivetv.cc
playerradio.cc
playervideorec.cc
tfeed.cc
tfeed.h
vfeed.h

index c841f4508a29219c2d6efddb39289f174c31380b..2541718370e2628ab19330f820a38d2826d9364f 100644 (file)
--- 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.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
-#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 aafb6e987864aebc94f3c3df0c9a86b2af6aa40c..d2ea5508863caccaa4a2252bd0a181abfcc703de 100644 (file)
--- 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.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef AFEED_H
 #define AFEED_H
 
-#include <stdio.h>
-#include <time.h>
-
-
-#include "threadsystem.h"
+#include <thread>
+#include <mutex>
 
 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;
index 585be832b82480ae427ea7f16a6fbfa117f2521f..648dab8171cabe201e9dffeb72ddb2855311fbad 100644 (file)
@@ -68,7 +68,6 @@ int PlayerLiveRadio::init()
     return 0;
   }
 
-  afeed.init();
   audio->stop();
 
   initted = true;
index 156db58a6bf5a20d7cd5a6b37c6ffff3e62591ce..4e2e3f7c2ac179d51d60d9da8139b889597eed21 100644 (file)
@@ -97,8 +97,6 @@ int PlayerLiveTV::init()
     return 0;
   }
 
-  afeed.init();
-  tfeed.init();
 
   video->stop();
   video->blank();
index b291a285734729da5ec11d46c2c9cc539aa554af..a1f9c1faf26c68b75d8a8882280872004c7ec7ba 100644 (file)
@@ -62,7 +62,6 @@ bool PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthFrames, bool isPesRecor
     return false;
   }
 
-  afeed.init();
   audio->stop();
 
   lengthBytes = tlengthBytes;
index 8b575320401b5a51332d8be798867401132d1e2b..83a02eac0b07b10193b52f08ad8d5856b28e1ac2 100644 (file)
@@ -86,9 +86,6 @@ int PlayerVideoRec::init(bool p_isPesRecording, double framespersecond)
     return 0;
   }
 
-  afeed.init();
-  tfeed.init();
-
   video->stop();
   video->blank();
   audio->stop();
index b1289e1fbf11627364f63d51deba955effb1c393..97e5284f75893743a490ced69fd7a307b3bfadc7 100644 (file)
--- a/tfeed.cc
+++ b/tfeed.cc
@@ -1,5 +1,4 @@
 /*
-
     Copyright 2008 Marten Richter
     
     This file is part of VOMP.
     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 <https://www.gnu.org/licenses/>.
+*/
 
-#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 255ce17b56adb75c6b431308a365d9793a649c64..4cb26a0ddbb7618b05481a7ccc2fa618d7c4048f 100644 (file)
--- a/tfeed.h
+++ b/tfeed.h
     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 <https://www.gnu.org/licenses/>.
 */
 
-
 #ifndef TFEED_H
 #define TFEED_H
 
+#include <thread>
+#include <mutex>
 
-#include <stdio.h>
-#include <time.h>
+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 e911048390e9af83544ae45b4fd9a133de60779b..098538cf6176050bfcf963d0f7eb4e1ae326392a 100644 (file)
--- 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