<div dir="ltr"><div><div><div>Ilkka,<br><br></div>Are you suggesting adding a new condition variable on which read will wait until download thread signals?<br><br></div>Regards,<br></div>Avishay<br><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Aug 15, 2013 at 8:05 AM, Ilkka Ollakka <span dir="ltr"><<a href="mailto:ileoo@videolan.org" target="_blank">ileoo@videolan.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hi,<br>
<br>
I think it would be better to implement this with signal wait with<br>
timeout instead of polling. So download thread would signal that new<br>
stuff is ready.<br>
<br>
On Thu, Aug 15, 2013 at 06:52:09AM -0400, Avishay Spitzer wrote:<br>
> From 768e199c6ac6d539f1a00606a26a905a5f1b1886 Mon Sep 17 00:00:00 2001<br>
> From: Avishay Spitzer <<a href="mailto:savishay@gmail.com">savishay@gmail.com</a>><br>
> Date: Thu, 15 Aug 2013 06:41:35 -0400<br>
> Subject: [PATCH 2/2] Added a retry mechanism with backoff to the read<br>
> function of HLS module to handle situations where<br>
> stream packets may delay due to slow connections or<br>
> short playlists. In case hls_Read returns 0, the read<br>
> function will wait until new data arrives.<br>
<br>
> ---<br>
> modules/stream_filter/httplive.c | 48 +++++++++++++++++++++++++++++++++-----<br>
> 1 file changed, 42 insertions(+), 6 deletions(-)<br>
<br>
> diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c<br>
> index ed708bf..62ab17b 100644<br>
> --- a/modules/stream_filter/httplive.c<br>
> +++ b/modules/stream_filter/httplive.c<br>
> @@ -2280,16 +2280,52 @@ static int Read(stream_t *s, void *buffer, unsigned int i_read)<br>
> {<br>
> stream_sys_t *p_sys = s->p_sys;<br>
> ssize_t length = 0;<br>
> + uint32_t retries_counter = 0, aggregate_delay = 0;<br>
<br>
> assert(p_sys->hls_stream);<br>
<br>
> - if (p_sys->b_error)<br>
> - return 0;<br>
> + while (length == 0)<br>
> + {<br>
> + // In case an error occurred or the stream was closed return 0<br>
> + if (p_sys->b_error || !vlc_object_alive(s))<br>
> + return 0;<br>
<br>
> - /* NOTE: buffer might be NULL if caller wants to skip data */<br>
> - length = hls_Read(s, (uint8_t*) buffer, i_read);<br>
> - if (length < 0)<br>
> - return 0;<br>
> + /* NOTE: buffer might be NULL if caller wants to skip data */<br>
> + length = hls_Read(s, (uint8_t*) buffer, i_read);<br>
> +<br>
> + // An error has occurred in hls_Read<br>
> + if (length < 0)<br>
> + return 0;<br>
> +<br>
> + // No data is available yet so we need to wait until new data will arrive.<br>
> + // We use a retry mechanism with increasing backoff (up to 100ms per single sleep)<br>
> + if (length == 0)<br>
> + {<br>
> + uint32_t delay = 0;<br>
> +<br>
> + retries_counter++;<br>
> +<br>
> + if (retries_counter < 10)<br>
> + delay = 10; // ms<br>
> + else if (retries_counter < 25)<br>
> + delay = 25; // ms<br>
> + else if (retries_counter < 100)<br>
> + delay = 50; // ms<br>
> + else<br>
> + delay = 100; // ms<br>
> +<br>
> + aggregate_delay += delay;<br>
> +<br>
> + msleep(delay * 1000);<br>
> + }<br>
> + }<br>
> +<br>
> + if (retries_counter > 0)<br>
> + {<br>
> + msg_Info(s, "got data after %u retries (delay of [%u]ms)",<br>
> + retries_counter,<br>
> + aggregate_delay);<br>
> + }<br>
<br>
> p_sys->playback.offset += length;<br>
> return length;<br>
<span class="HOEnZb"><font color="#888888">--<br>
Ilkka Ollakka<br>
Is a computer language with goto's totally Wirth-less?<br>
</font></span><br>_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
<br></blockquote></div><br></div>