# HG changeset patch # User stefano # Date 1270390889 0 # Node ID 310b3b1b2921b6f9f4a358a165a72cb3594a8be1 # Parent 742d48f7f5fbc5d54808b493b00405e250bb9e5c 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 diff -r 742d48f7f5fb -r 310b3b1b2921 file.c --- a/file.c Sun Apr 04 12:20:10 2010 +0000 +++ b/file.c Sun Apr 04 14:21:29 2010 +0000 @@ -26,6 +26,7 @@ #include #endif #include +#include #include #include #include "os_support.h" @@ -73,8 +74,11 @@ 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); }