changeset 3322:cdd3f5ac06b2

-slave patch by Kilian A. Foth <foth@informatik.uni-hamburg.de>
author arpi
date Tue, 04 Dec 2001 21:04:28 +0000
parents 2f7b731602db
children 7cd9dd989662
files DOCS/mplayer.1 cfg-mplayer.h mplayer.c
diffstat 3 files changed, 83 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/mplayer.1	Tue Dec 04 20:41:00 2001 +0000
+++ b/DOCS/mplayer.1	Tue Dec 04 21:04:28 2001 +0000
@@ -81,6 +81,7 @@
 .RB [ \-bpp\ depth ]
 .RB [ \-flip ]
 .RB [ \-playlist\ <filename> ]
+.RB [ \-slave ]
 .I - or file or device
 .PP
 .SH DESCRIPTION
@@ -246,6 +247,19 @@
 .TP
 .B \-playlist <file>
 play files according to this filelist (1 file/row).
+
+.TP
+.B \-slave
+This option switches on slave mode. This is intended for use
+of mplayer as a backend to other programs. Instead of intercepting keyboard
+events, mplayer will read simplistic command lines from its stdin.
+See section 
+.B SLAVE MODE PROTOCOL
+for the syntax.
+
+
+
+
 .IP
 .SH "ADVANCED OPTIONS"
 .TP
@@ -549,6 +563,20 @@
 
 7 or 8          adjust saturation
 
+.SH SLAVE MODE PROTOCOL
+If the -slave switch is given, playback is controlled by a 
+line-based protocol with the following tokens:
+.TP
+       stop            pause playback
+
+play            resume playback
+
+seek <NUM>      continue at second NUM
+
+skip <NUM>      skip NUM seconds (may be negative)
+
+quit            exit mplayer
+
 .IP
 .SH FILES AND DIRECTORIES
 .TP
--- a/cfg-mplayer.h	Tue Dec 04 20:41:00 2001 +0000
+++ b/cfg-mplayer.h	Tue Dec 04 21:04:28 2001 +0000
@@ -244,6 +244,8 @@
 	{"nodapsync", &dapsync, CONF_TYPE_FLAG, 0, 1, 0},
 	{"softsleep", &softsleep, CONF_TYPE_FLAG, 0, 0, 1},
 
+	{"slave", &slave_mode, CONF_TYPE_FLAG, 0, 0, 1},
+
 
 #define MAIN_CONF
 #include "cfg-common.h"
--- a/mplayer.c	Tue Dec 04 20:41:00 2001 +0000
+++ b/mplayer.c	Tue Dec 04 21:04:28 2001 +0000
@@ -73,6 +73,7 @@
 #include "Gui/mplayer/play.h"
 #endif
 
+int slave_mode=0;
 int verbose=0;
 int quiet=0;
 
@@ -1245,7 +1246,7 @@
 
 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
 
-if(!use_stdin){
+if(!use_stdin && !slave_mode){
   getch2_enable();  // prepare stdin for hotkeys...
   inited_flags|=INITED_GETCH2;
 }
@@ -1682,7 +1683,23 @@
 #endif
       if (audio_out && sh_audio)
          audio_out->pause();	// pause audio, keep data if possible
-         while(
+
+      if(slave_mode) {
+        fd_set set;
+        struct timeval timeout;
+        while (1) {
+          usec_sleep(1000);
+          FD_ZERO (&set);
+          FD_SET (STDIN_FILENO, &set);
+          timeout.tv_sec = 0;
+          timeout.tv_usec = 1000;
+          if(1==select(FD_SETSIZE, &set, NULL, NULL, &timeout)) {
+            break;
+          }
+        }
+      } else {
+
+        while(
 #ifdef HAVE_LIRC
              lirc_mp_getinput()<=0 &&
 #endif
@@ -1699,6 +1716,7 @@
 #endif
              if(use_stdin) usec_sleep(1000); // do not eat the CPU
          }
+      }
          osd_function=OSD_PLAY;
       if (audio_out && sh_audio)
         audio_out->resume();	// resume audio
@@ -1721,6 +1739,39 @@
 
 //================= Keyboard events, SEEKing ====================
 
+/* slave mode */ 
+ if(slave_mode) {
+   char buffer[1024];
+   fd_set set;
+   struct timeval timeout;
+   int arg;
+   
+   FD_ZERO (&set);
+   FD_SET (STDIN_FILENO, &set);
+   timeout.tv_sec = 0;
+   timeout.tv_usec = 1000;
+  
+   if(1 == select (FD_SETSIZE, &set, NULL, NULL, &timeout)) {
+     fgets(buffer, 1024, stdin);
+     if(!strcmp("play\n", buffer)) {
+       osd_function=OSD_PLAY;
+     } else if(!strcmp("stop\n", buffer)) {
+       osd_function=OSD_PAUSE;
+     } else if(!strncmp("seek ", buffer, 5)) {
+       sscanf(buffer+5, "%d", &arg);
+       rel_seek_secs = arg-d_video->pts;
+     } else if(!strncmp("skip ", buffer, 5)) {
+       sscanf(buffer+5, "%d", &arg);
+       rel_seek_secs = arg;
+     } else if(!strcmp("quit\n", buffer)) {
+       exit_player(MSGTR_Exit_quit);
+     } 
+   } else {
+     osd_function=OSD_PLAY;
+   }
+ } else
+ 
+/* interactive mode */
 { int c;
   while(
 #ifdef HAVE_LIRC