[vlc-devel] [PATCH] HLS: implement pause

Rémi Denis-Courmont remi at remlab.net
Mon Aug 26 14:32:13 CEST 2013


On Sat, 24 Aug 2013 22:41:25 +0200, Rafaël Carré <funman at videolan.org>
wrote:
> @@ -1810,7 +1818,11 @@ static int hls_Download(stream_t *s, segment_t
> *segment)
>              assert(segment->data->i_buffer == segment->size);
>              p_block = NULL;
>          }
> +        vlc_mutex_lock(&p_sys->lock);
> +        while (p_sys->paused)
> +            vlc_cond_wait(&p_sys->wait, &p_sys->lock);
>          length = stream_Read(p_ts, segment->data->p_buffer + curlen,
>          segment->size - curlen);

Here, the lock protects the TS stream. But down below, the same lock
protects the source stream. I fail to grasp the rationale.

Also does this not get stuck if the user stops the stream while paused?

> +        vlc_mutex_unlock(&p_sys->lock);
>          if (length <= 0)
>              break;
>          curlen += length;
> @@ -1975,6 +1988,12 @@ static int Open(vlc_object_t *p_this)
>      s->pf_peek = Peek;
>      s->pf_control = Control;
>  
> +    stream_Control (s->p_source, STREAM_CAN_PAUSE, &p_sys->can_pause);
> +    p_sys->paused = false;

The source stream is the M3U8 list, is it not? It would be simpler to just
load the whole file than to pause it. That would also avoid hitting the bug
whereby the HTTP access times out when paused.

> +
> +    vlc_cond_init(&p_sys->wait);
> +    vlc_mutex_init(&p_sys->lock);
> +
>      /* Parse HLS m3u8 content. */
>      uint8_t *buffer = NULL;
>      ssize_t len = read_M3U8_from_stream(s->p_source, &buffer);
> @@ -2047,6 +2066,9 @@ fail:
>      }
>      vlc_array_destroy(p_sys->hls_stream);
>  
> +    vlc_mutex_destroy(&p_sys->lock);
> +    vlc_cond_destroy(&p_sys->wait);
> +
>      /* */
>      free(p_sys->m3u8);
>      free(p_sys);
> @@ -2087,6 +2109,10 @@ static void Close(vlc_object_t *p_this)
>      vlc_array_destroy(p_sys->hls_stream);
>  
>      /* */
> +
> +    vlc_mutex_destroy(&p_sys->lock);
> +    vlc_cond_destroy(&p_sys->wait);
> +
>      free(p_sys->m3u8);
>      if (p_sys->peeked)
>          block_Release (p_sys->peeked);
> @@ -2529,13 +2555,26 @@ static int Control(stream_t *s, int i_query,
> va_list args)
>          case STREAM_CAN_CONTROL_PACE:
>              *(va_arg (args, bool *)) = true;
>              break;
> +        case STREAM_CAN_PAUSE:
> +            *(va_arg (args, bool *)) = p_sys->can_pause;
> +            break;
>          case STREAM_CAN_FASTSEEK:
> -        case STREAM_CAN_PAUSE: /* TODO */
>              *(va_arg (args, bool *)) = false;
>              break;
>          case STREAM_GET_POSITION:
>              *(va_arg (args, uint64_t *)) = p_sys->playback.offset;
>              break;
> +        case STREAM_SET_PAUSE_STATE:
> +        {
> +            bool paused = va_arg (args, unsigned);
> +
> +            vlc_mutex_lock(&p_sys->lock);
> +            stream_Control(s->p_source, STREAM_SET_PAUSE_STATE,
paused);

There.

> +            p_sys->paused = paused;
> +            vlc_cond_signal(&p_sys->wait);
> +            vlc_mutex_unlock(&p_sys->lock);
> +            break;
> +        }
>          case STREAM_SET_POSITION:
>              if (hls_MaySeek(s))
>              {

-- 
Rémi Denis-Courmont
Sent from my collocated server



More information about the vlc-devel mailing list