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