comparison v4l2.c @ 975:36a69fbabcfb libavformat

Add support for drivers that can change the capture size on VIDIOC_S_FMT
author lucabe
date Tue, 28 Feb 2006 11:28:09 +0000
parents e0cfc88ad93a
children 2d57ce58f576
comparison
equal deleted inserted replaced
974:e0cfc88ad93a 975:36a69fbabcfb
146 *capabilities = cap.capabilities; 146 *capabilities = cap.capabilities;
147 147
148 return fd; 148 return fd;
149 } 149 }
150 150
151 static int device_init(int fd, int width, int height, int pix_fmt) 151 static int device_init(int fd, int *width, int *height, int pix_fmt)
152 { 152 {
153 struct v4l2_format fmt; 153 struct v4l2_format fmt;
154 int res;
154 155
155 memset(&fmt, 0, sizeof(struct v4l2_format)); 156 memset(&fmt, 0, sizeof(struct v4l2_format));
156 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 157 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
157 fmt.fmt.pix.width = width; 158 fmt.fmt.pix.width = *width;
158 fmt.fmt.pix.height = height; 159 fmt.fmt.pix.height = *height;
159 fmt.fmt.pix.pixelformat = pix_fmt; 160 fmt.fmt.pix.pixelformat = pix_fmt;
160 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; 161 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
161 return ioctl (fd, VIDIOC_S_FMT, &fmt); 162 res = ioctl(fd, VIDIOC_S_FMT, &fmt);
163 if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
164 av_log(NULL, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);
165 *width = fmt.fmt.pix.width;
166 *height = fmt.fmt.pix.height;
167 }
168
169 return res;
162 } 170 }
163 171
164 static int first_field(int fd) 172 static int first_field(int fd)
165 { 173 {
166 int res; 174 int res;
416 return AVERROR_IO; 424 return AVERROR_IO;
417 } 425 }
418 av_log(s1, AV_LOG_ERROR, "[%d]Capabilities: %x\n", s->fd, capabilities); 426 av_log(s1, AV_LOG_ERROR, "[%d]Capabilities: %x\n", s->fd, capabilities);
419 427
420 desired_format = fmt_ff2v4l(ap->pix_fmt); 428 desired_format = fmt_ff2v4l(ap->pix_fmt);
421 if (desired_format == 0 || (device_init(s->fd, width, height, desired_format) < 0)) { 429 if (desired_format == 0 || (device_init(s->fd, &width, &height, desired_format) < 0)) {
422 int i, done; 430 int i, done;
423 431
424 done = 0; i = 0; 432 done = 0; i = 0;
425 while (!done) { 433 while (!done) {
426 desired_format = fmt_conversion_table[i].v4l2_fmt; 434 desired_format = fmt_conversion_table[i].v4l2_fmt;
427 if (device_init(s->fd, width, height, desired_format) < 0) { 435 if (device_init(s->fd, &width, &height, desired_format) < 0) {
428 desired_format = 0; 436 desired_format = 0;
429 i++; 437 i++;
430 } else { 438 } else {
431 done = 1; 439 done = 1;
432 } 440 }