Commit 4081bb04 authored by Philipp Zabel's avatar Philipp Zabel Committed by Nicolas Dufresne

v4l2object: use S_SELECTION instead of S_CROP in gst_v4l2_object_set_crop

The S_CROP call doesn't work on mem2mem output queues. Use the
S_SELECTION call to set the crop rectangle and only fall back to
S_CROP for ancient kernels.
This will allow v4l2videoenc to set the coded size on the output
queue via S_FMT and then set the visible size via the crop rectangle,
as required by the V4L2 codec API.

https://bugzilla.gnome.org/show_bug.cgi?id=796672
parent 161dd7a5
...@@ -3949,13 +3949,19 @@ unsupported_format: ...@@ -3949,13 +3949,19 @@ unsupported_format:
gboolean gboolean
gst_v4l2_object_set_crop (GstV4l2Object * obj) gst_v4l2_object_set_crop (GstV4l2Object * obj)
{ {
struct v4l2_selection sel = { 0 };
struct v4l2_crop crop = { 0 }; struct v4l2_crop crop = { 0 };
sel.type = obj->type;
sel.target = V4L2_SEL_TGT_CROP;
sel.flags = 0;
sel.r.left = obj->align.padding_left;
sel.r.top = obj->align.padding_top;
sel.r.width = obj->info.width;
sel.r.height = obj->info.height;
crop.type = obj->type; crop.type = obj->type;
crop.c.left = obj->align.padding_left; crop.c = sel.r;
crop.c.top = obj->align.padding_top;
crop.c.width = obj->info.width;
crop.c.height = obj->info.height;
if (obj->align.padding_left + obj->align.padding_top + if (obj->align.padding_left + obj->align.padding_top +
obj->align.padding_right + obj->align.padding_bottom == 0) { obj->align.padding_right + obj->align.padding_bottom == 0) {
...@@ -3967,14 +3973,25 @@ gst_v4l2_object_set_crop (GstV4l2Object * obj) ...@@ -3967,14 +3973,25 @@ gst_v4l2_object_set_crop (GstV4l2Object * obj)
"Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top, "Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
crop.c.width, crop.c.height); crop.c.width, crop.c.height);
if (obj->ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) { if (obj->ioctl (obj->video_fd, VIDIOC_S_SELECTION, &sel) < 0) {
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_S_CROP failed"); if (errno != ENOTTY) {
return FALSE; GST_WARNING_OBJECT (obj->dbg_obj,
} "Failed to set crop rectangle with VIDIOC_S_SELECTION: %s",
g_strerror (errno));
return FALSE;
} else {
if (obj->ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) {
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_S_CROP failed");
return FALSE;
}
if (obj->ioctl (obj->video_fd, VIDIOC_G_CROP, &crop) < 0) { if (obj->ioctl (obj->video_fd, VIDIOC_G_CROP, &crop) < 0) {
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_G_CROP failed"); GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_G_CROP failed");
return FALSE; return FALSE;
}
sel.r = crop.c;
}
} }
GST_DEBUG_OBJECT (obj->dbg_obj, GST_DEBUG_OBJECT (obj->dbg_obj,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment