[FFmpeg-devel] [PATCH] Fix seeking HTTP when server uses chunked encoding

Tomas Härdin tomas.hardin
Tue May 11 17:18:53 CEST 2010

On Tue, 2010-05-11 at 09:15 -0400, Ronald S. Bultje wrote:
> Hi Thomas,
> On Tue, May 11, 2010 at 3:58 AM, Tomas H?rdin <tomas.hardin at codemill.se> wrote:
> > Attached is a patch that changes http_connect() to not rely on this
> > behavior of http_write(). http_write() instead always uses chunked
> > encoding, while http_connect() simply uses url_write().
> So basically your patch removes the codepath of non-chunked encoding.
> This is fine, but then do it completely. There's still remnants left.
> Basically, as long as the "post" variable is still there, I consider
> the codepath to be there.

Well, post is just a shorthand for "h->flags & URL_WRONLY" - the GET and
POST parts simply share a bit of code. I'm therefore a bit unsure what
you mean.

The only case I can think of where the old code would upload data
without chunked encoding would be when h->flags & URL_RDWR, which never
happens as far as I can tell from the code. The real question then
becomes whether http_open() should be paranoid and check for that flag
and fail if it's set. That would guarantee that http_write() will only
be called when in write-only mode, from url_write() (avio.c:195).

Note that the code must always perform chunked encoding since the size
of the data to be written is not known in advance.

I've attached two patches. The first patch resets chunksize before
parsing the headers, which fixes the rare case of a resource switching
chunked encoding off between seeks (could happen once the size of a
resource becomes known to the server). It also disallows read-write mode
and removes the unused http_write() prototype.

The second patch does a bit of refactoring to http_connect() as well,
splitting it up into two functions: http_send_request() and

Please state any preference for either solution (or neither?). Both
patches pass regression tests and my own GET and POST tests (seeking in
ffplay, transcoding to/from HTTP).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: chunked_seeking2.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100511/a3e75342/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chunked_seeking3.patch
Type: text/x-patch
Size: 3927 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100511/a3e75342/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100511/a3e75342/attachment.pgp>

More information about the ffmpeg-devel mailing list