v4l2transform: Setup cropping if needed

This commit is contained in:
Nicolas Dufresne 2014-03-20 15:31:22 -04:00
parent 2676ac9075
commit d4c24cc52f
3 changed files with 46 additions and 4 deletions

View file

@ -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 gboolean
gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps) gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
{ {

View file

@ -263,6 +263,8 @@ GstCaps * gst_v4l2_object_get_caps (GstV4l2Object * v4l2object,
gboolean gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, gboolean gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object,
GstVideoInfo * info); GstVideoInfo * info);
gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj);
gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object, gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
GstQuery * query); GstQuery * query);

View file

@ -209,23 +209,30 @@ gst_v4l2_transform_set_caps (GstBaseTransform * trans, GstCaps * incaps,
if (!gst_v4l2_object_set_format (self->v4l2capture, outcaps)) if (!gst_v4l2_object_set_format (self->v4l2capture, outcaps))
goto outcaps_failed; 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: incaps_failed:
{ {
GST_ERROR_OBJECT (self, "failed to set input caps: %" GST_PTR_FORMAT, GST_ERROR_OBJECT (self, "failed to set input caps: %" GST_PTR_FORMAT,
incaps); incaps);
return FALSE; goto failed;
} }
outcaps_failed: outcaps_failed:
{ {
gst_v4l2_object_stop (self->v4l2output); gst_v4l2_object_stop (self->v4l2output);
GST_ERROR_OBJECT (self, "failed to set output caps: %" GST_PTR_FORMAT, GST_ERROR_OBJECT (self, "failed to set output caps: %" GST_PTR_FORMAT,
outcaps); outcaps);
return FALSE; goto failed;
} }
failed:
return FALSE;
} }
static gboolean static gboolean