Mercurial > mplayer.hg
annotate libmpdemux/tvi_v4l.c @ 3099:897d46457708
runtime cpu detection
author | michael |
---|---|
date | Sat, 24 Nov 2001 22:16:29 +0000 |
parents | 4307478ad922 |
children | b35b40ade7e9 |
rev | line source |
---|---|
2802 | 1 /* |
2 v4l interface for libmpemux/tvi | |
3 | |
4 (C) Alex Beregszaszi <alex@naxine.org> | |
5 | |
6 Some ideas are based on xawtv/libng's grab-v4l.c written by | |
7 Gerd Knorr <kraxel@bytesex.org> | |
8 | |
9 CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE! | |
10 */ | |
11 | |
2790 | 12 #include "config.h" |
13 | |
14 #ifdef USE_TV | |
15 | |
16 #include <stdio.h> | |
17 #include <errno.h> | |
18 #include <fcntl.h> | |
2802 | 19 #include <signal.h> |
2790 | 20 #include <sys/ioctl.h> |
21 #include <sys/types.h> | |
22 #include <linux/videodev.h> | |
23 #include <unistd.h> | |
24 #include <sys/mman.h> | |
2931 | 25 #include <stdlib.h> |
26 #include <string.h> | |
2790 | 27 |
2830 | 28 #include "mp_msg.h" |
29 #include "../libao2/afmt.h" | |
30 #include "../libvo/img_format.h" | |
31 #include "../libvo/fastmemcpy.h" | |
32 | |
2790 | 33 #include "tv.h" |
34 | |
35 static tvi_info_t info = { | |
36 "Video for Linux TV Input", | |
37 "v4l", | |
2802 | 38 "Alex Beregszaszi <alex@naxine.org>", |
39 "under development" | |
40 }; | |
41 | |
2790 | 42 typedef struct { |
2802 | 43 /* general */ |
2790 | 44 char *video_device; |
45 int fd; | |
46 struct video_capability capability; | |
47 struct video_channel *channels; | |
2841 | 48 int act_channel; |
2790 | 49 struct video_tuner tuner; |
2802 | 50 |
51 /* video */ | |
2790 | 52 struct video_picture picture; |
2802 | 53 int format; /* output format */ |
2790 | 54 int width; |
55 int height; | |
2802 | 56 int bytesperline; |
57 | |
58 struct video_mbuf mbuf; | |
59 unsigned char *mmap; | |
60 struct video_mmap *buf; | |
61 int nbuf; | |
62 int queue; | |
63 | |
64 /* audio */ | |
65 struct video_audio audio; | |
2790 | 66 } priv_t; |
67 | |
68 #include "tvi_def.h" | |
69 | |
2841 | 70 static const char *device_cap2name[] = { |
2790 | 71 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping", |
2802 | 72 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder", |
73 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL | |
74 }; | |
75 | |
2841 | 76 static const char *device_palette2name[] = { |
2802 | 77 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422", |
78 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p", | |
79 "yuv420p", "yuv410p", NULL | |
80 }; | |
81 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN") | |
82 | |
2841 | 83 static const char *audio_mode2name[] = { |
84 "unknown", "mono", "stereo", "language1", "language2", NULL | |
85 }; | |
86 | |
2802 | 87 static int palette2depth(int palette) |
88 { | |
2810 | 89 switch(palette) |
90 { | |
91 case VIDEO_PALETTE_RGB555: | |
92 return(15); | |
93 case VIDEO_PALETTE_RGB565: | |
94 return(16); | |
95 case VIDEO_PALETTE_RGB24: | |
96 return(24); | |
97 case VIDEO_PALETTE_RGB32: | |
98 return(32); | |
99 case VIDEO_PALETTE_YUV420P: | |
100 return(12); | |
101 case VIDEO_PALETTE_YUV422: | |
102 case VIDEO_PALETTE_UYVY: | |
103 return(16); | |
104 } | |
105 return(-1); | |
2802 | 106 } |
107 | |
108 static int format2palette(int format) | |
109 { | |
2810 | 110 switch(format) |
111 { | |
112 case IMGFMT_RGB15: | |
113 return(VIDEO_PALETTE_RGB555); | |
114 case IMGFMT_RGB16: | |
115 return(VIDEO_PALETTE_RGB565); | |
116 case IMGFMT_RGB24: | |
117 return(VIDEO_PALETTE_RGB24); | |
118 case IMGFMT_RGB32: | |
119 return(VIDEO_PALETTE_RGB32); | |
120 case IMGFMT_YV12: | |
121 return(VIDEO_PALETTE_YUV420P); | |
122 case IMGFMT_UYVY: | |
123 return(VIDEO_PALETTE_YUV422); | |
124 } | |
125 return(-1); | |
2802 | 126 } |
127 | |
128 #if 0 | |
129 struct STRTAB { | |
130 long nr; | |
131 const char *str; | |
132 }; | |
133 | |
134 static struct STRTAB stereo[] = { | |
135 { 0, "auto" }, | |
136 { VIDEO_SOUND_MONO, "mono" }, | |
137 { VIDEO_SOUND_STEREO, "stereo" }, | |
138 { VIDEO_SOUND_LANG1, "lang1" }, | |
139 { VIDEO_SOUND_LANG2, "lang1" }, | |
140 { -1, NULL } | |
141 }; | |
142 | |
143 static struct STRTAB norms_v4l[] = { | |
144 { VIDEO_MODE_PAL, "PAL" }, | |
145 { VIDEO_MODE_NTSC, "NTSC" }, | |
146 { VIDEO_MODE_SECAM, "SECAM" }, | |
147 { VIDEO_MODE_AUTO, "AUTO" }, | |
148 { -1, NULL } | |
149 }; | |
150 | |
151 static struct STRTAB norms_bttv[] = { | |
152 { VIDEO_MODE_PAL, "PAL" }, | |
153 { VIDEO_MODE_NTSC, "NTSC" }, | |
154 { VIDEO_MODE_SECAM, "SECAM" }, | |
155 { 3, "PAL-NC" }, | |
156 { 4, "PAL-M" }, | |
157 { 5, "PAL-N" }, | |
158 { 6, "NTSC-JP" }, | |
159 { -1, NULL } | |
2790 | 160 }; |
161 | |
2802 | 162 static unsigned short _format2palette[VIDEO_FMT_COUNT] = { |
163 0, /* unused */ | |
164 VIDEO_PALETTE_HI240, /* RGB8 */ | |
165 VIDEO_PALETTE_GREY, | |
166 VIDEO_PALETTE_RGB555, | |
167 VIDEO_PALETTE_RGB565, | |
168 0, | |
169 0, | |
170 VIDEO_PALETTE_RGB24, | |
171 VIDEO_PALETTE_RGB32, | |
172 0, | |
173 0, | |
174 0, | |
175 0, | |
176 VIDEO_PALETTE_YUV422, | |
177 VIDEO_PALETTE_YUV422P, | |
178 VIDEO_PALETTE_YUV420P, | |
179 }; | |
180 #define FMT2PAL(fmt) ((fmt < sizeof(format2palette)/sizeof(unsigned short)) ? \ | |
181 format2palette[fmt] : 0); | |
182 | |
183 const unsigned int vfmt_to_depth[] = { | |
184 0, | |
185 8, | |
186 8, | |
187 16, | |
188 16, | |
189 16, | |
190 16, | |
191 24, | |
192 32, | |
193 24, | |
194 32, | |
195 16, | |
196 32, | |
197 16, | |
198 16, | |
199 12, | |
200 0, | |
201 0, | |
202 }; | |
203 #endif | |
204 | |
205 static int one = 1, zero = 0; | |
206 | |
2790 | 207 tvi_handle_t *tvi_init_v4l(char *device) |
208 { | |
209 tvi_handle_t *h; | |
210 priv_t *priv; | |
211 | |
212 h = new_handle(); | |
213 if (!h) | |
214 return(NULL); | |
215 | |
216 priv = h->priv; | |
217 | |
2802 | 218 /* set video device name */ |
2790 | 219 if (!device) |
220 { | |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
221 priv->video_device = (char *)malloc(strlen("/dev/video0")); |
2802 | 222 sprintf(priv->video_device, "/dev/video0"); |
2790 | 223 } |
224 else | |
225 { | |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
226 priv->video_device = (char *)malloc(strlen(device)); |
2790 | 227 strcpy(priv->video_device, device); |
228 } | |
229 | |
230 return(h); | |
231 } | |
232 | |
2802 | 233 static int init(priv_t *priv, tvi_param_t *params) |
2790 | 234 { |
235 int i; | |
236 | |
2810 | 237 priv->fd = open(priv->video_device, O_RDWR); |
2790 | 238 if (priv->fd == -1) |
239 { | |
2818 | 240 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", |
2802 | 241 priv->video_device, strerror(errno)); |
2790 | 242 goto err; |
243 } | |
244 | |
2818 | 245 mp_msg(MSGT_TV, MSGL_V, "Video fd: %d\n", priv->fd); |
2790 | 246 |
2802 | 247 /* get capabilities (priv->capability is needed!) */ |
2790 | 248 if (ioctl(priv->fd, VIDIOCGCAP, &priv->capability) == -1) |
249 { | |
2818 | 250 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2790 | 251 goto err; |
252 } | |
253 | |
254 fcntl(priv->fd, F_SETFD, FD_CLOEXEC); | |
2818 | 255 // siginit(); |
2802 | 256 |
257 #if 0 | |
258 for (i=0; params[i].opt; i++) | |
259 { | |
260 if (!strcmp(params[i].opt, "input")) | |
261 priv->input = (int)*(void **)params[i].value; | |
262 } | |
263 printf("priv->input: %d\n", priv->input); | |
264 #endif | |
265 | |
2818 | 266 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name); |
267 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: "); | |
2841 | 268 for (i = 0; device_cap2name[i] != NULL; i++) |
2790 | 269 if (priv->capability.type & (1 << i)) |
2841 | 270 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]); |
2818 | 271 mp_msg(MSGT_TV, MSGL_INFO, "\n"); |
272 mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type); | |
273 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n", | |
2790 | 274 priv->capability.minwidth, priv->capability.minheight, |
275 priv->capability.maxwidth, priv->capability.maxheight); | |
276 priv->width = priv->capability.minwidth; | |
277 priv->height = priv->capability.minheight; | |
2818 | 278 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels); |
2790 | 279 |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
280 priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels); |
2790 | 281 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels); |
282 for (i = 0; i < priv->capability.channels; i++) | |
283 { | |
284 priv->channels[i].channel = i; | |
2841 | 285 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
286 { | |
287 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); | |
288 break; | |
289 } | |
2818 | 290 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%d)\n", i, |
2790 | 291 priv->channels[i].name, |
292 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "", | |
293 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "", | |
294 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "", | |
2802 | 295 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "", |
296 priv->channels[i].tuners, | |
297 priv->channels[i].norm); | |
298 } | |
299 | |
2841 | 300 if (priv->capability.audios) |
301 { | |
302 mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios); | |
303 | |
304 for (i = 0; i < priv->capability.audios; i++) | |
305 { | |
306 priv->audio.audio = i; | |
307 if (ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio) == -1) | |
308 { | |
309 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); | |
310 break; | |
311 } | |
312 | |
313 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio.audio, | |
314 priv->audio.name); | |
315 if (priv->audio.flags & VIDEO_AUDIO_MUTABLE) | |
316 mp_msg(MSGT_TV, MSGL_V, "muted=%s ", | |
317 (priv->audio.flags & VIDEO_AUDIO_MUTE) ? "yes" : "no"); | |
318 mp_msg(MSGT_TV, MSGL_V, "volume=%d bass=%d treble=%d balance=%d mode=%s\n", | |
319 priv->audio.volume, priv->audio.bass, priv->audio.treble, | |
320 priv->audio.balance, audio_mode2name[priv->audio.mode]); | |
321 } | |
322 } | |
323 | |
2802 | 324 if (!(priv->capability.type & VID_TYPE_CAPTURE)) |
325 { | |
2818 | 326 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n"); |
2802 | 327 goto err; |
328 } | |
329 | |
330 /* map grab buffer */ | |
331 if (ioctl(priv->fd, VIDIOCGMBUF, &priv->mbuf) == -1) | |
332 { | |
2818 | 333 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno)); |
2802 | 334 goto err; |
2790 | 335 } |
336 | |
2818 | 337 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n", |
2802 | 338 priv->mbuf.size, priv->mbuf.frames); |
339 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | |
340 MAP_SHARED, priv->fd, 0); | |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
341 if (priv->mmap == (unsigned char *)-1) |
2802 | 342 { |
2818 | 343 mp_msg(MSGT_TV, MSGL_ERR, "Unabel to map memory for buffers: %s\n", strerror(errno)); |
2802 | 344 goto err; |
345 } | |
2818 | 346 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap); |
2790 | 347 |
2802 | 348 /* num of buffers */ |
349 priv->nbuf = priv->mbuf.frames; | |
2790 | 350 |
2802 | 351 /* video buffers */ |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
352 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap)); |
2802 | 353 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap)); |
2790 | 354 |
355 return(1); | |
356 | |
357 err: | |
358 if (priv->fd != -1) | |
359 close(priv->fd); | |
360 return(0); | |
361 } | |
362 | |
2802 | 363 static int uninit(priv_t *priv) |
2790 | 364 { |
2837 | 365 close(priv->fd); |
2802 | 366 #warning "Implement uninit!" |
2931 | 367 |
368 return(1); | |
2790 | 369 } |
370 | |
2802 | 371 static int start(priv_t *priv) |
2790 | 372 { |
2802 | 373 int i; |
374 | |
375 | |
376 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1) | |
2790 | 377 { |
2818 | 378 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); |
2802 | 379 return(0); |
2790 | 380 } |
381 | |
2802 | 382 priv->picture.palette = format2palette(priv->format); |
383 priv->picture.depth = palette2depth(priv->picture.palette); | |
384 priv->bytesperline = priv->width * priv->picture.depth / 8; | |
385 | |
2818 | 386 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n"); |
387 mp_msg(MSGT_TV, MSGL_INFO, " Depth: %d, Palette: %d (Format: %s)\n", priv->picture.depth, | |
2802 | 388 priv->picture.palette, vo_format_name(priv->format)); |
2818 | 389 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n", |
2802 | 390 priv->picture.brightness, priv->picture.hue, |
391 priv->picture.colour, priv->picture.contrast); | |
392 | |
393 | |
394 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1) | |
2790 | 395 { |
2818 | 396 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno)); |
2802 | 397 return(0); |
2790 | 398 } |
399 | |
2802 | 400 priv->nbuf = priv->mbuf.frames; |
401 for (i=0; i < priv->nbuf; i++) | |
402 { | |
403 priv->buf[i].format = priv->picture.palette; | |
404 priv->buf[i].frame = i; | |
405 priv->buf[i].width = priv->width; | |
406 priv->buf[i].height = priv->height; | |
2818 | 407 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]); |
2802 | 408 } |
2837 | 409 |
2931 | 410 #if 0 |
411 { | |
412 struct video_play_mode pmode; | |
413 | |
414 pmode.mode = VID_PLAY_NORMAL; | |
415 pmode.p1 = 1; | |
416 pmode.p2 = 0; | |
417 if (ioctl(priv->fd, VIDIOCSPLAYMODE, &pmode) == -1) | |
418 { | |
419 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno)); | |
420 // return(0); | |
421 } | |
422 } | |
423 #endif | |
2837 | 424 |
425 #if 0 | |
426 { | |
427 struct video_window win; | |
428 | |
429 win.x = 0; | |
430 win.y = 0; | |
431 win.width = priv->width; | |
432 win.height = priv->height; | |
433 win.chromakey = -1; | |
434 win.flags = 0; | |
435 | |
436 ioctl(priv->fd, VIDIOCSWIN, &win); | |
437 } | |
438 | |
2802 | 439 /* start capture */ |
440 if (ioctl(priv->fd, VIDIOCCAPTURE, &one) == -1) | |
441 { | |
2818 | 442 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno)); |
2802 | 443 return(0); |
444 } | |
2837 | 445 #endif |
446 | |
447 return(1); | |
2790 | 448 } |
449 | |
450 static int control(priv_t *priv, int cmd, void *arg) | |
451 { | |
2818 | 452 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n", |
2802 | 453 priv, cmd, arg); |
2790 | 454 switch(cmd) |
455 { | |
2802 | 456 /* ========== GENERIC controls =========== */ |
457 case TVI_CONTROL_IS_VIDEO: | |
458 { | |
459 if (priv->capability.type & VID_TYPE_CAPTURE) | |
460 return(TVI_CONTROL_TRUE); | |
461 return(TVI_CONTROL_FALSE); | |
462 } | |
463 case TVI_CONTROL_IS_AUDIO: | |
2841 | 464 #if 0 /* also disable audio for as it's not working! */ |
465 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO) | |
466 return(TVI_CONTROL_TRUE); | |
467 #endif | |
468 return(TVI_CONTROL_FALSE); | |
2802 | 469 case TVI_CONTROL_IS_TUNER: |
470 { | |
2841 | 471 // if (priv->capability.type & VID_TYPE_TUNER) |
472 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 473 return(TVI_CONTROL_TRUE); |
474 return(TVI_CONTROL_FALSE); | |
475 } | |
476 | |
477 /* ========== VIDEO controls =========== */ | |
2790 | 478 case TVI_CONTROL_VID_GET_FORMAT: |
2802 | 479 { |
480 int output_fmt = -1; | |
481 | |
482 #if 0 | |
483 switch(priv->palette) | |
484 { | |
485 case VIDEO_PALETTE_RGB555: | |
486 output_fmt = IMGFMT_RGB15; | |
487 break; | |
488 case VIDEO_PALETTE_RGB565: | |
489 output_fmt = IMGFMT_RGB16; | |
490 break; | |
491 case VIDEO_PALETTE_RGB24: | |
492 output_fmt = IMGFMT_RGB24; | |
493 break; | |
494 case VIDEO_PALETTE_RGB32: | |
495 output_fmt = IMGFMT_RGB32; | |
496 break; | |
497 case VIDEO_PALETTE_UYVY: | |
498 output_fmt = IMGFMT_UYVY; | |
499 break; | |
500 case VIDEO_PALETTE_YUV420P: | |
501 output_fmt = IMGFMT_YV12; | |
502 break; | |
503 default: | |
2818 | 504 mp_msg(MSGT_TV, MSGL_ERR, "no suitable output format found (%s)\n", |
2802 | 505 PALETTE(priv->palette)); |
506 return(TVI_CONTROL_FALSE); | |
507 } | |
508 #endif | |
509 output_fmt = priv->format; | |
510 (int)*(void **)arg = output_fmt; | |
2818 | 511 mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt)); |
2802 | 512 return(TVI_CONTROL_TRUE); |
513 } | |
514 case TVI_CONTROL_VID_SET_FORMAT: | |
515 priv->format = (int)*(void **)arg; | |
2790 | 516 return(TVI_CONTROL_TRUE); |
517 case TVI_CONTROL_VID_GET_PLANES: | |
518 (int)*(void **)arg = 1; | |
519 return(TVI_CONTROL_TRUE); | |
520 case TVI_CONTROL_VID_GET_BITS: | |
2810 | 521 (int)*(void **)arg = palette2depth(format2palette(priv->format)); |
2790 | 522 return(TVI_CONTROL_TRUE); |
523 case TVI_CONTROL_VID_GET_WIDTH: | |
524 (int)*(void **)arg = priv->width; | |
525 return(TVI_CONTROL_TRUE); | |
526 case TVI_CONTROL_VID_CHK_WIDTH: | |
527 { | |
528 int req_width = (int)*(void **)arg; | |
529 | |
2818 | 530 mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width); |
2810 | 531 if ((req_width >= priv->capability.minwidth) && |
532 (req_width <= priv->capability.maxwidth)) | |
2790 | 533 return(TVI_CONTROL_TRUE); |
534 return(TVI_CONTROL_FALSE); | |
535 } | |
536 case TVI_CONTROL_VID_SET_WIDTH: | |
537 priv->width = (int)*(void **)arg; | |
538 return(TVI_CONTROL_TRUE); | |
539 case TVI_CONTROL_VID_GET_HEIGHT: | |
540 (int)*(void **)arg = priv->height; | |
541 return(TVI_CONTROL_TRUE); | |
542 case TVI_CONTROL_VID_CHK_HEIGHT: | |
543 { | |
544 int req_height = (int)*(void **)arg; | |
545 | |
2818 | 546 mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height); |
2810 | 547 if ((req_height >= priv->capability.minheight) && |
548 (req_height <= priv->capability.maxheight)) | |
2790 | 549 return(TVI_CONTROL_TRUE); |
550 return(TVI_CONTROL_FALSE); | |
551 } | |
552 case TVI_CONTROL_VID_SET_HEIGHT: | |
553 priv->height = (int)*(void **)arg; | |
554 return(TVI_CONTROL_TRUE); | |
2937 | 555 case TVI_CONTROL_VID_GET_PICTURE: |
556 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1) | |
557 { | |
558 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
559 return(TVI_CONTROL_FALSE); | |
560 } | |
561 return(TVI_CONTROL_TRUE); | |
562 case TVI_CONTROL_VID_SET_PICTURE: | |
563 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1) | |
564 { | |
565 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
566 return(TVI_CONTROL_FALSE); | |
567 } | |
568 return(TVI_CONTROL_TRUE); | |
569 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
570 priv->picture.brightness = (int)*(void **)arg; | |
571 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
572 return(TVI_CONTROL_TRUE); | |
573 case TVI_CONTROL_VID_SET_HUE: | |
574 priv->picture.hue = (int)*(void **)arg; | |
575 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
576 return(TVI_CONTROL_TRUE); | |
577 case TVI_CONTROL_VID_SET_SATURATION: | |
578 priv->picture.colour = (int)*(void **)arg; | |
579 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
580 return(TVI_CONTROL_TRUE); | |
581 case TVI_CONTROL_VID_SET_CONTRAST: | |
582 priv->picture.contrast = (int)*(void **)arg; | |
583 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
584 return(TVI_CONTROL_TRUE); | |
2790 | 585 |
2802 | 586 /* ========== TUNER controls =========== */ |
587 case TVI_CONTROL_TUN_GET_FREQ: | |
588 { | |
589 unsigned long freq; | |
590 | |
591 if (ioctl(priv->fd, VIDIOCGFREQ, &freq) == -1) | |
592 { | |
2818 | 593 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno)); |
2802 | 594 return(TVI_CONTROL_FALSE); |
595 } | |
596 | |
597 /* tuner uses khz not mhz ! */ | |
2837 | 598 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
599 // freq /= 1000; | |
2802 | 600 (unsigned long)*(void **)arg = freq; |
601 return(TVI_CONTROL_TRUE); | |
602 } | |
2790 | 603 case TVI_CONTROL_TUN_SET_FREQ: |
604 { | |
2802 | 605 /* argument is in MHz ! */ |
606 unsigned long freq = (unsigned long)*(void **)arg; | |
607 | |
2837 | 608 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16); |
2802 | 609 |
610 /* tuner uses khz not mhz ! */ | |
2837 | 611 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
612 // freq *= 1000; | |
613 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16); | |
2802 | 614 if (ioctl(priv->fd, VIDIOCSFREQ, &freq) == -1) |
615 { | |
2818 | 616 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno)); |
2802 | 617 return(TVI_CONTROL_FALSE); |
618 } | |
619 return(TVI_CONTROL_TRUE); | |
620 } | |
621 case TVI_CONTROL_TUN_GET_TUNER: | |
622 { | |
623 if (ioctl(priv->fd, VIDIOCGTUNER, &priv->tuner) == -1) | |
624 { | |
2818 | 625 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 626 return(TVI_CONTROL_FALSE); |
627 } | |
628 | |
2818 | 629 mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name, |
2802 | 630 priv->tuner.rangelow, priv->tuner.rangehigh); |
631 return(TVI_CONTROL_TRUE); | |
632 } | |
633 case TVI_CONTROL_TUN_SET_TUNER: | |
634 { | |
635 if (ioctl(priv->fd, VIDIOCSTUNER, &priv->tuner) == -1) | |
636 { | |
2818 | 637 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 638 return(TVI_CONTROL_FALSE); |
639 } | |
640 return(TVI_CONTROL_TRUE); | |
641 } | |
642 case TVI_CONTROL_TUN_SET_NORM: | |
643 { | |
644 int req_mode = (int)*(void **)arg; | |
645 | |
646 if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) || | |
647 ((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) || | |
648 ((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) || | |
649 ((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM))) | |
650 { | |
2818 | 651 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n"); |
2802 | 652 return(TVI_CONTROL_FALSE); |
653 } | |
654 | |
655 priv->tuner.mode = req_mode; | |
2790 | 656 |
2802 | 657 if (control(priv->fd, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE) |
658 return(TVI_CONTROL_FALSE); | |
659 return(TVI_CONTROL_TRUE); | |
660 } | |
661 case TVI_CONTROL_TUN_GET_NORM: | |
662 { | |
663 (int)*(void **)arg = priv->tuner.mode; | |
664 | |
665 return(TVI_CONTROL_TRUE); | |
666 } | |
667 | |
668 /* ========== AUDIO controls =========== */ | |
669 case TVI_CONTROL_AUD_GET_FORMAT: | |
670 { | |
671 (int)*(void **)arg = AFMT_S16_LE; | |
672 return(TVI_CONTROL_TRUE); | |
673 } | |
674 case TVI_CONTROL_AUD_GET_CHANNELS: | |
675 { | |
676 (int)*(void **)arg = 2; | |
677 return(TVI_CONTROL_TRUE); | |
678 } | |
679 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
680 { | |
681 (int)*(void **)arg = 44100; | |
682 return(TVI_CONTROL_TRUE); | |
683 } | |
684 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
685 { | |
686 (int)*(void **)arg = 76000; | |
687 return(TVI_CONTROL_TRUE); | |
688 } | |
689 | |
690 /* ========== SPECIFIC controls =========== */ | |
691 case TVI_CONTROL_SPC_GET_INPUT: | |
692 { | |
693 int req_chan = (int)*(void **)arg; | |
694 int i; | |
695 | |
696 for (i = 0; i < priv->capability.channels; i++) | |
697 { | |
698 if (priv->channels[i].channel == req_chan) | |
699 break; | |
700 } | |
2841 | 701 |
702 priv->act_channel = i; | |
2802 | 703 |
704 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1) | |
705 { | |
2818 | 706 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); |
2802 | 707 return(TVI_CONTROL_FALSE); |
708 } | |
709 return(TVI_CONTROL_TRUE); | |
710 } | |
711 | |
712 case TVI_CONTROL_SPC_SET_INPUT: | |
713 { | |
714 struct video_channel chan; | |
715 int req_chan = (int)*(void **)arg; | |
716 int i; | |
717 | |
718 if (req_chan >= priv->capability.channels) | |
719 { | |
2818 | 720 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n", |
2802 | 721 req_chan, priv->capability.channels); |
722 return(TVI_CONTROL_FALSE); | |
723 } | |
724 | |
725 for (i = 0; i < priv->capability.channels; i++) | |
726 { | |
727 if (priv->channels[i].channel == req_chan) | |
728 chan = priv->channels[i]; | |
729 } | |
730 | |
731 if (ioctl(priv->fd, VIDIOCSCHAN, &chan) == -1) | |
732 { | |
2818 | 733 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
2802 | 734 return(TVI_CONTROL_FALSE); |
735 } | |
2818 | 736 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name); |
2802 | 737 |
2841 | 738 priv->act_channel = i; |
739 | |
2802 | 740 /* update tuner state */ |
2841 | 741 // if (priv->capability.type & VID_TYPE_TUNER) |
742 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 743 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
744 | |
745 /* update local channel list */ | |
746 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan); | |
747 return(TVI_CONTROL_TRUE); | |
2790 | 748 } |
749 } | |
750 | |
751 return(TVI_CONTROL_UNKNOWN); | |
752 } | |
753 | |
754 static int grab_video_frame(priv_t *priv, char *buffer, int len) | |
755 { | |
2802 | 756 int frame = priv->queue % priv->nbuf; |
2814 | 757 int nextframe = (priv->queue+1) % priv->nbuf; |
2802 | 758 |
2931 | 759 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d\n", |
2802 | 760 priv, buffer, len); |
761 | |
2931 | 762 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n", |
2814 | 763 priv->buf, nextframe, &priv->buf[nextframe]); |
764 if (ioctl(priv->fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1) | |
2790 | 765 { |
2818 | 766 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno)); |
2802 | 767 return(0); |
2790 | 768 } |
769 | |
2814 | 770 if (ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame].frame) == -1) |
2818 | 771 mp_msg(MSGT_TV, MSGL_ERR, "ioctl sync failed: %s\n", strerror(errno)); |
2802 | 772 priv->queue++; |
773 | |
2931 | 774 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n", |
2802 | 775 priv->mmap, priv->mbuf.offsets[frame], |
776 priv->mmap+priv->mbuf.offsets[frame]); | |
2931 | 777 |
778 /* XXX also directrendering would be nicer! */ | |
779 /* 3 times copying the same picture to other buffer :( */ | |
780 | |
781 /* copy the actual frame */ | |
2802 | 782 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len); |
783 | |
784 return(len); | |
2790 | 785 } |
786 | |
787 static int get_video_framesize(priv_t *priv) | |
788 { | |
2931 | 789 return(priv->bytesperline * priv->height); |
2790 | 790 } |
791 | |
792 static int grab_audio_frame(priv_t *priv, char *buffer, int len) | |
793 { | |
2931 | 794 return(65536); |
2790 | 795 } |
796 | |
797 static int get_audio_framesize(priv_t *priv) | |
798 { | |
2931 | 799 return(65536); |
2790 | 800 } |
801 | |
802 #endif /* USE_TV */ |