changeset 12835:4235ae5a2d60

cache min fill adjustment, based on patch by Jeremy Huddleston
author iive
date Fri, 16 Jul 2004 20:31:17 +0000
parents c457b1e671a7
children 9a310b31359f
files cfg-common.h etc/example.conf libmpdemux/cache2.c libmpdemux/demuxer.c mencoder.c mplayer.c
diffstat 6 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-common.h	Fri Jul 16 17:16:00 2004 +0000
+++ b/cfg-common.h	Fri Jul 16 20:31:17 2004 +0000
@@ -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
--- a/etc/example.conf	Fri Jul 16 17:16:00 2004 +0000
+++ b/etc/example.conf	Fri Jul 16 20:31:17 2004 +0000
@@ -116,6 +116,8 @@
 			# 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
--- a/libmpdemux/cache2.c	Fri Jul 16 17:16:00 2004 +0000
+++ b/libmpdemux/cache2.c	Fri Jul 16 20:31:17 2004 +0000
@@ -198,6 +198,9 @@
 #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 @@
   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 @@
     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())){
--- a/libmpdemux/demuxer.c	Fri Jul 16 17:16:00 2004 +0000
+++ b/libmpdemux/demuxer.c	Fri Jul 16 20:31:17 2004 +0000
@@ -1374,6 +1374,9 @@
 
 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 @@
       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;
--- a/mencoder.c	Fri Jul 16 17:16:00 2004 +0000
+++ b/mencoder.c	Fri Jul 16 20:31:17 2004 +0000
@@ -105,6 +105,9 @@
 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
--- a/mplayer.c	Fri Jul 16 17:16:00 2004 +0000
+++ b/mplayer.c	Fri Jul 16 20:31:17 2004 +0000
@@ -255,6 +255,9 @@
        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 @@
 #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;
 }