]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Widescreen support, segfault fix on livetv interrupt
authorChris Tallon <chris@vomp.tv>
Tue, 6 Sep 2005 22:40:10 +0000 (22:40 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 6 Sep 2005 22:40:10 +0000 (22:40 +0000)
command.cc
demuxer.cc
demuxer.h
message.h
playervideo.cc
video.cc
video.h
viewman.cc
viewman.h
vvideolive.cc
vvideolive.h

index 4a6a6fb4ba77d97437d0468263e5a1d3ac4ffe41..170483189528ecbc06b287c0affbeac27f18753f 100644 (file)
@@ -56,6 +56,8 @@ int Command::init()
     return 0;
   }
 
+  logger->log("Command", Log::DEBUG, "%p", this);
+
   return 1;
 }
 
@@ -152,6 +154,16 @@ void Command::processMessage(Message* m)
       handleCommand(Remote::STOP); // an odd way of doing it, but so simple
       break;
     }
+    case Message::STREAM_END:
+    {
+      // post a message to ViewMan and then run the viewman message queue
+      Message* m = new Message();
+      m->message = Message::STREAM_END;
+      m->to = VVideoLive::getInstance();
+      viewman->postMessage(m);
+      handleCommand(Remote::NA_NONE);
+      break;
+    }
     case Message::VDR_CONNECTED:
     {
       doJustConnected((VConnect*)m->from);
index 16fb793b21250d4ab0f10e3aeae7d1f9febd82aa..8a2fbf93725ceabf044da2e02c6fec629b3f7623 100644 (file)
@@ -29,6 +29,7 @@ Demuxer::Demuxer()
   if (instance) return;
   instance = this;
   initted = 0;
+  callback = NULL;
 }
 
 Demuxer::~Demuxer()
@@ -42,7 +43,7 @@ Demuxer* Demuxer::getInstance()
   return instance;
 }
 
-int Demuxer::init()
+int Demuxer::init(Callback* tcallback)
 {
   if (!initted)
   {
@@ -58,6 +59,7 @@ int Demuxer::init()
 
   reset();
   initted = 1;
+  callback = tcallback;
   return 1;
 }
 
@@ -67,7 +69,7 @@ void Demuxer::reset()
   video_current = audio_current = -1;
   horizontal_size = vertical_size = 0;
   aspect_ratio = (enum AspectRatio) 0;
-  frame_rate = bit_rate = 0;
+  cbAspectRatio = frame_rate = bit_rate = 0;
 }
 
 int Demuxer::shutdown()
@@ -107,6 +109,20 @@ void Demuxer::setVideoStream(int id)
   video_current = id;
 }
 
+void Demuxer::setAspectRatio()
+{
+  if (aspect_ratio != cbAspectRatio)
+  {
+    cbAspectRatio = aspect_ratio;
+    callback->call(this);
+  }
+}
+
+int Demuxer::getAspectRatio()
+{
+  return aspect_ratio;
+}
+
 int Demuxer::scan(UCHAR *buf, int len)
 {
   // Temporarily, just look for the lowest audio stream and return it
@@ -451,6 +467,7 @@ void Demuxer::parse_video_details(UCHAR* buf, int len)
         seeking = 0;
         buf += 8; // Minimum length of sequence header
         len -= 8;
+        setAspectRatio();
         break;
       case 0xb8: // Group header
                  // We're not going to bother parsing anything.
index 6fe6368d9d737d03b0ddde95a34b43a6ce1647f8..c4bcfcb008cf4d0c660ffd13f602251d31b07f23 100644 (file)
--- a/demuxer.h
+++ b/demuxer.h
@@ -35,6 +35,7 @@ however, no code was copied verbatim.
 #include "stream.h"
 #include "log.h"
 #include "defines.h"
+#include "callback.h"
 
 class Demuxer
 {
@@ -42,7 +43,7 @@ class Demuxer
     Demuxer();
     ~Demuxer();
     static Demuxer* getInstance();
-    int init();
+    int init(Callback* callback);
     void reset();
     void flush();
     void flushAudio();
@@ -54,6 +55,14 @@ class Demuxer
     int scan(UCHAR* buf, int len);
     int put(UCHAR* buf, int len);
 
+    int getAspectRatio();
+
+    enum AspectRatio
+    {
+      ASPECT_4_3  = 2,
+      ASPECT_16_9 = 3
+    };
+
   private:
     static Demuxer* instance;
     Stream videostream;
@@ -63,6 +72,9 @@ class Demuxer
     int seeking;
     UCHAR* inbuf;
 
+    void setAspectRatio();
+    Callback* callback;
+
     int video_current, audio_current;
     int state_frametype, state_framepos;
     int state_stream_fill, state_vid_parsed;
@@ -134,17 +146,13 @@ class Demuxer
       FRAMETYPE_VIDMAX = FRAMETYPE_VID15
     };
 
-    enum AspectRatio
-    {
-      ASPECT_4_3  = 2,
-      ASPECT_16_9 = 3
-    };
-
     int horizontal_size;
     int vertical_size;
     enum AspectRatio aspect_ratio;
     int frame_rate;
     int bit_rate;
+
+    int cbAspectRatio;
 };
 
 #endif
index 190cfc48917a142e8e0003200e576ec84517bf0a..e68c83ec43a541538389a19ffdbce277d79915a8 100644 (file)
--- a/message.h
+++ b/message.h
@@ -53,6 +53,7 @@ class Message
     const static ULONG ADD_VIEW = 14;
     const static ULONG CHANNEL_UP = 15;
     const static ULONG CHANNEL_DOWN = 16;
+    const static ULONG STREAM_END = 17;
 };
 
 #endif
index 8bba1bf12fb599602344c120fdd9bccf5dd527cf..aadf76ee41d8c5503072ee6ee6f1cba6630ea1d1 100644 (file)
@@ -47,7 +47,7 @@ int PlayerVideo::init()
 
   video = Video::getInstance();
 
-  if (!demuxer.init())
+  if (!demuxer.init(this))
   {
     Log::getInstance()->log("Player", Log::ERR, "Demuxer failed to init");
     shutdown();
@@ -490,7 +490,35 @@ void PlayerVideo::jumpToPercent(int percent)
 
 void PlayerVideo::call(void* caller)
 {
-  threadSignalNoLock();
+  if (caller == &demuxer)
+  {
+    Log* temp = Log::getInstance();
+    temp->log("Player", Log::DEBUG, "Callback from demuxer");
+    if (video->getAspectRatio() == Video::ASPECT16X9)
+    {
+      temp->log("Player", Log::DEBUG, "TV is 16:9, so will try to do a switch");
+
+      int dxCurrentAspect = demuxer.getAspectRatio();
+      if (dxCurrentAspect == Demuxer::ASPECT_4_3)
+      {
+        temp->log("Player", Log::DEBUG, "Demuxer said video is 4:3 aspect, switching TV");
+        video->setMode(Video::LETTERBOX);   // swap these lines over
+      }
+      else if (dxCurrentAspect == Demuxer::ASPECT_16_9)
+      {
+        temp->log("Player", Log::DEBUG, "Demuxer said video is 16:9 aspect, switching TV");
+        video->setMode(Video::NORMAL);      // if these are the wrong way around
+      }
+      else
+      {
+        temp->log("Player", Log::DEBUG, "Demuxer said video is something else... ignoring");
+      }
+    }
+  }
+  else
+  {
+    threadSignalNoLock();
+  }
 }
 
 // Feed thread
@@ -602,8 +630,9 @@ void PlayerVideo::threadMethod()
   // end of recording
   Log::getInstance()->log("Player", Log::DEBUG, "Recording playback ends");
   Message* m = new Message();
-  m->message = Message::STOP_PLAYBACK;
-  Log::getInstance()->log("Player", Log::DEBUG, "Posting message...");
+  if (streamLength) m->message = Message::STOP_PLAYBACK;  // recording
+  else m->message = Message::STREAM_END;                  // live
+  Log::getInstance()->log("Player", Log::DEBUG, "Posting message to %p...", commandMessageQueue);
   commandMessageQueue->postMessage(m);
   Log::getInstance()->log("Player", Log::DEBUG, "Message posted...");
 }
index 576c554d1bed76786f296786dcfc8b46d963df41..32d0fa91248b2f5c7a1090dcadda772a236c819b 100644 (file)
--- a/video.cc
+++ b/video.cc
@@ -152,12 +152,10 @@ int Video::setMode(UCHAR tmode)
       && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
   mode = tmode;
 
-//  mode = LETTERBOX;
+  if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
 
-//  if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
-
-  int a = ioctl(fdVideo, AV_SET_VID_MODE, mode);
-  printf("Mode requested: %i, result: %i\n", mode, a);
+//  int a = ioctl(fdVideo, AV_SET_VID_MODE, mode);
+//  printf("Mode requested: %i, result: %i\n", mode, a);
 
   return 1;
 }
@@ -345,3 +343,8 @@ UINT Video::getScreenHeight()
 {
   return screenHeight;
 }
+
+UCHAR Video::getAspectRatio()
+{
+  return aspectRatio;
+}
diff --git a/video.h b/video.h
index 29aa1a1d038839aaf88f90b35681bf3df2b664ff..4ab987e3f425ba0841fdfbde87cd9c97575eed0a 100644 (file)
--- a/video.h
+++ b/video.h
@@ -80,6 +80,7 @@ class Video
     int setFormat(UCHAR format);
     int setConnection(UCHAR connection);
     int setAspectRatio(UCHAR aspectRatio);
+    UCHAR getAspectRatio();
     int setMode(UCHAR mode);
     int setSource();
     int setPosition(int x, int y);
index 7748681b91d8bdbaf73c85c16d64a89bc1005ea6..70a36548e0688fa2f64d9e80fec0ebe12a4b4a14 100644 (file)
@@ -285,48 +285,57 @@ int ViewMan::handleCommand(UCHAR command)
   int retVal2 = 0;
   int i;
 
