annotate simpletv.c @ 9:ef818ccd826f default tip

Oops, delete reference to variable no longer really used.
author darius
date Sun, 21 Aug 2005 12:36:14 +0000
parents fc60aa65d85f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
1 /* Capture and store a 24 bit RGB image as a PPM file */
769b155a34f9 Initial revision
darius
parents:
diff changeset
2 /* Copyright (c) 2000 Randall Hopper
769b155a34f9 Initial revision
darius
parents:
diff changeset
3 *
769b155a34f9 Initial revision
darius
parents:
diff changeset
4 * Based on a grab.c from Roger Hardiman, which was
769b155a34f9 Initial revision
darius
parents:
diff changeset
5 * based on an original program by Mark Tinguely and Jim Lowe .
769b155a34f9 Initial revision
darius
parents:
diff changeset
6 *
769b155a34f9 Initial revision
darius
parents:
diff changeset
7 * All rights reserved.
769b155a34f9 Initial revision
darius
parents:
diff changeset
8 *
769b155a34f9 Initial revision
darius
parents:
diff changeset
9 * Redistribution and use in source and binary forms, with or without
769b155a34f9 Initial revision
darius
parents:
diff changeset
10 * modification, are permitted provided that the following conditions
769b155a34f9 Initial revision
darius
parents:
diff changeset
11 * are met:
769b155a34f9 Initial revision
darius
parents:
diff changeset
12 * 1. Redistributions of source code must retain the above copyright
769b155a34f9 Initial revision
darius
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
769b155a34f9 Initial revision
darius
parents:
diff changeset
14 * 2. Redistributions in binary form must reproduce the above copyright
769b155a34f9 Initial revision
darius
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in the
769b155a34f9 Initial revision
darius
parents:
diff changeset
16 * documentation and/or other materials provided with the distribution.
769b155a34f9 Initial revision
darius
parents:
diff changeset
17 * 3. All advertising materials mentioning features or use of this software
769b155a34f9 Initial revision
darius
parents:
diff changeset
18 * must display the following acknowledgement:
769b155a34f9 Initial revision
darius
parents:
diff changeset
19 * This product includes software developed by Mark Tinguely and Jim Lowe
769b155a34f9 Initial revision
darius
parents:
diff changeset
20 * 4. The name of the author may not be used to endorse or promote products
769b155a34f9 Initial revision
darius
parents:
diff changeset
21 * derived from this software without specific prior written permission.
769b155a34f9 Initial revision
darius
parents:
diff changeset
22 *
769b155a34f9 Initial revision
darius
parents:
diff changeset
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
769b155a34f9 Initial revision
darius
parents:
diff changeset
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
769b155a34f9 Initial revision
darius
parents:
diff changeset
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
769b155a34f9 Initial revision
darius
parents:
diff changeset
26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
769b155a34f9 Initial revision
darius
parents:
diff changeset
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
769b155a34f9 Initial revision
darius
parents:
diff changeset
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
769b155a34f9 Initial revision
darius
parents:
diff changeset
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
769b155a34f9 Initial revision
darius
parents:
diff changeset
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
769b155a34f9 Initial revision
darius
parents:
diff changeset
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
769b155a34f9 Initial revision
darius
parents:
diff changeset
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
769b155a34f9 Initial revision
darius
parents:
diff changeset
33 * POSSIBILITY OF SUCH DAMAGE.
769b155a34f9 Initial revision
darius
parents:
diff changeset
34 */
769b155a34f9 Initial revision
darius
parents:
diff changeset
35
769b155a34f9 Initial revision
darius
parents:
diff changeset
36 #include <assert.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
37 #include <stdio.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
38 #include <unistd.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
39 #include <string.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
40 #include <stdlib.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
41 #include <errno.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
42 #include <sys/types.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
43 #include <poll.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
44 #include <sys/mman.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
45 #include <sys/fcntl.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
46 #include <sys/time.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
47 #include <libgen.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
48 #include <sys/soundcard.h>
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
49 #include <dev/bktr/ioctl_bt848.h>
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
50 #include <dev/bktr/ioctl_meteor.h>
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
51 #include <machine/param.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
52 #include <sys/types.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
53 #include <sys/ipc.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
54 #include <sys/shm.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
55 #include <X11/Xlib.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
56 #include <X11/Xutil.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
57 #include <X11/extensions/XShm.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
58 #include <X11/extensions/Xvlib.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
59 #ifndef USE_XVIMAGES
769b155a34f9 Initial revision
darius
parents:
diff changeset
60 #include "Hermes/Hermes.h"
769b155a34f9 Initial revision
darius
parents:
diff changeset
61 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
62
769b155a34f9 Initial revision
darius
parents:
diff changeset
63 #include <lirc/lirc_client.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
64
769b155a34f9 Initial revision
darius
parents:
diff changeset
65 /* Some BT848/BT878 cards have gain control hardware which takes
769b155a34f9 Initial revision
darius
parents:
diff changeset
66 1 or 2 seconds to settle. If you get a washed out / too bright
769b155a34f9 Initial revision
darius
parents:
diff changeset
67 image, change the GRABBER_SETTLE_TIME from 0 to either 1 or 2
769b155a34f9 Initial revision
darius
parents:
diff changeset
68 */
769b155a34f9 Initial revision
darius
parents:
diff changeset
69 /*#define GRABBER_SETTLE_TIME 10*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
70 #define GRABBER_SETTLE_TIME 0
769b155a34f9 Initial revision
darius
parents:
diff changeset
71
769b155a34f9 Initial revision
darius
parents:
diff changeset
72
769b155a34f9 Initial revision
darius
parents:
diff changeset
73 #define PAL 1
769b155a34f9 Initial revision
darius
parents:
diff changeset
74 #define NTSC 2
769b155a34f9 Initial revision
darius
parents:
diff changeset
75
769b155a34f9 Initial revision
darius
parents:
diff changeset
76 /* PAL is 768 x 576. NTSC is 640 x 480 */
769b155a34f9 Initial revision
darius
parents:
diff changeset
77 #define PAL_HEIGHT 576
769b155a34f9 Initial revision
darius
parents:
diff changeset
78 #define NTSC_HEIGHT 480
769b155a34f9 Initial revision
darius
parents:
diff changeset
79
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
80 int bktr_fd;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
81 int tuner_fd;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
82 unsigned char *bktr_buffer;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
83 #if 1
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
84 int width = 320;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
85 int height = 240;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
86 #else
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
87 int width = 720;
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
88 int height = 576;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
89 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
90
769b155a34f9 Initial revision
darius
parents:
diff changeset
91 #ifndef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
92 static XImage *rgb_image;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
93 static Pixmap pmap;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
94 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
95 static XShmSegmentInfo shminfo;
769b155a34f9 Initial revision
darius
parents:
diff changeset
96 static Display *disp;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
97 static Window win;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
98 static Visual *vis;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
99 static int scr;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
100 static GC gc;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
101 static int depth;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
102 static Colormap cmap;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
103 static XVisualInfo *vi;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
104 static int bits_per_pixel;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
105 static XvImage *yuv_image;
769b155a34f9 Initial revision
darius
parents:
diff changeset
106 static XvAdaptorInfo *xv_adaptors;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
107 static int xv_num_adaptors;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
108 static int xv_adaptor;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
109 static int xv_format_id;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
110
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
111 static int channel;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
112
769b155a34f9 Initial revision
darius
parents:
diff changeset
113 #define DO_IOCTL_GERR(str) fprintf(stderr, "ioctl(%s) failed: %s\n", \
769b155a34f9 Initial revision
darius
parents:
diff changeset
114 str, strerror(errno) )
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
115 #define DO_IOCTL_SERR(str,arg) fprintf(stderr, "ioctl(%s, %ld) failed: %s\n", \
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
116 str, (long)arg, strerror(errno) )
769b155a34f9 Initial revision
darius
parents:
diff changeset
117 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
118
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
119 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
120 Close() {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
121 close(tuner_fd);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
122 close(bktr_fd);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
123 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
124
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
125 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
126 Open() {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
127 struct meteor_geomet geo;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
128 int buffer_size, format, source, c;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
129 char *device_name;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
130
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
131 format = PAL; /* default value */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
132 source = 1; /* default value */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
133 device_name = "/dev/bktr0"; /* default value */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
134
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
135 /* Open the Meteor or Bt848/Bt878 grabber */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
136 if ((bktr_fd = open(device_name, O_RDONLY)) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
137 printf("open failed: %d\n", errno);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
138 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
139 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
140 if ((tuner_fd = open("/dev/tuner0", O_RDONLY)) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
141 printf("open failed: %d\n", errno);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
142 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
143 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
144 /* set up the capture type and size */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
145 geo.rows = height;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
146 geo.columns = width;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
147 geo.frames = 1;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
148 #ifdef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
149 /* Should be YUV_12, but 422 actually gives a synced picture. Though */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
150 geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
151
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
152 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
153 geo.oformat = METEOR_GEO_RGB24;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
154 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
155
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
156 /* switch from interlaced capture to single field capture if */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
157 /* the grab height is less than half the normal TV height */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
158 /* this gives better quality captures when the object in the TV */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
159 /* picture is moving */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
160 if ((format == PAL) && (height <= (PAL_HEIGHT / 2)))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
161 geo.oformat |= METEOR_GEO_ODD_ONLY;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
162 if ((format == NTSC) && (height <= (NTSC_HEIGHT / 2)))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
163 geo.oformat |= METEOR_GEO_ODD_ONLY;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
164
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
165 if (ioctl(bktr_fd, METEORSETGEO, &geo) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
166 printf("METEORSETGEO ioctl failed: %d\n", errno);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
167 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
168 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
169 /* Select PAL or NTSC */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
170 switch (format) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
171 case PAL:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
172 c = METEOR_FMT_PAL;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
173 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
174 case NTSC:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
175 c = METEOR_FMT_NTSC;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
176 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
177 default:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
178 c = METEOR_FMT_NTSC;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
179 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
180 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
181
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
182 c = BT848_IFORM_F_PALBDGHI;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
183 if (ioctl(bktr_fd, BT848SFMT, &c) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
184 DO_IOCTL_SERR("BT848SFMT", c);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
185 return;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
186 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
187 c = AUDIO_TUNER;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
188 if (ioctl(tuner_fd, BT848_SAUDIO, &c) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
189 DO_IOCTL_SERR("BT848SFMT", c);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
190 return;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
191 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
192 c = CHNLSET_AUSTRALIA;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
193 if (ioctl(tuner_fd, TVTUNER_SETTYPE, &c) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
194 DO_IOCTL_SERR("TVTUNER_SETTYPE", c);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
195 return;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
196 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
197 if (ioctl(tuner_fd, TVTUNER_SETCHNL, &channel) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
198 DO_IOCTL_SERR("TVTUNER_SETCHNL", channel);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
199 return;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
200 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
201 /* Select the Video Source */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
202 /* Video In, Tuner, S-Video */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
203 switch (source) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
204 case 0:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
205 c = METEOR_INPUT_DEV0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
206 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
207 case 1:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
208 c = METEOR_INPUT_DEV1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
209 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
210 case 2:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
211 c = METEOR_INPUT_DEV2;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
212 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
213 case 3:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
214 c = METEOR_INPUT_DEV3;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
215 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
216 default:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
217 c = METEOR_INPUT_DEV0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
218 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
219 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
220
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
221 printf("Input - %x\n", c);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
222 if (ioctl(bktr_fd, METEORSINPUT, &c) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
223 printf("ioctl failed: %d\n", errno);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
224 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
225 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
226 /* Use mmap to Map the drivers grab buffer */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
227 buffer_size = width * height * 4; /* R,G,B,spare */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
228 bktr_buffer = (unsigned char *)mmap((caddr_t) 0, buffer_size, PROT_READ,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
229 MAP_SHARED, bktr_fd, (off_t) 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
230
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
231 if (bktr_buffer == (unsigned char *)MAP_FAILED)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
232 exit(1);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
233
769b155a34f9 Initial revision
darius
parents:
diff changeset
234
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
235 /* We may need to wait for a short time to allow the grabber */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
236 /* brightness to settle down */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
237 sleep(GRABBER_SETTLE_TIME);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
238 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
239
769b155a34f9 Initial revision
darius
parents:
diff changeset
240 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
241
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
242 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
243 Capture() {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
244 int c;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
245
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
246 /* Perform a single frame capture */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
247 c = METEOR_CAP_SINGLE;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
248 ioctl(bktr_fd, METEORCAPTUR, &c);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
249 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
250
769b155a34f9 Initial revision
darius
parents:
diff changeset
251 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
252
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
253 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
254 SaveImage() {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
255 unsigned char *line_buffer;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
256 int o , w, h;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
257 unsigned char *p;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
258 unsigned char header[30];
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
259 char *filename = "t.ppm" /* argv[3] */ ;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
260
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
261 /* Create the output file */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
262 if ((o = open(filename, O_WRONLY | O_CREAT, 0644)) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
263 printf("ppm open failed: %d\n", errno);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
264 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
265 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
266 /* make PPM header and save to file */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
267 sprintf(header, "P6\n%d\n%d\n255\n", width, height);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
268 write(o, header, strlen(header));
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
269
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
270 /* save the RGB data to PPM file */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
271 /* save this one line at a time */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
272 line_buffer = (unsigned char *)malloc(width * 3 * sizeof(unsigned char));
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
273 p = bktr_buffer;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
274 for (h = 0; h < height; h++) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
275 for (w = 0; w < width; w++) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
276 line_buffer[(w * 3) + 2] = *p++; /* blue */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
277 line_buffer[(w * 3) + 1] = *p++; /* green */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
278 line_buffer[(w * 3) + 0] = *p++; /* red */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
279 p++; /* NULL byte */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
280 }
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
281 write(o, line_buffer, width * 3);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
282 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
283 close(o);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
284 free(line_buffer);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
285 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
286
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
287 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
288 X_ShowCursor(void) {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
289 XDefineCursor(disp, win, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
290 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
291
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
292 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
293 X_HideCursor(void) {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
294 Cursor no_ptr;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
295 Pixmap bm_no;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
296 XColor black , dummy;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
297 Colormap colormap;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
298 static unsigned char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
299
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
300 colormap = DefaultColormap(disp, DefaultScreen(disp));
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
301 XAllocNamedColor(disp, colormap, "black", &black, &dummy);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
302 bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
303 no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
304
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
305 XDefineCursor(disp, win, no_ptr);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
306 XFreeCursor(disp, no_ptr);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
307 if (bm_no != None)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
308 XFreePixmap(disp, bm_no);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
309
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
310 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
311
769b155a34f9 Initial revision
darius
parents:
diff changeset
312 /*
769b155a34f9 Initial revision
darius
parents:
diff changeset
313 * Sends the EWMH fullscreen state event.
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
314 *
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
315 * action: could be on of _NET_WM_STATE_REMOVE -- remove state
769b155a34f9 Initial revision
darius
parents:
diff changeset
316 * _NET_WM_STATE_ADD -- add state
769b155a34f9 Initial revision
darius
parents:
diff changeset
317 * _NET_WM_STATE_TOGGLE -- toggle
769b155a34f9 Initial revision
darius
parents:
diff changeset
318 */
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
319 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
320 #define _NET_WM_STATE_ADD 1 /* add/set property */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
321 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
322 void
769b155a34f9 Initial revision
darius
parents:
diff changeset
323 vo_x11_ewmh_fullscreen(int action) {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
324 XEvent xev;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
325
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
326 assert(action == _NET_WM_STATE_REMOVE ||
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
327 action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
328
769b155a34f9 Initial revision
darius
parents:
diff changeset
329
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
330 /* init X event structure for _NET_WM_FULLSCREEN client msg */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
331 xev.xclient.type = ClientMessage;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
332 xev.xclient.serial = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
333 xev.xclient.send_event = True;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
334 xev.xclient.message_type = XInternAtom(disp, "_NET_WM_STATE", False);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
335 xev.xclient.window = win;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
336 xev.xclient.format = 32;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
337 xev.xclient.data.l[0] = action;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
338 xev.xclient.data.l[1] = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
339 xev.xclient.data.l[2] = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
340 xev.xclient.data.l[3] = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
341 xev.xclient.data.l[4] = 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
342
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
343 /* finally send that damn thing */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
344 if (!XSendEvent(disp, DefaultRootWindow(disp), False,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
345 SubstructureRedirectMask | SubstructureNotifyMask,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
346 &xev)) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
347 fprintf(stderr, "Failed to send fullscreen command\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
348 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
349 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
350
769b155a34f9 Initial revision
darius
parents:
diff changeset
351
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
352 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
353 X_Setup(int w, int h) {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
354 XGCValues gcvals;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
355 Window root;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
356 XVisualInfo vinfo_pref;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
357 int num_vis;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
358 XPixmapFormatValues *pf;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
359 int num_pf , pfi, i, j;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
360 XSizeHints sz_hint;
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
361
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
362 disp = XOpenDisplay(NULL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
363 if (!disp) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
364 fprintf(stderr, "X-Error: unable to connect to display\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
365 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
366 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
367 XSynchronize(disp, True);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
368
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
369 scr = DefaultScreen(disp);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
370 vis = DefaultVisual(disp, scr);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
371 root = DefaultRootWindow(disp);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
372 depth = DefaultDepth(disp, scr);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
373
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
374 vinfo_pref.screen = scr;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
375 vinfo_pref.visualid = XVisualIDFromVisual(vis);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
376 vi = XGetVisualInfo(disp, VisualScreenMask | VisualIDMask,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
377 &vinfo_pref, &num_vis);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
378 assert(num_vis == 1);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
379
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
380 win = XCreateSimpleWindow(disp, root, 0, 0, w, h, 0, 0, 0);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
381 gc = XCreateGC(disp, win, (unsigned long)0, &gcvals);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
382 XSetForeground(disp, gc, 0);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
383 XSetBackground(disp, gc, 1);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
384
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
385 XMapWindow(disp, win);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
386 cmap = DefaultColormap(disp, scr);
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
387
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
388 sz_hint.flags = PAspect;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
389 sz_hint.min_aspect.x = width;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
390 sz_hint.min_aspect.y = height;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
391 sz_hint.max_aspect.x = width;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
392 sz_hint.max_aspect.y = height;
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
393
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
394 /* set min height/width to 4 to avoid off by one errors */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
395 sz_hint.min_width = sz_hint.min_height = 4;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
396 sz_hint.flags |= PMinSize;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
397 XSetWMNormalHints(disp, win, &sz_hint);
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
398
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
399 XSync(disp, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
400
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
401 /* Setup with Xv extension */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
402 xv_adaptor = -1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
403 xv_format_id = -1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
404 XvQueryAdaptors(disp, root, &xv_num_adaptors, &xv_adaptors);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
405 for (i = 0; i < xv_num_adaptors; i++) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
406 XvAdaptorInfo *adaptor = &xv_adaptors[i];
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
407 int takes_images;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
408
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
409 takes_images = adaptor->type & (XvInputMask | XvImageMask);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
410 if (takes_images) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
411 XvImageFormatValues *formats;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
412 int num_formats;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
413
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
414 formats = XvListImageFormats(disp, adaptor->base_id, &num_formats);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
415 for (j = 0; j < num_formats; j++)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
416 if (formats[j].type == XvYUV && formats[j].format == XvPlanar &&
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
417 strcmp(formats[j].guid, "YV12") == 0)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
418 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
419 if (j < num_formats) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
420 xv_adaptor = i;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
421 xv_format_id = formats[j].id;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
422 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
423 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
424 }
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
425 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
426 assert(xv_adaptor >= 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
427
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
428 /* Create an image to captured frames */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
429 #ifdef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
430 yuv_image = XvShmCreateImage(disp, xv_adaptors[xv_adaptor].base_id,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
431 xv_format_id, 0, w, h, &shminfo);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
432 if (!yuv_image)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
433 fprintf(stderr, "X-Error: unable to create XvShm XImage\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
434
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
435 shminfo.shmid = shmget(IPC_PRIVATE, yuv_image->data_size, IPC_CREAT | 0777);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
436 if (shminfo.shmid == -1)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
437 fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
438
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
439 shminfo.shmaddr = yuv_image->data = shmat(shminfo.shmid, 0, 0);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
440 yuv_image->data = shminfo.shmaddr;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
441 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
442 rgb_image = XShmCreateImage(disp, vis, depth, ZPixmap, NULL, &shminfo, w, h);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
443 if (!rgb_image)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
444 fprintf(stderr, "X-Error: unable to create XShm XImage\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
445
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
446 shminfo.shmid = shmget(IPC_PRIVATE,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
447 rgb_image->bytes_per_line * rgb_image->height,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
448 IPC_CREAT | 0777);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
449 if (shminfo.shmid == -1)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
450 fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
451
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
452 shminfo.shmaddr = rgb_image->data = shmat(shminfo.shmid, 0, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
453 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
454
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
455 if (!XShmAttach(disp, &shminfo))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
456 fprintf(stderr, "X-Error: unable to attach XShm Shared Memory Segment\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
457
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
458 /* Create a pixmap for the window background */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
459 #ifdef OLD
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
460 pmap = XShmCreatePixmap(disp, win, shminfo.shmaddr, &shminfo, w, h, depth);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
461 if (!pmap)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
462 fprintf(stderr, "Unable to create pixmap\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
463 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
464
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
465 /* Determine bits-per-pixel for pixmaps */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
466 pf = XListPixmapFormats(disp, &num_pf);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
467 assert(pf);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
468 for (pfi = 0; pfi < num_pf; pfi++)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
469 if (pf[pfi].depth == vi->depth)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
470 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
471 assert(pfi < num_pf);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
472 bits_per_pixel = pf[pfi].bits_per_pixel;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
473 XFree(pf);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
474
769b155a34f9 Initial revision
darius
parents:
diff changeset
475 #ifdef OLD
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
476 XSetWindowBackgroundPixmap(disp, win, pmap);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
477 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
478 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
479
769b155a34f9 Initial revision
darius
parents:
diff changeset
480 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
481
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
482 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
483 X_Shutdown() {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
484 XShmDetach(disp, &shminfo);
5
8b6b46a1261d - Move to 5.x+ includes
darius
parents: 3
diff changeset
485 #ifdef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
486 shmctl(shminfo.shmid, IPC_RMID, 0);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
487 shmdt(shminfo.shmaddr);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
488 XFree(yuv_image);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
489 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
490 XDestroyImage(rgb_image);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
491 #endif
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
492 shmdt(shminfo.shmaddr);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
493 shmctl(shminfo.shmid, IPC_RMID, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
494 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
495
769b155a34f9 Initial revision
darius
parents:
diff changeset
496
769b155a34f9 Initial revision
darius
parents:
diff changeset
497 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
498
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
499 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
500 X_Display(void) {
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
501 int _w , _h, _d;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
502 Window _dw;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
503
769b155a34f9 Initial revision
darius
parents:
diff changeset
504 #ifdef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
505 XGetGeometry(disp, win, &_dw, &_d, &_d, &_w, &_h, &_d, &_d);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
506 XvShmPutImage(disp, xv_adaptors[xv_adaptor].base_id, win,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
507 gc, yuv_image, 0, 0, yuv_image->width, yuv_image->height,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
508 0, 0, _w, _h, True);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
509 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
510 XShmPutImage(disp, win, gc, rgb_image, 0, 0, 0, 0,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
511 rgb_image->width, rgb_image->height, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
512 #endif
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
513 XSync(disp, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
514 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
515
769b155a34f9 Initial revision
darius
parents:
diff changeset
516 #define CMD_NONE 0
769b155a34f9 Initial revision
darius
parents:
diff changeset
517 #define CMD_CHNUP 1
769b155a34f9 Initial revision
darius
parents:
diff changeset
518 #define CMD_CHNDN 2
769b155a34f9 Initial revision
darius
parents:
diff changeset
519 #define CMD_MUTE 3
769b155a34f9 Initial revision
darius
parents:
diff changeset
520 #define CMD_QUIT 4
769b155a34f9 Initial revision
darius
parents:
diff changeset
521 #define CMD_RELOAD 5
769b155a34f9 Initial revision
darius
parents:
diff changeset
522 #define CMD_CURSOR 6
769b155a34f9 Initial revision
darius
parents:
diff changeset
523 #define CMD_VOLDN 7
769b155a34f9 Initial revision
darius
parents:
diff changeset
524 #define CMD_VOLUP 8
769b155a34f9 Initial revision
darius
parents:
diff changeset
525 #define CMD_FSTOGGLE 9
769b155a34f9 Initial revision
darius
parents:
diff changeset
526
769b155a34f9 Initial revision
darius
parents:
diff changeset
527 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
528
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
529 int
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
530 main(int argc, char *argv[]) {
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
531 #ifndef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
532 HermesHandle conv;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
533 HermesFormat fmt_source, fmt_dest;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
534 #endif
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
535 XEvent e;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
536 char *scratch_buf, *code, *c, *mixerdev;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
537 int frames, channelidx, oldchan, mute, cursor, fd, ret, cmd;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
538 int exitnow, mfd, uselirc, curvol;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
539 struct timeval then, now, diff, lastmove;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
540 float rate;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
541 KeySym key;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
542 char text [255];
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
543 int channellist[] = {2, 7, 9, 10, 28};
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
544 struct lirc_config *config;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
545 struct pollfd fds[1];
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
546
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
547 #define NUMCHANS (sizeof(channellist) / sizeof(channellist[0]))
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
548
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
549 channelidx = mute = cursor = 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
550
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
551 oldchan = channel = channellist[channelidx];
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
552
769b155a34f9 Initial revision
darius
parents:
diff changeset
553 #ifndef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
554 if (!Hermes_Init()) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
555 printf("Couldn't initialise Hermes!\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
556 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
557 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
558 conv = Hermes_ConverterInstance(HERMES_CONVERT_NORMAL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
559 if (!conv) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
560 printf("Could not obtain converter instance from Hermes!\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
561 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
562 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
563 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
564
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
565 X_Setup(width, height);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
566 XSelectInput(disp, win, KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
567
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
568 X_HideCursor();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
569
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
570 /* Open Capture device */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
571 Open();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
572
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
573 /* Open audio mixer */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
574 mixerdev = "/dev/mixer";
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
575 if ((mfd = open(mixerdev, O_RDWR)) == -1)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
576 fprintf(stderr, "Unable to open %s - %s\n", mixerdev, strerror(errno));
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
577
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
578 /* Talk to LIRC */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
579 if ((fd = lirc_init(basename(argv[0]), 1)) == -1) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
580 fprintf(stderr, "Unable to init lirc client library\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
581 uselirc = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
582 } else {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
583 if (lirc_readconfig(NULL, &config, NULL) != 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
584 fprintf(stderr, "Unable to parse config file\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
585 uselirc = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
586 } else
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
587 uselirc = 1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
588 fds[0].fd = fd;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
589 fds[0].events = POLLRDNORM;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
590 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
591
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
592 #ifndef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
593 /* Conversion from and to formats */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
594 fmt_source.indexed = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
595 fmt_source.bits = 32;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
596 fmt_source.r = 0xff0000;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
597 fmt_source.g = 0x00ff00;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
598 fmt_source.b = 0x0000ff;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
599 fmt_source.a = 0;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
600
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
601 fmt_dest.indexed = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
602 fmt_dest.bits = bits_per_pixel;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
603 fmt_dest.r = vi->red_mask;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
604 fmt_dest.g = vi->green_mask;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
605 fmt_dest.b = vi->blue_mask;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
606 fmt_dest.a = 0;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
607 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
608 scratch_buf = malloc(width * height);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
609 #endif
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
610
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
611 frames = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
612 gettimeofday(&then, NULL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
613 gettimeofday(&lastmove, NULL);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
614
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
615 exitnow = 0;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
616
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
617 /* Capture loop */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
618 while (1) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
619 if (frames == 50) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
620 gettimeofday(&now, NULL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
621 timersub(&now, &then, &diff);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
622
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
623 rate = (float)frames / (float)(diff.tv_usec / 1000000.0 + diff.tv_sec);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
624
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
625 printf("%d frames in %.2f seconds, rate %.2f\n", frames, (float)(diff.tv_usec / 1000000.0) + diff.tv_sec, rate);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
626 gettimeofday(&then, NULL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
627 frames = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
628 XResetScreenSaver(disp);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
629 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
630 frames++;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
631
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
632 timersub(&now, &lastmove, &diff);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
633 if (((float)diff.tv_usec / 1000000.0 + (float)diff.tv_sec) > 2.0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
634 if (cursor) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
635 X_HideCursor();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
636 cursor = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
637 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
638 } else {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
639 if (!cursor) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
640 X_ShowCursor();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
641 cursor = 1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
642 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
643 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
644
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
645 if (XCheckMaskEvent(disp, PointerMotionMask, &e) && e.type == MotionNotify) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
646 gettimeofday(&lastmove, NULL);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
647 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
648 cmd = CMD_NONE;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
649
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
650 if (XCheckMaskEvent(disp, ButtonReleaseMask, &e)) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
651 printf("e.type = %d\n", e.type);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
652 cmd = CMD_MUTE;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
653 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
654 if (XCheckMaskEvent(disp, KeyReleaseMask, &e) && e.type == KeyRelease) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
655 gettimeofday(&lastmove, NULL);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
656
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
657 XLookupString(&e.xkey, text, 255, &key, 0);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
658 printf("Press - %c\n", text[0]);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
659
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
660 switch (text[0]) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
661 case 'q':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
662 cmd = CMD_QUIT;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
663 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
664
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
665 case '=':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
666 case '+':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
667 cmd = CMD_CHNUP;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
668 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
669
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
670 case '-':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
671 cmd = CMD_CHNDN;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
672 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
673
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
674 case 'h':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
675 cmd = CMD_CURSOR;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
676 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
677
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
678 case 'm':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
679 cmd = CMD_MUTE;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
680 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
681
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
682 case 'r':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
683 cmd = CMD_RELOAD;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
684 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
685
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
686 case ',':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
687 cmd = CMD_VOLDN;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
688 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
689
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
690 case '.':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
691 cmd = CMD_VOLUP;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
692 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
693
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
694 case 'f':
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
695 cmd = CMD_FSTOGGLE;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
696 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
697 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
698 }
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
699
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
700 /* Poll for IR events */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
701 if (uselirc) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
702 fds[0].revents = 0;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
703
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
704 while (1) {
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
705
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
706 if (poll(fds, 1, 0) == -1) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
707 fprintf(stderr, "Poll failed - %s\n", strerror(errno));
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
708 exit(EXIT_FAILURE);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
709 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
710 if ((fds[0].revents & POLLRDNORM) != 0) {
9
ef818ccd826f Oops, delete reference to variable no longer really used.
darius
parents: 8
diff changeset
711 fprintf(stderr, "Processing IR..\n");
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
712
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
713 /* Try and get an event */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
714 if (lirc_nextcode(&code) == 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
715 if (code == NULL) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
716 continue;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
717 }
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
718
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
719 /* Translate it (via the config file) */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
720 while ((ret = lirc_code2char(config, code, &c)) == 0 &&
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
721 c != NULL) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
722 fprintf(stderr, "Got command \"%s\"\n", c);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
723
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
724 if (!strcmp(c, "Mute"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
725 cmd = CMD_MUTE;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
726 else if (!strcmp(c, "CH_UP"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
727 cmd = CMD_CHNUP;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
728 else if (!strcmp(c, "CH_DOWN"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
729 cmd = CMD_CHNDN;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
730 else if (!strcmp(c, "Power"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
731 cmd = CMD_QUIT;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
732 else if (!strcmp(c, "VOL_UP"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
733 cmd = CMD_VOLUP;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
734 else if (!strcmp(c, "VOL_DOWN"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
735 cmd = CMD_VOLDN;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
736 else if (!strcmp(c, "AV/TV"))
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
737 cmd = CMD_FSTOGGLE;
7
210d197c77f9 Tolerate LIRC going away.
darius
parents: 6
diff changeset
738
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
739 free(code);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
740 }
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
741 } else {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
742 /* lircd probably died */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
743 uselirc = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
744 fprintf(stderr, "Failed to communicate with LIRC - daemon exited?");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
745 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
746 } else
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
747 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
748 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
749 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
750 switch (cmd) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
751 case CMD_QUIT:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
752 exitnow = 1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
753 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
754
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
755 case CMD_CHNUP:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
756 case CMD_CHNDN:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
757 if (cmd == CMD_CHNUP)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
758 channelidx++;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
759 else
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
760 channelidx--;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
761
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
762 if (channelidx < 0)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
763 channelidx = NUMCHANS - 1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
764 if (channelidx > NUMCHANS - 1)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
765 channelidx = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
766
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
767 channel = channellist[channelidx];
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
768
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
769 printf("Channel - %d\n", channel);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
770 if (oldchan != channel) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
771 oldchan = channel;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
772
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
773 if (ioctl(tuner_fd, TVTUNER_SETCHNL, &channel) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
774 DO_IOCTL_SERR("TVTUNER_SETCHNL", channel);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
775 exit(1);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
776 }
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
777 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
778 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
779
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
780 case CMD_MUTE:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
781 if (mute)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
782 mute = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
783 else
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
784 mute = 1;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
785
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
786 printf("Mute - %d\n", mute);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
787 if (ioctl(tuner_fd, BT848_SAUDIO, &mute) < 0) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
788 DO_IOCTL_SERR("BT848_SAUDIO", mute);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
789 exit(1);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
790 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
791 break;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
792
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
793 case CMD_CURSOR:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
794 if (cursor) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
795 printf("Cursor hidden\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
796 X_HideCursor();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
797 cursor = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
798 } else {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
799 printf("Cursor revealed\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
800 X_ShowCursor();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
801 cursor = 1;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
802 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
803 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
804
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
805 case CMD_RELOAD:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
806 printf("Reloading\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
807 Close();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
808 Open();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
809 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
810
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
811 case CMD_VOLUP:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
812 case CMD_VOLDN:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
813 if (ioctl(mfd, MIXER_READ(SOUND_MIXER_VOLUME), &curvol) == -1) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
814 fprintf(stderr, "Unable to read current volume - %s\n", strerror(errno));
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
815 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
816 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
817 curvol = curvol & 0x7f;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
818
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
819 if (cmd == CMD_VOLUP)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
820 curvol += 5;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
821 else
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
822 curvol -= 5;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
823
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
824 if (curvol < 0)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
825 curvol = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
826 if (curvol > 100)
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
827 curvol = 100;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
828
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
829 printf("Setting volume to %d\n", curvol);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
830 curvol |= curvol << 8;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
831
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
832 if (ioctl(mfd, MIXER_WRITE(SOUND_MIXER_VOLUME), &curvol) == -1) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
833 fprintf(stderr, "Unable to write volume - %s\n", strerror(errno));
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
834 break;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
835 }
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
836 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
837
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
838 case CMD_FSTOGGLE:
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
839 vo_x11_ewmh_fullscreen(_NET_WM_STATE_TOGGLE);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
840 break;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
841
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
842 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
843
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
844 Capture();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
845
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
846 #ifdef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
847 /* bktr's YUV_12 is planar W*H bytes Y, W/2*H/2 bytes U, */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
848 /* W/2*H/2 bytes V. Xv's YV12 is the same with U and V */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
849 /* planes reversed. */
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
850 {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
851 int y_off , u_off, v_off;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
852 y_off = 0;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
853 u_off = width * height;
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
854 v_off = u_off + width * height / 4;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
855
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
856 assert(yuv_image->data_size == width * height * 3 / 2);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
857 memcpy(yuv_image->data, bktr_buffer, u_off - y_off);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
858 memcpy(yuv_image->data + u_off, bktr_buffer + v_off, v_off - u_off);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
859 memcpy(yuv_image->data + v_off, bktr_buffer + u_off, v_off - u_off);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
860 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
861 #else
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
862 /* SaveImage(); */
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
863
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
864 Hermes_ConverterRequest(conv, &fmt_source, &fmt_dest);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
865 Hermes_ConverterCopy(conv, bktr_buffer, 0, 0, width, height, width * 4,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
866 rgb_image->data, 0, 0, width, height,
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
867 rgb_image->bytes_per_line);
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
868 #endif
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
869
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
870 X_Display();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
871 if (exitnow) {
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
872 printf("quitting\n");
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
873 break;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
874 }
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
875 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
876
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
877 #ifndef USE_XVIMAGES
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
878 Hermes_ConverterReturn(conv);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
879 Hermes_Done();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
880 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
881
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
882 X_Shutdown();
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
883 lirc_freeconfig(config);
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
884 lirc_deinit();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
885
8
fc60aa65d85f Reindent with c-basic-offset = 4
darius
parents: 7
diff changeset
886 return 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
887 }