Live TV updates
authorChris Tallon <chris@vomp.tv>
Sun, 2 Dec 2007 18:01:22 +0000 (18:01 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 2 Dec 2007 18:01:22 +0000 (18:01 +0000)
afeed.cc
demuxer.cc
playerlivetv.cc
playerlivetv.h
vfeed.cc

index 5b8dce927a72e67a04fda1ca1761521c8b4ffa70..7efcffd5e9a31792856949999152a2c1c388d46d 100644 (file)
--- a/afeed.cc
+++ b/afeed.cc
@@ -76,14 +76,12 @@ void AFeed::threadMethod()
 
       if (alen)
       {
-//        Log::getInstance()->log("AFeed", Log::DEBUG, "Written %i", alen);
         cb.call(this);
       }
       else
       {
-//        Log::getInstance()->log("AFeed", Log::DEBUG, "No data delay");
         //MILLISLEEP(100);
-          MILLISLEEP(20); //Performance Issue Marten
+        MILLISLEEP(20); //Performance Issue Marten
       }
     }
     else
index b9ec4ab51d01c0eff25b4ef7cb47a8f6556acceb..1443b7bab98e9a0b3b37562d285ea94a359d1b7c 100644 (file)
@@ -179,6 +179,7 @@ int Demuxer::init(Callback* tcallback, DrainTarget* audio, DrainTarget* video, U
 
 void Demuxer::reset()
 {
+  Log::getInstance()->log("Demuxer", Log::DEBUG, "Reset called");
   flush();
   video_current = audio_current = -1;
   horizontal_size = vertical_size = 0;
@@ -206,6 +207,8 @@ int Demuxer::shutdown()
 
 void Demuxer::flush()
 {
+  Log::getInstance()->log("Demuxer", Log::DEBUG, "Flush called");
+
   videostream.flush();
   audiostream.flush();
 }
index c88d056379e34e4914a9bb8bba1b54521bc0aaa1..22a10fbe5fff722d55a02dd866472b54e1d5b173 100644 (file)
@@ -45,8 +45,7 @@ PlayerLiveTV::PlayerLiveTV(MessageQueue* tmessageQueue, void* tmessageReceiver,
   vdr = VDR::getInstance();
   initted = false;
 
-//  videoStartup = false;
-//  preBuffering = false;
+  videoStartup = false;
 
   stopNow = false;
   state = 1;
@@ -127,42 +126,27 @@ void PlayerLiveTV::go(ULONG index)
   i.instruction = 1;
   i.channelIndex = index;
   instructions.push(i);
-  
   threadStart();
 }
 
 void PlayerLiveTV::setChannel(ULONG index)
 {
-//  demuxer->setVID(Vpid);
-//  demuxer->setAID(Apid);
-//  play();
   logger->log("PlayerLiveTV", Log::DEBUG, "setChannel");
-  
   struct PLTVInstruction i;
   i.instruction = 1;
   i.channelIndex = index;
   instructions.push(i);  
-  
   threadSignalNoLock();
 }
 
 void PlayerLiveTV::stop()
 {
   logger->log("PlayerLiveTV", Log::DEBUG, "stop");
-
   struct PLTVInstruction i;
   i.instruction = 2;
   instructions.push(i);
-  
-  logger->log("PlayerLiveTV", Log::DEBUG, "Pushed instruction");
-
   threadSignal();
-
-  logger->log("PlayerLiveTV", Log::DEBUG, "Signal sent");
-
   threadStop();
-
-  logger->log("PlayerLiveTV", Log::DEBUG, "Stop returning");
 }
 
 // ----------------------------------- Callback
@@ -208,22 +192,37 @@ void PlayerLiveTV::call(void* caller)
     {
       logger->log("PlayerLiveTV", Log::DEBUG, "Demuxer said video is something else... ignoring");
     }
-
   }
-  else
+  else if (caller == &afeed)
   {
-    if (videoStartup)
+    if (state == S_VIDEOSTARTUP)
     {
-      logger->log("PlayerLiveTV", Log::DEBUG, "Video startup");
-      videoStartup = false;
-      video->reset();
-      video->play();
-      video->sync();
-      vfeed.release();
+      logger->log("PlayerLiveTV", Log::DEBUG, "afeed video startup");
+      videoStartup = true;
+      threadSignalNoLock();
+    }
+  }
+  /*
+  else if (caller == &vfeed)
+  {
+    if (videoStartup2)
+    {
+      logger->log("PlayerLiveTV", Log::DEBUG, "Video startup %i", videoStartup2count);
+      
+      if (++videoStartup2count == 2)
+      {
+        videoStartup2 = false;
+
+        video->unPause();
+        audio->unPause();
+        
+        audio->systemMuteOff();
+      }
     }
 
     threadSignalNoLock();
   }
+*/
 }
 
 // -----------------------------------
