[MPlayer-dev-eng] PATCHes

Eric Lammerts eric at lammerts.org
Sun May 12 14:53:27 CEST 2002


On Sun, 12 May 2002, [iso-8859-2] Gábor Lénárt wrote:
> About a year ago I wrote several programs for svgalib and those times
> SIGUSR1 and SIGUSR2 are used by svgalib itself, so if it's true nowdays
> as well, that patch may be incomatible with svgalib vo imho, because
> as far as I can remember that patch uses SIGUSR1.

I rewrote the patch to use a socketpair.

Eric

Index: cache2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cache2.c,v
retrieving revision 1.13
diff -u -r1.13 cache2.c
--- cache2.c	5 May 2002 21:43:16 -0000	1.13
+++ cache2.c	12 May 2002 13:02:06 -0000
@@ -15,6 +15,7 @@
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <unistd.h>

 #include "../linux/shmem.h"
@@ -47,6 +48,8 @@
 //  int fifo_flag;  // 1 if we should use FIFO to notice cache about buffer reads.
   // callback
   stream_t* stream;
+  int signal_fd[2];
+  int sleeping[2];
 } cache_vars_t;

 static int min_fill=0;
@@ -60,6 +63,24 @@
   printf("%3d %%  (%3d%%)\n",100*newb/s->buffer_size,100*min_fill/s->buffer_size);
 }

+static void cache_usleep(cache_vars_t* s, int idx, long usec)
+{
+  fd_set rfds;
+  struct timeval tv;
+
+  FD_ZERO(&rfds);
+  FD_SET(s->signal_fd[idx], &rfds);
+  tv.tv_sec = 0;
+  tv.tv_usec = usec;
+  s->sleeping[idx] = 1;
+  if(select(s->signal_fd[idx]+1, &rfds, NULL, NULL, &tv)) {
+  	  char buf[64];
+  	  // discard bytes
+  	  while(read(s->signal_fd[idx], buf, sizeof(buf)) == sizeof(buf)) { }
+  }
+  s->sleeping[idx] = 0;
+}
+
 int cache_read(cache_vars_t* s,unsigned char* buf,int size){
   int total=0;
   while(size>0){
@@ -70,8 +91,10 @@
     if(s->read_filepos>=s->max_filepos || s->read_filepos<s->min_filepos){
 	// eof?
 	if(s->eof) break;
+	// kick the baby!
+	if(s->sleeping[0]) write(s->signal_fd[1], "", 1);
 	// waiting for buffer fill...
-	usleep(READ_USLEEP_TIME); // 10ms
+	cache_usleep(s, 1, READ_USLEEP_TIME);
 	continue; // try again...
     }

@@ -205,6 +228,9 @@
   s->stream=stream; // callback
   s->prefill=size*prefill;

+  socketpair(AF_UNIX, SOCK_STREAM, 0, s->signal_fd);
+  fcntl(s->signal_fd[0], F_SETFL, O_NONBLOCK);
+  fcntl(s->signal_fd[1], F_SETFL, O_NONBLOCK);
   if((stream->cache_pid=fork())){
     // wait until cache is filled at least prefill_init %
     mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %d [%d] %d  pre:%d  eof:%d  \n",
@@ -224,8 +250,10 @@
 // cache thread mainloop:
   signal(SIGTERM,exit_sighandler); // kill
   while(1){
-    if(!cache_fill(s)){
-	 usleep(FILL_USLEEP_TIME); // idle
+    if(cache_fill(s)){
+      if(s->sleeping[1]) write(s->signal_fd[0], "", 1);
+    } else {
+      cache_usleep(s, 0, FILL_USLEEP_TIME); // idle
     }
 //	 cache_stats(s->cache_data);
   }




More information about the MPlayer-dev-eng mailing list