mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-04 22:48:54 +00:00
v4l: pass the bytesperline around
When setting a format, return the bytesperline to the caller so that it can be used to allocate buffers.
This commit is contained in:
parent
1ef806181c
commit
59b86d2558
4 changed files with 24 additions and 6 deletions
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue