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