[FFmpeg-cvslog] r22971 - trunk/libavdevice/v4l2.c

stefano subversion
Tue Apr 27 00:07:15 CEST 2010


Author: stefano
Date: Tue Apr 27 00:07:15 2010
New Revision: 22971

Log:
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.

Modified:
   trunk/libavdevice/v4l2.c

Modified: trunk/libavdevice/v4l2.c
==============================================================================
--- trunk/libavdevice/v4l2.c	Tue Apr 27 00:00:57 2010	(r22970)
+++ trunk/libavdevice/v4l2.c	Tue Apr 27 00:07:15 2010	(r22971)
@@ -586,14 +586,6 @@ static int v4l2_read_header(AVFormatCont
     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(AVFormatCont
     }
     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);



More information about the ffmpeg-cvslog mailing list