[MPlayer-dev-eng] [PATCH v3 5/5] stream_pvr: allow initial latency when opening stream

Reza Arbab arbab at panix.com
Fri Feb 12 17:29:48 CET 2016


When opening an hdpvr device, there may be a significant delay before
first receiving data, especially at higher bitrates. This can cause
mplayer to time out and exit.

Move the existing device polling code to a static function. Use a
generous 5 second timeout for the first read of the stream.

Signed-off-by: Reza Arbab <arbab at panix.com>
---
 v3:
  * Move the "first" flag into struct pvr_t, so there is one per device.

 v2:
  * Add "Waiting for stream to begin..." message.
  * Instead of adding a new poll in pvr_stream_open, use a longer timeout for
    the first poll pvr_stream_read does.
  * Return -1 on poll timeout.

 stream/stream_pvr.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index 4657210..41d8a23 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -111,6 +111,7 @@ typedef struct stationlist_s {
 struct pvr_t {
   int dev_fd;
   char *video_dev;
+  int first;
 
   /* v4l2 params */
   int mute;
@@ -149,6 +150,7 @@ pvr_init (void)
   pvr = calloc (1, sizeof (struct pvr_t));
   pvr->dev_fd = -1;
   pvr->video_dev = strdup (PVR_DEFAULT_DEVICE);
+  pvr->first = 1;
 
   /* v4l2 params */
   pvr->mute = 0;
@@ -1593,6 +1595,26 @@ v4l2_display_settings (struct pvr_t *pvr)
   return 0;
 }
 
+static int
+poll_device (struct pvr_t *pvr, int timeout)
+{
+  struct pollfd pfds[1];
+  int ret;
+
+  pfds[0].fd = pvr->dev_fd;
+  pfds[0].events = POLLIN | POLLPRI;
+
+  ret = poll (pfds, 1, timeout);
+  if (!ret)
+  {
+    mp_msg (MSGT_OPEN, MSGL_WARN,
+            "%s %dms timeout polling stream device\n",
+            LOG_LEVEL_PVR, timeout);
+  }
+
+  return ret;
+}
+
 /* stream layer */
 
 static void
@@ -1610,7 +1632,6 @@ pvr_stream_close (stream_t *stream)
 static int
 pvr_stream_read (stream_t *stream, char *buffer, int size)
 {
-  struct pollfd pfds[1];
   struct pvr_t *pvr;
   int rk, fd, pos;
 
@@ -1626,15 +1647,18 @@ pvr_stream_read (stream_t *stream, char *buffer, int size)
 
   while (pos < size)
   {
-    pfds[0].fd = fd;
-    pfds[0].events = POLLIN | POLLPRI;
-
-    if (!poll (pfds, 1, 500))
+    if (pvr->first)
     {
-      mp_msg (MSGT_OPEN, MSGL_ERR,
-              "%s 500ms timeout polling stream device\n", LOG_LEVEL_PVR);
-      return -1;
+      mp_msg (MSGT_OPEN, MSGL_INFO,
+              "%s Waiting for stream to begin...\n", LOG_LEVEL_PVR);
+      rk = poll_device (pvr, 5000);
+      pvr->first = 0;
     }
+    else
+      rk = poll_device (pvr, 500);
+
+    if (!rk)
+      return -1;
 
     rk = read (fd, &buffer[pos], size-pos);
     if (rk < 0)
-- 
2.5.0



More information about the MPlayer-dev-eng mailing list