mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 03:00:35 +00:00
v4l2transform: Setup cropping if needed
This commit is contained in:
parent
2676ac9075
commit
d4c24cc52f
3 changed files with 46 additions and 4 deletions
|
@ -2825,6 +2825,39 @@ unsupported_format:
|
|||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_v4l2_object_set_crop (GstV4l2Object * obj)
|
||||
{
|
||||
struct v4l2_crop crop = { 0 };
|
||||
|
||||
crop.type = obj->type;
|
||||
crop.c.left = obj->align.padding_left;
|
||||
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 +
|
||||
obj->align.padding_right + obj->align.padding_bottom == 0) {
|
||||
GST_DEBUG_OBJECT (obj->element, "no cropping needed");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (obj->element,
|
||||
"Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
|
||||
crop.c.width, crop.c.height);
|
||||
|
||||
if (v4l2_ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) {
|
||||
GST_WARNING_OBJECT (obj->element, "VIDIOC_S_CROP failed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (obj->element,
|
||||
"Got cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
|
||||
crop.c.width, crop.c.height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
|
||||
{
|
||||
|
|
|
@ -262,6 +262,8 @@ GstCaps * gst_v4l2_object_get_caps (GstV4l2Object * v4l2object,
|
|||
|
||||
gboolean gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object,
|
||||
GstVideoInfo * info);
|
||||
|
||||
gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj);
|
||||
|
||||
gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
|
||||
GstQuery * query);
|
||||
|
|
|
@ -209,23 +209,30 @@ gst_v4l2_transform_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
|||
if (!gst_v4l2_object_set_format (self->v4l2capture, outcaps))
|
||||
goto outcaps_failed;
|
||||
|
||||
return TRUE;
|
||||
/* FIXME implement fallback if crop not supported */
|
||||
if (!gst_v4l2_object_set_crop (self->v4l2output))
|
||||
goto failed;
|
||||
|
||||
if (!gst_v4l2_object_set_crop (self->v4l2capture))
|
||||
goto failed;
|
||||
|
||||
return TRUE;
|
||||
|
||||
incaps_failed:
|
||||
{
|
||||
GST_ERROR_OBJECT (self, "failed to set input caps: %" GST_PTR_FORMAT,
|
||||
incaps);
|
||||
return FALSE;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
outcaps_failed:
|
||||
{
|
||||
gst_v4l2_object_stop (self->v4l2output);
|
||||
GST_ERROR_OBJECT (self, "failed to set output caps: %" GST_PTR_FORMAT,
|
||||
outcaps);
|
||||
return FALSE;
|
||||
goto failed;
|
||||
}
|
||||
failed:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
Loading…
Reference in a new issue