5081
|
1 /*
|
5572
|
2 (C)2002 Charles R. Henrich (henrich@msu.edu)
|
|
3 *BSD (hopefully, requires working driver!) BrookTree capture support.
|
5081
|
4
|
5572
|
5 Still in (active) development!
|
5081
|
6
|
5572
|
7 v1.1 Mar 13 2002 Fully functional, need to move ring buffer to
|
|
8 the kernel driver.
|
|
9 v1.0 Feb 19 2002 First Release, need to add support for changing
|
|
10 audio parameters.
|
5081
|
11 */
|
|
12
|
|
13 #include "config.h"
|
|
14
|
|
15 #if defined(USE_TV) && defined(HAVE_TV_BSDBT848)
|
|
16
|
5572
|
17 #define RINGSIZE 8
|
|
18 #define FRAGSIZE 4096 /* (2^12 see SETFRAGSIZE below) */
|
|
19
|
5081
|
20 #define TRUE (1==1)
|
|
21 #define FALSE (1==0)
|
|
22
|
|
23 #define PAL_WIDTH 768
|
|
24 #define PAL_HEIGHT 576
|
5572
|
25 #define PAL_FPS 25
|
5081
|
26
|
|
27 #define NTSC_WIDTH 640
|
|
28 #define NTSC_HEIGHT 480
|
5572
|
29 #define NTSC_FPS 30
|
5081
|
30
|
|
31 #include <stdio.h>
|
|
32 #include <stdlib.h>
|
|
33 #include <unistd.h>
|
|
34 #include <fcntl.h>
|
|
35 #include <sys/types.h>
|
|
36 #include <sys/mman.h>
|
5572
|
37 #include <sys/filio.h>
|
|
38 #include <sys/time.h>
|
5081
|
39 #include <signal.h>
|
|
40 #include <string.h>
|
|
41
|
5872
|
42 #ifdef __NetBSD__
|
|
43 #include <dev/ic/bt8xx.h>
|
|
44 #else
|
5081
|
45 #include <machine/ioctl_meteor.h>
|
|
46 #include <machine/ioctl_bt848.h>
|
5872
|
47 #endif
|
5572
|
48
|
5142
|
49 #ifdef HAVE_SYS_SOUNDCARD_H
|
|
50 #include <sys/soundcard.h>
|
|
51 #else
|
5886
|
52 #ifdef HAVE_SOUNDCARD_H
|
|
53 #include <soundcard.h>
|
|
54 #else
|
5081
|
55 #include <machine/soundcard.h>
|
5142
|
56 #endif
|
5886
|
57 #endif
|
5081
|
58
|
|
59 #include "../libvo/img_format.h"
|
|
60 #include "tv.h"
|
|
61
|
|
62 /* information about this file */
|
|
63 static tvi_info_t info = {
|
5572
|
64 "Brooktree848 Support",
|
|
65 "bsdbt848",
|
|
66 "Charles Henrich",
|
|
67 "in development"
|
5081
|
68 };
|
|
69
|
5572
|
70 typedef struct {
|
|
71 int dirty;
|
|
72 double timestamp;
|
|
73 char *buf;
|
|
74 } RBFRAME;
|
|
75
|
5081
|
76 /* private data's */
|
|
77 typedef struct {
|
|
78
|
|
79 /* Audio */
|
5572
|
80 char *dspdev;
|
|
81 int dspready;
|
|
82 int dspfd;
|
|
83 int dspsamplesize;
|
|
84 int dspstereo;
|
|
85 int dspspeed;
|
|
86 int dspfmt;
|
|
87 int dspframesize;
|
|
88 int dsprate;
|
|
89 long long dspbytesread;
|
5081
|
90
|
|
91 /* Video */
|
5572
|
92 char *btdev;
|
|
93 int videoready;
|
|
94 int btfd;
|
|
95 int source;
|
|
96 int maxfps;
|
|
97 int fps;
|
|
98 int iformat;
|
|
99 int maxheight;
|
|
100 int maxwidth;
|
|
101 struct meteor_geomet geom;
|
|
102 struct meteor_capframe capframe;
|
|
103
|
|
104 /* Frame Buffer */
|
|
105
|
|
106 int framebufsize;
|
|
107 float timestamp;
|
|
108 int curpaintframe;
|
|
109 int curbufframe;
|
|
110 unsigned char *livebuf;
|
|
111 RBFRAME framebuf[RINGSIZE];
|
5081
|
112
|
|
113 /* Inputs */
|
|
114
|
5572
|
115 int input;
|
5081
|
116
|
|
117 /* Tuner */
|
|
118
|
5572
|
119 char *tunerdev;
|
|
120 int tunerfd;
|
|
121 int tunerready;
|
|
122 u_long tunerfreq;
|
|
123 struct bktr_chnlset cset;
|
|
124
|
|
125 /* Other */
|
|
126
|
|
127 int immediatemode;
|
|
128 double starttime;
|
5081
|
129
|
|
130 } priv_t;
|
|
131
|
|
132 #include "tvi_def.h"
|
|
133
|
|
134 static priv_t *G_private=NULL;
|
|
135
|
5572
|
136 static int getinput(int innumber);
|
5081
|
137
|
|
138 static void processframe(int signal)
|
|
139 {
|
5572
|
140 struct timeval curtime;
|
|
141
|
|
142 if(G_private->immediatemode == TRUE) return;
|
|
143
|
|
144 gettimeofday(&curtime, NULL);
|
|
145
|
|
146 if(G_private->framebuf[G_private->curpaintframe].dirty == TRUE)
|
|
147 {
|
|
148 memcpy(G_private->framebuf[G_private->curpaintframe].buf,
|
|
149 G_private->livebuf, G_private->framebufsize);
|
|
150
|
|
151 G_private->framebuf[G_private->curpaintframe].dirty = FALSE;
|
|
152
|
|
153 G_private->framebuf[G_private->curpaintframe].timestamp =
|
|
154 curtime.tv_sec + curtime.tv_usec*.000001;
|
|
155
|
|
156 G_private->curpaintframe++;
|
|
157
|
|
158 if(G_private->curpaintframe >= RINGSIZE) G_private->curpaintframe = 0;
|
|
159 }
|
5081
|
160
|
|
161 return;
|
|
162 }
|
|
163
|
|
164 /* handler creator - entry point ! */
|
|
165 tvi_handle_t *tvi_init_bsdbt848(char *device)
|
|
166 {
|
5572
|
167 return(new_handle());
|
5081
|
168 }
|
|
169
|
|
170 static int control(priv_t *priv, int cmd, void *arg)
|
|
171 {
|
5572
|
172 switch(cmd)
|
|
173 {
|
5081
|
174
|
|
175 /* Tuner Controls */
|
|
176
|
5572
|
177 case TVI_CONTROL_IS_TUNER:
|
|
178 if(priv->tunerready == FALSE) return TVI_CONTROL_FALSE;
|
|
179 return(TVI_CONTROL_TRUE);
|
5081
|
180
|
5572
|
181 case TVI_CONTROL_TUN_GET_FREQ:
|
|
182 {
|
|
183 if(ioctl(priv->tunerfd, TVTUNER_GETFREQ, &priv->tunerfreq) < 0)
|
|
184 {
|
|
185 perror("GETFREQ:ioctl");
|
|
186 return(TVI_CONTROL_FALSE);
|
|
187 }
|
5081
|
188
|
5572
|
189 (int)*(void **)arg = priv->tunerfreq;
|
|
190 return(TVI_CONTROL_TRUE);
|
|
191 }
|
|
192
|
|
193 case TVI_CONTROL_TUN_SET_FREQ:
|
|
194 {
|
|
195 priv->tunerfreq = (int)*(void **)arg;
|
5081
|
196
|
5572
|
197 if(ioctl(priv->tunerfd, TVTUNER_SETFREQ, &priv->tunerfreq) < 0)
|
|
198 {
|
|
199 perror("SETFREQ:ioctl");
|
|
200 return(0);
|
|
201 }
|
5081
|
202
|
5572
|
203 return(TVI_CONTROL_TRUE);
|
|
204 }
|
5081
|
205
|
5572
|
206 case TVI_CONTROL_TUN_GET_TUNER:
|
|
207 case TVI_CONTROL_TUN_SET_TUNER:
|
5081
|
208
|
|
209 /* Inputs */
|
|
210
|
|
211 case TVI_CONTROL_SPC_GET_INPUT:
|
5572
|
212 {
|
|
213 if(ioctl(priv->btfd, METEORGINPUT, &priv->input) < 0)
|
|
214 {
|
|
215 perror("GINPUT:ioctl");
|
|
216 return(TVI_CONTROL_FALSE);
|
|
217 }
|
5081
|
218
|
5572
|
219 (int)*(void **)arg = priv->input;
|
|
220 return(TVI_CONTROL_TRUE);
|
|
221 }
|
|
222
|
5081
|
223 case TVI_CONTROL_SPC_SET_INPUT:
|
5572
|
224 {
|
|
225 priv->input = getinput((int)*(void **)arg);
|
5081
|
226
|
5572
|
227 if(ioctl(priv->btfd, METEORSINPUT, &priv->input) < 0)
|
|
228 {
|
|
229 perror("tunerfreq:ioctl");
|
|
230 return(0);
|
|
231 }
|
5081
|
232
|
5572
|
233 return(TVI_CONTROL_TRUE);
|
|
234 }
|
5081
|
235
|
|
236 /* Audio Controls */
|
|
237
|
5572
|
238 case TVI_CONTROL_IS_AUDIO:
|
|
239 if(priv->dspready == FALSE) return TVI_CONTROL_FALSE;
|
|
240 return(TVI_CONTROL_TRUE);
|
|
241
|
|
242 case TVI_CONTROL_AUD_GET_FORMAT:
|
|
243 {
|
|
244 (int)*(void **)arg = AFMT_S16_LE;
|
|
245 return(TVI_CONTROL_TRUE);
|
|
246 }
|
|
247 case TVI_CONTROL_AUD_GET_CHANNELS:
|
|
248 {
|
|
249 (int)*(void **)arg = 2;
|
|
250 return(TVI_CONTROL_TRUE);
|
|
251 }
|
|
252 case TVI_CONTROL_AUD_SET_SAMPLERATE:
|
|
253 {
|
|
254 int dspspeed = (int)*(void **)arg;
|
5081
|
255
|
5572
|
256 if(ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &dspspeed) == -1)
|
|
257 {
|
|
258 perror("invalidaudiorate");
|
|
259 return(TVI_CONTROL_FALSE);
|
|
260 }
|
|
261
|
|
262 priv->dspspeed = dspspeed;
|
|
263
|
|
264 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/
|
|
265 priv->fps * (priv->dspstereo+1);
|
|
266 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8*
|
|
267 (priv->dspstereo+1);
|
|
268
|
|
269 return(TVI_CONTROL_TRUE);
|
|
270 }
|
|
271 case TVI_CONTROL_AUD_GET_SAMPLERATE:
|
|
272 {
|
|
273 (int)*(void **)arg = priv->dspspeed;
|
|
274 return(TVI_CONTROL_TRUE);
|
|
275 }
|
|
276 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
|
|
277 {
|
|
278 (int)*(void **)arg = priv->dspsamplesize/8;
|
|
279 return(TVI_CONTROL_TRUE);
|
|
280 }
|
5081
|
281
|
|
282 /* Video Controls */
|
|
283
|
5572
|
284 case TVI_CONTROL_IS_VIDEO:
|
|
285 if(priv->videoready == FALSE) return TVI_CONTROL_FALSE;
|
|
286 return(TVI_CONTROL_TRUE);
|
5081
|
287
|
5572
|
288 case TVI_CONTROL_TUN_SET_NORM:
|
|
289 {
|
|
290 int req_mode = (int)*(void **)arg;
|
5081
|
291
|
5572
|
292 priv->iformat = METEOR_FMT_AUTOMODE;
|
5081
|
293
|
5572
|
294 if(req_mode == TV_NORM_PAL)
|
|
295 {
|
|
296 priv->iformat = METEOR_FMT_PAL;
|
|
297 priv->maxheight = PAL_HEIGHT;
|
|
298 priv->maxwidth = PAL_WIDTH;
|
|
299 priv->maxfps = PAL_FPS;
|
|
300 priv->fps = PAL_FPS;
|
5081
|
301
|
5572
|
302 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
|
5081
|
303
|
5572
|
304 if(priv->geom.rows > priv->maxheight)
|
|
305 {
|
|
306 priv->geom.rows = priv->maxheight;
|
|
307 }
|
5081
|
308
|
5572
|
309 if(priv->geom.columns > priv->maxwidth)
|
|
310 {
|
|
311 priv->geom.columns = priv->maxwidth;
|
|
312 }
|
|
313 }
|
5081
|
314
|
5572
|
315 if(req_mode == TV_NORM_NTSC)
|
|
316 {
|
|
317 priv->iformat = METEOR_FMT_NTSC;
|
|
318 priv->maxheight = NTSC_HEIGHT;
|
|
319 priv->maxwidth = NTSC_WIDTH;
|
|
320 priv->maxfps = NTSC_FPS;
|
|
321 priv->fps = NTSC_FPS;
|
5081
|
322
|
5572
|
323 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/
|
|
324 priv->fps * (priv->dspstereo+1);
|
|
325 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8 *
|
|
326 (priv->dspstereo+1);
|
5081
|
327
|
5572
|
328 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
|
5081
|
329
|
5572
|
330 if(priv->geom.rows > priv->maxheight)
|
|
331 {
|
|
332 priv->geom.rows = priv->maxheight;
|
|
333 }
|
|
334
|
|
335 if(priv->geom.columns > priv->maxwidth)
|
|
336 {
|
|
337 priv->geom.columns = priv->maxwidth;
|
|
338 }
|
|
339 }
|
|
340
|
|
341 if(req_mode == TV_NORM_SECAM) priv->iformat = METEOR_FMT_SECAM;
|
5081
|
342
|
5572
|
343 if(ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0)
|
|
344 {
|
|
345 perror("format:ioctl");
|
|
346 return(TVI_CONTROL_FALSE);
|
|
347 }
|
|
348
|
|
349 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
|
|
350 {
|
|
351 perror("geo:ioctl");
|
|
352 return(0);
|
|
353 }
|
5081
|
354
|
5572
|
355 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
|
|
356 {
|
|
357 perror("fps:ioctl");
|
|
358 return(0);
|
|
359 }
|
5081
|
360
|
5572
|
361 return(TVI_CONTROL_TRUE);
|
|
362 }
|
|
363
|
|
364 case TVI_CONTROL_VID_GET_FORMAT:
|
|
365 (int)*(void **)arg = IMGFMT_UYVY;
|
|
366 return(TVI_CONTROL_TRUE);
|
5081
|
367
|
5572
|
368 case TVI_CONTROL_VID_SET_FORMAT:
|
|
369 {
|
|
370 int req_fmt = (int)*(void **)arg;
|
5081
|
371
|
5572
|
372 if(req_fmt != IMGFMT_UYVY) return(TVI_CONTROL_FALSE);
|
5081
|
373
|
5572
|
374 return(TVI_CONTROL_TRUE);
|
|
375 }
|
|
376 case TVI_CONTROL_VID_SET_WIDTH:
|
|
377 priv->geom.columns = (int)*(void **)arg;
|
|
378
|
|
379 if(priv->geom.columns > priv->maxwidth)
|
|
380 {
|
|
381 priv->geom.columns = priv->maxwidth;
|
|
382 }
|
5081
|
383
|
5572
|
384 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
|
|
385 {
|
|
386 perror("width:ioctl");
|
|
387 return(0);
|
|
388 }
|
5081
|
389
|
5572
|
390 return(TVI_CONTROL_TRUE);
|
5081
|
391
|
5572
|
392 case TVI_CONTROL_VID_GET_WIDTH:
|
|
393 (int)*(void **)arg = priv->geom.columns;
|
|
394 return(TVI_CONTROL_TRUE);
|
5081
|
395
|
5572
|
396 case TVI_CONTROL_VID_SET_HEIGHT:
|
|
397 priv->geom.rows = (int)*(void **)arg;
|
|
398
|
|
399 if(priv->geom.rows > priv->maxheight)
|
|
400 {
|
|
401 priv->geom.rows = priv->maxheight;
|
|
402 }
|
5081
|
403
|
5572
|
404 if(priv->geom.rows <= priv->maxheight / 2)
|
|
405 {
|
|
406 priv->geom.oformat |= METEOR_GEO_EVEN_ONLY;
|
|
407 }
|
5081
|
408
|
5572
|
409 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
|
|
410 {
|
|
411 perror("height:ioctl");
|
|
412 return(0);
|
|
413 }
|
5081
|
414
|
5572
|
415 return(TVI_CONTROL_TRUE);
|
5081
|
416
|
5572
|
417 case TVI_CONTROL_VID_GET_HEIGHT:
|
|
418 (int)*(void **)arg = priv->geom.rows;
|
|
419 return(TVI_CONTROL_TRUE);
|
5081
|
420
|
5572
|
421 case TVI_CONTROL_VID_GET_FPS:
|
|
422 (int)*(void **)arg = (int)priv->fps;
|
|
423 return(TVI_CONTROL_TRUE);
|
5081
|
424
|
|
425 /*
|
5572
|
426 case TVI_CONTROL_VID_SET_FPS:
|
|
427 priv->fps = (int)*(void **)arg;
|
5081
|
428
|
5572
|
429 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
|
5081
|
430
|
5572
|
431 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
|
|
432 {
|
|
433 perror("fps:ioctl");
|
|
434 return(0);
|
|
435 }
|
5081
|
436
|
5572
|
437 return(TVI_CONTROL_TRUE);
|
5081
|
438 */
|
|
439
|
5572
|
440 case TVI_CONTROL_VID_CHK_WIDTH:
|
|
441 case TVI_CONTROL_VID_CHK_HEIGHT:
|
|
442 return(TVI_CONTROL_TRUE);
|
5081
|
443
|
5572
|
444 case TVI_CONTROL_IMMEDIATE:
|
|
445 priv->immediatemode = TRUE;
|
|
446 return(TVI_CONTROL_TRUE);
|
|
447 }
|
|
448
|
|
449 return(TVI_CONTROL_UNKNOWN);
|
5081
|
450 }
|
|
451
|
|
452 static int init(priv_t *priv)
|
|
453 {
|
|
454 int marg;
|
5572
|
455 int count;
|
5081
|
456
|
|
457 G_private = priv; /* Oooh, sick */
|
|
458
|
|
459 /* Video Configuration */
|
|
460
|
|
461 priv->videoready = TRUE;
|
|
462 priv->btdev = strdup("/dev/bktr0");
|
5572
|
463 priv->immediatemode = FALSE;
|
5081
|
464 priv->iformat = METEOR_FMT_PAL;
|
|
465 priv->maxheight = PAL_HEIGHT;
|
|
466 priv->maxwidth = PAL_WIDTH;
|
|
467 priv->maxfps = PAL_FPS;
|
|
468 priv->source = METEOR_INPUT_DEV0;
|
|
469 priv->fps = priv->maxfps;
|
|
470
|
5572
|
471 priv->starttime=0;
|
|
472 priv->curpaintframe=0;
|
|
473 priv->curbufframe=0;
|
5081
|
474
|
|
475 priv->geom.columns = priv->maxwidth;
|
|
476 priv->geom.rows = priv->maxheight;
|
|
477 priv->geom.frames = 1;
|
|
478 priv->geom.oformat = METEOR_GEO_YUV_PACKED;
|
|
479
|
|
480 priv->btfd = open(priv->btdev, O_RDONLY);
|
|
481
|
|
482 if(priv->btfd < 0)
|
5572
|
483 {
|
|
484 perror("bktr open");
|
|
485 priv->videoready = FALSE;
|
|
486 }
|
5081
|
487
|
|
488 if(priv->videoready == TRUE &&
|
|
489 ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0)
|
5572
|
490 {
|
|
491 perror("FMT:ioctl");
|
|
492 }
|
5081
|
493
|
|
494 if(priv->videoready == TRUE &&
|
|
495 ioctl(priv->btfd, METEORSINPUT, &priv->source) < 0)
|
5572
|
496 {
|
|
497 perror("SINPUT:ioctl");
|
|
498 }
|
5081
|
499
|
|
500 if(priv->videoready == TRUE &&
|
|
501 ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
|
5572
|
502 {
|
|
503 perror("SFPS:ioctl");
|
|
504 }
|
5081
|
505
|
|
506 if(priv->videoready == TRUE &&
|
|
507 ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
|
5572
|
508 {
|
|
509 perror("SGEO:ioctl");
|
|
510 }
|
5081
|
511
|
|
512 if(priv->videoready == TRUE)
|
5572
|
513 {
|
|
514 priv->framebufsize = (priv->geom.columns * priv->geom.rows * 2);
|
|
515
|
|
516 priv->livebuf = (u_char *)mmap((caddr_t)0, priv->framebufsize, PROT_READ,
|
|
517 MAP_SHARED, priv->btfd, (off_t)0);
|
5081
|
518
|
5572
|
519 if(priv->livebuf == (u_char *) MAP_FAILED)
|
|
520 {
|
|
521 perror("mmap");
|
|
522 priv->videoready = FALSE;
|
|
523 }
|
5081
|
524
|
5572
|
525 for(count=0;count<RINGSIZE;count++)
|
|
526 {
|
|
527 priv->framebuf[count].buf = malloc(priv->framebufsize);
|
5081
|
528
|
5572
|
529 if(priv->framebuf[count].buf == NULL)
|
|
530 {
|
|
531 perror("framebufmalloc");
|
|
532 priv->videoready = FALSE;
|
|
533 break;
|
|
534 }
|
|
535
|
|
536 priv->framebuf[count].dirty = TRUE;
|
|
537 priv->framebuf[count].timestamp = 0;
|
|
538 }
|
|
539 }
|
5081
|
540
|
|
541 /* Tuner Configuration */
|
|
542
|
|
543 priv->tunerdev = strdup("/dev/tuner0");
|
|
544 priv->tunerready = TRUE;
|
|
545
|
|
546 priv->tunerfd = open(priv->tunerdev, O_RDONLY);
|
|
547
|
|
548 if(priv->tunerfd < 0)
|
5572
|
549 {
|
|
550 perror("tune open");
|
|
551 priv->tunerready = FALSE;
|
|
552 }
|
5081
|
553
|
|
554 /* Audio Configuration */
|
|
555
|
|
556 priv->dspready = TRUE;
|
|
557 priv->dspdev = strdup("/dev/dsp");
|
|
558 priv->dspsamplesize = 16;
|
|
559 priv->dspstereo = 1;
|
|
560 priv->dspspeed = 44100;
|
|
561 priv->dspfmt = AFMT_S16_LE;
|
5572
|
562 priv->dspbytesread = 0;
|
|
563 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8*(priv->dspstereo+1);
|
5081
|
564 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/priv->fps *
|
5572
|
565 (priv->dspstereo+1);
|
5081
|
566
|
5572
|
567 if((priv->dspfd = open ("/dev/dsp", O_RDONLY, 0)) < 0)
|
|
568 {
|
|
569 perror("/dev/dsp open");
|
|
570 priv->dspready = FALSE;
|
|
571 }
|
5081
|
572
|
5572
|
573 marg = (256 << 16) | 12;
|
5081
|
574
|
|
575 if (ioctl(priv->dspfd, SNDCTL_DSP_SETFRAGMENT, &marg ) < 0 )
|
5572
|
576 {
|
|
577 perror("setfrag");
|
|
578 priv->dspready = FALSE;
|
|
579 }
|
5081
|
580
|
|
581 if((priv->dspready == TRUE) &&
|
5572
|
582 ((ioctl(priv->dspfd, SNDCTL_DSP_SAMPLESIZE, &priv->dspsamplesize) == -1) ||
|
5081
|
583 (ioctl(priv->dspfd, SNDCTL_DSP_STEREO, &priv->dspstereo) == -1) ||
|
|
584 (ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &priv->dspspeed) == -1) ||
|
5572
|
585 (ioctl(priv->dspfd, SNDCTL_DSP_SETFMT, &priv->dspfmt) == -1)))
|
|
586 {
|
|
587 perror ("configuration of /dev/dsp failed");
|
|
588 close(priv->dspfd);
|
|
589 priv->dspready = FALSE;
|
|
590 }
|
5081
|
591
|
|
592 return(1);
|
|
593 }
|
|
594
|
|
595 /* that's the real start, we'got the format parameters (checked with control) */
|
|
596 static int start(priv_t *priv)
|
|
597 {
|
5572
|
598 int tmp;
|
|
599 struct timeval curtime;
|
5081
|
600 int marg;
|
|
601
|
5572
|
602 fprintf(stderr,"START\n");
|
5081
|
603 if(priv->videoready == FALSE) return(0);
|
|
604
|
|
605 signal(SIGUSR1, processframe);
|
|
606 signal(SIGALRM, processframe);
|
|
607
|
|
608 marg = SIGUSR1;
|
|
609
|
|
610 if(ioctl(priv->btfd, METEORSSIGNAL, &marg) < 0)
|
5572
|
611 {
|
|
612 perror("METEORSSIGNAL failed");
|
|
613 return(0);
|
|
614 }
|
|
615
|
|
616 read(priv->dspfd, &tmp, 2);
|
|
617
|
|
618 gettimeofday(&curtime, NULL);
|
|
619
|
|
620 priv->starttime = curtime.tv_sec + (curtime.tv_usec *.000001);
|
5081
|
621
|
|
622 marg = METEOR_CAP_CONTINOUS;
|
|
623
|
|
624 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0)
|
5572
|
625 {
|
|
626 perror("METEORCAPTUR failed");
|
|
627 return(0);
|
|
628 }
|
5081
|
629
|
|
630 return(1);
|
|
631 }
|
|
632
|
|
633 static int uninit(priv_t *priv)
|
|
634 {
|
|
635 int marg;
|
|
636
|
|
637 if(priv->videoready == FALSE) return(0);
|
|
638
|
|
639 marg = METEOR_SIG_MODE_MASK;
|
|
640
|
|
641 if(ioctl( priv->btfd, METEORSSIGNAL, &marg) < 0 )
|
5572
|
642 {
|
|
643 perror("METEORSSIGNAL");
|
|
644 return(0);
|
|
645 }
|
5081
|
646
|
|
647 marg = METEOR_CAP_STOP_CONT;
|
|
648
|
|
649 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0 )
|
5572
|
650 {
|
|
651 perror("METEORCAPTUR STOP");
|
|
652 return(0);
|
|
653 }
|
5081
|
654
|
|
655 close(priv->btfd);
|
|
656 close(priv->dspfd);
|
|
657
|
|
658 priv->dspfd = -1;
|
|
659 priv->btfd = -1;
|
|
660
|
|
661 priv->dspready = priv->videoready = FALSE;
|
|
662
|
|
663 return(1);
|
|
664 }
|
|
665
|
|
666
|
5572
|
667 static double grabimmediate_video_frame(priv_t *priv, char *buffer, int len)
|
5081
|
668 {
|
5572
|
669 struct timeval curtime;
|
5081
|
670 sigset_t sa_mask;
|
|
671
|
|
672 if(priv->videoready == FALSE) return(0);
|
|
673
|
|
674 alarm(1);
|
|
675 sigfillset(&sa_mask);
|
|
676 sigdelset(&sa_mask,SIGINT);
|
|
677 sigdelset(&sa_mask,SIGUSR1);
|
|
678 sigdelset(&sa_mask,SIGALRM);
|
|
679 sigsuspend(&sa_mask);
|
|
680 alarm(0);
|
|
681
|
5572
|
682 memcpy(buffer, priv->livebuf, len);
|
|
683
|
|
684 /* PTS = 0, show the frame NOW, this routine is only used in playback mode
|
|
685 without audio capture .. */
|
|
686
|
|
687 return(0);
|
|
688 }
|
|
689
|
|
690 static double grab_video_frame(priv_t *priv, char *buffer, int len)
|
|
691 {
|
|
692 struct timeval curtime;
|
|
693 double timestamp=0;
|
|
694 sigset_t sa_mask;
|
|
695
|
|
696 if(priv->videoready == FALSE) return(0);
|
5081
|
697
|
5572
|
698 if(priv->immediatemode == TRUE)
|
|
699 {
|
|
700 return grabimmediate_video_frame(priv, buffer, len);
|
|
701 }
|
|
702
|
|
703 while(priv->framebuf[priv->curbufframe].dirty == TRUE)
|
|
704 {
|
|
705 alarm(1);
|
|
706 sigemptyset(&sa_mask);
|
|
707 sigsuspend(&sa_mask);
|
|
708 alarm(0);
|
|
709 }
|
|
710
|
|
711 memcpy(buffer, priv->framebuf[priv->curbufframe].buf, len);
|
|
712 timestamp = priv->framebuf[priv->curbufframe].timestamp;
|
|
713 priv->framebuf[priv->curbufframe].dirty = TRUE;
|
|
714
|
|
715 priv->curbufframe++;
|
|
716 if(priv->curbufframe >= RINGSIZE) priv->curbufframe = 0;
|
|
717
|
|
718 return(timestamp-priv->starttime);
|
5081
|
719 }
|
|
720
|
|
721 static int get_video_framesize(priv_t *priv)
|
|
722 {
|
|
723 return(priv->geom.columns*priv->geom.rows*16/8);
|
|
724 }
|
|
725
|
5572
|
726 static double grab_audio_frame(priv_t *priv, char *buffer, int len)
|
5081
|
727 {
|
5572
|
728 struct timeval curtime;
|
|
729 double curpts;
|
|
730 double timeskew;
|
|
731 int bytesavail;
|
5081
|
732 int bytesread;
|
|
733 int ret;
|
|
734
|
|
735 if(priv->dspready == FALSE) return 0;
|
|
736
|
5572
|
737 gettimeofday(&curtime, NULL);
|
|
738
|
5081
|
739 /* Get exactly one frame of audio, which forces video sync to audio.. */
|
|
740
|
|
741 bytesread=read(priv->dspfd, buffer, len);
|
|
742
|
|
743 while(bytesread < len)
|
5572
|
744 {
|
|
745 ret=read(priv->dspfd, &buffer[bytesread], len-bytesread);
|
5081
|
746
|
5572
|
747 if(ret == -1)
|
|
748 {
|
|
749 perror("Audio read failed!");
|
|
750 return 0;
|
|
751 }
|
|
752
|
|
753 bytesread+=ret;
|
|
754 }
|
|
755
|
|
756 priv->dspbytesread += bytesread;
|
|
757
|
|
758 curpts = curtime.tv_sec + curtime.tv_usec * .000001;
|
5081
|
759
|
5572
|
760 timeskew = priv->dspbytesread * 1.0 / priv->dsprate - (curpts-priv->starttime);
|
5081
|
761
|
5572
|
762 if(timeskew > .125/priv->fps)
|
|
763 {
|
|
764 priv->starttime -= timeskew;
|
|
765 }
|
|
766 else
|
|
767 {
|
|
768 if(timeskew < -.125/priv->fps)
|
|
769 {
|
|
770 priv->starttime -= timeskew;
|
|
771 }
|
|
772 }
|
5081
|
773
|
5572
|
774 return(priv->dspbytesread * 1.0 / priv->dsprate);
|
5081
|
775 }
|
|
776
|
|
777 static int get_audio_framesize(priv_t *priv)
|
|
778 {
|
5572
|
779 int bytesavail;
|
|
780
|
5081
|
781 if(priv->dspready == FALSE) return 0;
|
|
782
|
5572
|
783 if(ioctl(priv->dspfd, FIONREAD, &bytesavail) < 0)
|
|
784 {
|
|
785 perror("FIONREAD");
|
|
786 return(TVI_CONTROL_FALSE);
|
|
787 }
|
|
788
|
|
789 /* When mencoder wants audio data, it wants data..
|
|
790 it wont go do anything else until it gets it :( */
|
|
791
|
|
792 if(bytesavail == 0) return FRAGSIZE;
|
|
793
|
|
794 return(bytesavail);
|
5081
|
795 }
|
|
796
|
|
797 static int getinput(int innumber)
|
|
798 {
|
|
799 switch(innumber)
|
5572
|
800 {
|
|
801 case 0: return METEOR_INPUT_DEV0; /* RCA */
|
|
802 case 1: return METEOR_INPUT_DEV1; /* Tuner */
|
|
803 case 2: return METEOR_INPUT_DEV2; /* In 1 */
|
|
804 case 3: return METEOR_INPUT_DEV3; /* In 2 */
|
|
805 case 4: return METEOR_INPUT_DEV_RGB; /* RGB */
|
|
806 case 5: return METEOR_INPUT_DEV_SVIDEO; /* SVid */
|
|
807 }
|
5081
|
808
|
|
809 return 0;
|
|
810 }
|
|
811
|
|
812 #endif /* USE_TV */
|