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
pull/126/head
Michael Niedermayer 18 years ago
parent ecec87afc6
commit 8e287af090
  1. 3
      libavformat/avio.c
  2. 2
      libavformat/avio.h
  3. 3
      libavformat/aviobuf.c

@ -148,9 +148,12 @@ offset_t url_filesize(URLContext *h)
{ {
offset_t pos, size; offset_t pos, size;
size= url_seek(h, 0, AVSEEK_SIZE);
if(size<0){
pos = url_seek(h, 0, SEEK_CUR); pos = url_seek(h, 0, SEEK_CUR);
size = url_seek(h, -1, SEEK_END)+1; size = url_seek(h, -1, SEEK_END)+1;
url_seek(h, pos, SEEK_SET); url_seek(h, pos, SEEK_SET);
}
return size; return size;
} }

@ -69,6 +69,8 @@ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
/* not implemented */ /* not implemented */
int url_poll(URLPollEntry *poll_table, int n, int timeout); int url_poll(URLPollEntry *poll_table, int n, int timeout);
#define AVSEEK_SIZE 0x10000
typedef struct URLProtocol { typedef struct URLProtocol {
const char *name; const char *name;
int (*url_open)(URLContext *h, const char *filename, int flags); int (*url_open)(URLContext *h, const char *filename, int flags);

@ -170,8 +170,11 @@ offset_t url_fsize(ByteIOContext *s)
if (!s->seek) if (!s->seek)
return -EPIPE; return -EPIPE;
size = s->seek(s->opaque, 0, AVSEEK_SIZE);
if(size<0){
size = s->seek(s->opaque, -1, SEEK_END) + 1; size = s->seek(s->opaque, -1, SEEK_END) + 1;
s->seek(s->opaque, s->pos, SEEK_SET); s->seek(s->opaque, s->pos, SEEK_SET);
}
return size; return size;
} }

Loading…
Cancel
Save