From 9b0d8c680f63463b1dcf6cf5597018549d469c0b Mon Sep 17 00:00:00 2001 From: iive Date: Fri, 16 Jul 2004 20:31:17 +0000 Subject: cache min fill adjustment, based on patch by Jeremy Huddleston git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12836 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfg-common.h | 4 +++- etc/example.conf | 2 ++ libmpdemux/cache2.c | 19 +++++++++++++++---- libmpdemux/demuxer.c | 7 +++++-- mencoder.c | 3 +++ mplayer.c | 5 ++++- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cfg-common.h b/cfg-common.h index 699619b375..ac9f159680 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -10,8 +10,10 @@ // ------------------------- stream options -------------------- #ifdef USE_STREAM_CACHE - {"cache", &stream_cache_size, CONF_TYPE_INT, CONF_RANGE, 4, 65536, NULL}, + {"cache", &stream_cache_size, CONF_TYPE_INT, CONF_RANGE, 32, 1048576, NULL}, {"nocache", &stream_cache_size, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + {"cache-min", &stream_cache_min_percent, CONF_TYPE_FLOAT, CONF_RANGE, 0, 99, NULL}, + {"cache-prefill", &stream_cache_prefill_percent, CONF_TYPE_FLOAT, CONF_RANGE, 0, 99, NULL}, #else {"cache", "MPlayer was compiled without cache2 support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, #endif diff --git a/etc/example.conf b/etc/example.conf index 0911bc973b..a235c1c271 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -116,6 +116,8 @@ framedrop = yes # drop frames, when not in sync (slow CPU, videocard, # etc) cache = 8192 # use 8Mb input cache by default +cache_min = 20.0 # Prefill 20% of the cache before initially playing +cache_prefill = 5.0 # Prefill 5% of the cache before restarting playback if it empties # slang = en # DVD : display english subtitles if available # alang = en # DVD : play english audio tracks if available diff --git a/libmpdemux/cache2.c b/libmpdemux/cache2.c index 370f47a3fe..d6ef3bccd8 100644 --- a/libmpdemux/cache2.c +++ b/libmpdemux/cache2.c @@ -198,6 +198,9 @@ cache_vars_t* cache_init(int size,int sector){ #endif memset(s,0,sizeof(cache_vars_t)); num=size/sector; + if(num < 16){ + num = 16; + }//32kb min_size s->buffer_size=num*sector; s->sector_size=sector; #ifndef WIN32 @@ -206,8 +209,7 @@ cache_vars_t* cache_init(int size,int sector){ s->buffer=malloc(s->buffer_size); #endif s->fill_limit=8*sector; - s->back_size=size/2; - s->prefill=size/20; // default: 5% + s->back_size=s->buffer_size/2; return s; } @@ -246,11 +248,20 @@ int stream_enable_cache(stream_t *stream,int size,int min,int prefill){ return 1; } - if(size<32*1024) size=32*1024; // 32kb min s=cache_init(size,ss); stream->cache_data=s; s->stream=stream; // callback - s->prefill=size*prefill; + s->prefill=prefill; + + + //make sure that we won't wait from cache_fill + //more data than it is alowed to fill + if (s->prefill > s->buffer_size - s->fill_limit ){ + s->prefill = s->buffer_size - s->fill_limit; + } + if (min > s->buffer_size - s->fill_limit) { + min = s->buffer_size - s->fill_limit; + } #ifndef WIN32 if((stream->cache_pid=fork())){ diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index 558748d266..8557be9cb1 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -1374,6 +1374,9 @@ int audio_stream_cache = 0; extern int hr_mp3_seek; +extern float stream_cache_min_percent; +extern float stream_cache_prefill_percent; + demuxer_t* demux_open(stream_t *vs,int file_format,int audio_id,int video_id,int dvdsub_id,char* filename){ stream_t *as = NULL,*ss = NULL; demuxer_t *vd,*ad = NULL,*sd = NULL; @@ -1386,8 +1389,8 @@ demuxer_t* demux_open(stream_t *vs,int file_format,int audio_id,int video_id,int return NULL; } if(audio_stream_cache) { - if(!stream_enable_cache(as,audio_stream_cache*1024,audio_stream_cache*1024/5, - audio_stream_cache*1024/20)) { + if(!stream_enable_cache(as,audio_stream_cache*1024,audio_stream_cache*1024*(stream_cache_min_percent / 100.0), + audio_stream_cache*1024*(stream_cache_prefill_percent / 100.0))) { free_stream(as); mp_msg(MSGT_DEMUXER,MSGL_ERR,"Can't enable audio stream cache\n"); return NULL; diff --git a/mencoder.c b/mencoder.c index 211e97eb53..ad595f50c5 100644 --- a/mencoder.c +++ b/mencoder.c @@ -105,6 +105,9 @@ int forced_subs_only=0; int stream_cache_size=-1; #ifdef USE_STREAM_CACHE extern int cache_fill_status; + +float stream_cache_min_percent=20.0; +float stream_cache_prefill_percent=5.0; #else #define cache_fill_status 0 #endif diff --git a/mplayer.c b/mplayer.c index c5052e4e9c..288ffba522 100644 --- a/mplayer.c +++ b/mplayer.c @@ -255,6 +255,9 @@ int forced_subs_only=0; int stream_cache_size=-1; #ifdef USE_STREAM_CACHE extern int cache_fill_status; + +float stream_cache_min_percent=20.0; +float stream_cache_prefill_percent=5.0; #else #define cache_fill_status 0 #endif @@ -1375,7 +1378,7 @@ goto_enable_cache: #endif if(stream_cache_size>0){ current_module="enable_cache"; - if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20)) + if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024*(stream_cache_min_percent / 100.0),stream_cache_size*1024*(stream_cache_prefill_percent / 100.0))) if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file; } -- cgit v1.2.3