[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 15:25:50 CET 2011


On Fri, Feb 11, 2011 at 11:30:23AM +0100, Jean-Paul Saman wrote:
> On Fri, Feb 11, 2011 at 10:32 AM, Laurent Aimar <fenrir at elivagar.org> wrote:
> > 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).
> 
> I have no idea how that works. AFAIK you cannot reopen an input with a
> different URL.
 Not sure to understand, but the API is simple:

stream_t *s = stream_UrlNew(access, "http://example.com/file");
while (char *p = stream_Readline(s)) { free(p); }
stream_Delete(s);

Regards,

-- 
fenrir



More information about the vlc-devel mailing list