From 5b33a553763f5499c6627fb5cff0659e37edf22c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 4 Apr 2010 14:21:29 +0000 Subject: Implement support to the AVSEEK_SIZE operation in file_seek(). Avoid the need to use seeking for getting the file size, use fstat instead, which is significantly faster. See thread: Subject: [FFmpeg-devel] [PATCH] Add support to AVSEEK_SIZE to the file protocol seek callback Date: Fri, 2 Apr 2010 13:13:27 +0200 Originally committed as revision 22799 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/file.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'libavformat/file.c') diff --git a/libavformat/file.c b/libavformat/file.c index 9b60a5f1f8..d42a678c98 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -26,6 +26,7 @@ #include #endif #include +#include #include #include #include "os_support.h" @@ -73,8 +74,11 @@ static int file_write(URLContext *h, unsigned char *buf, int size) static int64_t file_seek(URLContext *h, int64_t pos, int whence) { int fd = (intptr_t) h->priv_data; - if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) - return AVERROR_NOTSUPP; + if (whence == AVSEEK_SIZE) { + struct stat st; + int ret = fstat(fd, &st); + return ret < 0 ? AVERROR(errno) : st.st_size; + } return lseek(fd, pos, whence); } -- cgit v1.2.3