aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/cache.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-12-26 01:23:54 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-26 01:24:27 +0100
commit312151bb9af62a29429821e13871311f670e9d5a (patch)
treebe67340839f748e2fdf10d08089f0b9fe2de2c0c /libavformat/cache.c
parentce3551896ab4e19d5fa00b7580206b1bfa13675f (diff)
downloadffmpeg-312151bb9af62a29429821e13871311f670e9d5a.tar.gz
avformat/cache: avoid lseek() on reading from the cache if possible
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/cache.c')
-rw-r--r--libavformat/cache.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libavformat/cache.c b/libavformat/cache.c
index 9a0c4bba03..f1e623a04d 100644
--- a/libavformat/cache.c
+++ b/libavformat/cache.c
@@ -156,8 +156,12 @@ static int cache_read(URLContext *h, unsigned char *buf, int size)
av_assert0(entry->logical_pos <= c->logical_pos);
if (in_block_pos < entry->size) {
int64_t physical_target = entry->physical_pos + in_block_pos;
- //FIXME avoid seek if unneeded
- r = lseek(c->fd, physical_target, SEEK_SET);
+
+ if (c->cache_pos != physical_target) {
+ r = lseek(c->fd, physical_target, SEEK_SET);
+ } else
+ r = c->cache_pos;
+
if (r >= 0) {
c->cache_pos = r;
r = read(c->fd, buf, FFMIN(size, entry->size - in_block_pos));