From 8e287af090d0ef65043f3b30573ead754375ff8f Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Mon, 1 Jan 2007 21:49:09 +0000
Subject: [PATCH] seekless filesize retrieving support in 7 lines of code, also
 doesnt break compatibility

Originally committed as revision 7395 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavformat/avio.c    | 3 +++
 libavformat/avio.h    | 2 ++
 libavformat/aviobuf.c | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index a2b8a832590..f2fe0e13c68 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -148,9 +148,12 @@ offset_t url_filesize(URLContext *h)
 {
     offset_t pos, size;
 
+    size= url_seek(h, 0, AVSEEK_SIZE);
+    if(size<0){
     pos = url_seek(h, 0, SEEK_CUR);
     size = url_seek(h, -1, SEEK_END)+1;
     url_seek(h, pos, SEEK_SET);
+    }
     return size;
 }
 
diff --git a/libavformat/avio.h b/libavformat/avio.h
index f0fd1a85cf4..27fb241e337 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -69,6 +69,8 @@ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
 /* not implemented */
 int url_poll(URLPollEntry *poll_table, int n, int timeout);
 
+#define AVSEEK_SIZE 0x10000
+
 typedef struct URLProtocol {
     const char *name;
     int (*url_open)(URLContext *h, const char *filename, int flags);
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index f3e7d5081fa..450b4cf11d3 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -170,8 +170,11 @@ offset_t url_fsize(ByteIOContext *s)
 
     if (!s->seek)
         return -EPIPE;
+    size = s->seek(s->opaque, 0, AVSEEK_SIZE);
+    if(size<0){
     size = s->seek(s->opaque, -1, SEEK_END) + 1;
     s->seek(s->opaque, s->pos, SEEK_SET);
+    }
     return size;
 }
 
-- 
GitLab