annotate simpletv.c @ 1:769b155a34f9 SIMPETV_0_1

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