Mercurial > mplayer.hg
comparison libmpdemux/tvi_bsdbt848.c @ 5081:7473fca49ca0
initial
author | alex |
---|---|
date | Fri, 15 Mar 2002 14:59:32 +0000 |
parents | |
children | 7fc559dbc607 |
comparison
equal
deleted
inserted
replaced
5080:f333b10ec34f | 5081:7473fca49ca0 |
---|---|
1 /* | |
2 (C)2002 Charles R. Henrich (henrich@msu.edu) | |
3 *BSD (hopefully, requires working driver!) BrookTree capture support. | |
4 | |
5 Still in (active) development! | |
6 | |
7 v1.0 Feb 19 2002 First Release, need to add support for changing | |
8 audio parameters. | |
9 */ | |
10 | |
11 #include "config.h" | |
12 | |
13 #if defined(USE_TV) && defined(HAVE_TV_BSDBT848) | |
14 | |
15 #define TRUE (1==1) | |
16 #define FALSE (1==0) | |
17 | |
18 #define PAL_WIDTH 768 | |
19 #define PAL_HEIGHT 576 | |
20 #define PAL_FPS 25 | |
21 | |
22 #define NTSC_WIDTH 640 | |
23 #define NTSC_HEIGHT 480 | |
24 #define NTSC_FPS 30 | |
25 | |
26 #include <stdio.h> | |
27 #include <stdlib.h> | |
28 #include <unistd.h> | |
29 #include <fcntl.h> | |
30 #include <sys/types.h> | |
31 #include <sys/mman.h> | |
32 #include <signal.h> | |
33 #include <string.h> | |
34 | |
35 #include <machine/ioctl_meteor.h> | |
36 #include <machine/ioctl_bt848.h> | |
37 #include <machine/soundcard.h> | |
38 | |
39 #include "../libvo/img_format.h" | |
40 #include "tv.h" | |
41 | |
42 /* information about this file */ | |
43 static tvi_info_t info = { | |
44 "Brooktree848 Support", | |
45 "bt848", | |
46 "Charles Henrich", | |
47 "in development" | |
48 }; | |
49 | |
50 /* private data's */ | |
51 typedef struct { | |
52 | |
53 /* Audio */ | |
54 char *dspdev; | |
55 int dspready; | |
56 int dspfd; | |
57 int dspsamplesize; | |
58 int dspstereo; | |
59 int dspspeed; | |
60 int dspfmt; | |
61 int dspframesize; | |
62 | |
63 /* Video */ | |
64 char *btdev; | |
65 int videoready; | |
66 int btfd; | |
67 int source; | |
68 int maxfps; | |
69 int fps; | |
70 int iformat; | |
71 int maxheight; | |
72 int maxwidth; | |
73 struct meteor_geomet geom; | |
74 struct meteor_capframe capframe; | |
75 int buffersize; | |
76 unsigned char *buffer; | |
77 int currentframe; | |
78 | |
79 /* Inputs */ | |
80 | |
81 int input; | |
82 | |
83 /* Tuner */ | |
84 | |
85 char *tunerdev; | |
86 int tunerfd; | |
87 int tunerready; | |
88 u_long tunerfreq; | |
89 struct bktr_chnlset cset; | |
90 | |
91 } priv_t; | |
92 | |
93 #include "tvi_def.h" | |
94 | |
95 static priv_t *G_private=NULL; | |
96 | |
97 | |
98 static void processframe(int signal) | |
99 { | |
100 G_private->currentframe++; | |
101 | |
102 return; | |
103 } | |
104 | |
105 /* handler creator - entry point ! */ | |
106 tvi_handle_t *tvi_init_bsdbt848(char *device) | |
107 { | |
108 return(new_handle()); | |
109 } | |
110 | |
111 static int control(priv_t *priv, int cmd, void *arg) | |
112 { | |
113 switch(cmd) | |
114 { | |
115 | |
116 /* Tuner Controls */ | |
117 | |
118 case TVI_CONTROL_IS_TUNER: | |
119 if(priv->tunerready == FALSE) return TVI_CONTROL_FALSE; | |
120 return(TVI_CONTROL_TRUE); | |
121 | |
122 case TVI_CONTROL_TUN_GET_FREQ: | |
123 { | |
124 if(ioctl(priv->tunerfd, TVTUNER_GETFREQ, &priv->tunerfreq) < 0) | |
125 { | |
126 perror("GETFREQ:ioctl"); | |
127 return(TVI_CONTROL_FALSE); | |
128 } | |
129 | |
130 (int)*(void **)arg = priv->tunerfreq; | |
131 return(TVI_CONTROL_TRUE); | |
132 } | |
133 | |
134 case TVI_CONTROL_TUN_SET_FREQ: | |
135 { | |
136 priv->tunerfreq = (int)*(void **)arg; | |
137 | |
138 if(ioctl(priv->tunerfd, TVTUNER_SETFREQ, &priv->tunerfreq) < 0) | |
139 { | |
140 perror("SETFREQ:ioctl"); | |
141 return(0); | |
142 } | |
143 | |
144 return(TVI_CONTROL_TRUE); | |
145 } | |
146 | |
147 case TVI_CONTROL_TUN_GET_TUNER: | |
148 case TVI_CONTROL_TUN_SET_TUNER: | |
149 | |
150 /* Inputs */ | |
151 | |
152 case TVI_CONTROL_SPC_GET_INPUT: | |
153 { | |
154 if(ioctl(priv->btfd, METEORGINPUT, &priv->input) < 0) | |
155 { | |
156 perror("GINPUT:ioctl"); | |
157 return(TVI_CONTROL_FALSE); | |
158 } | |
159 | |
160 (int)*(void **)arg = priv->input; | |
161 return(TVI_CONTROL_TRUE); | |
162 } | |
163 | |
164 case TVI_CONTROL_SPC_SET_INPUT: | |
165 { | |
166 priv->input = getinput((int)*(void **)arg); | |
167 | |
168 if(ioctl(priv->btfd, METEORSINPUT, &priv->input) < 0) | |
169 { | |
170 perror("tunerfreq:ioctl"); | |
171 return(0); | |
172 } | |
173 | |
174 return(TVI_CONTROL_TRUE); | |
175 } | |
176 | |
177 /* Audio Controls */ | |
178 | |
179 case TVI_CONTROL_IS_AUDIO: | |
180 if(priv->dspready == FALSE) return TVI_CONTROL_FALSE; | |
181 return(TVI_CONTROL_TRUE); | |
182 | |
183 case TVI_CONTROL_AUD_GET_FORMAT: | |
184 { | |
185 (int)*(void **)arg = AFMT_S16_LE; | |
186 return(TVI_CONTROL_TRUE); | |
187 } | |
188 case TVI_CONTROL_AUD_GET_CHANNELS: | |
189 { | |
190 (int)*(void **)arg = 2; | |
191 return(TVI_CONTROL_TRUE); | |
192 } | |
193 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
194 { | |
195 (int)*(void **)arg = 44100; | |
196 return(TVI_CONTROL_TRUE); | |
197 } | |
198 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
199 { | |
200 (int)*(void **)arg = priv->dspsamplesize; | |
201 return(TVI_CONTROL_TRUE); | |
202 } | |
203 | |
204 /* Video Controls */ | |
205 | |
206 case TVI_CONTROL_IS_VIDEO: | |
207 if(priv->videoready == FALSE) return TVI_CONTROL_FALSE; | |
208 return(TVI_CONTROL_TRUE); | |
209 | |
210 case TVI_CONTROL_TUN_SET_NORM: | |
211 { | |
212 int req_mode = (int)*(void **)arg; | |
213 | |
214 priv->iformat = METEOR_FMT_AUTOMODE; | |
215 | |
216 if(req_mode == TV_NORM_PAL) | |
217 { | |
218 priv->iformat = METEOR_FMT_PAL; | |
219 priv->maxheight = PAL_HEIGHT; | |
220 priv->maxwidth = PAL_WIDTH; | |
221 priv->maxfps = PAL_FPS; | |
222 priv->fps = PAL_FPS; | |
223 | |
224 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps; | |
225 | |
226 if(priv->geom.rows > priv->maxheight) | |
227 { | |
228 priv->geom.rows = priv->maxheight; | |
229 } | |
230 | |
231 if(priv->geom.columns > priv->maxwidth) | |
232 { | |
233 priv->geom.columns = priv->maxwidth; | |
234 } | |
235 } | |
236 | |
237 if(req_mode == TV_NORM_NTSC) | |
238 { | |
239 priv->iformat = METEOR_FMT_NTSC; | |
240 priv->maxheight = NTSC_HEIGHT; | |
241 priv->maxwidth = NTSC_WIDTH; | |
242 priv->maxfps = NTSC_FPS; | |
243 priv->fps = NTSC_FPS; | |
244 | |
245 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/ | |
246 priv->fps * (priv->dspstereo+1); | |
247 | |
248 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps; | |
249 | |
250 if(priv->geom.rows > priv->maxheight) | |
251 { | |
252 priv->geom.rows = priv->maxheight; | |
253 } | |
254 | |
255 if(priv->geom.columns > priv->maxwidth) | |
256 { | |
257 priv->geom.columns = priv->maxwidth; | |
258 } | |
259 } | |
260 | |
261 if(req_mode == TV_NORM_SECAM) priv->iformat = METEOR_FMT_SECAM; | |
262 | |
263 if(ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0) | |
264 { | |
265 perror("format:ioctl"); | |
266 return(TVI_CONTROL_FALSE); | |
267 } | |
268 | |
269 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0) | |
270 { | |
271 perror("geo:ioctl"); | |
272 return(0); | |
273 } | |
274 | |
275 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0) | |
276 { | |
277 perror("fps:ioctl"); | |
278 return(0); | |
279 } | |
280 | |
281 return(TVI_CONTROL_TRUE); | |
282 } | |
283 | |
284 case TVI_CONTROL_VID_GET_FORMAT: | |
285 (int)*(void **)arg = IMGFMT_UYVY; | |
286 return(TVI_CONTROL_TRUE); | |
287 | |
288 case TVI_CONTROL_VID_SET_FORMAT: | |
289 { | |
290 int req_fmt = (int)*(void **)arg; | |
291 | |
292 if(req_fmt != IMGFMT_UYVY) return(TVI_CONTROL_FALSE); | |
293 | |
294 return(TVI_CONTROL_TRUE); | |
295 } | |
296 case TVI_CONTROL_VID_SET_WIDTH: | |
297 priv->geom.columns = (int)*(void **)arg; | |
298 | |
299 if(priv->geom.columns > priv->maxwidth) | |
300 { | |
301 priv->geom.columns = priv->maxwidth; | |
302 } | |
303 | |
304 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0) | |
305 { | |
306 perror("width:ioctl"); | |
307 return(0); | |
308 } | |
309 | |
310 return(TVI_CONTROL_TRUE); | |
311 | |
312 case TVI_CONTROL_VID_GET_WIDTH: | |
313 (int)*(void **)arg = priv->geom.columns; | |
314 return(TVI_CONTROL_TRUE); | |
315 | |
316 case TVI_CONTROL_VID_SET_HEIGHT: | |
317 priv->geom.rows = (int)*(void **)arg; | |
318 | |
319 if(priv->geom.rows > priv->maxheight) | |
320 { | |
321 priv->geom.rows = priv->maxheight; | |
322 } | |
323 | |
324 if(priv->geom.rows <= priv->maxheight / 2) | |
325 { | |
326 priv->geom.oformat |= METEOR_GEO_EVEN_ONLY; | |
327 } | |
328 | |
329 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0) | |
330 { | |
331 perror("height:ioctl"); | |
332 return(0); | |
333 } | |
334 | |
335 return(TVI_CONTROL_TRUE); | |
336 | |
337 case TVI_CONTROL_VID_GET_HEIGHT: | |
338 (int)*(void **)arg = priv->geom.rows; | |
339 return(TVI_CONTROL_TRUE); | |
340 | |
341 case TVI_CONTROL_VID_GET_FPS: | |
342 (int)*(void **)arg = (int)priv->fps; | |
343 return(TVI_CONTROL_TRUE); | |
344 | |
345 /* | |
346 case TVI_CONTROL_VID_SET_FPS: | |
347 priv->fps = (int)*(void **)arg; | |
348 | |
349 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps; | |
350 | |
351 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0) | |
352 { | |
353 perror("fps:ioctl"); | |
354 return(0); | |
355 } | |
356 | |
357 return(TVI_CONTROL_TRUE); | |
358 */ | |
359 | |
360 case TVI_CONTROL_VID_CHK_WIDTH: | |
361 case TVI_CONTROL_VID_CHK_HEIGHT: | |
362 return(TVI_CONTROL_TRUE); | |
363 | |
364 } | |
365 return(TVI_CONTROL_UNKNOWN); | |
366 } | |
367 | |
368 static int init(priv_t *priv) | |
369 { | |
370 int marg; | |
371 | |
372 G_private = priv; /* Oooh, sick */ | |
373 | |
374 /* Video Configuration */ | |
375 | |
376 priv->videoready = TRUE; | |
377 priv->btdev = strdup("/dev/bktr0"); | |
378 priv->iformat = METEOR_FMT_PAL; | |
379 priv->maxheight = PAL_HEIGHT; | |
380 priv->maxwidth = PAL_WIDTH; | |
381 priv->maxfps = PAL_FPS; | |
382 priv->source = METEOR_INPUT_DEV0; | |
383 priv->fps = priv->maxfps; | |
384 | |
385 priv->currentframe=0; | |
386 | |
387 priv->geom.columns = priv->maxwidth; | |
388 priv->geom.rows = priv->maxheight; | |
389 priv->geom.frames = 1; | |
390 priv->geom.oformat = METEOR_GEO_YUV_PACKED; | |
391 | |
392 priv->btfd = open(priv->btdev, O_RDONLY); | |
393 | |
394 if(priv->btfd < 0) | |
395 { | |
396 perror("bktr open"); | |
397 priv->videoready = FALSE; | |
398 } | |
399 | |
400 if(priv->videoready == TRUE && | |
401 ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0) | |
402 { | |
403 perror("FMT:ioctl"); | |
404 } | |
405 | |
406 if(priv->videoready == TRUE && | |
407 ioctl(priv->btfd, METEORSINPUT, &priv->source) < 0) | |
408 { | |
409 perror("SINPUT:ioctl"); | |
410 } | |
411 | |
412 if(priv->videoready == TRUE && | |
413 ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0) | |
414 { | |
415 perror("SFPS:ioctl"); | |
416 } | |
417 | |
418 if(priv->videoready == TRUE && | |
419 ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0) | |
420 { | |
421 perror("SGEO:ioctl"); | |
422 } | |
423 | |
424 if(priv->videoready == TRUE) | |
425 { | |
426 priv->buffersize = (priv->geom.columns * priv->geom.rows * 2); | |
427 | |
428 priv->buffer = (u_char *)mmap((caddr_t)0, priv->buffersize, PROT_READ, | |
429 MAP_SHARED, priv->btfd, (off_t)0); | |
430 | |
431 if(priv->buffer == (u_char *) MAP_FAILED) | |
432 { | |
433 perror("mmap"); | |
434 priv->videoready = FALSE; | |
435 } | |
436 | |
437 } | |
438 | |
439 /* Tuner Configuration */ | |
440 | |
441 priv->tunerdev = strdup("/dev/tuner0"); | |
442 priv->tunerready = TRUE; | |
443 | |
444 priv->tunerfd = open(priv->tunerdev, O_RDONLY); | |
445 | |
446 if(priv->tunerfd < 0) | |
447 { | |
448 perror("tune open"); | |
449 priv->tunerready = FALSE; | |
450 } | |
451 | |
452 /* Audio Configuration */ | |
453 | |
454 priv->dspready = TRUE; | |
455 priv->dspdev = strdup("/dev/dsp"); | |
456 priv->dspsamplesize = 16; | |
457 priv->dspstereo = 1; | |
458 priv->dspspeed = 44100; | |
459 priv->dspfmt = AFMT_S16_LE; | |
460 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/priv->fps * | |
461 (priv->dspstereo+1); | |
462 | |
463 if((priv->dspfd = open ("/dev/dsp", O_RDWR, 0)) < 0) | |
464 { | |
465 perror("/dev/dsp open"); | |
466 priv->dspready = FALSE; | |
467 } | |
468 | |
469 marg = (256 << 16) | 13; | |
470 | |
471 if (ioctl(priv->dspfd, SNDCTL_DSP_SETFRAGMENT, &marg ) < 0 ) | |
472 { | |
473 perror("setfrag"); | |
474 priv->dspready = FALSE; | |
475 } | |
476 | |
477 if((priv->dspready == TRUE) && | |
478 (ioctl(priv->dspfd, SNDCTL_DSP_SAMPLESIZE, &priv->dspsamplesize) == -1) || | |
479 (ioctl(priv->dspfd, SNDCTL_DSP_STEREO, &priv->dspstereo) == -1) || | |
480 (ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &priv->dspspeed) == -1) || | |
481 (ioctl(priv->dspfd, SNDCTL_DSP_SETFMT, &priv->dspfmt) == -1)) | |
482 { | |
483 perror ("configuration of /dev/dsp failed"); | |
484 close(priv->dspfd); | |
485 priv->dspready = FALSE; | |
486 } | |
487 | |
488 return(1); | |
489 } | |
490 | |
491 /* that's the real start, we'got the format parameters (checked with control) */ | |
492 static int start(priv_t *priv) | |
493 { | |
494 int marg; | |
495 | |
496 if(priv->videoready == FALSE) return(0); | |
497 | |
498 signal(SIGUSR1, processframe); | |
499 signal(SIGALRM, processframe); | |
500 | |
501 marg = SIGUSR1; | |
502 | |
503 if(ioctl(priv->btfd, METEORSSIGNAL, &marg) < 0) | |
504 { | |
505 perror("METEORSSIGNAL failed"); | |
506 return(0); | |
507 } | |
508 | |
509 marg = METEOR_CAP_CONTINOUS; | |
510 | |
511 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0) | |
512 { | |
513 perror("METEORCAPTUR failed"); | |
514 return(0); | |
515 } | |
516 | |
517 return(1); | |
518 } | |
519 | |
520 static int uninit(priv_t *priv) | |
521 { | |
522 int marg; | |
523 | |
524 if(priv->videoready == FALSE) return(0); | |
525 | |
526 marg = METEOR_SIG_MODE_MASK; | |
527 | |
528 if(ioctl( priv->btfd, METEORSSIGNAL, &marg) < 0 ) | |
529 { | |
530 perror("METEORSSIGNAL"); | |
531 return(0); | |
532 } | |
533 | |
534 marg = METEOR_CAP_STOP_CONT; | |
535 | |
536 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0 ) | |
537 { | |
538 perror("METEORCAPTUR STOP"); | |
539 return(0); | |
540 } | |
541 | |
542 close(priv->btfd); | |
543 close(priv->dspfd); | |
544 | |
545 priv->dspfd = -1; | |
546 priv->btfd = -1; | |
547 | |
548 priv->dspready = priv->videoready = FALSE; | |
549 | |
550 return(1); | |
551 } | |
552 | |
553 | |
554 static int grab_video_frame(priv_t *priv, char *buffer, int len) | |
555 { | |
556 sigset_t sa_mask; | |
557 | |
558 if(priv->videoready == FALSE) return(0); | |
559 | |
560 alarm(1); | |
561 sigfillset(&sa_mask); | |
562 sigdelset(&sa_mask,SIGINT); | |
563 sigdelset(&sa_mask,SIGUSR1); | |
564 sigdelset(&sa_mask,SIGALRM); | |
565 sigsuspend(&sa_mask); | |
566 alarm(0); | |
567 | |
568 memcpy(buffer, priv->buffer, len); | |
569 | |
570 return(priv->currentframe); | |
571 } | |
572 | |
573 static int get_video_framesize(priv_t *priv) | |
574 { | |
575 return(priv->geom.columns*priv->geom.rows*16/8); | |
576 } | |
577 | |
578 static int grab_audio_frame(priv_t *priv, char *buffer, int len) | |
579 { | |
580 struct audio_buf_info abi; | |
581 int bytesread; | |
582 int ret; | |
583 | |
584 if(priv->dspready == FALSE) return 0; | |
585 | |
586 /* Get exactly one frame of audio, which forces video sync to audio.. */ | |
587 | |
588 bytesread=read(priv->dspfd, buffer, len); | |
589 | |
590 while(bytesread < len) | |
591 { | |
592 ret=read(priv->dspfd, &buffer[bytesread], len-bytesread); | |
593 | |
594 if(ret == -1) | |
595 { | |
596 perror("Audio read failed!"); | |
597 return 0; | |
598 } | |
599 | |
600 bytesread+=ret; | |
601 } | |
602 | |
603 if(ioctl(priv->dspfd, SNDCTL_DSP_GETISPACE, &abi) < 0) | |
604 { | |
605 perror("abi:ioctl"); | |
606 return(TVI_CONTROL_FALSE); | |
607 } | |
608 | |
609 return(abi.bytes/len); | |
610 } | |
611 | |
612 static int get_audio_framesize(priv_t *priv) | |
613 { | |
614 if(priv->dspready == FALSE) return 0; | |
615 | |
616 return(priv->dspframesize); | |
617 } | |
618 | |
619 static int getinput(int innumber) | |
620 { | |
621 switch(innumber) | |
622 { | |
623 case 0: return METEOR_INPUT_DEV0; /* RCA */ | |
624 case 1: return METEOR_INPUT_DEV1; /* Tuner */ | |
625 case 2: return METEOR_INPUT_DEV2; /* In 1 */ | |
626 case 3: return METEOR_INPUT_DEV3; /* In 2 */ | |
627 case 4: return METEOR_INPUT_DEV_RGB; /* RGB */ | |
628 case 5: return METEOR_INPUT_DEV_SVIDEO; /* SVid */ | |
629 } | |
630 | |
631 return 0; | |
632 } | |
633 | |
634 #endif /* USE_TV */ |