[vlc-devel] [vlc-commits] stream_filter/httplive.c: read a HLS m3u8 file in one go, parse later

Laurent Aimar fenrir at elivagar.org
Fri Feb 11 10:32:59 CET 2011


Hi,

On Fri, Feb 11, 2011 at 10:14:07AM +0100, Jean-Paul Saman wrote:
> +/* Read M3U8 file */
> +static uint8_t *access_ReadM3U8(stream_t *s, vlc_url_t *url)
> +{
> +    stream_sys_t *p_sys = (stream_sys_t *) s->p_sys;
> +
> +    /* Download new playlist file from server */
> +    if (AccessOpen(s, url) != VLC_SUCCESS)
> +        return NULL;
> +
> +    ssize_t size = p_sys->p_access->info.i_size;
> +    if (size == 0) size = 1024; /* no Content-Length */
> +
> +    msg_Err(s, "Stream size is %"PRId64, size);
> +
> +    uint8_t *buffer = calloc(1, size);
> +    if (buffer == NULL)
> +    {
> +        AccessClose(s);
> +        return NULL;
> +    }
> +
> +    size_t length = 0, curlen = 0;
> +    do
> +    {
> +        length = p_sys->p_access->pf_read(p_sys->p_access, buffer + curlen, size - curlen);
> +        if ((length <= 0) || (length >= size))
> +            break;
> +        curlen += length;
> +        if (curlen >= size)
> +        {
> +            uint8_t *tmp = realloc(*buffer, size + 1024);
> +            if (tmp == NULL)
> +                break;
> +            size += 1024;
> +            *buffer = tmp;
> +        }
> +    } while (vlc_object_alive(s));
> +
> +    AccessClose(s);
> +    return buffer;
> +}
 Is there a specific reason for using access_t? If you open a stream_t directly
it should simplify the code (here and when reading the data segment too).

-- 
fenrir




More information about the vlc-devel mailing list