Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Patch: xawtv could control vdr ;-))



Hello,

here is an untested (I have no DVB-s card at work...) patch against
xawtv-3.75 to gain control over vdr using the keyboard.
But maybe it could interest some of the list ;-))
It would be great if it could go into xawtv...

The first patch:

--- begin Makefile.in patch ---

--- xawtv-3.75/Makefile.in	2002-06-19 17:13:15.000000000 +0200
+++ xawtv-3.75-vdr/Makefile.in	2002-06-27 18:25:36.000000000 +0200
@@ -66,6 +66,7 @@
 CFLAGS	+= -DCONFIGFILE='"$(config)"'
 CFLAGS	+= -DLIBDIR='"$(libdir)"'
 CFLAGS	+= -DVERSION='"$(VERSION)"'
+CFLAGS  += -DHAVE_VDR
 
 # shared objects need -fPIC
 %.so : CFLAGS += -fPIC

--- end Makefile.in patch ---

should be made for configure (in a way if it find vdr in the PATH
and/or with enable/disable...) but I don't know how...

The second one is for the key definition:

--- begin x11/Xawtv.ad patch ---

--- xawtv-3.75/x11/Xawtv.ad	2002-03-26 11:52:19.000000000 +0100
+++ xawtv-3.75-vdr/x11/Xawtv.ad	2002-06-28 14:07:29.000000000 +0200
@@ -180,7 +180,35 @@
 	<Key>KP_6:		Command(keypad,6)		\n\
 	<Key>KP_7:		Command(keypad,7)		\n\
 	<Key>KP_8:		Command(keypad,8)		\n\
-	<Key>KP_9:		Command(keypad,9)
+	<Key>KP_9:		Command(keypad,9)		\n\
+	<Key>Page_Up:		VDRKey(Up)			\n\
+	<Key>Page_Down:		VDRKey(Down)			\n\
+	<Key>M:			VDRKey(Menu)			\n\
+	<Key>KP_Enter:		VDRKey(Ok)			\n\
+	<Key>BackSpace:		VDRKey(Back)			\n\
+	<Key>Left:		VDRKey(Left)			\n\
+	<Key>Right:		VDRKey(Right)			\n\
+	<Key>F1:		VDRKey(Red)			\n\
+	<Key>F2:		VDRKey(Green)			\n\
+	<Key>F3:		VDRKey(Yellow)			\n\
+	<Key>F4:		VDRKey(Blue)			\n\
+	<Key>KP_0:		VDRKey(0)			\n\
+	<Key>KP_1:		VDRKey(1)			\n\
+	<Key>KP_2:		VDRKey(2)			\n\
+	<Key>KP_3:		VDRKey(3)			\n\
+	<Key>KP_4:		VDRKey(4)			\n\
+	<Key>KP_5:		VDRKey(5)			\n\
+	<Key>KP_6:		VDRKey(6)			\n\
+	<Key>KP_7:		VDRKey(7)			\n\
+	<Key>KP_8:		VDRKey(8)			\n\
+	<Key>KP_9:		VDRKey(9)			\n\
+	<Key>P:			VDRKey(Power)			\n\
+	<Key>KP_Add:		VDRKey(VolUp)			\n\
+	<Key>KP_Subtract:	VDRKey(VolDn)			\n\
+	Ctrl<Key>M:		VDRKey(Mute)			\n\
+	<Key>C:			VDRKey(Channels)		\n\
+	<Key>N:			VDRKey(None)
+	
 
 ! ----------------------------------------------------------------------------
 ! Options window

--- end x11/Xawtv.ad patch ---

