]> git.vomp.tv Git - vompclient.git/commitdiff
Simplify VFeed. Switch to std::thread
authorChris Tallon <chris@vomp.tv>
Tue, 25 Feb 2020 16:19:21 +0000 (16:19 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 25 Feb 2020 16:19:21 +0000 (16:19 +0000)
playerlivetv.cc
playervideorec.cc
playervideorec.h
vfeed.cc
vfeed.h

index d055dcaf57fd357809fd40d3c84d46abd5900ecb..156db58a6bf5a20d7cd5a6b37c6ffff3e62591ce 100644 (file)
@@ -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;
         }
index 0d138bf27a10066b8e9436f6b5a04cc6d6e3949f..8b575320401b5a51332d8be798867401132d1e2b 100644 (file)
@@ -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();
     }
 
index 05e47b8e5bf94e184f9af3b70f66d8f6e9f5be81..f55169ea543db0ac5ca8063fc77136ef842a4378 100644 (file)
@@ -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{};
index c3823a58363a482c4fa1b587eba4e66b6a3a0279..0bc69dd64000a134750d6adb3579664e778c1d0a 100644 (file)
--- 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.
 
     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 "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 18acf382a3c144816e141ef94c1c32f2d9dec00d..e911048390e9af83544ae45b4fd9a133de60779b 100644 (file)
--- 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.
 
     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 VFEED_H
 #define VFEED_H
 
-#include <stdio.h>
-#include <time.h>
-
-#ifndef WIN32
-#ifdef __ANDROID__
-#include "threadpandroid.h"
-#else
-#include "threadp.h"
-#endif
-#else
-#include "threadwin.h"
-#endif
+#include <thread>
+#include <mutex>
 
 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