@@ -266,7 +265,8 @@ void PlayerLiveTV::chunkToDemuxer()
   StreamChunk s = streamChunks.front();
   streamChunks.pop();
   logger->log("PlayerLiveTV", Log::DEBUG, "About to call demuxer with %p %lu", s.data, s.len);
-  demuxer->put((UCHAR*)s.data, s.len);
+  int a = demuxer->put((UCHAR*)s.data, s.len);
+  logger->log("PlayerLiveTV", Log::DEBUG, "put %i to demuxer", a);
   free(s.data);  
 }
 
@@ -280,20 +280,22 @@ void PlayerLiveTV::switchState(UCHAR newState)
     {
       switch(newState)
       {
-        case S_STOP:
-        {
-          abort();
-        }
         case S_PREBUFFERING:
         {
-          break;
-        }
-        case S_PLAY:
-        {
-          abort();
+          video->blank();
+          audio->stop();
+          audio->unPause();
+          audio->reset();
+
+          audio->setStreamType(Audio::MPEG2_PES);
+          audio->systemMuteOff();
+          video->reset();
+          demuxer->reset();
+          demuxer->seek();
+          state = newState;
+          return;
         }
       }
-      break;
     }
     
     case S_PREBUFFERING:    // FROM S_PREBUFFERING
@@ -304,35 +306,48 @@ void PlayerLiveTV::switchState(UCHAR newState)
         {
           vdr->stopStreaming();
           clearStreamChunks();
-          break;
+          state = newState;          
+          return;
         }      
         case S_PREBUFFERING:
         {
           vdr->stopStreaming();
           clearStreamChunks();
-          break;
+          state = newState;
+          return;
         }
-        case S_PLAY:
+        case S_VIDEOSTARTUP:
         {
-          videoStartup = true;
+          logger->log("PlayerLiveTV", Log::DEBUG, "doing ss to videostartup");
 
-          audio->reset();
-          audio->setStreamType(Audio::MPEG2_PES);
-          audio->systemMuteOff();
-          video->reset();
-          demuxer->reset();
-          demuxer->seek();
-          
           audio->sync();
           audio->play();
+          //audio->systemMuteOn();
           video->sync();
           video->pause();
           afeed.start();
           vfeed.start();
-          break;
+          state = newState;
+          return;
+        }
+      }
+    }
+    
+    case S_VIDEOSTARTUP:     // FROM S_VIDEOSTARTUP
+    {
+      switch(newState)
+      {
+        case S_PLAY:
+        {
+          logger->log("PlayerLiveTV", Log::DEBUG, "doing ss to play");
+          video->reset();
+          video->play();
+          video->sync();
+          vfeed.release();
+          state = newState;
+          return;
         }
       }
-      break;
     }
     
     case S_PLAY:     // FROM S_PLAY
@@ -349,8 +364,10 @@ void PlayerLiveTV::switchState(UCHAR newState)
           video->blank();
           audio->stop();
           audio->unPause();
+          audio->reset();
           video->reset();
-          break;
+          state = newState;
+          return;
         }
         case S_PREBUFFERING:
         {
@@ -362,20 +379,22 @@ void PlayerLiveTV::switchState(UCHAR newState)
           video->blank();
           audio->stop();
           audio->unPause();
+          audio->reset();
+
+          audio->setStreamType(Audio::MPEG2_PES);
+   //       audio->systemMuteOn();
           video->reset();
           demuxer->reset();
-          break;
-        }
-        case S_PLAY:
-        {
-          abort();
+          demuxer->seek();
+          state = newState;
+          return;
         }
       }
