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