[MPlayer-G2-dev] [PATCH] Select realtime scheduler

Raindel Shachar raindel at techunix.technion.ac.il
Sun Feb 1 11:35:45 CET 2004


Hi,
  I attach a patch that allows mplayer to ask for realtime scheduler, so
that it will get it's CPU slice whenever it need it, preventing sleep
overruns.
     Cheers,
     Shachar
-------------- next part --------------
Index: configure.g1
===================================================================
RCS file: /cvsroot/mplayer/g2/configure.g1,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 configure.g1
--- configure.g1	31 Jan 2004 20:16:18 -0000	1.1.1.1
+++ configure.g1	1 Feb 2004 10:16:10 -0000
@@ -262,6 +262,7 @@
   --enable-sse2          build with sse2 support [autodetect]
   --disable-fastmemcpy   disable 3dnow/sse/mmx optimized memcpy() [enable]
   --disable-big-endian   Force byte order to little endian [autodetect]
+  --enable-realtime      enable realtime scheduling setting in mplayer [autodetected]
   --enable-big-endian    Force byte order to big endian [autodetect]
   --enable-debug[=1-3]   compile debugging information into mplayer [disable]
   --enable-profile       compile profiling information into mplayer [disable]
@@ -1101,6 +1102,7 @@
 _fribidiconfig='fribidi-config'
 _inet6=auto
 _gethostbyname2=auto
+_realtime=auto
 for ac_option do
   case "$ac_option" in
   # Skip 1st pass
@@ -1294,6 +1296,9 @@
   --enable-fribidi)     _fribidi=yes    ;;
   --disable-fribidi)    _fribidi=no     ;;
 
+  --enable-realtime)    _realtime=yes   ;;
+  --disable-realtime)   _realtime=no    ;;
+
   --enable-inet6)	_inet6=yes	;;
   --disable-inet6)	_inet6=no	;;
 
@@ -2065,6 +2070,32 @@
 echores "yes (using $_ld_pthread)"
 
 
+echocheck "realtime scheduler"
+if test "$_realtime" = no; then
+  _def_realtime='#undef HAVE_REALTIME'
+  echores "no"
+else
+  if linux ; then
+    cat > $TMPC << EOF
+#include <sched.h>
+int main(void) { struct sched_param sparam; 
+sparam.sched_priority = sched_get_priority_max(SCHED_RR); 
+sched_setscheduler(0, SCHED_RR, &sparam);
+return 0; }
+EOF
+    if cc_check || test "$_realtime" = yes && test "$_realtime" != no ; then
+      _def_realtime='#define HAVE_REALTIME 1'
+      echores "yes (with linux sched_setscheduler)"
+    else
+      _def_realtime='#undef HAVE_REALTIME'
+      echores "no"
+    fi
+  else
+    _def_realtime='#undef HAVE_REALTIME'
+    echores "no (not implemented for this OS)"
+  fi
+fi
+
 echocheck "sys/soundcard.h"
 cat > $TMPC << EOF
 #include <sys/soundcard.h>
@@ -5870,6 +5901,8 @@
 $_def_vesa
 $_def_xdpms
 $_def_aa
+/* Enables realtime scheduler setting */
+$_def_realtime
 
 /* used by GUI: */
 $_def_xshape
Index: test-play.c
===================================================================
RCS file: /cvsroot/mplayer/g2/test-play.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 test-play.c
--- test-play.c	31 Jan 2004 20:16:18 -0000	1.1.1.1
+++ test-play.c	1 Feb 2004 10:16:12 -0000
@@ -36,6 +36,8 @@
 
 static int autosync=30;
 
+static int realtime=0;
+
 // -vc/-vfm/-ac/-afm:
 static char** a_codec_name_list=NULL;
 static char** a_codec_fm_list=NULL;
@@ -63,6 +65,10 @@
 extern int divx_quality;
 
 static config_t main_config[]={
+
+	{"realtime", &realtime, CONF_TYPE_FLAG, 0, 0, 1, NULL, "Try to get realtime scheduler"},
+
+
 	{"dumpstream", &dumpstream, CONF_TYPE_FLAG, 0, 0, 1, NULL, "dump raw stream"},
 	{"sub",&sub_filename, CONF_TYPE_STRING, 0, 0, 0, NULL, "external subtitles stream"},
 	{"subdemuxer",&sub_demuxer_name, CONF_TYPE_STRING, 0, 0, 0, NULL, "force external subtitles demuxer"},
@@ -200,6 +206,14 @@
     }
   }
 
+  // INIT Realtime priority (if supported)
+#ifdef HAVE_REALTIME
+  if(realtime) {
+    mp_msg(MSGT_CPLAYER,MSGL_INFO,"Trying to set realtime priority...\n");
+    set_realtime();
+  }
+#endif  
+
 //INIT stream  
   stream=open_stream(filename);
   if(!stream){
Index: osdep/Makefile
===================================================================
RCS file: /cvsroot/mplayer/g2/osdep/Makefile,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Makefile
--- osdep/Makefile	31 Jan 2004 20:16:18 -0000	1.1.1.1
+++ osdep/Makefile	1 Feb 2004 10:16:18 -0000
@@ -7,6 +7,7 @@
 
 getch = getch2.c
 timer = timer-lx.c
+realtime = realtime-lx.c
 ifeq ($(MACOSX),yes)
 timer = timer-macosx.c
 endif
@@ -22,7 +23,8 @@
 endif
 SRCS += $(timer)
 SRCS += $(getch)
+SRCS += $(realtime)
 
 OBJS=$(SRCS:.c=.o)
 
--- /dev/null   2003-01-30 12:24:37.000000000 +0200
+++ osdep/realtime-lx.c 2004-01-31 23:40:20.000000000 +0200
@@ -0,1 +1,13 @@
+#include "../config.h"
+
+#ifdef HAVE_REALTIME
+#include <sched.h>
+
+void set_realtime(void)
+{
+  struct sched_param sparam;
+  sparam.sched_priority = sched_get_priority_max(SCHED_RR);
+  sched_setscheduler(0, SCHED_FIFO, &sparam);
+}
+#endif
--- /dev/null   2003-01-30 12:24:37.000000000 +0200
+++ osdep/realtime.h    2004-01-31 23:40:25.000000000 +0200
@@ -0,0 +1,6 @@
+#ifndef REALTIME_H_
+#define REALTIME_H_ 1
+
+extern void set_realtime(void);
+
+#endif


More information about the MPlayer-G2-dev mailing list