changeset 7:210d197c77f9

Tolerate LIRC going away.
author darius
date Sun, 21 Aug 2005 12:35:01 +0000
parents f0cbbe964629
children fc60aa65d85f
files simpletv.c
diffstat 1 files changed, 35 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/simpletv.c	Tue Jun 28 13:14:03 2005 +0000
+++ b/simpletv.c	Sun Aug 21 12:35:01 2005 +0000
@@ -84,8 +84,8 @@
 int		width = 320;
 int		height = 240;
 #else
-int		width = 640;
-int		height = 480;
+int		width = 720;
+int		height = 576;
 #endif
 
 #ifndef USE_XVIMAGES
@@ -112,7 +112,7 @@
 
 #define DO_IOCTL_GERR(str)     fprintf(stderr, "ioctl(%s) failed: %s\n", \
                                        str, strerror(errno) )
-#define DO_IOCTL_SERR(str,arg) fprintf(stderr, "ioctl(%s, %ld) failed: %s\n",\
+#define DO_IOCTL_SERR(str,arg) fprintf(stderr, "ioctl(%s, %ld) failed: %s\n", \
                                        str, (long)arg, strerror(errno) )
 /*--------------------------------------------------------------------------*/
 
@@ -148,6 +148,7 @@
 #ifdef USE_XVIMAGES
 	/* Should be YUV_12, but 422 actually gives a synced picture.  Though  */
 	geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
+	
 #else
 	geo.oformat = METEOR_GEO_RGB24;
 #endif
@@ -225,7 +226,7 @@
 	/* Use mmap to Map the drivers grab buffer */
 	buffer_size = width * height * 4;	/* R,G,B,spare */
 	bktr_buffer = (unsigned char *)mmap((caddr_t) 0, buffer_size, PROT_READ,
-	    MAP_SHARED, bktr_fd, (off_t) 0);
+					    MAP_SHARED, bktr_fd, (off_t) 0);
 
 	if (bktr_buffer == (unsigned char *)MAP_FAILED)
 		exit(1);
@@ -323,7 +324,7 @@
 	XEvent		xev;
 
 	assert(action == _NET_WM_STATE_REMOVE ||
-	    action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
+	       action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
 
 
 	/* init X event structure for _NET_WM_FULLSCREEN client msg */
@@ -341,8 +342,8 @@
 
 	/* finally send that damn thing */
 	if (!XSendEvent(disp, DefaultRootWindow(disp), False,
-	    SubstructureRedirectMask | SubstructureNotifyMask,
-	    &xev)) {
+			SubstructureRedirectMask | SubstructureNotifyMask,
+			&xev)) {
 		fprintf(stderr, "Failed to send fullscreen command\n");
 	}
 }
@@ -373,7 +374,7 @@
 	vinfo_pref.screen = scr;
 	vinfo_pref.visualid = XVisualIDFromVisual(vis);
 	vi = XGetVisualInfo(disp, VisualScreenMask | VisualIDMask,
-	    &vinfo_pref, &num_vis);
+			    &vinfo_pref, &num_vis);
 	assert(num_vis == 1);
 
 	win = XCreateSimpleWindow(disp, root, 0, 0, w, h, 0, 0, 0);
@@ -427,7 +428,7 @@
 	/* Create an image to captured frames  */
 #ifdef USE_XVIMAGES
 	yuv_image = XvShmCreateImage(disp, xv_adaptors[xv_adaptor].base_id,
-					       xv_format_id, 0, w, h, &shminfo);
+				     xv_format_id, 0, w, h, &shminfo);
 	if (!yuv_image)
 		fprintf(stderr, "X-Error: unable to create XvShm XImage\n");
 
@@ -443,8 +444,8 @@
 		fprintf(stderr, "X-Error: unable to create XShm XImage\n");
 
 	shminfo.shmid = shmget(IPC_PRIVATE,
-	    rgb_image->bytes_per_line * rgb_image->height,
-	    IPC_CREAT | 0777);
+			       rgb_image->bytes_per_line * rgb_image->height,
+			       IPC_CREAT | 0777);
 	if (shminfo.shmid == -1)
 		fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
 
