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

Michael Niedermayer michaelni
Sat Jul 17 01:59:25 CEST 2010


On Sat, Jul 17, 2010 at 02:28:12AM +0300, Martin Storsj? wrote:
> 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
>  aviobuf.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> a0c5539f4d6e0d880d9eaf25f5ece5a592eed128  0001-aviobuf-Do-short-seeks-forward-by-reading-instead-of.patch
> From c49b24ffb6729acfbe97d9a312a0e02315a4acbc 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 |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index d4db268..7a28ef1 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -28,6 +28,8 @@
>  
>  #define IO_BUFFER_SIZE 32768
>  
> +#define SHORT_SEEK_THRESHOLD 4096
> +
>  static void fill_buffer(ByteIOContext *s);
>  #if LIBAVFORMAT_VERSION_MAJOR >= 53
>  static int url_resetbuf(ByteIOContext *s, int flags);
> @@ -153,7 +155,9 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)

>          offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {

id try to write it similar to this test and i would suggest to doxument
the define, except these, ok

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

Avoid a single point of failure, be that a person or equipment.
-------------- 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/20100717/19b296d1/attachment.pgp>



More information about the ffmpeg-devel mailing list