Mercurial > mplayer.hg
annotate libmpdemux/tvi_v4l.c @ 5729:6a76686dda2d
okej, back again, reworded
author | gabucino |
---|---|
date | Sat, 20 Apr 2002 12:31:09 +0000 |
parents | 8cd761968f35 |
children | f2bad7299936 |
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; |
60 | |
61 struct video_mbuf mbuf; | |
62 unsigned char *mmap; | |
63 struct video_mmap *buf; | |
64 int nbuf; | |
65 int queue; | |
66 | |
67 /* audio */ | |
3815 | 68 int audio_id; |
69 char *audio_device; | |
70 struct video_audio audio[MAX_AUDIO_CHANNELS]; | |
71 int audio_fd; | |
72 int audio_channels[MAX_AUDIO_CHANNELS]; | |
73 int audio_format[MAX_AUDIO_CHANNELS]; | |
74 int audio_samplesize[MAX_AUDIO_CHANNELS]; | |
75 int audio_samplerate[MAX_AUDIO_CHANNELS]; | |
76 int audio_blocksize; | |
2790 | 77 } priv_t; |
78 | |
79 #include "tvi_def.h" | |
80 | |
2841 | 81 static const char *device_cap2name[] = { |
2790 | 82 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping", |
2802 | 83 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder", |
84 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL | |
85 }; | |
86 | |
2841 | 87 static const char *device_palette2name[] = { |
2802 | 88 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422", |
89 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p", | |
90 "yuv420p", "yuv410p", NULL | |
91 }; | |
92 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN") | |
93 | |
2841 | 94 static const char *audio_mode2name[] = { |
95 "unknown", "mono", "stereo", "language1", "language2", NULL | |
96 }; | |
97 | |
2802 | 98 static int palette2depth(int palette) |
99 { | |
2810 | 100 switch(palette) |
101 { | |
3220 | 102 /* component */ |
2810 | 103 case VIDEO_PALETTE_RGB555: |
104 return(15); | |
105 case VIDEO_PALETTE_RGB565: | |
106 return(16); | |
107 case VIDEO_PALETTE_RGB24: | |
108 return(24); | |
109 case VIDEO_PALETTE_RGB32: | |
110 return(32); | |
3220 | 111 /* planar */ |
112 case VIDEO_PALETTE_YUV411P: | |
2810 | 113 case VIDEO_PALETTE_YUV420P: |
3220 | 114 case VIDEO_PALETTE_YUV410P: |
2810 | 115 return(12); |
3220 | 116 /* packed */ |
3815 | 117 case VIDEO_PALETTE_YUV422P: |
2810 | 118 case VIDEO_PALETTE_YUV422: |
3220 | 119 case VIDEO_PALETTE_YUYV: |
2810 | 120 case VIDEO_PALETTE_UYVY: |
3220 | 121 case VIDEO_PALETTE_YUV420: |
122 case VIDEO_PALETTE_YUV411: | |
2810 | 123 return(16); |
124 } | |
125 return(-1); | |
2802 | 126 } |
127 | |
128 static int format2palette(int format) | |
129 { | |
2810 | 130 switch(format) |
131 { | |
132 case IMGFMT_RGB15: | |
133 return(VIDEO_PALETTE_RGB555); | |
134 case IMGFMT_RGB16: | |
135 return(VIDEO_PALETTE_RGB565); | |
136 case IMGFMT_RGB24: | |
137 return(VIDEO_PALETTE_RGB24); | |
138 case IMGFMT_RGB32: | |
139 return(VIDEO_PALETTE_RGB32); | |
140 case IMGFMT_YV12: | |
3703 | 141 case IMGFMT_I420: |
2810 | 142 return(VIDEO_PALETTE_YUV420P); |
143 case IMGFMT_UYVY: | |
144 return(VIDEO_PALETTE_YUV422); | |
3815 | 145 case IMGFMT_YUY2: |
146 return(VIDEO_PALETTE_YUYV); | |
2810 | 147 } |
148 return(-1); | |
2802 | 149 } |
150 | |
151 static int one = 1, zero = 0; | |
152 | |
2790 | 153 tvi_handle_t *tvi_init_v4l(char *device) |
154 { | |
155 tvi_handle_t *h; | |
156 priv_t *priv; | |
157 | |
158 h = new_handle(); | |
159 if (!h) | |
160 return(NULL); | |
161 | |
162 priv = h->priv; | |
163 | |
2802 | 164 /* set video device name */ |
2790 | 165 if (!device) |
5088 | 166 priv->video_device = strdup("/dev/video"); |
2790 | 167 else |
3611 | 168 priv->video_device = strdup(device); |
169 | |
170 /* allocation failed */ | |
171 if (!priv->video_device) { | |
172 free_handle(h); | |
173 return(NULL); | |
2790 | 174 } |
175 | |
3815 | 176 /* set audio device name */ |
5088 | 177 priv->audio_device = "/dev/dsp"; |
3815 | 178 |
2790 | 179 return(h); |
180 } | |
181 | |
3815 | 182 static int init(priv_t *priv) |
2790 | 183 { |
184 int i; | |
185 | |
3815 | 186 priv->video_fd = open(priv->video_device, O_RDWR); |
5088 | 187 mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %x\n", priv->video_fd, |
188 priv->video_device); | |
3815 | 189 if (priv->video_fd == -1) |
2790 | 190 { |
2818 | 191 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", |
2802 | 192 priv->video_device, strerror(errno)); |
2790 | 193 goto err; |
194 } | |
195 | |
3815 | 196 mp_msg(MSGT_TV, MSGL_V, "Video fd: %d\n", priv->video_fd); |
2790 | 197 |
2802 | 198 /* get capabilities (priv->capability is needed!) */ |
3815 | 199 if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) |
2790 | 200 { |
2818 | 201 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2790 | 202 goto err; |
203 } | |
204 | |
3815 | 205 fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC); |
2802 | 206 |
2818 | 207 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name); |
208 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: "); | |
2841 | 209 for (i = 0; device_cap2name[i] != NULL; i++) |
2790 | 210 if (priv->capability.type & (1 << i)) |
2841 | 211 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]); |
2818 | 212 mp_msg(MSGT_TV, MSGL_INFO, "\n"); |
213 mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type); | |
214 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n", | |
2790 | 215 priv->capability.minwidth, priv->capability.minheight, |
216 priv->capability.maxwidth, priv->capability.maxheight); | |
217 priv->width = priv->capability.minwidth; | |
218 priv->height = priv->capability.minheight; | |
2818 | 219 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels); |
2790 | 220 |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
221 priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels); |
3611 | 222 if (!priv->channels) |
223 goto malloc_failed; | |
2790 | 224 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels); |
225 for (i = 0; i < priv->capability.channels; i++) | |
226 { | |
227 priv->channels[i].channel = i; | |
3815 | 228 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2841 | 229 { |
230 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); | |
231 break; | |
232 } | |
2818 | 233 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%d)\n", i, |
2790 | 234 priv->channels[i].name, |
235 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "", | |
236 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "", | |
237 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "", | |
2802 | 238 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "", |
239 priv->channels[i].tuners, | |
240 priv->channels[i].norm); | |
241 } | |
242 | |
3815 | 243 /* audio chanlist */ |
2841 | 244 if (priv->capability.audios) |
245 { | |
246 mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios); | |
247 | |
248 for (i = 0; i < priv->capability.audios; i++) | |
249 { | |
3815 | 250 if (i >= MAX_AUDIO_CHANNELS) |
251 { | |
252 mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (incrase in source!) (%d > %d)\n", | |
253 i, MAX_AUDIO_CHANNELS); | |
254 i = priv->capability.audios; | |
255 break; | |
256 } | |
257 | |
3284 | 258 priv->audio[i].audio = i; |
3815 | 259 if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) |
2841 | 260 { |
261 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); | |
262 break; | |
263 } | |
264 | |
3815 | 265 if (priv->audio[i].volume <= 0) |
266 priv->audio[i].volume = 100; | |
267 priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE; | |
268 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]); | |
269 | |
270 switch(priv->audio[i].mode) | |
271 { | |
272 case VIDEO_SOUND_MONO: | |
273 case VIDEO_SOUND_LANG1: | |
274 case VIDEO_SOUND_LANG2: | |
275 priv->audio_channels[i] = 1; | |
276 break; | |
277 case VIDEO_SOUND_STEREO: | |
278 priv->audio_channels[i] = 2; | |
279 break; | |
280 } | |
281 | |
282 priv->audio_format[i] = AFMT_S16_LE; | |
283 priv->audio_samplerate[i] = 44100; | |
284 priv->audio_samplesize[i] = /*76000*/priv->audio_channels[i]* | |
285 16*priv->audio_samplerate[i]/8; | |
286 | |
287 /* display stuff */ | |
3284 | 288 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio, |
289 priv->audio[i].name); | |
290 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE) | |
2841 | 291 mp_msg(MSGT_TV, MSGL_V, "muted=%s ", |
3284 | 292 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no"); |
2841 | 293 mp_msg(MSGT_TV, MSGL_V, "volume=%d bass=%d treble=%d balance=%d mode=%s\n", |
3284 | 294 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble, |
295 priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]); | |
3815 | 296 mp_msg(MSGT_TV, MSGL_V, " channels: %d, samplerate: %d, samplesize: %d, format: %s\n", |
297 priv->audio_channels[i], priv->audio_samplerate[i], priv->audio_samplesize[i], | |
298 audio_out_format_name(priv->audio_format[i])); | |
2841 | 299 } |
300 } | |
301 | |
2802 | 302 if (!(priv->capability.type & VID_TYPE_CAPTURE)) |
303 { | |
2818 | 304 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n"); |
2802 | 305 goto err; |
306 } | |
307 | |
308 /* map grab buffer */ | |
3815 | 309 if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1) |
2802 | 310 { |
2818 | 311 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno)); |
2802 | 312 goto err; |
2790 | 313 } |
314 | |
2818 | 315 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n", |
2802 | 316 priv->mbuf.size, priv->mbuf.frames); |
317 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | |
3815 | 318 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
|
319 if (priv->mmap == (unsigned char *)-1) |
2802 | 320 { |
3815 | 321 mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno)); |
2802 | 322 goto err; |
323 } | |
2818 | 324 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap); |
2790 | 325 |
2802 | 326 /* num of buffers */ |
327 priv->nbuf = priv->mbuf.frames; | |
2790 | 328 |
2802 | 329 /* video buffers */ |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
330 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap)); |
3611 | 331 if (!priv->buf) |
332 goto malloc_failed; | |
2802 | 333 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap)); |
2790 | 334 |
3815 | 335 /* audio init */ |
5088 | 336 #if 1 |
3815 | 337 priv->audio_fd = open(priv->audio_device, O_RDONLY); |
338 if (priv->audio_fd < 0) | |
339 { | |
340 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", | |
341 priv->audio_device, strerror(errno)); | |
342 } | |
343 else | |
344 { | |
345 int ioctl_param; | |
346 | |
347 fcntl(priv->audio_fd, F_SETFL, O_NONBLOCK); | |
348 | |
349 #if 0 | |
350 ioctl_param = 0x7fff000d; /* 8k */ | |
351 printf("ioctl dsp setfragment: %d\n", | |
352 ioctl(priv->audio_fd, SNDCTL_DSP_SETFRAGMENT, &ioctl_param)); | |
353 #endif | |
354 | |
355 ioctl_param = 0 ; | |
356 printf("ioctl dsp getfmt: %d\n", | |
357 ioctl(priv->audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param)); | |
358 | |
359 printf("Supported formats: %x\n", ioctl_param); | |
360 if (!(ioctl_param & priv->audio_format[priv->audio_id])) | |
361 printf("notsupported format\n"); | |
362 | |
363 ioctl_param = priv->audio_format[priv->audio_id]; | |
364 printf("ioctl dsp setfmt: %d\n", | |
365 ioctl(priv->audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param)); | |
366 | |
367 // ioctl(priv->audio_fd, SNDCTL_DSP_GETISPACE, &ioctl_param); | |
368 // printf("getispace: %d\n", ioctl_param); | |
369 | |
370 if (priv->audio_channels[priv->audio_id] > 2) | |
371 { | |
372 ioctl_param = priv->audio_channels[priv->audio_id]; | |
373 printf("ioctl dsp channels: %d\n", | |
374 ioctl(priv->audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param)); | |
375 } | |
376 else | |
377 { | |
378 // if (priv->audio_channels[priv->audio_id] == 2) | |
379 // ioctl_param = 1; | |
380 // else | |
381 // ioctl_param = 0; | |
382 | |
383 ioctl_param = (priv->audio_channels[priv->audio_id] == 2); | |
384 printf("ioctl dsp stereo: %d (req: %d)\n", | |
385 ioctl(priv->audio_fd, SNDCTL_DSP_STEREO, &ioctl_param), | |
386 ioctl_param); | |
387 } | |
388 | |
389 ioctl_param = priv->audio_samplerate[priv->audio_id]; | |
390 printf("ioctl dsp speed: %d\n", | |
391 ioctl(priv->audio_fd, SNDCTL_DSP_SPEED, &ioctl_param)); | |
392 | |
393 #if 0 | |
394 ioctl_param = 0; | |
395 ioctl_param = ~PCM_ENABLE_INPUT; | |
396 printf("ioctl dsp trigger: %d\n", | |
397 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param)); | |
398 ioctl_param = PCM_ENABLE_INPUT; | |
399 printf("ioctl dsp trigger: %d\n", | |
400 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param)); | |
401 #endif | |
402 | |
403 printf("ioctl dsp trigger: %d\n", | |
404 ioctl(priv->audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param)); | |
405 printf("trigger: %x\n", ioctl_param); | |
406 ioctl_param = PCM_ENABLE_INPUT; | |
407 printf("ioctl dsp trigger: %d\n", | |
408 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param)); | |
409 | |
410 printf("ioctl dsp getblocksize: %d\n", | |
411 ioctl(priv->audio_fd, SNDCTL_DSP_GETBLKSIZE, &priv->audio_blocksize)); | |
412 printf("blocksize: %d\n", priv->audio_blocksize); | |
413 } | |
414 #endif | |
2790 | 415 return(1); |
416 | |
3611 | 417 |
418 malloc_failed: | |
419 if (priv->channels) | |
420 free(priv->channels); | |
421 if (priv->buf) | |
422 free(priv->buf); | |
2790 | 423 err: |
3815 | 424 if (priv->video_fd != -1) |
425 close(priv->video_fd); | |
2790 | 426 return(0); |
427 } | |
428 | |
2802 | 429 static int uninit(priv_t *priv) |
2790 | 430 { |
3815 | 431 close(priv->video_fd); |
432 | |
433 priv->audio[priv->audio_id].volume = 0; | |
434 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE; | |
435 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
436 close(priv->audio_fd); | |
2802 | 437 #warning "Implement uninit!" |
2931 | 438 |
439 return(1); | |
2790 | 440 } |
441 | |
2802 | 442 static int start(priv_t *priv) |
2790 | 443 { |
2802 | 444 int i; |
445 | |
446 | |
3815 | 447 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1) |
2790 | 448 { |
2818 | 449 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); |
2802 | 450 return(0); |
2790 | 451 } |
452 | |
2802 | 453 priv->picture.palette = format2palette(priv->format); |
454 priv->picture.depth = palette2depth(priv->picture.palette); | |
455 priv->bytesperline = priv->width * priv->picture.depth / 8; | |
3815 | 456 // if (IMGFMT_IS_BGR(priv->format) || IMGFMT_IS_RGB(priv->format)) |
457 // priv->bytesperline = priv->width * priv->picture.depth / 8; | |
458 // if ((priv->format == IMGFMT_YV12) || (priv->format == IMGFMT_I420) || (priv->format == IMGFMT_IYUV)) | |
459 // priv->bytesperline = priv->width * 3 / 2; | |
460 | |
461 printf("palette: %d, depth: %d, bytesperline: %d\n", | |
462 priv->picture.palette, priv->picture.depth, priv->bytesperline); | |
463 | |
2818 | 464 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n"); |
465 mp_msg(MSGT_TV, MSGL_INFO, " Depth: %d, Palette: %d (Format: %s)\n", priv->picture.depth, | |
2802 | 466 priv->picture.palette, vo_format_name(priv->format)); |
2818 | 467 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n", |
2802 | 468 priv->picture.brightness, priv->picture.hue, |
469 priv->picture.colour, priv->picture.contrast); | |
470 | |
471 | |
3815 | 472 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1) |
2790 | 473 { |
2818 | 474 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno)); |
2802 | 475 return(0); |
2790 | 476 } |
477 | |
2802 | 478 priv->nbuf = priv->mbuf.frames; |
479 for (i=0; i < priv->nbuf; i++) | |
480 { | |
481 priv->buf[i].format = priv->picture.palette; | |
482 priv->buf[i].frame = i; | |
483 priv->buf[i].width = priv->width; | |
484 priv->buf[i].height = priv->height; | |
2818 | 485 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]); |
2802 | 486 } |
2837 | 487 |
2931 | 488 #if 0 |
489 { | |
490 struct video_play_mode pmode; | |
491 | |
492 pmode.mode = VID_PLAY_NORMAL; | |
493 pmode.p1 = 1; | |
494 pmode.p2 = 0; | |
3815 | 495 if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1) |
2931 | 496 { |
497 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno)); | |
498 // return(0); | |
499 } | |
500 } | |
501 #endif | |
2837 | 502 |
503 #if 0 | |
504 { | |
505 struct video_window win; | |
506 | |
507 win.x = 0; | |
508 win.y = 0; | |
509 win.width = priv->width; | |
510 win.height = priv->height; | |
511 win.chromakey = -1; | |
512 win.flags = 0; | |
5088 | 513 //win.clipcount = 0; |
2837 | 514 |
3815 | 515 ioctl(priv->video_fd, VIDIOCSWIN, &win); |
2837 | 516 } |
517 | |
2802 | 518 /* start capture */ |
3815 | 519 if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1) |
2802 | 520 { |
2818 | 521 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno)); |
2802 | 522 return(0); |
523 } | |
2837 | 524 #endif |
525 | |
526 return(1); | |
2790 | 527 } |
528 | |
529 static int control(priv_t *priv, int cmd, void *arg) | |
530 { | |
2818 | 531 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n", |
2802 | 532 priv, cmd, arg); |
2790 | 533 switch(cmd) |
534 { | |
2802 | 535 /* ========== GENERIC controls =========== */ |
536 case TVI_CONTROL_IS_VIDEO: | |
537 { | |
538 if (priv->capability.type & VID_TYPE_CAPTURE) | |
539 return(TVI_CONTROL_TRUE); | |
540 return(TVI_CONTROL_FALSE); | |
541 } | |
542 case TVI_CONTROL_IS_AUDIO: | |
5088 | 543 // return(TVI_CONTROL_FALSE); |
3815 | 544 /* also disable audio for as it's not working! */ |
2841 | 545 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO) |
3815 | 546 { |
547 // printf("yeah, audio csennel!!"); | |
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 { | |
3815 | 741 (int)*(void **)arg = priv->audio_samplesize[priv->audio_id]; |
2802 | 742 return(TVI_CONTROL_TRUE); |
743 } | |
744 | |
745 /* ========== SPECIFIC controls =========== */ | |
746 case TVI_CONTROL_SPC_GET_INPUT: | |
747 { | |
748 int req_chan = (int)*(void **)arg; | |
749 int i; | |
750 | |
751 for (i = 0; i < priv->capability.channels; i++) | |
752 { | |
753 if (priv->channels[i].channel == req_chan) | |
754 break; | |
755 } | |
2841 | 756 |
757 priv->act_channel = i; | |
2802 | 758 |
3815 | 759 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2802 | 760 { |
2818 | 761 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); |
2802 | 762 return(TVI_CONTROL_FALSE); |
763 } | |
764 return(TVI_CONTROL_TRUE); | |
765 } | |
766 | |
767 case TVI_CONTROL_SPC_SET_INPUT: | |
768 { | |
769 struct video_channel chan; | |
770 int req_chan = (int)*(void **)arg; | |
771 int i; | |
772 | |
773 if (req_chan >= priv->capability.channels) | |
774 { | |
2818 | 775 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n", |
2802 | 776 req_chan, priv->capability.channels); |
777 return(TVI_CONTROL_FALSE); | |
778 } | |
779 | |
780 for (i = 0; i < priv->capability.channels; i++) | |
781 { | |
782 if (priv->channels[i].channel == req_chan) | |
783 chan = priv->channels[i]; | |
784 } | |
785 | |
3815 | 786 if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1) |
2802 | 787 { |
2818 | 788 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
2802 | 789 return(TVI_CONTROL_FALSE); |
790 } | |
2818 | 791 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name); |
2802 | 792 |
2841 | 793 priv->act_channel = i; |
794 | |
2802 | 795 /* update tuner state */ |
2841 | 796 // if (priv->capability.type & VID_TYPE_TUNER) |
797 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 798 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
799 | |
800 /* update local channel list */ | |
801 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan); | |
802 return(TVI_CONTROL_TRUE); | |
2790 | 803 } |
804 } | |
805 | |
806 return(TVI_CONTROL_UNKNOWN); | |
807 } | |
808 | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
809 static double grab_video_frame(priv_t *priv, char *buffer, int len) |
2790 | 810 { |
2802 | 811 int frame = priv->queue % priv->nbuf; |
2814 | 812 int nextframe = (priv->queue+1) % priv->nbuf; |
2802 | 813 |
3284 | 814 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d)\n", |
2802 | 815 priv, buffer, len); |
816 | |
2931 | 817 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n", |
2814 | 818 priv->buf, nextframe, &priv->buf[nextframe]); |
3815 | 819 if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1) |
2790 | 820 { |
2818 | 821 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno)); |
2802 | 822 return(0); |
2790 | 823 } |
3711 | 824 |
3815 | 825 while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 && |
3711 | 826 (errno == EAGAIN || errno == EINTR)); |
827 mp_dbg(MSGT_TV, MSGL_DBG3, "picture sync failed\n"); | |
828 | |
2802 | 829 priv->queue++; |
830 | |
2931 | 831 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n", |
2802 | 832 priv->mmap, priv->mbuf.offsets[frame], |
833 priv->mmap+priv->mbuf.offsets[frame]); | |
2931 | 834 |
835 /* XXX also directrendering would be nicer! */ | |
836 /* 3 times copying the same picture to other buffer :( */ | |
837 | |
838 /* copy the actual frame */ | |
2802 | 839 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len); |
840 | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
841 return(0); |
2790 | 842 } |
843 | |
844 static int get_video_framesize(priv_t *priv) | |
845 { | |
2931 | 846 return(priv->bytesperline * priv->height); |
2790 | 847 } |
848 | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
849 static double grab_audio_frame(priv_t *priv, char *buffer, int len) |
2790 | 850 { |
3815 | 851 int in_len = 0; |
5088 | 852 // int max_tries = 128; |
3815 | 853 |
5088 | 854 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n", |
3815 | 855 priv, buffer, len); |
856 | |
5088 | 857 // while (--max_tries > 0) |
3815 | 858 for (;;) |
859 { | |
860 in_len = read(priv->audio_fd, buffer, len); | |
861 // printf("in_len: %d\n", in_len); | |
862 // fflush(NULL); | |
863 | |
864 if (in_len > 0) | |
865 break; | |
866 if (!((in_len == 0) || (in_len == -1 && (errno == EAGAIN || errno == EINTR)))) | |
867 { | |
868 in_len = 0; /* -EIO */ | |
869 break; | |
870 } | |
871 } | |
5088 | 872 // printf("tries: %d\n", 128-max_tries); |
3815 | 873 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
874 return 0; //(in_len); // FIXME! |
2790 | 875 } |
876 | |
877 static int get_audio_framesize(priv_t *priv) | |
878 { | |
3815 | 879 return(priv->audio_blocksize); |
880 // return(priv->audio_samplesize[priv->audio_id]); | |
2790 | 881 } |
882 | |
883 #endif /* USE_TV */ |