Browse code

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

Michael Niedermayer authored on 2007/01/02 06:49:09
Showing 3 changed files
... ...
@@ -148,9 +148,12 @@ offset_t url_filesize(URLContext *h)
148 148
 {
149 149
     offset_t pos, size;
150 150
 
151
+    size= url_seek(h, 0, AVSEEK_SIZE);
152
+    if(size<0){
151 153
     pos = url_seek(h, 0, SEEK_CUR);
152 154
     size = url_seek(h, -1, SEEK_END)+1;
153 155
     url_seek(h, pos, SEEK_SET);
156
+    }
154 157
     return size;
155 158
 }
156 159
 
... ...
@@ -69,6 +69,8 @@ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
69 69
 /* not implemented */
70 70
 int url_poll(URLPollEntry *poll_table, int n, int timeout);
71 71
 
72
+#define AVSEEK_SIZE 0x10000
73
+
72 74
 typedef struct URLProtocol {
73 75
     const char *name;
74 76
     int (*url_open)(URLContext *h, const char *filename, int flags);
... ...
@@ -170,8 +170,11 @@ offset_t url_fsize(ByteIOContext *s)
170 170
 
171 171
     if (!s->seek)
172 172
         return -EPIPE;
173
+    size = s->seek(s->opaque, 0, AVSEEK_SIZE);
174
+    if(size<0){
173 175
     size = s->seek(s->opaque, -1, SEEK_END) + 1;
174 176
     s->seek(s->opaque, s->pos, SEEK_SET);
177
+    }
175 178
     return size;
176 179
 }
177 180