[xiph-cvs] cvs commit: snatch libsnatch.c snatch.pl x11.c
Monty
xiphmont at xiph.org
Sat Nov 3 02:02:23 PST 2001
xiphmont 01/11/03 02:02:23
Modified: . libsnatch.c snatch.pl x11.c
Log:
Added backchannel, synthetic events
Revision Changes Path
1.2 +48 -25 snatch/libsnatch.c
Index: libsnatch.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/libsnatch.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- libsnatch.c 2001/11/02 23:10:28 1.1
+++ libsnatch.c 2001/11/03 10:02:22 1.2
@@ -4,6 +4,7 @@
#define _GNU_SOURCE
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
+#define _REENTRANT
#include <stdlib.h>
#include <unistd.h>
@@ -20,6 +21,7 @@
#include <stdarg.h>
#include <linux/soundcard.h>
#include <pthread.h>
+#include <X11/Xlib.h>
static int (*libc_open)(const char *,int,mode_t);
static int (*libc_connect)(int sockfd, const struct sockaddr *serv_addr,
@@ -32,9 +34,8 @@
static int (*libc_ioctl)(int,int,void *);
static pid_t (*libc_fork)(void);
-/* of the members of the poll family, RP only uses select */
-static int (*libc_select)(int,fd_set *,fd_set *,fd_set *,
- struct timeval *timeout);
+static Display *(*xlib_xopen)(const char *);
+static Display *Xdisplay;
static int debug;
static char *outpath;
@@ -54,6 +55,10 @@
static pthread_t snatch_backchannel_thread;
+static char username[256];
+static char password[256];
+static int snatch_active=1;
+
#include "x11.c" /* yeah, ugly, but I don't want to leak symbols.
Oh and I'm lazy. */
@@ -86,8 +91,8 @@
if(ret==NULL){
char *dlerr=dlerror();
fprintf(stderr,
- "**ERROR: libsnatch.so could not find the function '%s()'\n"
- " in libc. This shouldn't happen and I'm not going to\n"
+ "**ERROR: libsnatch.so could not find the function '%s()'.\n"
+ " This shouldn't happen and I'm not going to\n"
" make any wild guesses as to what caused it. The\n"
" error returned by dlsym() was:\n %s",
symbol,(dlerr?dlerr:"no such symbol"));
@@ -106,8 +111,9 @@
(unsigned long)pthread_self());
while(1){
- char length;
- size_t bytes=fread(&length,1,1,backchannel_fd);
+ char rq;
+ char buffer[256];
+ size_t bytes=fread(&rq,1,1,backchannel_fd);
if(bytes<=0){
fprintf(stderr,"**ERROR: Backchannel lost! exit(1)ing...\n");
@@ -116,6 +122,33 @@
if(debug)
fprintf(stderr," ...: Backchannel request\n");
+
+ switch(rq){
+ case 'K':
+ bytes=fread(buffer,1,256,backchannel_fd);
+ FakeKeycode(buffer[0],buffer[1],buffer[2],rpplay_window);
+ break;
+ case 'U':
+ fread(username,1,256,backchannel_fd);
+ break;
+ case 'P':
+ fread(password,1,256,backchannel_fd);
+ break;
+ case 'A':
+ snatch_active=1;
+ FakeExposeRPPlay();
+ break;
+ case 'I':
+ snatch_active=0;
+ FakeExposeRPPlay();
+ break;
+ case 'S':
+ FakeKeycode(9,0,1,rpplay_window);
+ break;
+ case 'G':
+ FakeKeycode(43,0,1,rpplay_window);
+ break;
+ }
}
}
@@ -138,7 +171,7 @@
libc_connect=get_me_symbol("connect");
libc_ioctl=get_me_symbol("ioctl");
libc_fork=get_me_symbol("fork");
- libc_select=get_me_symbol("select");
+ xlib_xopen=get_me_symbol("XOpenDisplay");
/* output path? */
outpath=getenv("SNATCH_OUTPUT_PATH");
@@ -524,22 +557,12 @@
return((*libc_ioctl)(fd,rq,arg));
}
-int select(int n, fd_set *readfds, fd_set *writefds,
- fd_set *exceptfds, struct timeval *timeout){
- int ret;
-
- ret=(*libc_select)(n,readfds,writefds,exceptfds,timeout);
-
- /* it turns out that RealPlayer busywaits using select [jeez], so we
- don't need to do any extra work to wake it up to send our own
- events. However, just in case, if we're called with a large
- timeout, shave it down a bit. */
- /* do we have a pending synthetic event? */
-
- /* is one of the read fds our X socket? */
-
- return (*libc_select)(n,readfds,writefds,exceptfds,timeout);
-
+Display *XOpenDisplay(const char *d){
+ if(!XInitThreads()){
+ fprintf(stderr,"**ERROR: Unable to set multithreading support in Xlib.\n"
+ " exit(1)ing...\n\n");
+ exit(1);
+ }
+ return(Xdisplay=(*xlib_xopen)(d));
}
-
1.2 +2 -0 snatch/snatch.pl
Index: snatch.pl
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatch.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- snatch.pl 2001/11/02 23:10:28 1.1
+++ snatch.pl 2001/11/03 10:02:22 1.2
@@ -16,6 +16,8 @@
die $! unless listen(LISTEN_SOCK,SOMAXCONN);
die $! unless accept(COMM_SOCK,LISTEN_SOCK);
+undef $/;
+
while(1){
$char=getc STDIN;
syswrite COMM_SOCK,$char,1;
1.2 +122 -61 snatch/x11.c
Index: x11.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/x11.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- x11.c 2001/11/02 23:10:28 1.1
+++ x11.c 2001/11/03 10:02:22 1.2
@@ -4,12 +4,14 @@
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
+#include <X11/Xlib.h>
#include "snatchppm.h"
static int savefile=-1;
static unsigned long window_id_base=0;
static unsigned long window_id_mask=0;
+static unsigned long root_window=0;
static unsigned long rpshell_window=0;
static unsigned long rpmain_window=0;
static unsigned long rpmenu_window=0;
@@ -74,6 +76,8 @@
unsigned long parent=ILong(&buf[8]);
if((id & ~window_id_mask) == window_id_base){
+ if(!root_window)
+ root_window=parent;
if(parent==rpshell_window){
rpmain_window=id;
@@ -154,7 +158,7 @@
if(n>26 && !memcmp(data,"RealPlayer\0RCACoreAppShell\0",27)){
/* it's our shell window above the WM parent */
rpshell_window=id;
-
+
/* re-setup */
rpmain_window=0;
rpmenu_window=0;
@@ -183,7 +187,7 @@
static void PutImage(unsigned char *buf){
int id=ILong(&buf[4]);
- if(id==rpvideo_window){
+ if(snatch_active && id==rpvideo_window){
int width=IShort(&buf[12])+IByte(&buf[20]);
int height=IShort(&buf[14]);
int n = width*height*4,i,j;
@@ -303,61 +307,63 @@
}
/* blank background */
- if(bigendian_p){
- int lower=(play_blacklower==-1?y+height:play_blacklower);
- for(i=play_blackupper;i<lower;i++)
- if(i>=y && i<y+height)
- for(j=play_blackleft;j<play_blackright;j++)
- if(j>=x && j<x+width){
- ptr[(i-y)*width*4+(j-x)*4]=0x00;
- ptr[(i-y)*width*4+(j-x)*4+1]=snatchppm[0];
- ptr[(i-y)*width*4+(j-x)*4+2]=snatchppm[1];
- ptr[(i-y)*width*4+(j-x)*4+3]=snatchppm[2];
- }
- }else{
- int lower=(play_blacklower==-1?y+height:play_blacklower);
- for(i=play_blackupper;i<lower;i++)
- if(i>=y && i<y+height)
- for(j=play_blackleft;j<play_blackright;j++)
- if(j>=x && j<x+width){
- ptr[(i-y)*width*4+(j-x)*4+3]=0x00;
- ptr[(i-y)*width*4+(j-x)*4+2]=snatchppm[0];
+ if(snatch_active){
+ if(bigendian_p){
+ int lower=(play_blacklower==-1?y+height:play_blacklower);
+ for(i=play_blackupper;i<lower;i++)
+ if(i>=y && i<y+height)
+ for(j=play_blackleft;j<play_blackright;j++)
+ if(j>=x && j<x+width){
+ ptr[(i-y)*width*4+(j-x)*4]=0x00;
+ ptr[(i-y)*width*4+(j-x)*4+1]=snatchppm[0];
+ ptr[(i-y)*width*4+(j-x)*4+2]=snatchppm[1];
+ ptr[(i-y)*width*4+(j-x)*4+3]=snatchppm[2];
+ }
+ }else{
+ int lower=(play_blacklower==-1?y+height:play_blacklower);
+ for(i=play_blackupper;i<lower;i++)
+ if(i>=y && i<y+height)
+ for(j=play_blackleft;j<play_blackright;j++)
+ if(j>=x && j<x+width){
+ ptr[(i-y)*width*4+(j-x)*4+3]=0x00;
+ ptr[(i-y)*width*4+(j-x)*4+2]=snatchppm[0];
ptr[(i-y)*width*4+(j-x)*4+1]=snatchppm[1];
ptr[(i-y)*width*4+(j-x)*4]=snatchppm[2];
- }
- }
-
- /* paint logo */
- if(logo_y!=-1){
- for(i=0;i<snatchheight;i++){
- if(i+logo_y>=y && i+logo_y<height+y){
- char *snatch=snatchppm+snatchwidth*3*i;
- char *real;
- long end;
-
- k=x-logo_x;
- if(k<0)k=0;
- end=x+snatchwidth-logo_x;
- j=(logo_x-x)*4;
- if(j<0)j=0;
-
- real=ptr+width*4*(i+logo_y-y);
- snatch=snatchppm+snatchwidth*3*i;
-
- if(bigendian_p){
- for(k*=3;k<snatchwidth*3 && j<width*4;){
- real[++j]=snatch[k++];
- real[++j]=snatch[k++];
- real[++j]=snatch[k++];
- ++j;
- }
+ }
+ }
+
+ /* paint logo */
+ if(logo_y!=-1){
+ for(i=0;i<snatchheight;i++){
+ if(i+logo_y>=y && i+logo_y<height+y){
+ char *snatch=snatchppm+snatchwidth*3*i;
+ char *real;
+ long end;
+
+ k=x-logo_x;
+ if(k<0)k=0;
+ end=x+snatchwidth-logo_x;
+ j=(logo_x-x)*4;
+ if(j<0)j=0;
+ real=ptr+width*4*(i+logo_y-y);
+ snatch=snatchppm+snatchwidth*3*i;
- }else{
- for(k*=3;k<snatchwidth*3 && j<width*4;j+=4){
- real[j+2]=snatch[k++];
- real[j+1]=snatch[k++];
- real[j]=snatch[k++];
+ if(bigendian_p){
+ for(k*=3;k<snatchwidth*3 && j<width*4;){
+ real[++j]=snatch[k++];
+ real[++j]=snatch[k++];
+ real[++j]=snatch[k++];
+ ++j;
+ }
+
+
+ }else{
+ for(k*=3;k<snatchwidth*3 && j<width*4;j+=4){
+ real[j+2]=snatch[k++];
+ real[j+1]=snatch[k++];
+ real[j]=snatch[k++];
+ }
}
}
}
@@ -401,14 +407,17 @@
long togo=n;
unsigned char *p=buf;
- while(togo>0){
- int bw=(*libc_write)(X_fd,p,togo);
- if(bw<0 && (errno==EAGAIN || errno==EINTR))bw=0;
- if(bw>=0)
- p+=bw;
- else
- return(bw);
- togo-=bw;
+ if(n){
+ while(togo>0){
+ int bw=(*libc_write)(X_fd,p,togo);
+ if(bw<0 && (errno==EAGAIN || errno==EINTR))bw=0;
+ if(bw>=0)
+ p+=bw;
+ else{
+ return(bw);
+ }
+ togo-=bw;
+ }
}
return(0);
}
@@ -583,4 +592,56 @@
return;
}
+static void FakeKeycode(int keycode, int shift, int ctrl,
+ unsigned long window){
+ XKeyEvent event;
+ memset(&event,0,sizeof(event));
+
+ event.display=Xdisplay;
+ event.type=2; /* key down */
+ event.keycode=keycode;
+ event.root=root_window;
+ event.window=window;
+ event.state=(shift?1:0)|(ctrl?4:0);
+
+ XSendEvent(Xdisplay,(Window)window,0,0,(XEvent *)&event);
+
+ event.type=3; /* key up */
+
+ XSendEvent(Xdisplay,(Window)window,0,0,(XEvent *)&event);
+
+}
+
+void FakeButton1(unsigned long window){
+
+ XButtonEvent event;
+ memset(&event,0,sizeof(event));
+
+ event.display=Xdisplay;
+ event.type=4; /* key down */
+ event.button=1;
+ event.root=root_window;
+ event.window=window;
+
+ XSendEvent(Xdisplay,(Window)window,0,0,(XEvent *)&event);
+
+ event.type=5; /* key up */
+ event.state=0x100;
+
+ XSendEvent(Xdisplay,(Window)window,0,0,(XEvent *)&event);
+
+}
+
+void FakeExposeRPPlay(void){
+ XExposeEvent event;
+ memset(&event,0,sizeof(event));
+
+ event.display=Xdisplay;
+ event.type=12;
+ event.window=rpplay_window;
+ event.width=rpplay_width;
+ event.height=rpplay_height;
+
+ XSendEvent(Xdisplay,(Window)rpplay_window,0,0,(XEvent *)&event);
+}
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list