<div dir="ltr"><div><div><div><div>Ilkka,<br><br></div>The problem in TS module, is that once HLS module (HTTPLive stream filter) has no data, TS will think that it has reached EOF and VLC will stop playing.<br><br></div><div>
TS decides that it has reached EOF if the "read" operation return 0, and this is what HLS module return if it has no data.<br></div><div><br>I don't think that it can be solved from within the HLS module because HLS has no control over this. I think that TS module should treat these situations gracefully and retry (as I implemented).<br>
<br></div>If you have another idea please let me know.<br><br></div>Regards,<br></div>Avishay<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 8:37 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>
I think this patch tries to fix issue in wrong place. If the problem is<br>
in HLS slow start or short HLS playlists, issue should be handled in<br>
httplive stream filter.<br>
<br>
On Wed, Aug 14, 2013 at 04:13:46AM -0400, Avishay Spitzer wrote:<br>
> From 15f5f247e783895e95020e4f0529bd112bf77b6d Mon Sep 17 00:00:00 2001<br>
> From: Avishay Spitzer <<a href="mailto:savishay@gmail.com">savishay@gmail.com</a>><br>
> Date: Wed, 14 Aug 2013 03:52:44 -0400<br>
> Subject: [PATCH 1/3] In case of slow connections or short HLS playlists,<br>
>  packets may not arrive on time and TS module will<br>
>  declare EOF which will case VLC to stop playing the<br>
>  stream. Problem was solved by adding a retries<br>
>  mechanism with increasing backoff.<br>
<br>
> ---<br>
>  modules/demux/ts.c |   37 ++++++++++++++++++++++++++++++++++++-<br>
>  1 file changed, 36 insertions(+), 1 deletion(-)<br>
<br>
> diff --git a/modules/demux/ts.c b/modules/demux/ts.c<br>
> index 5c4a288..dd74e36 100644<br>
> --- a/modules/demux/ts.c<br>
> +++ b/modules/demux/ts.c<br>
> @@ -334,6 +334,9 @@ struct demux_sys_t<br>
<br>
>      /* */<br>
>      bool        b_start_record;<br>
> +<br>
> +    /* Counts number of times ReadTSPacket returned NULL for implemeting a retries mechanism */<br>
> +    uint64_t         b_get_packet_retry;<br>
>  };<br>
<br>
>  static int Demux    ( demux_t *p_demux );<br>
> @@ -570,6 +573,9 @@ static int Open( vlc_object_t *p_this )<br>
>      p_sys->i_packet_size = i_packet_size;<br>
>      vlc_mutex_init( &p_sys->csa_lock );<br>
<br>
> +    // Initialize retries counter<br>
> +    p_sys->b_get_packet_retry = 0;<br>
> +<br>
>      p_sys->buffer = NULL;<br>
>      p_demux->pf_demux = Demux;<br>
>      p_demux->pf_control = Control;<br>
> @@ -949,9 +955,38 @@ static int Demux( demux_t *p_demux )<br>
>          block_t     *p_pkt;<br>
>          if( !(p_pkt = ReadTSPacket( p_demux )) )<br>
>          {<br>
> -            return 0;<br>
> +             // Retries mechanism - start<br>
> +             // In case of live streams TS packets may delay due to slow connections or short<br>
> +             // playlists (in case of HLS).<br>
> +             // We don't want to declare EOF (by returning 0 here) right away so we add a retries<br>
> +             // mechanism with increasing backoff.<br>
> +             // Retries are limited to 100 retries per packet and since backoff is based on an<br>
> +             // arithmetic progression the aggregate waiting time until declaring EOF is<br>
> +             // 100*(100+1)/2=5050ms.<br>
> +             // In order to make the stream continuous after reaching 100 retries each backoff<br>
> +             // will last 100ms and EOF will not be declared.<br>
> +<br>
> +             // If 100 retries failed then kill this stream to avoid VLC getting stuck<br>
> +             if (!(vlc_object_alive (p_demux)))<br>
> +                     return 0;<br>
> +<br>
> +             // Increase the retries count before sleeping (avoids 0ms sleep)<br>
> +             p_sys->b_get_packet_retry++;<br>
> +<br>
> +             // Sleep for 1ms times the retries counter before returning<br>
> +             msleep(((p_sys->b_get_packet_retry >= 100) ? 100 : p_sys->b_get_packet_retry) * 1000);<br>
> +<br>
> +             // If the vlc object is not alive after sleeping get out<br>
> +             if (!(vlc_object_alive (p_demux)))<br>
> +                     return 0;<br>
> +             // Retries mechanism - end<br>
> +<br>
> +             return 1;<br>
>          }<br>
<br>
> +     // If packet was received correctly zero retries counter<br>
> +     p_sys->b_get_packet_retry = 0;<br>
> +<br>
>          if( p_sys->b_start_record )<br>
>          {<br>
>              /* Enable recording once synchronized */<br>
<span class="HOEnZb"><font color="#888888">--<br>
Ilkka Ollakka<br>
There's an old proverb that says just about whatever you want it to.<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>