From 0792847d4aeca71c0e61d47a9734d192506f1249 Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 10 Nov 2010 17:21:28 +0000 Subject: cache: read up to 64 KiB at once from stream_file Make the file protocol read up to 64 KiB at once when the cache is used, assuming that files will generally be readable with high bandwidth. This should improve performance when playing e.g. from high-latency network shares. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32616 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 6 +++++- stream/stream.h | 1 + stream/stream_file.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index d7a8005917..2785a0c60f 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -39,6 +39,7 @@ #include #include +#include "libavutil/avutil.h" #include "osdep/shmem.h" #include "osdep/timer.h" #if defined(__MINGW32__) @@ -168,6 +169,7 @@ static int cache_fill(cache_vars_t *s) { int back,back2,newb,space,len,pos; off_t read=s->read_filepos; + int read_chunk; if(readmin_filepos || read>s->max_filepos){ // seek... @@ -213,7 +215,9 @@ static int cache_fill(cache_vars_t *s) if(space>s->buffer_size-pos) space=s->buffer_size-pos; // limit one-time block size - if(space>4*s->sector_size) space=4*s->sector_size; + read_chunk = s->stream->read_chunk; + if (!read_chunk) read_chunk = 4*s->sector_size; + space = FFMIN(space, read_chunk); #if 1 // back+newb+space <= buffer_size diff --git a/stream/stream.h b/stream/stream.h index 24a140d255..021296b247 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -155,6 +155,7 @@ typedef struct stream { int type; // see STREAMTYPE_* int flags; int sector_size; // sector size (seek will be aligned on this size if non 0) + int read_chunk; // maximum amount of data to read at once to limit latency (0 for default) unsigned int buf_pos,buf_len; off_t pos,start_pos,end_pos; int eof; diff --git a/stream/stream_file.c b/stream/stream_file.c index f506a0f644..22be803fba 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -187,6 +187,7 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) { stream->fill_buffer = fill_buffer; stream->write_buffer = write_buffer; stream->control = control; + stream->read_chunk = 64*1024; m_struct_free(&stream_opts,opts); return STREAM_OK; -- cgit v1.2.3