[Ffmpeg-devel] [PATCH/RFC] http seeking

Michael Niedermayer michaelni
Thu Jan 4 21:49:47 CET 2007


Hi

On Wed, Jan 03, 2007 at 11:42:27PM -0500, Ronald S. Bultje wrote:
> Hi,
> 
> attached is my new attempt at HTTP seeking. It's using AVSEEK_SIZE for
> retrieving the filesize. It uses the Range request header as defined in
> the HTTP 1.1 spec. Seek failures are handled by keeping the old
> connection open until after the seek has succeeded. is_stream is set by
> the Content-Range property in the server reply header.
> 
> I've tested this on a variety on audio/video formats (avi, quicktime,
> mp3, mpeg/vob) and it works for all of them, although performance isn't
> always optimal (e.g. quicktime seeks a lot, leading to considerable
> demuxer slowdowns, mp3 caches a lot of data and so the first seek takes
> a while to complete, large DVD-size vob movies don't play at full speed
> b/c of network slowness here, etc.). I'm sure that can be worked on at
> some point.
> 
> Comments welcome.

[...]
> +            }
> +	    h->is_streamed = 0; /* we _can_ in fact seek */

tab


[...]
> +static offset_t http_seek(URLContext *h, offset_t off, int whence)
> +{
> +    HTTPContext *s = h->priv_data;
> +    URLContext *hd = s->hd;
> +    offset_t old_off = s->off;
> +
> +    if (s->filesize == -1 && (whence == SEEK_END || whence == AVSEEK_SIZE))
> +        return -1;
> +    else if (whence == AVSEEK_SIZE)
> +        return s->filesize;
> +    else if (h->is_streamed == 1)
> +        return -1;

if (whence == AVSEEK_SIZE)
    return s->filesize;
else if (s->filesize == -1 && whence == SEEK_END || h->is_streamed)
    return -1;


> +
> +    /* we save the old context in case the seek fails */
> +    s->hd = NULL;
> +    switch (whence) {
> +        case SEEK_SET:
> +            s->off = off;
> +            break;
> +        case SEEK_CUR:
> +            s->off += off;
> +            break;
> +        case SEEK_END:
> +            s->off = s->filesize - off;

its + off

> +            break;
> +    }
> +    off = s->off;

if(whence == SEEK_CUR)
    off += s->off;
else if(whence == SEEK_END)
    off += s->filesize;
s->off= off;


> +    /* if it fails, continue on old connection */
> +    if (http_open_cnx(h) < 0) {
> +        s->hd = hd;
> +        s->off = old_off;
> +        return -1;
> +    } else if (s->off != off) {
> +        http_close_cnx (h);
> +        s->hd = hd;
> +        s->off = old_off;
> +        return -1;
> +    } else {
> +        URLContext *new = s->hd;
> +        s->hd = hd;
> +        http_close_cnx(h);
> +        s->hd = new;
> +    }
> +
> +    return s->off;
> +}


if (http_open_cnx(h) < 0) {
} else if(s->off != off) {
    url_close(s->hd);
} else{
    url_close(hd);
    return s->off;
}
s->hd = hd;
s->off = old_off;
return -1;

also maybe ttp_open_cnx() should fail and return -1 if s->off != off

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070104/8d02a837/attachment.pgp>



More information about the ffmpeg-devel mailing list