[vlc-devel] [PATCH] VLC unable to play HLS live stream

Ilkka Ollakka ileoo at videolan.org
Wed Aug 14 14:37:20 CEST 2013


I think this patch tries to fix issue in wrong place. If the problem is
in HLS slow start or short HLS playlists, issue should be handled in
httplive stream filter.

On Wed, Aug 14, 2013 at 04:13:46AM -0400, Avishay Spitzer wrote:
> From 15f5f247e783895e95020e4f0529bd112bf77b6d Mon Sep 17 00:00:00 2001
> From: Avishay Spitzer <savishay at gmail.com>
> Date: Wed, 14 Aug 2013 03:52:44 -0400
> Subject: [PATCH 1/3] In case of slow connections or short HLS playlists,
>  packets may not arrive on time and TS module will
>  declare EOF which will case VLC to stop playing the
>  stream. Problem was solved by adding a retries
>  mechanism with increasing backoff.

> ---
>  modules/demux/ts.c |   37 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 36 insertions(+), 1 deletion(-)

> diff --git a/modules/demux/ts.c b/modules/demux/ts.c
> index 5c4a288..dd74e36 100644
> --- a/modules/demux/ts.c
> +++ b/modules/demux/ts.c
> @@ -334,6 +334,9 @@ struct demux_sys_t

>      /* */
>      bool        b_start_record;
> +
> +    /* Counts number of times ReadTSPacket returned NULL for implemeting a retries mechanism */
> +    uint64_t 	b_get_packet_retry;
>  };

>  static int Demux    ( demux_t *p_demux );
> @@ -570,6 +573,9 @@ static int Open( vlc_object_t *p_this )
>      p_sys->i_packet_size = i_packet_size;
>      vlc_mutex_init( &p_sys->csa_lock );

> +    // Initialize retries counter
> +    p_sys->b_get_packet_retry = 0;
> +
>      p_sys->buffer = NULL;
>      p_demux->pf_demux = Demux;
>      p_demux->pf_control = Control;
> @@ -949,9 +955,38 @@ static int Demux( demux_t *p_demux )
>          block_t     *p_pkt;
>          if( !(p_pkt = ReadTSPacket( p_demux )) )
>          {
> -            return 0;
> +		// Retries mechanism - start
> +		// In case of live streams TS packets may delay due to slow connections or short
> +		// playlists (in case of HLS).
> +		// We don't want to declare EOF (by returning 0 here) right away so we add a retries
> +		// mechanism with increasing backoff.
> +		// Retries are limited to 100 retries per packet and since backoff is based on an 
> +		// arithmetic progression the aggregate waiting time until declaring EOF is
> +		// 100*(100+1)/2=5050ms.
> +		// In order to make the stream continuous after reaching 100 retries each backoff
> +		// will last 100ms and EOF will not be declared.
> +
> +        	// If 100 retries failed then kill this stream to avoid VLC getting stuck
> +        	if (!(vlc_object_alive (p_demux)))
> +        		return 0;
> +
> +		// Increase the retries count before sleeping (avoids 0ms sleep)
> +        	p_sys->b_get_packet_retry++;
> +
> +        	// Sleep for 1ms times the retries counter before returning
> +        	msleep(((p_sys->b_get_packet_retry >= 100) ? 100 : p_sys->b_get_packet_retry) * 1000);
> +
> +        	// If the vlc object is not alive after sleeping get out
> +        	if (!(vlc_object_alive (p_demux)))
> +        		return 0;
> +		// Retries mechanism - end
> +
> +            	return 1;
>          }

> +    	// If packet was received correctly zero retries counter
> +    	p_sys->b_get_packet_retry = 0;
> +
>          if( p_sys->b_start_record )
>          {
>              /* Enable recording once synchronized */
-- 
Ilkka Ollakka
There's an old proverb that says just about whatever you want it to.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20130814/293e61cd/attachment.sig>


More information about the vlc-devel mailing list