[FFmpeg-cvslog] r22799 - trunk/libavformat/file.c

stefano subversion
Sun Apr 4 16:21:29 CEST 2010


Author: stefano
Date: Sun Apr  4 16:21:29 2010
New Revision: 22799

Log:
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

Modified:
   trunk/libavformat/file.c

Modified: trunk/libavformat/file.c
==============================================================================
--- trunk/libavformat/file.c	Sun Apr  4 15:50:38 2010	(r22798)
+++ trunk/libavformat/file.c	Sun Apr  4 16:21:29 2010	(r22799)
@@ -26,6 +26,7 @@
 #include <io.h>
 #endif
 #include <unistd.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <stdlib.h>
 #include "os_support.h"
@@ -73,8 +74,11 @@ static int file_write(URLContext *h, uns
 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);
 }
 



More information about the ffmpeg-cvslog mailing list