@@ -503,11 +504,11 @@
 #ifdef USE_XVIMAGES
 	XGetGeometry(disp, win, &_dw, &_d, &_d, &_w, &_h, &_d, &_d);
 	XvShmPutImage(disp, xv_adaptors[xv_adaptor].base_id, win,
-	    gc, yuv_image, 0, 0, yuv_image->width, yuv_image->height,
-	    0, 0, _w, _h, True);
+		      gc, yuv_image, 0, 0, yuv_image->width, yuv_image->height,
+		      0, 0, _w, _h, True);
 #else
 	XShmPutImage(disp, win, gc, rgb_image, 0, 0, 0, 0,
-	    rgb_image->width, rgb_image->height, False);
+		     rgb_image->width, rgb_image->height, False);
 #endif
 	XSync(disp, False);
 }
@@ -532,9 +533,9 @@
 	HermesFormat	fmt_source, fmt_dest;
 #endif
 	XEvent		e;
-	char           *scratch_buf, *code, *c, *mixerdev;
-	int		frames    , channelidx, oldchan, mute, cursor, fd, ret, cmd;
-	int		exitnow   , mfd, uselirc, curvol;
+	char           	*scratch_buf, *code, *c, *mixerdev;
+	int		frames, channelidx, oldchan, mute, cursor, fd, ret, cmd;
+	int		exitnow, mfd, uselirc, curvol;
 	struct timeval	then, now, diff, lastmove;
 	float		rate;
 	KeySym		key;
@@ -542,7 +543,7 @@
 	int		channellist[] = {2, 7, 9, 10, 28};
 	struct lirc_config *config;
 	struct pollfd	fds[1];
-
+    
 #define NUMCHANS (sizeof(channellist) / sizeof(channellist[0]))
 
 	channelidx = mute = cursor = 0;
@@ -695,24 +696,29 @@
 				break;
 			}
 		}
+
 		/* Poll for IR events */
 		if (uselirc) {
 			fds[0].revents = 0;
 
 			while (1) {
+		
 				if (poll(fds, 1, 0) == -1) {
 					fprintf(stderr, "Poll failed - %s\n", strerror(errno));
 					exit(EXIT_FAILURE);
 				}
 				if ((fds[0].revents & POLLRDNORM) != 0) {
-					fprintf(stderr, "Processing IR..\n");
+					fprintf(stderr, "Processing IR.. \n", lircfails);
 
+					/* Try and get an event */
 					if (lirc_nextcode(&code) == 0) {
-						if (code == NULL)
+						if (code == NULL) {
 							continue;
-
+						}
+			
+						/* Translate it (via the config file) */
 						while ((ret = lirc_code2char(config, code, &c)) == 0 &&
-						    c != NULL) {
+						       c != NULL) {
 							fprintf(stderr, "Got command \"%s\"\n", c);
 
 							if (!strcmp(c, "Mute"))
@@ -729,9 +735,13 @@
 								cmd = CMD_VOLDN;
 							else if (!strcmp(c, "AV/TV"))
 								cmd = CMD_FSTOGGLE;
-
+			    
 							free(code);
 						}
+					} else {
+						/* lircd probably died */
+						uselirc = 0;
+						fprintf(stderr, "Failed to communicate with LIRC - daemon exited?");
 					}
 				} else
 					break;
@@ -853,8 +863,8 @@
 
 		Hermes_ConverterRequest(conv, &fmt_source, &fmt_dest);
 		Hermes_ConverterCopy(conv, bktr_buffer, 0, 0, width, height, width * 4,
-		    rgb_image->data, 0, 0, width, height,
-		    rgb_image->bytes_per_line);
+				     rgb_image->data, 0, 0, width, height,
+				     rgb_image->bytes_per_line);
 #endif
 
 		X_Display();