Mercurial > mplayer.hg
comparison libmpdemux/tvi_v4l.c @ 2810:1f0bcdb49910
tv update
author | alex |
---|---|
date | Sun, 11 Nov 2001 01:44:54 +0000 |
parents | 09d5c9834580 |
children | 37fc45a05082 |
comparison
equal
deleted
inserted
replaced
2809:b8e0d8204ff2 | 2810:1f0bcdb49910 |
---|---|
30 "v4l", | 30 "v4l", |
31 "Alex Beregszaszi <alex@naxine.org>", | 31 "Alex Beregszaszi <alex@naxine.org>", |
32 "under development" | 32 "under development" |
33 }; | 33 }; |
34 | 34 |
35 struct vid_fmt { | |
36 int fmtid; | |
37 int width; | |
38 int height; | |
39 int bytesperline; | |
40 }; | |
41 | |
42 typedef struct { | 35 typedef struct { |
43 /* general */ | 36 /* general */ |
44 char *video_device; | 37 char *video_device; |
45 int fd; | 38 int fd; |
46 struct video_capability capability; | 39 struct video_capability capability; |
79 }; | 72 }; |
80 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN") | 73 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN") |
81 | 74 |
82 static int palette2depth(int palette) | 75 static int palette2depth(int palette) |
83 { | 76 { |
84 if (palette == VIDEO_PALETTE_YUV420P) | 77 switch(palette) |
85 return 12; | 78 { |
86 return 32; | 79 case VIDEO_PALETTE_RGB555: |
80 return(15); | |
81 case VIDEO_PALETTE_RGB565: | |
82 return(16); | |
83 case VIDEO_PALETTE_RGB24: | |
84 return(24); | |
85 case VIDEO_PALETTE_RGB32: | |
86 return(32); | |
87 case VIDEO_PALETTE_YUV420P: | |
88 return(12); | |
89 case VIDEO_PALETTE_YUV422: | |
90 case VIDEO_PALETTE_UYVY: | |
91 return(16); | |
92 } | |
93 return(-1); | |
87 } | 94 } |
88 | 95 |
89 static int format2palette(int format) | 96 static int format2palette(int format) |
90 { | 97 { |
91 if (format == IMGFMT_YV12) | 98 switch(format) |
92 return VIDEO_PALETTE_YUV420P; | 99 { |
93 return VIDEO_PALETTE_RGB24; | 100 case IMGFMT_RGB15: |
101 return(VIDEO_PALETTE_RGB555); | |
102 case IMGFMT_RGB16: | |
103 return(VIDEO_PALETTE_RGB565); | |
104 case IMGFMT_RGB24: | |
105 return(VIDEO_PALETTE_RGB24); | |
106 case IMGFMT_RGB32: | |
107 return(VIDEO_PALETTE_RGB32); | |
108 case IMGFMT_YV12: | |
109 return(VIDEO_PALETTE_YUV420P); | |
110 case IMGFMT_UYVY: | |
111 return(VIDEO_PALETTE_YUV422); | |
112 } | |
113 return(-1); | |
94 } | 114 } |
95 | 115 |
96 #if 0 | 116 #if 0 |
97 struct STRTAB { | 117 struct STRTAB { |
98 long nr; | 118 long nr; |
218 | 238 |
219 static int init(priv_t *priv, tvi_param_t *params) | 239 static int init(priv_t *priv, tvi_param_t *params) |
220 { | 240 { |
221 int i; | 241 int i; |
222 | 242 |
223 priv->fd = open(priv->video_device, O_RDONLY); | 243 priv->fd = open(priv->video_device, O_RDWR); |
224 if (priv->fd == -1) | 244 if (priv->fd == -1) |
225 { | 245 { |
226 printf("v4l: unable to open '%s': %s\n", | 246 printf("v4l: unable to open '%s': %s\n", |
227 priv->video_device, strerror(errno)); | 247 priv->video_device, strerror(errno)); |
228 goto err; | 248 goto err; |
247 priv->input = (int)*(void **)params[i].value; | 267 priv->input = (int)*(void **)params[i].value; |
248 } | 268 } |
249 printf("priv->input: %d\n", priv->input); | 269 printf("priv->input: %d\n", priv->input); |
250 #endif | 270 #endif |
251 | 271 |
252 printf("Selected device: %s\n", priv->capability.name); | 272 printf("Selected device: %s\n", priv->capability.name); |
253 printf(" Capabilites: "); | 273 printf(" Capabilites: "); |
254 for (i = 0; device_cap[i] != NULL; i++) | 274 for (i = 0; device_cap[i] != NULL; i++) |
255 if (priv->capability.type & (1 << i)) | 275 if (priv->capability.type & (1 << i)) |
256 printf("%s ", device_cap[i]); | 276 printf("%s ", device_cap[i]); |
257 printf("\n"); | 277 printf("\n"); |
297 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | 317 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, |
298 MAP_SHARED, priv->fd, 0); | 318 MAP_SHARED, priv->fd, 0); |
299 if (priv->mmap == -1) | 319 if (priv->mmap == -1) |
300 { | 320 { |
301 printf("Unabel to map memory for buffers: %s\n", strerror(errno)); | 321 printf("Unabel to map memory for buffers: %s\n", strerror(errno)); |
302 priv->mmap = malloc(priv->mbuf.size); /* our buffer */ | |
303 } | |
304 if (!priv->mmap) | |
305 { | |
306 printf("Unable to allocate memory for buffers: %s\n", strerror(errno)); | |
307 goto err; | 322 goto err; |
308 } | 323 } |
309 printf("our buffer: %p\n", priv->mmap); | 324 printf("our buffer: %p\n", priv->mmap); |
310 | 325 |
311 /* num of buffers */ | 326 /* num of buffers */ |
439 return(TVI_CONTROL_TRUE); | 454 return(TVI_CONTROL_TRUE); |
440 case TVI_CONTROL_VID_GET_PLANES: | 455 case TVI_CONTROL_VID_GET_PLANES: |
441 (int)*(void **)arg = 1; | 456 (int)*(void **)arg = 1; |
442 return(TVI_CONTROL_TRUE); | 457 return(TVI_CONTROL_TRUE); |
443 case TVI_CONTROL_VID_GET_BITS: | 458 case TVI_CONTROL_VID_GET_BITS: |
444 (int)*(void **)arg = 12; | 459 (int)*(void **)arg = palette2depth(format2palette(priv->format)); |
445 return(TVI_CONTROL_TRUE); | 460 return(TVI_CONTROL_TRUE); |
446 case TVI_CONTROL_VID_GET_WIDTH: | 461 case TVI_CONTROL_VID_GET_WIDTH: |
447 (int)*(void **)arg = priv->width; | 462 (int)*(void **)arg = priv->width; |
448 return(TVI_CONTROL_TRUE); | 463 return(TVI_CONTROL_TRUE); |
449 case TVI_CONTROL_VID_CHK_WIDTH: | 464 case TVI_CONTROL_VID_CHK_WIDTH: |
450 { | 465 { |
451 int req_width = (int)*(void **)arg; | 466 int req_width = (int)*(void **)arg; |
452 | 467 |
453 printf("Requested width: %d\n", req_width); | 468 printf("Requested width: %d\n", req_width); |
454 if ((req_width > priv->capability.minwidth) && | 469 if ((req_width >= priv->capability.minwidth) && |
455 (req_width < priv->capability.maxwidth)) | 470 (req_width <= priv->capability.maxwidth)) |
456 return(TVI_CONTROL_TRUE); | 471 return(TVI_CONTROL_TRUE); |
457 return(TVI_CONTROL_FALSE); | 472 return(TVI_CONTROL_FALSE); |
458 } | 473 } |
459 case TVI_CONTROL_VID_SET_WIDTH: | 474 case TVI_CONTROL_VID_SET_WIDTH: |
460 priv->width = (int)*(void **)arg; | 475 priv->width = (int)*(void **)arg; |
465 case TVI_CONTROL_VID_CHK_HEIGHT: | 480 case TVI_CONTROL_VID_CHK_HEIGHT: |
466 { | 481 { |
467 int req_height = (int)*(void **)arg; | 482 int req_height = (int)*(void **)arg; |
468 | 483 |
469 printf("Requested height: %d\n", req_height); | 484 printf("Requested height: %d\n", req_height); |
470 if ((req_height > priv->capability.minheight) && | 485 if ((req_height >= priv->capability.minheight) && |
471 (req_height < priv->capability.maxheight)) | 486 (req_height <= priv->capability.maxheight)) |
472 return(TVI_CONTROL_TRUE); | 487 return(TVI_CONTROL_TRUE); |
473 return(TVI_CONTROL_FALSE); | 488 return(TVI_CONTROL_FALSE); |
474 } | 489 } |
475 case TVI_CONTROL_VID_SET_HEIGHT: | 490 case TVI_CONTROL_VID_SET_HEIGHT: |
476 priv->height = (int)*(void **)arg; | 491 priv->height = (int)*(void **)arg; |
652 { | 667 { |
653 printf("ioctl mcapture failed: %s\n", strerror(errno)); | 668 printf("ioctl mcapture failed: %s\n", strerror(errno)); |
654 return(0); | 669 return(0); |
655 } | 670 } |
656 | 671 |
657 ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame]); | 672 if (ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame]) == -1) |
673 printf("ioctl sync failed: %s\n", strerror(errno)); | |
658 priv->queue++; | 674 priv->queue++; |
659 | 675 |
660 printf("mmap: %p + offset: %d => %p\n", | 676 printf("mmap: %p + offset: %d => %p\n", |
661 priv->mmap, priv->mbuf.offsets[frame], | 677 priv->mmap, priv->mbuf.offsets[frame], |
662 priv->mmap+priv->mbuf.offsets[frame]); | 678 priv->mmap+priv->mbuf.offsets[frame]); |