aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2010-04-26 22:07:15 +0000
committerStefano Sabatini <stefano.sabatini-lala@poste.it>2010-04-26 22:07:15 +0000
commit932d775fa2d66ce26ce182c8499678f97ecad63c (patch)
treeb060e7a230b67b7942dfc44e2ed3cf805fbd70f2
parent687dc3555db2fef2d649374d421ea95eeab93078 (diff)
downloadffmpeg-932d775fa2d66ce26ce182c8499678f97ecad63c.tar.gz
Implement v4l2 input size autodetection in v4l2_read_header().
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
-rw-r--r--libavdevice/v4l2.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 814273948e..88d2fbc55e 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -586,14 +586,6 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
uint32_t desired_format, capabilities;
enum CodecID codec_id;
- if (ap->width <= 0 || ap->height <= 0) {
- av_log(s1, AV_LOG_ERROR, "Wrong size (%dx%d)\n", ap->width, ap->height);
- return AVERROR(EINVAL);
- }
-
- if(avcodec_check_dimensions(s1, ap->width, ap->height) < 0)
- return AVERROR(EINVAL);
-
st = av_new_stream(s1, 0);
if (!st) {
return AVERROR(ENOMEM);
@@ -610,7 +602,25 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities);
+ if (!s->width && !s->height) {
+ struct v4l2_format fmt;
+
+ av_log(s1, AV_LOG_INFO, "Size value (%dx%d) unspecified, querying the device for the current settings\n",
+ s->width, s->height);
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
+ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", strerror(errno));
+ return AVERROR(errno);
+ }
+ s->width = fmt.fmt.pix.width;
+ s->height = fmt.fmt.pix.height;
+ av_log(s1, AV_LOG_INFO, "Setting size to value %dx%d\n", s->width, s->height);
+ }
+
desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id);
+ if (avcodec_check_dimensions(s1, s->width, s->height) < 0)
+ return AVERROR(EINVAL);
+
if (desired_format == 0) {
av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
"codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt);