[FFmpeg-cvslog] r24280 - trunk/libavformat/aviobuf.c

Reinhard Tartler siretart
Mon Jul 19 22:00:06 CEST 2010


On Sat, Jul 17, 2010 at 21:17:01 (CEST), Michael Niedermayer wrote:

> On Sat, Jul 17, 2010 at 07:26:30AM +0200, mstorsjo wrote:
>> Author: mstorsjo
>> Date: Sat Jul 17 07:26:30 2010
>> New Revision: 24280
>> 
>> Log:
>> aviobuf: Do short seeks forward by reading and skipping data instead of a proper seek
>> 
>> This improves performance on e.g. seekable http.
>
> This one is a candidate for backporting to 0.5/0.6 if it applies

thanks for the hint, applied to 0.6 cleanly.

For 0.5, this hunk did not apply that cleanly, here is the resulting
diff:

Index: libavformat/aviobuf.c
===================================================================
--- libavformat/aviobuf.c       (Revision 24335)
+++ libavformat/aviobuf.c       (Arbeitskopie)
@@ -27,6 +27,13 @@
 
 #define IO_BUFFER_SIZE 32768
 
+/**
+ * Do seeks within this distance ahead of the current buffer by skipping
+ * data instead of calling the protocol seek function, for seekable
+ * protocols.
+ */
+#define SHORT_SEEK_THRESHOLD 4096
+
 static void fill_buffer(ByteIOContext *s);
 
 int init_put_byte(ByteIOContext *s,
@@ -151,8 +158,10 @@
         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 && offset1 < (s->buf_end - s->buffer) + (1<<16)){
+    } else if ((s->is_streamed ||
+               offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) &&
+               !s->write_flag && offset1 >= 0 &&
+              (whence != SEEK_END || force)) {
         while(s->pos < offset && !s->eof_reached)
             fill_buffer(s);
         if (s->eof_reached)

I'd feel more comfortable if someone could take a look if the old
condition  "offset1 < (s->buf_end - s->buffer) + (1<<16)" can be really
replaced with "offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer)"

I guess yes, but another eyeball would make me feel more comfortable.

-- 
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4




More information about the ffmpeg-cvslog mailing list