If you change the files so, the normal keys definitions of xawtv are
used first and in case the new ones aren't already defined, they are
used (just comment the one you don't want with a "!" or put the vdr keys
before, I hadn't done it to make it easyer to include in xawtv...).

And the laste one is for x11/xawtv.c:

--- begin x11/xawtv.c patch ---

--- xawtv-3.75/x11/xawtv.c	2002-06-14 13:23:56.000000000 +0200
+++ xawtv-3.75-vdr/x11/xawtv.c	2002-06-28 15:40:42.000000000 +0200
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -210,6 +211,11 @@
 void ChannelAction(Widget, XEvent*, String*, Cardinal*);
 void StayOnTop(Widget, XEvent*, String*, Cardinal*);
 void PopupAction(Widget, XEvent*, String*, Cardinal*);
+#ifdef HAVE_VDR
+void VDRClosedConnectionHandler( int );
+void SetupVDRConnection( void );
+void VDRKey(Widget, XEvent*, String*, Cardinal* );
+#endif
 
 static XtActionsRec actionTable[] = {
     { "CloseMain",   CloseMainAction  },
@@ -228,6 +234,9 @@
 #ifdef HAVE_ZVBI
     { "Vtx",         VtxAction },
 #endif
+#ifdef HAVE_VDR
+    { "VDRKey",      VDRKey },
+#endif
 };
 
 static struct STRTAB cap_list[] = {
@@ -237,6 +246,123 @@
     {  -1, NULL,     },
 };
 
+/*--- VDR emulation of remote control -------------------------------------*/
+
+#ifdef HAVE_VDR
+static int vdr_sock = -1;
+static struct sockaddr_in vdr_sockaddr;
+
+void VDRClosedConnectionHandler( int signum )
+{
+    if (vdr_sock != -1)
+    {
+	close(vdr_sock);
+        vdr_sock = -1;
+    }
+}
+
+void SetupVDRConnection( void )
+{
+    int oldflags;
+    struct protoent *proto_ent;
+    char c;
+
+    signal(SIGPIPE, VDRClosedConnectionHandler);
+    
+    if (!(proto_ent=getprotobyname("TCP"))) {
+         perror( "xawtv-vdr" );
+         return;
+    }
+    if ((vdr_sock=socket(PF_INET, SOCK_STREAM, proto_ent->p_proto)) < 0) {
+         perror( "xawtv-vdr" );
+         return;
+    }
+    vdr_sockaddr.sin_family = PF_INET;
+    /* FIXME do not hardwire the port */
+    vdr_sockaddr.sin_port = htons( 2001 );
+    /* FIXME handle both loopback and normal ip */
+    vdr_sockaddr.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
+    if (connect(vdr_sock, (struct sockaddr *)&vdr_sockaddr,
+                sizeof(vdr_sockaddr))) {
+         perror( "xawtv-vdr" );
+         return;
+    }
+    /* make it non-blocking */
+    oldflags = fcntl(vdr_sock, F_GETFL, 0);
+    if (oldflags < 0) {
+        perror( "xawtv-vdr" );
+        return;
+    }
+    oldflags |= O_NONBLOCK;
+    if (fcntl(vdr_sock, F_SETFL, oldflags) < 0) {
+        perror( "xawtv-vdr" );
+        return;
+    }
+    /* skip the greeting message */
+    do {
+	c = '\0';
+        if (read(vdr_sock, &c, 1) < 0) {
+	    if( errno == EAGAIN )
+	        continue;
+	    perror( "xawtv-vdr" );
+            close(vdr_sock);
+	    vdr_sock = -1;
+	    break;
+        }
+    } while (c != '\n');
+}
+
+void VDRKey(Widget widget, XEvent *event,
+               String *params, Cardinal *num_params)
+{
+    int i;
+    char c;
+    
+    if (vdr_sock < 0)
+	SetupVDRConnection();
+    if (vdr_sock < 0)
+	return;
+    if (write(vdr_sock, "HITK ", 5) < 0) {
+        perror( "xawtv-vdr" );
+	close(vdr_sock);
+	vdr_sock = -1;
+	return;
+    }
+    for (i = 0; i < *num_params; i++) {
+	if (write(vdr_sock, params[i], strlen(params[i])) < 0) {
+            perror( "xawtv-vdr" );
+	    close(vdr_sock);
+	    vdr_sock = -1;
+	    return;
+	}
+	if (write(vdr_sock, " ", 1) < 0) {
+            perror( "xawtv-vdr" );
+	    close(vdr_sock);
+	    vdr_sock = -1;
+	    return;
+	}
+    }
+    if (write(vdr_sock, "\r\n", sizeof("\r\n")) < 0) {
+        perror( "xawtv-vdr" );
+	close(vdr_sock);
+	vdr_sock = -1;
+	return;
+    }
+    /* skip the answer */
+    do {
+	c = '\0';
+        if (read(vdr_sock, &c, 1) < 0) {
+	    if( errno == EAGAIN )
+	        continue;
+            perror( "xawtv-vdr" );
+	    close(vdr_sock);
+	    vdr_sock = -1;
+	    break;
+        }
+    } while (c != '\n');
+}
+#endif
+
 /*--- exit ----------------------------------------------------------------*/
 
 void
@@ -1802,6 +1928,11 @@
     signal(SIGHUP,SIG_IGN); /* don't really need a tty ... */
     XtAppMainLoop(app_context);
 
+#ifdef HAVE_VDR
+    if( vdr_sock >= 0 )
+        close(vdr_sock);
+#endif
+    
     /* keep compiler happy */
     return 0;
 }

--- end x11/xawtv.c patch ---

I'll test it tonight at home ;-))
Xawtv-3.75 could be found at http://bytesex.org/xawtv/

	Grégoire
________________________________________________________________
http://ulima.unil.ch/greg ICQ:16624071 mailto:greg@ulima.unil.ch




Home | Main Index | Thread Index