-  // handle command return values
-  // 0 - drop through to next view
-  // 1 - dont drop to next view, but not handled
-  // 2 - handled - stop command here
-  // 4 - handled - delete this view
-
-  for (i=topView; i>0; i--)
+  if (command != Remote::NA_NONE)
   {
-    retVal = views[i]->handleCommand(command);
-    if (retVal == 1)
-    {
-      // not handled but don't give to any more views
-      pthread_mutex_unlock(&viewManLock);
-      return 0;
-    }
 
-    if (retVal == 2)
+    // handle command return values
+    // 0 - drop through to next view
+    // 1 - dont drop to next view, but not handled
+    // 2 - handled - stop command here
+    // 4 - handled - delete this view
+
+    for (i=topView; i>0; i--)
     {
-      // command handled
-      if (views[i]->seconds)
+      retVal = views[i]->handleCommand(command);
+      if (retVal == 1)
       {
-        struct timespec currentTime;
-        clock_gettime(CLOCK_REALTIME, &currentTime);
-        views[i]->delSec = currentTime.tv_sec + views[i]->seconds;
-        views[i]->delNSec = currentTime.tv_nsec;
-        resetThread();
+        // not handled but don't give to any more views
+        pthread_mutex_unlock(&viewManLock);
+        return 0;
+      }
+
+      if (retVal == 2)
+      {
+        // command handled
+        if (views[i]->seconds)
+        {
+          struct timespec currentTime;
+          clock_gettime(CLOCK_REALTIME, &currentTime);
+          views[i]->delSec = currentTime.tv_sec + views[i]->seconds;
+          views[i]->delNSec = currentTime.tv_nsec;
+          resetThread();
+        }
+        pthread_mutex_unlock(&viewManLock);
+        retVal2 = 1;
+        break;
+      }
+      else if (retVal == 4)
+      {
+  //      removeNoLock(views[i]);
+  //      Box::showAll();
+  //      resetThread();
+        removeView(views[i], 1);
+        pthread_mutex_unlock(&viewManLock);
+        retVal2 = 1;
+        break;
       }
-      pthread_mutex_unlock(&viewManLock);
-      retVal2 = 1;
-      break;
-    }
-    else if (retVal == 4)
-    {
-//      removeNoLock(views[i]);
-//      Box::showAll();
-//      resetThread();
-      removeView(views[i], 1);
-      pthread_mutex_unlock(&viewManLock);
-      retVal2 = 1;
-      break;
     }
   }
+  else
+  {
+    // fake the return code
+    retVal2 = 2;
+  }
 
   Log::getInstance()->log("ViewMan", Log::DEBUG, "out of handlecommand code, now on to messages");
 
index a742d51c01b5b00286a84903305ace06bef341d5..bd0eb7e98f4cb59c8efd7a6cccd6631fa8b44761 100644 (file)
--- a/viewman.h
+++ b/viewman.h
@@ -30,6 +30,7 @@
 #include "view.h"
 #include "message.h"
 #include "messagequeue.h"
+#include "remote.h"
 
 class ViewMan : public MessageQueue
 {
index 1e5f43b3750fe8e33cd4e492fe5f6f07290af066..93595d57ee3b8007d0f46bb1ba0c82e566078da5 100644 (file)
 
 #include "vvideolive.h"
 
+VVideoLive* VVideoLive::instance = NULL;
+
 VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType)
 {
+  instance = this;
   vdr = VDR::getInstance();
   viewman = ViewMan::getInstance();
   chanList = tchanList;
@@ -31,7 +34,7 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType)
   streamType = tstreamType;
   if (streamType == VDR::VIDEO)
   {
-    player = new PlayerVideo(NULL, 0);
+    player = new PlayerVideo(Command::getInstance(), 0);
   }
   else
   {
@@ -48,6 +51,12 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType)
 VVideoLive::~VVideoLive()
 {
   delete player;
+  instance = NULL;
+}
+
+VVideoLive* VVideoLive::getInstance()
+{
+  return instance;
 }
 
 void VVideoLive::draw()
@@ -142,7 +151,12 @@ void VVideoLive::processMessage(Message* m)
     vlb->draw();
     vlb->show();
   }
-
+  else if (m->message == Message::STREAM_END)
+  {
+    Log::getInstance()->log("VVideoLive", Log::DEBUG, "streamEnd");
+    stop();
+    play(1);
+  }
 }
 
 void VVideoLive::doBanner()
index 6925fe8571b0483f742d94214297400569ed5b32..2c72efe3414ef2721ba6a9c2bd44f61fbd2ef6c1 100644 (file)
 #include "colour.h"
 #include "osd.h"
 #include "vinfo.h"
+#include "command.h"
 
 class VVideoLive : public View
 {
   public:
     VVideoLive(ChannelList* chanList, ULONG streamType);
     ~VVideoLive();
+    static VVideoLive* getInstance();
     void draw();
     int handleCommand(int command);
     void processMessage(Message* m);
@@ -51,6 +53,7 @@ class VVideoLive : public View
     void stop(int noRemoveVLB = 0);
 
   private:
+    static VVideoLive* instance;
     ViewMan* viewman;
     VDR* vdr;
     Player* player;