Mercurial > mplayer.hg
annotate libmpdemux/tvi_v4l.c @ 3690:c42f1e391c5f
10l? streaming must be yes, auto is not enough because of Makefile
author | arpi |
---|---|
date | Sun, 23 Dec 2001 23:20:49 +0000 |
parents | 178c562948ff |
children | 3717145636b5 |
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) |
3611 | 230 priv->video_device = strdup("/dev/video0"); |
2790 | 231 else |
3611 | 232 priv->video_device = strdup(device); |
233 | |
234 /* allocation failed */ | |
235 if (!priv->video_device) { | |
236 free_handle(h); | |
237 return(NULL); | |
2790 | 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); |
3611 | 281 if (!priv->channels) |
282 goto malloc_failed; | |
2790 | 283 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels); |
284 for (i = 0; i < priv->capability.channels; i++) | |
285 { | |
286 priv->channels[i].channel = i; | |
2841 | 287 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
288 { | |
289 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); | |
290 break; | |
291 } | |
2818 | 292 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%d)\n", i, |
2790 | 293 priv->channels[i].name, |
294 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "", | |
295 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "", | |
296 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "", | |
2802 | 297 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "", |
298 priv->channels[i].tuners, | |
299 priv->channels[i].norm); | |
300 } | |
301 | |
2841 | 302 if (priv->capability.audios) |
303 { | |
304 mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios); | |
3284 | 305 |
306 priv->act_audio = 0; | |
2841 | 307 |
308 for (i = 0; i < priv->capability.audios; i++) | |
309 { | |
3284 | 310 priv->audio = realloc(priv->audio, sizeof(struct video_audio)*(i+1)); |
311 priv->audio[i].audio = i; | |
312 if (ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) | |
2841 | 313 { |
314 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); | |
315 break; | |
316 } | |
317 | |
3284 | 318 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio, |
319 priv->audio[i].name); | |
320 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE) | |
2841 | 321 mp_msg(MSGT_TV, MSGL_V, "muted=%s ", |
3284 | 322 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no"); |
2841 | 323 mp_msg(MSGT_TV, MSGL_V, "volume=%d bass=%d treble=%d balance=%d mode=%s\n", |
3284 | 324 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble, |
325 priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]); | |
326 | |
327 /* un-mute channels */ | |
328 priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE; | |
329 ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]); | |
2841 | 330 } |
331 } | |
332 | |
2802 | 333 if (!(priv->capability.type & VID_TYPE_CAPTURE)) |
334 { | |
2818 | 335 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n"); |
2802 | 336 goto err; |
337 } | |
338 | |
339 /* map grab buffer */ | |
340 if (ioctl(priv->fd, VIDIOCGMBUF, &priv->mbuf) == -1) | |
341 { | |
2818 | 342 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno)); |
2802 | 343 goto err; |
2790 | 344 } |
345 | |
2818 | 346 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n", |
2802 | 347 priv->mbuf.size, priv->mbuf.frames); |
348 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | |
349 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
|
350 if (priv->mmap == (unsigned char *)-1) |
2802 | 351 { |
2818 | 352 mp_msg(MSGT_TV, MSGL_ERR, "Unabel to map memory for buffers: %s\n", strerror(errno)); |
2802 | 353 goto err; |
354 } | |
2818 | 355 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap); |
2790 | 356 |
2802 | 357 /* num of buffers */ |
358 priv->nbuf = priv->mbuf.frames; | |
2790 | 359 |
2802 | 360 /* video buffers */ |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
361 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap)); |
3611 | 362 if (!priv->buf) |
363 goto malloc_failed; | |
2802 | 364 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap)); |
2790 | 365 |
366 return(1); | |
367 | |
3611 | 368 |
369 malloc_failed: | |
370 if (priv->channels) | |
371 free(priv->channels); | |
372 if (priv->buf) | |
373 free(priv->buf); | |
2790 | 374 err: |
375 if (priv->fd != -1) | |
376 close(priv->fd); | |
377 return(0); | |
378 } | |
379 | |
2802 | 380 static int uninit(priv_t *priv) |
2790 | 381 { |
2837 | 382 close(priv->fd); |
2802 | 383 #warning "Implement uninit!" |
2931 | 384 |
385 return(1); | |
2790 | 386 } |
387 | |
2802 | 388 static int start(priv_t *priv) |
2790 | 389 { |
2802 | 390 int i; |
391 | |
392 | |
393 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1) | |
2790 | 394 { |
2818 | 395 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); |
2802 | 396 return(0); |
2790 | 397 } |
398 | |
2802 | 399 priv->picture.palette = format2palette(priv->format); |
400 priv->picture.depth = palette2depth(priv->picture.palette); | |
401 priv->bytesperline = priv->width * priv->picture.depth / 8; | |
402 | |
2818 | 403 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n"); |
404 mp_msg(MSGT_TV, MSGL_INFO, " Depth: %d, Palette: %d (Format: %s)\n", priv->picture.depth, | |
2802 | 405 priv->picture.palette, vo_format_name(priv->format)); |
2818 | 406 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n", |
2802 | 407 priv->picture.brightness, priv->picture.hue, |
408 priv->picture.colour, priv->picture.contrast); | |
409 | |
410 | |
411 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1) | |
2790 | 412 { |
2818 | 413 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno)); |
2802 | 414 return(0); |
2790 | 415 } |
416 | |
2802 | 417 priv->nbuf = priv->mbuf.frames; |
418 for (i=0; i < priv->nbuf; i++) | |
419 { | |
420 priv->buf[i].format = priv->picture.palette; | |
421 priv->buf[i].frame = i; | |
422 priv->buf[i].width = priv->width; | |
423 priv->buf[i].height = priv->height; | |
2818 | 424 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]); |
2802 | 425 } |
2837 | 426 |
2931 | 427 #if 0 |
428 { | |
429 struct video_play_mode pmode; | |
430 | |
431 pmode.mode = VID_PLAY_NORMAL; | |
432 pmode.p1 = 1; | |
433 pmode.p2 = 0; | |
434 if (ioctl(priv->fd, VIDIOCSPLAYMODE, &pmode) == -1) | |
435 { | |
436 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno)); | |
437 // return(0); | |
438 } | |
439 } | |
440 #endif | |
2837 | 441 |
442 #if 0 | |
443 { | |
444 struct video_window win; | |
445 | |
446 win.x = 0; | |
447 win.y = 0; | |
448 win.width = priv->width; | |
449 win.height = priv->height; | |
450 win.chromakey = -1; | |
451 win.flags = 0; | |
452 | |
453 ioctl(priv->fd, VIDIOCSWIN, &win); | |
454 } | |
455 | |
2802 | 456 /* start capture */ |
457 if (ioctl(priv->fd, VIDIOCCAPTURE, &one) == -1) | |
458 { | |
2818 | 459 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno)); |
2802 | 460 return(0); |
461 } | |
2837 | 462 #endif |
463 | |
464 return(1); | |
2790 | 465 } |
466 | |
467 static int control(priv_t *priv, int cmd, void *arg) | |
468 { | |
2818 | 469 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n", |
2802 | 470 priv, cmd, arg); |
2790 | 471 switch(cmd) |
472 { | |
2802 | 473 /* ========== GENERIC controls =========== */ |
474 case TVI_CONTROL_IS_VIDEO: | |
475 { | |
476 if (priv->capability.type & VID_TYPE_CAPTURE) | |
477 return(TVI_CONTROL_TRUE); | |
478 return(TVI_CONTROL_FALSE); | |
479 } | |
480 case TVI_CONTROL_IS_AUDIO: | |
2841 | 481 #if 0 /* also disable audio for as it's not working! */ |
482 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO) | |
483 return(TVI_CONTROL_TRUE); | |
484 #endif | |
485 return(TVI_CONTROL_FALSE); | |
2802 | 486 case TVI_CONTROL_IS_TUNER: |
487 { | |
2841 | 488 // if (priv->capability.type & VID_TYPE_TUNER) |
489 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 490 return(TVI_CONTROL_TRUE); |
491 return(TVI_CONTROL_FALSE); | |
492 } | |
493 | |
494 /* ========== VIDEO controls =========== */ | |
2790 | 495 case TVI_CONTROL_VID_GET_FORMAT: |
2802 | 496 { |
497 int output_fmt = -1; | |
498 | |
499 output_fmt = priv->format; | |
500 (int)*(void **)arg = output_fmt; | |
2818 | 501 mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt)); |
2802 | 502 return(TVI_CONTROL_TRUE); |
503 } | |
504 case TVI_CONTROL_VID_SET_FORMAT: | |
505 priv->format = (int)*(void **)arg; | |
2790 | 506 return(TVI_CONTROL_TRUE); |
507 case TVI_CONTROL_VID_GET_PLANES: | |
3220 | 508 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */ |
2790 | 509 return(TVI_CONTROL_TRUE); |
510 case TVI_CONTROL_VID_GET_BITS: | |
2810 | 511 (int)*(void **)arg = palette2depth(format2palette(priv->format)); |
2790 | 512 return(TVI_CONTROL_TRUE); |
513 case TVI_CONTROL_VID_GET_WIDTH: | |
514 (int)*(void **)arg = priv->width; | |
515 return(TVI_CONTROL_TRUE); | |
516 case TVI_CONTROL_VID_CHK_WIDTH: | |
517 { | |
518 int req_width = (int)*(void **)arg; | |
519 | |
2818 | 520 mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width); |
2810 | 521 if ((req_width >= priv->capability.minwidth) && |
522 (req_width <= priv->capability.maxwidth)) | |
2790 | 523 return(TVI_CONTROL_TRUE); |
524 return(TVI_CONTROL_FALSE); | |
525 } | |
526 case TVI_CONTROL_VID_SET_WIDTH: | |
527 priv->width = (int)*(void **)arg; | |
528 return(TVI_CONTROL_TRUE); | |
529 case TVI_CONTROL_VID_GET_HEIGHT: | |
530 (int)*(void **)arg = priv->height; | |
531 return(TVI_CONTROL_TRUE); | |
532 case TVI_CONTROL_VID_CHK_HEIGHT: | |
533 { | |
534 int req_height = (int)*(void **)arg; | |
535 | |
2818 | 536 mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height); |
2810 | 537 if ((req_height >= priv->capability.minheight) && |
538 (req_height <= priv->capability.maxheight)) | |
2790 | 539 return(TVI_CONTROL_TRUE); |
540 return(TVI_CONTROL_FALSE); | |
541 } | |
542 case TVI_CONTROL_VID_SET_HEIGHT: | |
543 priv->height = (int)*(void **)arg; | |
544 return(TVI_CONTROL_TRUE); | |
2937 | 545 case TVI_CONTROL_VID_GET_PICTURE: |
546 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1) | |
547 { | |
548 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
549 return(TVI_CONTROL_FALSE); | |
550 } | |
551 return(TVI_CONTROL_TRUE); | |
552 case TVI_CONTROL_VID_SET_PICTURE: | |
553 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1) | |
554 { | |
555 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
556 return(TVI_CONTROL_FALSE); | |
557 } | |
558 return(TVI_CONTROL_TRUE); | |
559 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
560 priv->picture.brightness = (int)*(void **)arg; | |
561 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
562 return(TVI_CONTROL_TRUE); | |
563 case TVI_CONTROL_VID_SET_HUE: | |
564 priv->picture.hue = (int)*(void **)arg; | |
565 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
566 return(TVI_CONTROL_TRUE); | |
567 case TVI_CONTROL_VID_SET_SATURATION: | |
568 priv->picture.colour = (int)*(void **)arg; | |
569 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
570 return(TVI_CONTROL_TRUE); | |
571 case TVI_CONTROL_VID_SET_CONTRAST: | |
572 priv->picture.contrast = (int)*(void **)arg; | |
573 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
574 return(TVI_CONTROL_TRUE); | |
2790 | 575 |
2802 | 576 /* ========== TUNER controls =========== */ |
577 case TVI_CONTROL_TUN_GET_FREQ: | |
578 { | |
579 unsigned long freq; | |
580 | |
581 if (ioctl(priv->fd, VIDIOCGFREQ, &freq) == -1) | |
582 { | |
2818 | 583 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno)); |
2802 | 584 return(TVI_CONTROL_FALSE); |
585 } | |
586 | |
587 /* tuner uses khz not mhz ! */ | |
2837 | 588 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
589 // freq /= 1000; | |
2802 | 590 (unsigned long)*(void **)arg = freq; |
591 return(TVI_CONTROL_TRUE); | |
592 } | |
2790 | 593 case TVI_CONTROL_TUN_SET_FREQ: |
594 { | |
2802 | 595 /* argument is in MHz ! */ |
596 unsigned long freq = (unsigned long)*(void **)arg; | |
597 | |
2837 | 598 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16); |
2802 | 599 |
600 /* tuner uses khz not mhz ! */ | |
2837 | 601 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
602 // freq *= 1000; | |
603 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16); | |
2802 | 604 if (ioctl(priv->fd, VIDIOCSFREQ, &freq) == -1) |
605 { | |
2818 | 606 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno)); |
2802 | 607 return(TVI_CONTROL_FALSE); |
608 } | |
609 return(TVI_CONTROL_TRUE); | |
610 } | |
611 case TVI_CONTROL_TUN_GET_TUNER: | |
612 { | |
613 if (ioctl(priv->fd, VIDIOCGTUNER, &priv->tuner) == -1) | |
614 { | |
2818 | 615 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 616 return(TVI_CONTROL_FALSE); |
617 } | |
618 | |
2818 | 619 mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name, |
2802 | 620 priv->tuner.rangelow, priv->tuner.rangehigh); |
621 return(TVI_CONTROL_TRUE); | |
622 } | |
623 case TVI_CONTROL_TUN_SET_TUNER: | |
624 { | |
625 if (ioctl(priv->fd, VIDIOCSTUNER, &priv->tuner) == -1) | |
626 { | |
2818 | 627 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 628 return(TVI_CONTROL_FALSE); |
629 } | |
630 return(TVI_CONTROL_TRUE); | |
631 } | |
632 case TVI_CONTROL_TUN_SET_NORM: | |
633 { | |
634 int req_mode = (int)*(void **)arg; | |
635 | |
636 if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) || | |
637 ((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) || | |
638 ((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) || | |
639 ((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM))) | |
640 { | |
2818 | 641 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n"); |
2802 | 642 return(TVI_CONTROL_FALSE); |
643 } | |
644 | |
645 priv->tuner.mode = req_mode; | |
2790 | 646 |
2802 | 647 if (control(priv->fd, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE) |
648 return(TVI_CONTROL_FALSE); | |
649 return(TVI_CONTROL_TRUE); | |
650 } | |
651 case TVI_CONTROL_TUN_GET_NORM: | |
652 { | |
653 (int)*(void **)arg = priv->tuner.mode; | |
654 | |
655 return(TVI_CONTROL_TRUE); | |
656 } | |
657 | |
658 /* ========== AUDIO controls =========== */ | |
659 case TVI_CONTROL_AUD_GET_FORMAT: | |
660 { | |
661 (int)*(void **)arg = AFMT_S16_LE; | |
662 return(TVI_CONTROL_TRUE); | |
663 } | |
664 case TVI_CONTROL_AUD_GET_CHANNELS: | |
665 { | |
666 (int)*(void **)arg = 2; | |
667 return(TVI_CONTROL_TRUE); | |
668 } | |
669 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
670 { | |
671 (int)*(void **)arg = 44100; | |
672 return(TVI_CONTROL_TRUE); | |
673 } | |
674 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
675 { | |
676 (int)*(void **)arg = 76000; | |
677 return(TVI_CONTROL_TRUE); | |
678 } | |
679 | |
680 /* ========== SPECIFIC controls =========== */ | |
681 case TVI_CONTROL_SPC_GET_INPUT: | |
682 { | |
683 int req_chan = (int)*(void **)arg; | |
684 int i; | |
685 | |
686 for (i = 0; i < priv->capability.channels; i++) | |
687 { | |
688 if (priv->channels[i].channel == req_chan) | |
689 break; | |
690 } | |
2841 | 691 |
692 priv->act_channel = i; | |
2802 | 693 |
694 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1) | |
695 { | |
2818 | 696 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); |
2802 | 697 return(TVI_CONTROL_FALSE); |
698 } | |
699 return(TVI_CONTROL_TRUE); | |
700 } | |
701 | |
702 case TVI_CONTROL_SPC_SET_INPUT: | |
703 { | |
704 struct video_channel chan; | |
705 int req_chan = (int)*(void **)arg; | |
706 int i; | |
707 | |
708 if (req_chan >= priv->capability.channels) | |
709 { | |
2818 | 710 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n", |
2802 | 711 req_chan, priv->capability.channels); |
712 return(TVI_CONTROL_FALSE); | |
713 } | |
714 | |
715 for (i = 0; i < priv->capability.channels; i++) | |
716 { | |
717 if (priv->channels[i].channel == req_chan) | |
718 chan = priv->channels[i]; | |
719 } | |
720 | |
721 if (ioctl(priv->fd, VIDIOCSCHAN, &chan) == -1) | |
722 { | |
2818 | 723 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
2802 | 724 return(TVI_CONTROL_FALSE); |
725 } | |
2818 | 726 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name); |
2802 | 727 |
2841 | 728 priv->act_channel = i; |
729 | |
2802 | 730 /* update tuner state */ |
2841 | 731 // if (priv->capability.type & VID_TYPE_TUNER) |
732 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 733 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
734 | |
735 /* update local channel list */ | |
736 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan); | |
737 return(TVI_CONTROL_TRUE); | |
2790 | 738 } |
739 } | |
740 | |
741 return(TVI_CONTROL_UNKNOWN); | |
742 } | |
743 | |
744 static int grab_video_frame(priv_t *priv, char *buffer, int len) | |
745 { | |
2802 | 746 int frame = priv->queue % priv->nbuf; |
2814 | 747 int nextframe = (priv->queue+1) % priv->nbuf; |
2802 | 748 |
3284 | 749 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d)\n", |
2802 | 750 priv, buffer, len); |
751 | |
2931 | 752 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n", |
2814 | 753 priv->buf, nextframe, &priv->buf[nextframe]); |
754 if (ioctl(priv->fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1) | |
2790 | 755 { |
2818 | 756 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno)); |
2802 | 757 return(0); |
2790 | 758 } |
759 | |
2814 | 760 if (ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame].frame) == -1) |
2818 | 761 mp_msg(MSGT_TV, MSGL_ERR, "ioctl sync failed: %s\n", strerror(errno)); |
2802 | 762 priv->queue++; |
763 | |
2931 | 764 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n", |
2802 | 765 priv->mmap, priv->mbuf.offsets[frame], |
766 priv->mmap+priv->mbuf.offsets[frame]); | |
2931 | 767 |
768 /* XXX also directrendering would be nicer! */ | |
769 /* 3 times copying the same picture to other buffer :( */ | |
770 | |
771 /* copy the actual frame */ | |
2802 | 772 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len); |
773 | |
774 return(len); | |
2790 | 775 } |
776 | |
777 static int get_video_framesize(priv_t *priv) | |
778 { | |
2931 | 779 return(priv->bytesperline * priv->height); |
2790 | 780 } |
781 | |
782 static int grab_audio_frame(priv_t *priv, char *buffer, int len) | |
783 { | |
2931 | 784 return(65536); |
2790 | 785 } |
786 | |
787 static int get_audio_framesize(priv_t *priv) | |
788 { | |
2931 | 789 return(65536); |
2790 | 790 } |
791 | |
792 #endif /* USE_TV */ |