-      break;
     }    
   }  
   
-  state = newState;
+  logger->log("PlayerLiveTV", Log::EMERG, "Thread called state %u to state %u which is not supported", state, newState);
+  abort();
 }
 
 void PlayerLiveTV::threadMethod()
@@ -384,6 +403,12 @@ void PlayerLiveTV::threadMethod()
 
   while(1)
   {
+    if (videoStartup) // we are in S_VIDEOSTARTUP, afeed has signalled that it has written some data
+    {
+      switchState(S_PLAY);
+      videoStartup = false;
+    }  
+  
     while(!instructions.empty())
     {
       struct PLTVInstruction i = instructions.front();
@@ -422,13 +447,13 @@ void PlayerLiveTV::threadMethod()
     {
       if (state == S_PREBUFFERING)
       {
-        if (streamChunks.size() > 4)
+        if (streamChunks.size() > 9)
         {
           while(streamChunks.size()) chunkToDemuxer();
-          switchState(S_PLAY);
+          switchState(S_VIDEOSTARTUP);
         }
       }
-      else if (state == S_PLAY)
+      else if (state == S_PLAY || state == S_VIDEOSTARTUP)
       {
         while(streamChunks.size()) chunkToDemuxer();
       }
@@ -444,22 +469,3 @@ void PlayerLiveTV::threadMethod()
   logger->log("PlayerLiveTV", Log::DEBUG, "End of thread");
 }
 
-void PlayerLiveTV::threadPostStopCleanup()
-{
-  logger->log("PlayerLiveTV", Log::DEBUG, "Post stop cleanup");
-}
-
-// ----------------------------------- Dev
-
-#ifdef DEV
-void PlayerLiveTV::test1()
-{
-  logger->log("PlayerLiveTV", Log::DEBUG, "PLAYER TEST 1");
-}
-
-void PlayerLiveTV::test2()
-{
-  logger->log("PlayerLiveTV", Log::DEBUG, "PLAYER TEST 2");
-}
-#endif
-
index 21a214e0b9afe726f288d4270a6e1083eb7b4b29..ef28aa5c0f5d8a632bc6eb0c474ee7a85ba9c413 100644 (file)
@@ -92,14 +92,9 @@ class PlayerLiveTV : public Thread_TYPE, public Callback, public StreamReceiver
     const static UCHAR ASPECT43 = 4;
     const static UCHAR ASPECT169 = 5;
 
-#ifdef DEV
-    void test1();
-    void test2();
-#endif
-
   protected:
     void threadMethod();
-    void threadPostStopCleanup();
+    void threadPostStopCleanup() {};
 
   private:
 
@@ -122,11 +117,13 @@ class PlayerLiveTV : public Thread_TYPE, public Callback, public StreamReceiver
     UCHAR state;
     const static UCHAR S_STOP = 1;
     const static UCHAR S_PREBUFFERING = 2;
-    const static UCHAR S_PLAY = 3;
+    const static UCHAR S_VIDEOSTARTUP = 3;
+    const static UCHAR S_PLAY = 4;
     void switchState(UCHAR newState);
 
     bool videoStartup;
     bool stopNow;
+
         
     void clearStreamChunks();
     void chunkToDemuxer();
index c4409be997d381f27592ff1c161cf4fcac75d2d3..f08cc4bbebabbe9326e26ccc92f892df380c4d58 100644 (file)
--- a/vfeed.cc
+++ b/vfeed.cc
@@ -59,7 +59,9 @@ void VFeed::threadMethod()
 {
   bool vlen;
 
+  Log::getInstance()->log("VFeed", Log::DEBUG, "Started");
   threadWaitForSignal(); // Don't feed video until audio has started
+  Log::getInstance()->log("VFeed", Log::DEBUG, "Released");
 
   while(1)
   {