From 474a0e6223ad23dd5af8f9db37bf840df37510a7 Mon Sep 17 00:00:00 2001 From: arpi Date: Tue, 4 Dec 2001 21:04:28 +0000 Subject: [PATCH] -slave patch by Kilian A. Foth git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3323 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/mplayer.1 | 28 +++++++++++++++++++++++++ cfg-mplayer.h | 2 ++ mplayer.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/DOCS/mplayer.1 b/DOCS/mplayer.1 index 4a3630a7e7..413dcbaa84 100644 --- a/DOCS/mplayer.1 +++ b/DOCS/mplayer.1 @@ -81,6 +81,7 @@ mplayer \- Movie Player for Linux .RB [ \-bpp\ depth ] .RB [ \-flip ] .RB [ \-playlist\ ] +.RB [ \-slave ] .I - or file or device .PP .SH DESCRIPTION @@ -246,6 +247,19 @@ set aspect ratio of your screen. Examples: .TP .B \-playlist 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 @@ the DivX4 codec with -vc divx4) 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 continue at second NUM + +skip skip NUM seconds (may be negative) + +quit exit mplayer + .IP .SH FILES AND DIRECTORIES .TP diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 670616dec6..06d227a584 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -244,6 +244,8 @@ struct config conf[]={ {"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" diff --git a/mplayer.c b/mplayer.c index 5368856896..dbca05c518 100644 --- a/mplayer.c +++ b/mplayer.c @@ -73,6 +73,7 @@ extern void* mDisplay; // Display* mDisplay; #include "Gui/mplayer/play.h" #endif +int slave_mode=0; int verbose=0; int quiet=0; @@ -1245,7 +1246,7 @@ if(force_fps){ 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 @@ if(auto_quality>0){ #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 @@ if(auto_quality>0){ #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 @@ if(step_sec>0) { //================= 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