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
This commit is contained in:
parent
685598f58d
commit
5b33a55376
@ -26,6 +26,7 @@
|
|||||||
#include <io.h>
|
#include <io.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "os_support.h"
|
#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)
|
static int64_t file_seek(URLContext *h, int64_t pos, int whence)
|
||||||
{
|
{
|
||||||
int fd = (intptr_t) h->priv_data;
|
int fd = (intptr_t) h->priv_data;
|
||||||
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)
|
if (whence == AVSEEK_SIZE) {
|
||||||
return AVERROR_NOTSUPP;
|
struct stat st;
|
||||||
|
int ret = fstat(fd, &st);
|
||||||
|
return ret < 0 ? AVERROR(errno) : st.st_size;
|
||||||
|
}
|
||||||
return lseek(fd, pos, whence);
|
return lseek(fd, pos, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user