[vlc-devel] [PATCH] HLS: Wait for segment to be available

Tobias Güntner fatbull at web.de
Sat Apr 14 02:25:30 CEST 2012


Hello!

Am 13.04.2012 16:43, schrieb Frédéric Yhuel:
>          segment_t *segment = GetSegment(s);
> -        if (segment == NULL)
> -            break;
> +        vlc_mutex_lock(&p_sys->download.lock_wait);
> +        while (segment == NULL)
> +        {
> +            msg_Dbg(s, "GetSegment returned NULL");
> +            if (p_sys->b_error)
> +            {
> +                vlc_mutex_unlock(&p_sys->download.lock_wait);
> +                break;

Something is wrong here. This exits the inner loop only. The result is a
double unlock and potentially a segfault later because segment is still
NULL.

It might be cleaner to move the whole code to a separate function;
something like

        segment_t *segment = WaitForSegment(s);
        if (segment == NULL)
            break;

perhaps?

> +            }
> +            vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
> +            segment = GetSegment(s);

All calls to GetSegment except the first are made while holding the
lock. Is this really correct/necessary?

> +        }
> +        vlc_mutex_unlock(&p_sys->download.lock_wait);

Regards,
Tobias




More information about the vlc-devel mailing list