[PATCH v2 5/5] stream_pvr: allow initial latency when opening stream
Reza Arbab <[email protected]>
| Newsgroups | gmane.comp.video.mplayer.devel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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 | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c index 4657210..27857e5 100644 --- a/stream/stream_pvr.c +++ b/stream/stream_pvr.c @@ -1593,6 +1593,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 +1630,7 @@ pvr_stream_close (stream_t *stream) static int pvr_stream_read (stream_t *stream, char *buffer, int size) { - struct pollfd pfds[1]; + static int first = 1; struct pvr_t *pvr; int rk, fd, pos; @@ -1626,15 +1646,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 (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); + 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 _______________________________________________ MPlayer-dev-eng mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng