[MPlayer-cvslog] r24149 - in trunk: input/input.c mencoder.c osdep/getch2-win.c osdep/getch2.c osdep/getch2.h

uau subversion at mplayerhq.hu
Sat Aug 25 06:28:08 CEST 2007


Author: uau
Date: Sat Aug 25 06:28:08 2007
New Revision: 24149

Log:
Make terminal input work more like VO key input

The Unix version of getch2() could either return an internally buffered
key or do a second-level select() in addition to the input.c one and
then read more data. Change getch2() to always add all read keys with
mplayer_put_key() (like video output window keyboard input does) and
remove the internal select() from the Unix version. Make input.c call
mplayer_get_key() directly.

The primary motivation for this change is to make combining multiple
event sources under one select() easier. Now getch2() only needs to be
called when the corresponding fd is readable, and it will be possible to
handle events from X-based VOs with the same code.


Modified:
   trunk/input/input.c
   trunk/mencoder.c
   trunk/osdep/getch2-win.c
   trunk/osdep/getch2.c
   trunk/osdep/getch2.h

Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c	(original)
+++ trunk/input/input.c	Sat Aug 25 06:28:08 2007
@@ -17,6 +17,7 @@
 #ifdef MP_DEBUG
 #include <assert.h>
 #endif
+#include "mp_fifo.h"
 #include "osdep/getch2.h"
 #include "osdep/keycodes.h"
 #include "osdep/timer.h"
@@ -1061,15 +1062,14 @@ if(n>0){
     }
 #ifdef HAVE_POSIX_SELECT
     // No input from this fd
-    if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds)
-	&& key_fds[i].fd != 0)
+    if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds))
       continue;
 #endif
     if(key_fds[i].fd == 0) { // stdin is handled by getch2
-      code = getch2(time);
+      getch2();
+      code = mplayer_get_key(0);
       if(code < 0)
 	code = MP_INPUT_NOTHING;
-      did_sleep = 1;
     }
     else
       code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd);

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	(original)
+++ trunk/mencoder.c	Sat Aug 25 06:28:08 2007
@@ -225,6 +225,10 @@ int mp_input_check_interrupt(int time) {
   usec_sleep(time);
   return 0;
 }
+// Needed by getch2
+void mplayer_put_key(int code)
+{
+}
 
 #ifdef USE_ASS
 #include "libass/ass.h"

Modified: trunk/osdep/getch2-win.c
==============================================================================
--- trunk/osdep/getch2-win.c	(original)
+++ trunk/osdep/getch2-win.c	Sat Aug 25 06:28:08 2007
@@ -9,6 +9,7 @@
 #include <windows.h>
 #include "keycodes.h"
 #include "input/input.h"
+#include "mp_fifo.h"
 // HACK, stdin is used as something else below
 #undef stdin
 
@@ -34,13 +35,13 @@ void get_screen_size(){
 static HANDLE stdin;
 static int getch2_status=0;
 
-int getch2(int time){
+static int getch2_internal(void)
+{
 	INPUT_RECORD eventbuffer[128];
     DWORD retval;
    	int i=0;
     if(!getch2_status)return -1;    
     /*check if there are input events*/
-	WaitForSingleObject(stdin, time);
 	if(!GetNumberOfConsoleInputEvents(stdin,&retval))
 	{
 		printf("getch2: can't get number of input events: %i\n",GetLastError());
@@ -118,6 +119,12 @@ int getch2(int time){
 	return -1;
 }
 
+void getch2(void)
+{
+    int r = getch2_internal();
+    if (r >= 0)
+	mplayer_put_key(r);
+}
 
 void getch2_enable(){
 	DWORD retval;

Modified: trunk/osdep/getch2.c
==============================================================================
--- trunk/osdep/getch2.c	(original)
+++ trunk/osdep/getch2.c	Sat Aug 25 06:28:08 2007
@@ -35,6 +35,7 @@
 
 #include <unistd.h>
 
+#include "mp_fifo.h"
 #include "keycodes.h"
 
 #ifdef HAVE_TERMIOS
@@ -133,27 +134,19 @@ void get_screen_size(void){
 #endif
 }
 
-int getch2(int time){
+void getch2(void)
+{
   int len=0;
   int code=0;
   int i=0;
 
-  while(!getch2_len || (getch2_len==1 && getch2_buf[0]==27)){
-    fd_set rfds;
-    struct timeval tv;
     int retval;
-    /* Watch stdin (fd 0) to see when it has input. */
-    FD_ZERO(&rfds); FD_SET(0,&rfds);
-    /* Wait up to 'time' microseconds. */
-    tv.tv_sec=time/1000; tv.tv_usec = (time%1000)*1000;
-    retval=select(1, &rfds, NULL, NULL, &tv);
-    if(retval<=0) return -1;
-    /* Data is available now. */
     retval=read(0,&getch2_buf[getch2_len],BUF_LEN-getch2_len);
-    if(retval<1) return -1;
+    if (retval < 1)
+	return;
     getch2_len+=retval;
-  }
 
+    while (getch2_len > 0 && (getch2_len > 1 || getch2_buf[0] != 27)) {
     /* First find in the TERMCAP database: */
     for(i=0;i<getch2_key_db;i++){
       if((len=getch2_keys[i].len)<=getch2_len)
@@ -217,7 +210,8 @@ found:
     int i;
     for(i=0;i<getch2_len;i++) getch2_buf[i]=getch2_buf[len+i];
   }
-  return code;
+  mplayer_put_key(code);
+    }
 }
 
 static int getch2_status=0;

Modified: trunk/osdep/getch2.h
==============================================================================
--- trunk/osdep/getch2.h	(original)
+++ trunk/osdep/getch2.h	Sat Aug 25 06:28:08 2007
@@ -19,7 +19,7 @@ extern void getch2_enable(void);
 extern void getch2_disable(void);
 
 /* Read a character or a special key code (see keycodes.h) */
-extern int getch2(int halfdelay_time);
+extern void getch2(void);
 
 #ifdef __MINGW32__
 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);



More information about the MPlayer-cvslog mailing list