[FFmpeg-cvslog] avformat/cache: avoid lseek() on reading from the cache if possible
Michael Niedermayer
git at videolan.org
Fri Dec 26 02:23:14 CET 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Dec 26 01:23:54 2014 +0100| [312151bb9af62a29429821e13871311f670e9d5a] | committer: Michael Niedermayer
avformat/cache: avoid lseek() on reading from the cache if possible
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=312151bb9af62a29429821e13871311f670e9d5a
---
libavformat/cache.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavformat/cache.c b/libavformat/cache.c
index 9a0c4bb..f1e623a 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));
More information about the ffmpeg-cvslog
mailing list