[FFmpeg-devel] [RFC] seek when streamed

Michael Niedermayer michaelni
Sat Nov 24 19:17:00 CET 2007


On Sat, Nov 24, 2007 at 02:12:49PM +0100, Baptiste Coudurier wrote:
> Hi,
> 
> Michael Niedermayer wrote:
> > On Tue, Nov 13, 2007 at 12:31:55AM +0100, Baptiste Coudurier wrote:
> > 
> >>Hi,
> >>
> >>Michael Niedermayer wrote:
> >>
> >>>On Sun, Oct 07, 2007 at 10:59:33PM +0200, Baptiste Coudurier wrote:
> >>>
> >>>
> >>>>Hi
> >>>>
> >>>>I noticed a weird behaviour (bug ?) when seeking is requested when file
> >>>>is streamed:
> >>>>
> >>>>in url_fseek:
> >>>>   } else if(s->is_streamed && !s->write_flag &&
> >>>>        offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){
> >>>>       while(s->pos < offset && !s->eof_reached)
> >>>>           fill_buffer(s);
> >>>>       s->buf_ptr = s->buf_end + offset - s->pos;
> >>>>
> >>>>if eof_is_reached then s->pos might be < offset, therefore buf_ptr might
> >>>>be > buf_end. Next get_buffer will memcpy negative size:
> >>>>
> >>>>int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
> >>>>{
> >>>>   int len, size1;
> >>>>
> >>>>   size1 = size;
> >>>>   while (size > 0) {
> >>>>       len = s->buf_end - s->buf_ptr;
> >>>>       if (len > size)
> >>>>           len = size;
> >>>>       if (len == 0) {
> >>>>	   [...]
> >>>>	} else {
> >>>>	    memcpy(buf, s->buf_ptr, len);
> >>>>           buf += len;
> >>>>	[...]
> >>>>
> >>>>Note that url_fseek clear eof_reached.
> >>>>
> >>>>That will only happen when reading a streamed file.
> >>>>Im submitting the attached patch, but Im not sure what the correct
> >>>>behaviour should be. Any suggestion welcome.
> >>>
> >>>
> >>>i think returning some error for attempts to seek after the end of the
> >>>file seems appropriate
> >>>
> >>
> >>Ok, patch attached.
> > 
> > 
> > i think this is buggy, that is if the seek is slightly to before EOF
> > fill_buffer() could still set EOF as the end of the buffer is further
> > ahead
> > 
> 
> Im not sure I understood the sentence correctly.
> 
> According to fill_buffer code, eof_reached will be set only when
> URLContext read_packet will return <= 0, so when nothing could be read.
> 
> If the seek is close to EOF fill_buffer may read less than
> s->buffer_size but still > 0, update s->pos which may still be < offset,
> then fill_buffer another time, and maybe set eof_reached this time
> though s->pos will still be < offset since nothing could be read, so we
> would end with s->pos < offset, so seek failed and reporting error seems
> appropriate.
> 
> I see that s->eof_reached would still be set to 1, that would not be
> false as we are at eof effectively.
> 
> What would be buggy exactly ?

hmm, forget what i said, patch is ok if it works ...


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

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071124/29075859/attachment.pgp>



More information about the ffmpeg-devel mailing list