[vlc-devel] [PATCH 22/48] hls: Wait for segment ready
Hugo Beauzée-Luyssen
beauze.h at gmail.com
Mon Jan 9 16:16:31 CET 2012
From: Luc Saillard <luc.saillard at sfr.com>
---
modules/stream_filter/httplive.c | 49 +++++++++++++++++++++++++++++++++++--
1 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 01269b5..42a1ebe 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -128,6 +128,8 @@ struct stream_sys_t
uint64_t offset; /* current offset in media */
int stream; /* current hls_stream */
int segment; /* current segment for playback */
+ vlc_mutex_t lock_wait; /* protect segment download counter */
+ vlc_cond_t wait; /* some condition to wait on */
} playback;
/* Playlist */
@@ -2215,10 +2217,19 @@ check:
if ((p_sys->download.segment - p_sys->playback.segment == 0) &&
((count != p_sys->download.segment) || p_sys->b_live))
- msg_Err(s, "playback will stall");
+ {
+ msg_Err(s, "playback will stall");
+ return NULL;
+ }
else if ((p_sys->download.segment - p_sys->playback.segment < 3) &&
((count != p_sys->download.segment) || p_sys->b_live))
- msg_Warn(s, "playback in danger of stalling");
+ {
+ msg_Warn(s, "playback in danger of stalling download.segment=%d playback.segment=%d count=%d p_sys->download.segment=%d",
+ p_sys->download.segment, p_sys->playback.segment,
+ count, p_sys->download.segment);
+ return NULL;
+ }
+
}
return segment;
}
@@ -2227,15 +2238,47 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
{
stream_sys_t *p_sys = s->p_sys;
ssize_t copied = 0;
+ segment_t *segment;
do
{
/* Determine next segment to read. If this is a meta playlist and
* bandwidth conditions changed, then the stream might have switched
* to another bandwidth. */
- segment_t *segment = GetSegment(s);
+again:
+ segment = GetSegment(s);
if (segment == NULL)
+ {
+ if (copied == 0)
+ {
+#if 0
+ msg_Warn(s, "No Segment is available, and we have not read ony byte from the queue. Perhaps we should wait for more data ");
+ msg_Err(s, "hls_Read() segment %d should have been available (stream %d)",
+ p_sys->playback.segment, p_sys->playback.stream);
+
+ msg_Info(s, "Waiting for segment to be downloaded");
+
+ vlc_mutex_lock(&p_sys->download.lock_wait);
+
+ /* wake up the download segment thread if blocked */
+ vlc_cond_signal(&p_sys->download.wait);
+
+ mtime_t timeout = mdate() + 5000000;
+ if( vlc_cond_timedwait( &p_sys->download.wait, &p_sys->download.lock_wait, timeout ) )
+ msg_Warn(s, "hls_Read() reached timeout");
+ vlc_mutex_unlock(&p_sys->download.lock_wait);
+#endif
+ msleep(0.1 * 1000000);
+ if (!vlc_object_alive(s) || s->b_error || p_sys->b_quit)
+ return 0; /* eof? */
+ goto again;
+ }
+ else
+ {
+ msg_Dbg(s, "hls_Read() return %d", copied);
+ }
break;
+ }
vlc_mutex_lock(&segment->lock);
if (segment->data->i_buffer == 0)
--
1.7.8.3
More information about the vlc-devel
mailing list