annotate simpletv.c @ 4:8f7cda8e4af8

Remove binaries
author darius
date Tue, 04 Jan 2005 05:21:07 +0000
parents 8d7d1680db7d
children 8b6b46a1261d
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>
769b155a34f9 Initial revision
darius
parents:
diff changeset
49 #include <machine/ioctl_bt848.h>
769b155a34f9 Initial revision
darius
parents:
diff changeset
50 #include <machine/ioctl_meteor.h>
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
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
87 int width = 640;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
88 int height = 480;
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) )
769b155a34f9 Initial revision
darius
parents:
diff changeset
115 #define DO_IOCTL_SERR(str,arg) fprintf(stderr, "ioctl(%s, %ld) failed: %s\n",\
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() {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
121 close(tuner_fd);
8d7d1680db7d style(9) mostly with
darius
parents: 1
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() {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
127 struct meteor_geomet geo;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
128 int buffer_size, format, source, c;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
129 char *device_name;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
130
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
131 format = PAL; /* default value */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
132 source = 1; /* default value */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
133 device_name = "/dev/bktr0"; /* default value */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
134
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
135 /* Open the Meteor or Bt848/Bt878 grabber */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
136 if ((bktr_fd = open(device_name, O_RDONLY)) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
137 printf("open failed: %d\n", errno);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
138 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
139 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
140 if ((tuner_fd = open("/dev/tuner0", O_RDONLY)) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
141 printf("open failed: %d\n", errno);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
142 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
143 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
144 /* set up the capture type and size */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
145 geo.rows = height;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
146 geo.columns = width;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
147 geo.frames = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
148 #ifdef USE_XVIMAGES
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
149 /* Should be YUV_12, but 422 actually gives a synced picture. Though */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
150
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
151 /* geo.oformat = METEOR_GEO_YUV_12; */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
152 geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
153 /* geo.oformat = METEOR_GEO_YUV_12; */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
154 #else
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
155 geo.oformat = METEOR_GEO_RGB24;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
156 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
157
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
158 /* switch from interlaced capture to single field capture if */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
159 /* the grab height is less than half the normal TV height */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
160 /* this gives better quality captures when the object in the TV */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
161 /* picture is moving */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
162 if ((format == PAL) && (height <= (PAL_HEIGHT / 2)))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
163 geo.oformat |= METEOR_GEO_ODD_ONLY;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
164 if ((format == NTSC) && (height <= (NTSC_HEIGHT / 2)))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
165 geo.oformat |= METEOR_GEO_ODD_ONLY;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
166
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
167 if (ioctl(bktr_fd, METEORSETGEO, &geo) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
168 printf("METEORSETGEO ioctl failed: %d\n", errno);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
169 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
170 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
171 /* Select PAL or NTSC */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
172 switch (format) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
173 case PAL:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
174 c = METEOR_FMT_PAL;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
175 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
176 case NTSC:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
177 c = METEOR_FMT_NTSC;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
178 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
179 default:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
180 c = METEOR_FMT_NTSC;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
181 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
182 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
183
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
184 c = BT848_IFORM_F_PALBDGHI;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
185 if (ioctl(bktr_fd, BT848SFMT, &c) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
186 DO_IOCTL_SERR("BT848SFMT", c);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
187 return;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
188 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
189 c = AUDIO_TUNER;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
190 if (ioctl(tuner_fd, BT848_SAUDIO, &c) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
191 DO_IOCTL_SERR("BT848SFMT", c);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
192 return;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
193 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
194 c = CHNLSET_AUSTRALIA;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
195 if (ioctl(tuner_fd, TVTUNER_SETTYPE, &c) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
196 DO_IOCTL_SERR("TVTUNER_SETTYPE", c);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
197 return;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
198 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
199 if (ioctl(tuner_fd, TVTUNER_SETCHNL, &channel) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
200 DO_IOCTL_SERR("TVTUNER_SETCHNL", channel);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
201 return;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
202 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
203 /* Select the Video Source */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
204 /* Video In, Tuner, S-Video */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
205 switch (source) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
206 case 0:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
207 c = METEOR_INPUT_DEV0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
208 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
209 case 1:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
210 c = METEOR_INPUT_DEV1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
211 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
212 case 2:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
213 c = METEOR_INPUT_DEV2;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
214 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
215 case 3:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
216 c = METEOR_INPUT_DEV3;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
217 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
218 default:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
219 c = METEOR_INPUT_DEV0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
220 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
221 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
222
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
223 printf("Input - %x\n", c);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
224 if (ioctl(bktr_fd, METEORSINPUT, &c) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
225 printf("ioctl failed: %d\n", errno);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
226 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
227 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
228 /* Use mmap to Map the drivers grab buffer */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
229 buffer_size = width * height * 4; /* R,G,B,spare */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
230 bktr_buffer = (unsigned char *)mmap((caddr_t) 0, buffer_size, PROT_READ,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
231 MAP_SHARED, bktr_fd, (off_t) 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
232
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
233 if (bktr_buffer == (unsigned char *)MAP_FAILED)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
234 exit(1);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
235
769b155a34f9 Initial revision
darius
parents:
diff changeset
236
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
237 /* We may need to wait for a short time to allow the grabber */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
238 /* brightness to settle down */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
239 sleep(GRABBER_SETTLE_TIME);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
240 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
241
769b155a34f9 Initial revision
darius
parents:
diff changeset
242 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
243
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
244 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
245 Capture() {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
246 int c;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
247
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
248 /* Perform a single frame capture */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
249 c = METEOR_CAP_SINGLE;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
250 ioctl(bktr_fd, METEORCAPTUR, &c);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
251 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
252
769b155a34f9 Initial revision
darius
parents:
diff changeset
253 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
254
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
255 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
256 SaveImage() {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
257 unsigned char *line_buffer;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
258 int o , w, h;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
259 unsigned char *p;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
260 unsigned char header[30];
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
261 char *filename = "t.ppm" /* argv[3] */ ;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
262
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
263 /* Create the output file */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
264 if ((o = open(filename, O_WRONLY | O_CREAT, 0644)) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
265 printf("ppm open failed: %d\n", errno);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
266 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
267 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
268 /* make PPM header and save to file */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
269 sprintf(header, "P6\n%d\n%d\n255\n", width, height);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
270 write(o, header, strlen(header));
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
271
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
272 /* save the RGB data to PPM file */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
273 /* save this one line at a time */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
274 line_buffer = (unsigned char *)malloc(width * 3 * sizeof(unsigned char));
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
275 p = bktr_buffer;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
276 for (h = 0; h < height; h++) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
277 for (w = 0; w < width; w++) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
278 line_buffer[(w * 3) + 2] = *p++; /* blue */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
279 line_buffer[(w * 3) + 1] = *p++; /* green */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
280 line_buffer[(w * 3) + 0] = *p++; /* red */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
281 p++; /* NULL byte */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
282 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
283 write(o, line_buffer, width * 3);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
284 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
285 close(o);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
286 free(line_buffer);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
287 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
288
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
289 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
290 X_ShowCursor(void) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
291 XDefineCursor(disp, win, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
292 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
293
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
294 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
295 X_HideCursor(void) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
296 Cursor no_ptr;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
297 Pixmap bm_no;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
298 XColor black , dummy;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
299 Colormap colormap;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
300 static unsigned char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
301
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
302 colormap = DefaultColormap(disp, DefaultScreen(disp));
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
303 XAllocNamedColor(disp, colormap, "black", &black, &dummy);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
304 bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
305 no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
306
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
307 XDefineCursor(disp, win, no_ptr);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
308 XFreeCursor(disp, no_ptr);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
309 if (bm_no != None)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
310 XFreePixmap(disp, bm_no);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
311
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
312 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
313
769b155a34f9 Initial revision
darius
parents:
diff changeset
314 /*
769b155a34f9 Initial revision
darius
parents:
diff changeset
315 * Sends the EWMH fullscreen state event.
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
316 *
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
317 * action: could be on of _NET_WM_STATE_REMOVE -- remove state
769b155a34f9 Initial revision
darius
parents:
diff changeset
318 * _NET_WM_STATE_ADD -- add state
769b155a34f9 Initial revision
darius
parents:
diff changeset
319 * _NET_WM_STATE_TOGGLE -- toggle
769b155a34f9 Initial revision
darius
parents:
diff changeset
320 */
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
321 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
322 #define _NET_WM_STATE_ADD 1 /* add/set property */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
323 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
324 void
769b155a34f9 Initial revision
darius
parents:
diff changeset
325 vo_x11_ewmh_fullscreen(int action) {
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
326 XEvent xev;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
327
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
328 assert(action == _NET_WM_STATE_REMOVE ||
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
329 action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
330
769b155a34f9 Initial revision
darius
parents:
diff changeset
331
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
332 /* init X event structure for _NET_WM_FULLSCREEN client msg */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
333 xev.xclient.type = ClientMessage;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
334 xev.xclient.serial = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
335 xev.xclient.send_event = True;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
336 xev.xclient.message_type = XInternAtom(disp, "_NET_WM_STATE", False);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
337 xev.xclient.window = win;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
338 xev.xclient.format = 32;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
339 xev.xclient.data.l[0] = action;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
340 xev.xclient.data.l[1] = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
341 xev.xclient.data.l[2] = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
342 xev.xclient.data.l[3] = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
343 xev.xclient.data.l[4] = 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
344
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
345 /* finally send that damn thing */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
346 if (!XSendEvent(disp, DefaultRootWindow(disp), False,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
347 SubstructureRedirectMask | SubstructureNotifyMask,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
348 &xev)) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
349 fprintf(stderr, "Failed to send fullscreen command\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
350 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
351 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
352
769b155a34f9 Initial revision
darius
parents:
diff changeset
353
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
354 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
355 X_Setup(int w, int h) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
356 XGCValues gcvals;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
357 Window root;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
358 XVisualInfo vinfo_pref;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
359 int num_vis;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
360 XPixmapFormatValues *pf;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
361 int num_pf , pfi, i, j;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
362
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
363 disp = XOpenDisplay(NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
364 if (!disp) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
365 fprintf(stderr, "X-Error: unable to connect to display\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
366 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
367 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
368 XSynchronize(disp, True);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
369
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
370 scr = DefaultScreen(disp);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
371 vis = DefaultVisual(disp, scr);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
372 root = DefaultRootWindow(disp);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
373 depth = DefaultDepth(disp, scr);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
374
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
375 vinfo_pref.screen = scr;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
376 vinfo_pref.visualid = XVisualIDFromVisual(vis);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
377 vi = XGetVisualInfo(disp, VisualScreenMask | VisualIDMask,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
378 &vinfo_pref, &num_vis);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
379 assert(num_vis == 1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
380
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
381 win = XCreateSimpleWindow(disp, root, 0, 0, w, h, 0, 0, 0);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
382 gc = XCreateGC(disp, win, (unsigned long)0, &gcvals);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
383 XSetForeground(disp, gc, 0);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
384 XSetBackground(disp, gc, 1);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
385
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
386 XMapWindow(disp, win);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
387 cmap = DefaultColormap(disp, scr);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
388 XSync(disp, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
389
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
390 /* Setup with Xv extension */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
391 xv_adaptor = -1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
392 xv_format_id = -1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
393 XvQueryAdaptors(disp, root, &xv_num_adaptors, &xv_adaptors);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
394 for (i = 0; i < xv_num_adaptors; i++) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
395 XvAdaptorInfo *adaptor = &xv_adaptors[i];
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
396 int takes_images;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
397
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
398 takes_images = adaptor->type & (XvInputMask | XvImageMask);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
399 if (takes_images) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
400 XvImageFormatValues *formats;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
401 int num_formats;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
402
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
403 formats = XvListImageFormats(disp, adaptor->base_id, &num_formats);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
404 for (j = 0; j < num_formats; j++)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
405 if (formats[j].type == XvYUV && formats[j].format == XvPlanar &&
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
406 strcmp(formats[j].guid, "YV12") == 0)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
407 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
408 if (j < num_formats) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
409 xv_adaptor = i;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
410 xv_format_id = formats[j].id;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
411 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
412 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
413 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
414 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
415 assert(xv_adaptor >= 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
416
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
417 /* Create an image to captured frames */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
418 #ifdef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
419 yuv_im age = XvShmCreateImage(disp, xv_adaptors[xv_adaptor].base_id,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
420 xv_format_id, 0, w, h, &shminfo);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
421 if (!yuv_image)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
422 fprintf(stderr, "X-Error: unable to create XvShm XImage\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
423
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
424 shminfo.shmid = shmget(IPC_PRIVATE, yuv_image->data_size, IPC_CREAT | 0777);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
425 if (shminfo.shmid == -1)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
426 fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
427
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
428 shminfo.shmaddr = yuv_image->data = shmat(shminfo.shmid, 0, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
429 #else
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
430 rgb_image = XShmCreateImage(disp, vis, depth, ZPixmap, NULL, &shminfo, w, h);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
431 if (!rgb_image)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
432 fprintf(stderr, "X-Error: unable to create XShm XImage\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
433
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
434 shminfo.shmid = shmget(IPC_PRIVATE,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
435 rgb_image->bytes_per_line * rgb_image->height,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
436 IPC_CREAT | 0777);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
437 if (shminfo.shmid == -1)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
438 fprintf(stderr, "SharedMemory Error: unable to get identifier\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
439
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
440 shminfo.shmaddr = rgb_image->data = shmat(shminfo.shmid, 0, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
441 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
442
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
443 if (!XShmAttach(disp, &shminfo))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
444 fprintf(stderr, "X-Error: unable to attach XShm Shared Memory Segment\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
445
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
446 /* Create a pixmap for the window background */
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
447 #ifdef OLD
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
448 pmap = XShmCreatePixmap(disp, win, shminfo.shmaddr, &shminfo, w, h, depth);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
449 if (!pmap)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
450 fprintf(stderr, "Unable to create pixmap\n");
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
451 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
452
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
453 /* Determine bits-per-pixel for pixmaps */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
454 pf = XListPixmapFormats(disp, &num_pf);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
455 assert(pf);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
456 for (pfi = 0; pfi < num_pf; pfi++)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
457 if (pf[pfi].depth == vi->depth)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
458 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
459 assert(pfi < num_pf);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
460 bits_per_pixel = pf[pfi].bits_per_pixel;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
461 XFree(pf);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
462
769b155a34f9 Initial revision
darius
parents:
diff changeset
463 #ifdef OLD
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
464 XSetWindowBackgroundPixmap(disp, win, pmap);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
465 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
466 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
467
769b155a34f9 Initial revision
darius
parents:
diff changeset
468 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
469
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
470 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
471 X_Shutdown() {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
472 XShmDetach(disp, &shminfo);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
473 #ifdef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
474 #warning How do we destroy an XvImage?
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
475 #else
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
476 XDestroyImage(rgb_image);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
477 #endif
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
478 shmdt(shminfo.shmaddr);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
479 shmctl(shminfo.shmid, IPC_RMID, 0);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
480 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
481
769b155a34f9 Initial revision
darius
parents:
diff changeset
482
769b155a34f9 Initial revision
darius
parents:
diff changeset
483 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
484
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
485 void
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
486 X_Display(void) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
487 int _w , _h, _d;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
488 Window _dw;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
489
769b155a34f9 Initial revision
darius
parents:
diff changeset
490 #ifdef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
491 XGetGeometry(disp, win, &_dw, &_d, &_d, &_w, &_h, &_d, &_d);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
492 XvShmPutImage(disp, xv_adaptors[xv_adaptor].base_id, win,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
493 gc, yuv_image, 0, 0, yuv_image->width, yuv_image->height,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
494 0, 0, _w, _h, True);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
495 #else
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
496 XShmPutImage(disp, win, gc, rgb_image, 0, 0, 0, 0,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
497 rgb_image->width, rgb_image->height, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
498 #endif
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
499 XSync(disp, False);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
500 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
501
769b155a34f9 Initial revision
darius
parents:
diff changeset
502 #define CMD_NONE 0
769b155a34f9 Initial revision
darius
parents:
diff changeset
503 #define CMD_CHNUP 1
769b155a34f9 Initial revision
darius
parents:
diff changeset
504 #define CMD_CHNDN 2
769b155a34f9 Initial revision
darius
parents:
diff changeset
505 #define CMD_MUTE 3
769b155a34f9 Initial revision
darius
parents:
diff changeset
506 #define CMD_QUIT 4
769b155a34f9 Initial revision
darius
parents:
diff changeset
507 #define CMD_RELOAD 5
769b155a34f9 Initial revision
darius
parents:
diff changeset
508 #define CMD_CURSOR 6
769b155a34f9 Initial revision
darius
parents:
diff changeset
509 #define CMD_VOLDN 7
769b155a34f9 Initial revision
darius
parents:
diff changeset
510 #define CMD_VOLUP 8
769b155a34f9 Initial revision
darius
parents:
diff changeset
511 #define CMD_FSTOGGLE 9
769b155a34f9 Initial revision
darius
parents:
diff changeset
512
769b155a34f9 Initial revision
darius
parents:
diff changeset
513 /*--------------------------------------------------------------------------*/
769b155a34f9 Initial revision
darius
parents:
diff changeset
514
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
515 int
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
516 main(int argc, char *argv[]) {
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
517 #ifndef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
518 HermesHandle conv;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
519 HermesFormat fmt_source, fmt_dest;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
520 #endif
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
521 XEvent e;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
522 char *scratch_buf, *code, *c, *mixerdev;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
523 int frames , channelidx, oldchan, mute, cursor, fd, ret, cmd;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
524 int exitnow , mfd, uselirc, curvol;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
525 struct timeval then, now, diff, lastmove;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
526 float rate;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
527 KeySym key;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
528 char text [255];
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
529 int channellist[] = {2, 7, 9, 10, 28};
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
530 struct lirc_config *config;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
531 struct pollfd fds[1];
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
532
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
533 #define NUMCHANS (sizeof(channellist) / sizeof(channellist[0]))
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
534
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
535 channelidx = mute = cursor = 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
536
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
537 oldchan = channel = channellist[channelidx];
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
538
769b155a34f9 Initial revision
darius
parents:
diff changeset
539 #ifndef USE_XVIMAGES
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
540 if (!Hermes_Init()) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
541 printf("Couldn't initialise Hermes!\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
542 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
543 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
544 conv = Hermes_ConverterInstance(HERMES_CONVERT_NORMAL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
545 if (!conv) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
546 printf("Could not obtain converter instance from Hermes!\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
547 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
548 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
549 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
550
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
551 X_Setup(width, height);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
552 XSelectInput(disp, win, KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
553
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
554 X_HideCursor();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
555
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
556 /* Open Capture device */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
557 Open();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
558
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
559 /* Open audio mixer */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
560 mixerdev = "/dev/mixer";
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
561 if ((mfd = open(mixerdev, O_RDWR)) == -1)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
562 fprintf(stderr, "Unable to open %s - %s\n", mixerdev, strerror(errno));
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
563
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
564 /* Talk to LIRC */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
565 if ((fd = lirc_init(basename(argv[0]), 1)) == -1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
566 fprintf(stderr, "Unable to init lirc client library\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
567 uselirc = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
568 } else {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
569 if (lirc_readconfig(NULL, &config, NULL) != 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
570 fprintf(stderr, "Unable to parse config file\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
571 uselirc = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
572 } else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
573 uselirc = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
574 fds[0].fd = fd;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
575 fds[0].events = POLLRDNORM;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
576 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
577
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
578 #ifndef USE_XVIMAGES
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
579 /* Conversion from and to formats */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
580 fmt_source.indexed = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
581 fmt_source.bits = 32;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
582 fmt_source.r = 0xff0000;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
583 fmt_source.g = 0x00ff00;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
584 fmt_source.b = 0x0000ff;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
585 fmt_source.a = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
586
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
587 fmt_dest.indexed = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
588 fmt_dest.bits = bits_per_pixel;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
589 fmt_dest.r = vi->red_mask;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
590 fmt_dest.g = vi->green_mask;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
591 fmt_dest.b = vi->blue_mask;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
592 fmt_dest.a = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
593 #else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
594 scratch_buf = malloc(width * height);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
595 #endif
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
596
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
597 frames = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
598 gettimeofday(&then, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
599 gettimeofday(&lastmove, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
600
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
601 exitnow = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
602
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
603 /* Capture loop */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
604 while (1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
605 if (frames == 50) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
606 gettimeofday(&now, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
607 timersub(&now, &then, &diff);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
608
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
609 rate = (float)frames / (float)(diff.tv_usec / 1000000.0 + diff.tv_sec);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
610
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
611 printf("%d frames in %.2f seconds, rate %.2f\n", frames, (float)(diff.tv_usec / 1000000.0) + diff.tv_sec, rate);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
612 gettimeofday(&then, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
613 frames = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
614 XResetScreenSaver(disp);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
615 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
616 frames++;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
617
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
618 timersub(&now, &lastmove, &diff);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
619 if (((float)diff.tv_usec / 1000000.0 + (float)diff.tv_sec) > 2.0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
620 if (cursor) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
621 X_HideCursor();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
622 cursor = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
623 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
624 } else {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
625 if (!cursor) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
626 X_ShowCursor();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
627 cursor = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
628 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
629 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
630
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
631 if (XCheckMaskEvent(disp, PointerMotionMask, &e) && e.type == MotionNotify) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
632 gettimeofday(&lastmove, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
633 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
634 cmd = CMD_NONE;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
635
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
636 if (XCheckMaskEvent(disp, ButtonReleaseMask, &e)) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
637 printf("e.type = %d\n", e.type);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
638 cmd = CMD_MUTE;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
639 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
640 if (XCheckMaskEvent(disp, KeyReleaseMask, &e) && e.type == KeyRelease) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
641 gettimeofday(&lastmove, NULL);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
642
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
643 XLookupString(&e.xkey, text, 255, &key, 0);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
644 printf("Press - %c\n", text[0]);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
645
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
646 switch (text[0]) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
647 case 'q':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
648 cmd = CMD_QUIT;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
649 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
650
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
651 case '=':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
652 case '+':
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
653 cmd = CMD_CHNUP;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
654 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
655
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
656 case '-':
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
657 cmd = CMD_CHNDN;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
658 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
659
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
660 case 'h':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
661 cmd = CMD_CURSOR;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
662 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
663
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
664 case 'm':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
665 cmd = CMD_MUTE;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
666 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
667
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
668 case 'r':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
669 cmd = CMD_RELOAD;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
670 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
671
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
672 case ',':
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
673 cmd = CMD_VOLDN;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
674 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
675
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
676 case '.':
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
677 cmd = CMD_VOLUP;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
678 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
679
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
680 case 'f':
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
681 cmd = CMD_FSTOGGLE;
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
682 break;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
683 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
684 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
685 /* Poll for IR events */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
686 if (uselirc) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
687 fds[0].revents = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
688
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
689 while (1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
690 if (poll(fds, 1, 0) == -1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
691 fprintf(stderr, "Poll failed - %s\n", strerror(errno));
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
692 exit(EXIT_FAILURE);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
693 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
694 if ((fds[0].revents & POLLRDNORM) != 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
695 fprintf(stderr, "Processing IR..\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
696
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
697 if (lirc_nextcode(&code) == 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
698 if (code == NULL)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
699 continue;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
700
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
701 while ((ret = lirc_code2char(config, code, &c)) == 0 &&
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
702 c != NULL) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
703 fprintf(stderr, "Got command \"%s\"\n", c);
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
704
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
705 if (!strcmp(c, "Mute"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
706 cmd = CMD_MUTE;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
707 else if (!strcmp(c, "CH_UP"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
708 cmd = CMD_CHNUP;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
709 else if (!strcmp(c, "CH_DOWN"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
710 cmd = CMD_CHNDN;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
711 else if (!strcmp(c, "Power"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
712 cmd = CMD_QUIT;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
713 else if (!strcmp(c, "VOL_UP"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
714 cmd = CMD_VOLUP;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
715 else if (!strcmp(c, "VOL_DOWN"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
716 cmd = CMD_VOLDN;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
717 else if (!strcmp(c, "AV/TV"))
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
718 cmd = CMD_FSTOGGLE;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
719
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
720 free(code);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
721 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
722 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
723 } else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
724 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
725 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
726 }
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
727 switch (cmd) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
728 case CMD_QUIT:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
729 exitnow = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
730 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
731
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
732 case CMD_CHNUP:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
733 case CMD_CHNDN:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
734 if (cmd == CMD_CHNUP)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
735 channelidx++;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
736 else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
737 channelidx--;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
738
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
739 if (channelidx < 0)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
740 channelidx = NUMCHANS - 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
741 if (channelidx > NUMCHANS - 1)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
742 channelidx = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
743
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
744 channel = channellist[channelidx];
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
745
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
746 printf("Channel - %d\n", channel);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
747 if (oldchan != channel) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
748 oldchan = channel;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
749
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
750 if (ioctl(tuner_fd, TVTUNER_SETCHNL, &channel) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
751 DO_IOCTL_SERR("TVTUNER_SETCHNL", channel);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
752 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
753 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
754 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
755 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
756
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
757 case CMD_MUTE:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
758 if (mute)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
759 mute = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
760 else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
761 mute = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
762
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
763 printf("Mute - %d\n", mute);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
764 if (ioctl(tuner_fd, BT848_SAUDIO, &mute) < 0) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
765 DO_IOCTL_SERR("BT848_SAUDIO", mute);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
766 exit(1);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
767 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
768 break;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
769
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
770 case CMD_CURSOR:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
771 if (cursor) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
772 printf("Cursor hidden\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
773 X_HideCursor();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
774 cursor = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
775 } else {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
776 printf("Cursor revealed\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
777 X_ShowCursor();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
778 cursor = 1;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
779 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
780 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
781
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
782 case CMD_RELOAD:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
783 printf("Reloading\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
784 Close();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
785 Open();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
786 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
787
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
788 case CMD_VOLUP:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
789 case CMD_VOLDN:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
790 if (ioctl(mfd, MIXER_READ(SOUND_MIXER_VOLUME), &curvol) == -1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
791 fprintf(stderr, "Unable to read current volume - %s\n", strerror(errno));
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
792 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
793 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
794 curvol = curvol & 0x7f;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
795
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
796 if (cmd == CMD_VOLUP)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
797 curvol += 5;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
798 else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
799 curvol -= 5;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
800
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
801 if (curvol < 0)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
802 curvol = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
803 if (curvol > 100)
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
804 curvol = 100;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
805
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
806 printf("Setting volume to %d\n", curvol);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
807 curvol |= curvol << 8;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
808
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
809 if (ioctl(mfd, MIXER_WRITE(SOUND_MIXER_VOLUME), &curvol) == -1) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
810 fprintf(stderr, "Unable to write volume - %s\n", strerror(errno));
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
811 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
812 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
813 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
814
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
815 case CMD_FSTOGGLE:
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
816 vo_x11_ewmh_fullscreen(_NET_WM_STATE_TOGGLE);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
817 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
818
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
819 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
820
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
821 Capture();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
822
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
823 #ifdef USE_XVIMAGES
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
824 /* bktr's YUV_12 is planar W*H bytes Y, W/2*H/2 bytes U, */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
825 /* W/2*H/2 bytes V. Xv's YV12 is the same with U and V */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
826 /* planes reversed. */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
827 {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
828 int y_off , u_off, v_off;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
829 y_off = 0;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
830 u_off = width * height;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
831 v_off = u_off + width * height / 4;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
832
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
833 assert(yuv_image->data_size == width * height * 3 / 2);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
834 memcpy(yuv_image->data, bktr_buffer, u_off - y_off);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
835 memcpy(yuv_image->data + u_off, bktr_buffer + v_off, v_off - u_off);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
836 memcpy(yuv_image->data + v_off, bktr_buffer + u_off, v_off - u_off);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
837 }
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
838 #else
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
839 /* SaveImage(); */
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
840
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
841 Hermes_ConverterRequest(conv, &fmt_source, &fmt_dest);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
842 Hermes_ConverterCopy(conv, bktr_buffer, 0, 0, width, height, width * 4,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
843 rgb_image->data, 0, 0, width, height,
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
844 rgb_image->bytes_per_line);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
845 #endif
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
846
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
847 X_Display();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
848 if (exitnow) {
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
849 printf("quitting\n");
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
850 break;
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
851 }
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
852 }
769b155a34f9 Initial revision
darius
parents:
diff changeset
853
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
854 #ifndef USE_XVIMAGES
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
855 Hermes_ConverterReturn(conv);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
856 Hermes_Done();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
857 #endif
769b155a34f9 Initial revision
darius
parents:
diff changeset
858
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
859 X_Shutdown();
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
860 lirc_freeconfig(config);
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
861 lirc_deinit();
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
862
3
8d7d1680db7d style(9) mostly with
darius
parents: 1
diff changeset
863 return 0;
1
769b155a34f9 Initial revision
darius
parents:
diff changeset
864 }