From 59b86d25584065225723b05a3bd83f7a2d768b7b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 12 Jul 2011 16:46:21 +0100 Subject: [PATCH] v4l: pass the bytesperline around When setting a format, return the bytesperline to the caller so that it can be used to allocate buffers. --- sys/v4l2/gstv4l2object.c | 22 +++++++++++++++++++--- sys/v4l2/gstv4l2object.h | 2 +- sys/v4l2/gstv4l2sink.c | 3 ++- sys/v4l2/v4l2src_calls.c | 3 ++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index a29798a..227d0b6 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -2061,7 +2061,7 @@ gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object, gboolean gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat, - guint32 width, guint32 height, gboolean interlaced) + guint32 width, guint32 height, gboolean interlaced, guint32 * bytesperline) { gint fd = v4l2object->video_fd; struct v4l2_format format; @@ -2095,11 +2095,17 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat, if (v4l2_ioctl (fd, VIDIOC_G_FMT, &format) < 0) goto get_fmt_failed; + GST_DEBUG_OBJECT (v4l2object->element, "Got format to %dx%d, format " + "%" GST_FOURCC_FORMAT " stride %d", format.fmt.pix.width, + format.fmt.pix.height, GST_FOURCC_ARGS (format.fmt.pix.pixelformat), + format.fmt.pix.bytesperline); + if (format.type == v4l2object->type && format.fmt.pix.width == width && format.fmt.pix.height == height && format.fmt.pix.pixelformat == pixelformat && format.fmt.pix.field == field) { + GST_DEBUG_OBJECT (v4l2object->element, "format was good"); /* Nothing to do. We want to succeed immediately * here because setting the same format back * can still fail due to EBUSY. By short-circuiting @@ -2109,18 +2115,26 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat, * any caps change would require us to go to NULL * state to close the device and set format. */ + *bytesperline = format.fmt.pix.bytesperline; return TRUE; } + GST_DEBUG_OBJECT (v4l2object->element, "Setting format to %dx%d, format " + "%" GST_FOURCC_FORMAT, width, height, GST_FOURCC_ARGS (pixelformat)); + format.type = v4l2object->type; format.fmt.pix.width = width; format.fmt.pix.height = height; format.fmt.pix.pixelformat = pixelformat; format.fmt.pix.field = field; - if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0) { + if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0) goto set_fmt_failed; - } + + GST_DEBUG_OBJECT (v4l2object->element, "Got format to %dx%d, format " + "%" GST_FOURCC_FORMAT " stride %d", format.fmt.pix.width, + format.fmt.pix.height, GST_FOURCC_ARGS (format.fmt.pix.pixelformat), + format.fmt.pix.bytesperline); if (format.fmt.pix.width != width || format.fmt.pix.height != height) goto invalid_dimensions; @@ -2128,6 +2142,8 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat, if (format.fmt.pix.pixelformat != pixelformat) goto invalid_pixelformat; + *bytesperline = format.fmt.pix.bytesperline; + return TRUE; /* ERRORS */ diff --git a/sys/v4l2/gstv4l2object.h b/sys/v4l2/gstv4l2object.h index a7b590d..426126d 100644 --- a/sys/v4l2/gstv4l2object.h +++ b/sys/v4l2/gstv4l2object.h @@ -190,7 +190,7 @@ GstCaps* gst_v4l2_object_get_all_caps (void); GstStructure* gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc); -gboolean gst_v4l2_object_set_format (GstV4l2Object *v4l2object, guint32 pixelformat, guint32 width, guint32 height, gboolean interlaced); +gboolean gst_v4l2_object_set_format (GstV4l2Object *v4l2object, guint32 pixelformat, guint32 width, guint32 height, gboolean interlaced, guint32 *bytesperline); gboolean gst_v4l2_object_start_streaming (GstV4l2Object *v4l2object); gboolean gst_v4l2_object_stop_streaming (GstV4l2Object *v4l2object); diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c index 7d150b0..e4007af 100644 --- a/sys/v4l2/gstv4l2sink.c +++ b/sys/v4l2/gstv4l2sink.c @@ -623,6 +623,7 @@ gst_v4l2sink_set_caps (GstBaseSink * bsink, GstCaps * caps) guint fps_n, fps_d; guint size; GstV4l2BufferPool *newpool; + guint bytesperline; LOG_CAPS (v4l2sink, caps); @@ -659,7 +660,7 @@ gst_v4l2sink_set_caps (GstBaseSink * bsink, GstCaps * caps) } if (!gst_v4l2_object_set_format (v4l2sink->v4l2object, format->pixelformat, - w, h, interlaced)) + w, h, interlaced, &bytesperline)) goto invalid_format; if (!(v4l2sink->v4l2object->vcap.capabilities & V4L2_CAP_STREAMING)) diff --git a/sys/v4l2/v4l2src_calls.c b/sys/v4l2/v4l2src_calls.c index 43c0b48..e45bc7b 100644 --- a/sys/v4l2/v4l2src_calls.c +++ b/sys/v4l2/v4l2src_calls.c @@ -219,12 +219,13 @@ gst_v4l2src_set_capture (GstV4l2Src * v4l2src, guint32 pixelformat, { gint fd = v4l2src->v4l2object->video_fd; struct v4l2_streamparm stream; + guint32 bytesperline; if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')) return TRUE; if (!gst_v4l2_object_set_format (v4l2src->v4l2object, pixelformat, width, - height, interlaced)) { + height, interlaced, &bytesperline)) { /* error already reported */ return FALSE; } -- 2.7.4