[FFmpeg-devel] [PATCH] Do small seeks forward by skipping data instead of seeking, even for seekable protocols

Martin Storsjö martin
Sat Jul 17 01:28:12 CEST 2010


On Fri, 16 Jul 2010, Michael Niedermayer wrote:

> On Fri, Jul 16, 2010 at 04:21:03PM +0300, Martin Storsj? wrote:
> > Hi,
> > 
> > As in $subj - even if the underlying protocol is seekable (such as when 
> > reading a plain file over http), doing small seeks forward is 
> > prohibitively expensive (and sometimes errorprone, too) compared to simply 
> > skipping data.
> > 
> > Some demuxers (flvdec is the one I've been testing with) triggers these 
> > very often, sometimes after every few 100 KB or so.
> > 
> > This issue can be solved at two levels, both within aviobuf and within the 
> > http protocol - both have their advantages and disadvantages. See the 
> > attached patches - what do you prefer, or do you want it solved at both 
> > levels?
> > 
> > // Martin
> >  aviobuf.c |    4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 5a9197d19797b7b6e676233f18a1a20212b68f4f  0001-aviobuf-Do-short-seeks-forward-by-reading-instead-of.patch
> > From a75e45742885d0eb825f0aa96d862534dbb6de30 Mon Sep 17 00:00:00 2001
> > From: Martin Storsjo <martin at martin.st>
> > Date: Fri, 16 Jul 2010 15:43:54 +0300
> > Subject: [PATCH] aviobuf: Do short seeks forward by reading instead of calling the underlying protocol seek
> > 
> > ---
> >  libavformat/aviobuf.c |    4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 9f1187e..2fbde48 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -153,7 +153,9 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
> >          offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
> >          /* can do the seek inside the buffer */
> >          s->buf_ptr = s->buffer + offset1;
> > -    } else if(s->is_streamed && !s->write_flag && offset1 >= 0 &&
> > +    } else if ((s->is_streamed ||
> > +               s->buffer + offset1 < s->buf_ptr + s->buffer_size) &&
> > +               !s->write_flag && offset1 >= 0 &&
> >                (whence != SEEK_END || force)) {
> 
> arbitrary and obfuscated
> there should be a #define that specifyies at what threshold to apply a seek

Added a define and reorganized the condition slightly - do you feel that 
this is less obfuscated?

// Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-aviobuf-Do-short-seeks-forward-by-reading-instead-of.patch
Type: text/x-diff
Size: 1365 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100717/87620279/attachment.patch>



More information about the ffmpeg-devel mailing list