[Mplayer-cvslog] CVS: main/libmpdemux cache2.c,1.7,1.8 stream.h,1.16,1.17 test.c,1.5,1.6

Arpi of Ize arpi at mplayer.dev.hu
Mon Dec 17 17:55:42 CET 2001


Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv22699

Modified Files:
	cache2.c stream.h test.c 
Log Message:
initial precaching

Index: cache2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cache2.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- cache2.c	22 Oct 2001 17:08:24 -0000	1.7
+++ cache2.c	17 Dec 2001 16:55:40 -0000	1.8
@@ -8,6 +8,7 @@
 
 #define READ_USLEEP_TIME 10000
 #define FILL_USLEEP_TIME 50000
+#define PREFILL_USLEEP_TIME 200000
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,6 +32,7 @@
   int sector_size; // size of a single sector (2048/2324)
   int back_size;   // we should keep back_size amount of old bytes for backward seek
   int fill_limit;  // we should fill buffer only if space>=fill_limit
+  int prefill;	   // we should fill min prefill bytes if cache gets empty
   // filler's pointers:
   int eof;
   off_t min_filepos; // buffer contain only a part of the file, from min-max pos
@@ -183,6 +185,7 @@
   s->buffer=shmem_alloc(s->buffer_size);
   s->fill_limit=8*sector;
   s->back_size=size/2;
+  s->prefill=size/20; // default: 5%
   return s;
 }
 
@@ -191,15 +194,31 @@
   exit(0);
 }
 
-void stream_enable_cache(stream_t *s,int size){
-  int ss=(s->type==STREAMTYPE_VCD)?VCD_SECTOR_DATA:STREAM_BUFFER_SIZE;
-  s->cache_data=cache_init(size,ss);
-  ((cache_vars_t*)s->cache_data)->stream=s; // callback
-  if((s->cache_pid=fork())) return; // parent exits
+void stream_enable_cache(stream_t *stream,int size,float prefill_init,float prefill){
+  int ss=(stream->type==STREAMTYPE_VCD)?VCD_SECTOR_DATA:STREAM_BUFFER_SIZE;
+  int min=prefill_init*size;
+  cache_vars_t* s=cache_init(size,ss);
+  stream->cache_data=s;
+  s->stream=stream; // callback
+  s->prefill=size*prefill;
+  
+  if((stream->cache_pid=fork())){
+    // wait until cache is filled at least prefill_init %
+    while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
+	mp_msg(MSGT_CACHE,MSGL_STATUS,"\rCache fill: %5.2f%% (%d bytes)    ",
+	    (float)(s->max_filepos-s->read_filepos)/(float)(s->buffer_size),
+	    s->max_filepos-s->read_filepos
+	);
+	if(s->eof) break; // file is smaller than prefill size
+	usleep(PREFILL_USLEEP_TIME);
+    }
+    return; // parent exits
+  }
+  
 // cache thread mainloop:
   signal(SIGTERM,exit_sighandler); // kill
   while(1){
-    if(!cache_fill(s->cache_data)){
+    if(!cache_fill(s)){
 	 usleep(FILL_USLEEP_TIME); // idle
     }
 //	 cache_stats(s->cache_data);

Index: stream.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- stream.h	21 Nov 2001 10:30:59 -0000	1.16
+++ stream.h	17 Dec 2001 16:55:40 -0000	1.17
@@ -42,7 +42,7 @@
 } stream_t;
 
 #ifdef USE_STREAM_CACHE
-void stream_enable_cache(stream_t *s,int size);
+void stream_enable_cache(stream_t *stream,int size,float prefill_init,float prefill);
 #else
 // no cache
 #define cache_stream_fill_buffer(x) stream_fill_buffer(x)

Index: test.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/test.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- test.c	30 Oct 2001 17:03:11 -0000	1.5
+++ test.c	17 Dec 2001 16:55:40 -0000	1.6
@@ -46,7 +46,7 @@
 
   printf("success: format: %d  data: 0x%X - 0x%X\n",file_format, (int)(stream->start_pos),(int)(stream->end_pos));
 
-  stream_enable_cache(stream,2048*1024);
+  stream_enable_cache(stream,2048*1024,0,0);
 
   demuxer=demux_open(stream,file_format,-1,-1,-1);
   if(!demuxer){




More information about the MPlayer-cvslog mailing list