Move check on frame size after the device is opened and after
device_try_init() is attempted. If the provided size value is 0x0,
perform a VIDIOC_G_FMT ioctl() on the device, which sets size to the
current settings.
Originally committed as revision 22971 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -586,14 +586,6 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) |
586 | 586 |
uint32_t desired_format, capabilities; |
587 | 587 |
enum CodecID codec_id; |
588 | 588 |
|
589 |
- if (ap->width <= 0 || ap->height <= 0) { |
|
590 |
- av_log(s1, AV_LOG_ERROR, "Wrong size (%dx%d)\n", ap->width, ap->height); |
|
591 |
- return AVERROR(EINVAL); |
|
592 |
- } |
|
593 |
- |
|
594 |
- if(avcodec_check_dimensions(s1, ap->width, ap->height) < 0) |
|
595 |
- return AVERROR(EINVAL); |
|
596 |
- |
|
597 | 589 |
st = av_new_stream(s1, 0); |
598 | 590 |
if (!st) { |
599 | 591 |
return AVERROR(ENOMEM); |
... | ... |
@@ -610,7 +602,25 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) |
610 | 610 |
} |
611 | 611 |
av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities); |
612 | 612 |
|
613 |
+ if (!s->width && !s->height) { |
|
614 |
+ struct v4l2_format fmt; |
|
615 |
+ |
|
616 |
+ av_log(s1, AV_LOG_INFO, "Size value (%dx%d) unspecified, querying the device for the current settings\n", |
|
617 |
+ s->width, s->height); |
|
618 |
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
|
619 |
+ if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { |
|
620 |
+ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", strerror(errno)); |
|
621 |
+ return AVERROR(errno); |
|
622 |
+ } |
|
623 |
+ s->width = fmt.fmt.pix.width; |
|
624 |
+ s->height = fmt.fmt.pix.height; |
|
625 |
+ av_log(s1, AV_LOG_INFO, "Setting size to value %dx%d\n", s->width, s->height); |
|
626 |
+ } |
|
627 |
+ |
|
613 | 628 |
desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id); |
629 |
+ if (avcodec_check_dimensions(s1, s->width, s->height) < 0) |
|
630 |
+ return AVERROR(EINVAL); |
|
631 |
+ |
|
614 | 632 |
if (desired_format == 0) { |
615 | 633 |
av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for " |
616 | 634 |
"codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt); |