blob: 816a87186f39bf03e572aa3038d167c8c411af39 [file] [log] [blame]
From 693b42bc08df5a3e79d21c060910feaa7a830f96 Mon Sep 17 00:00:00 2001
From: Fabien Parent <fparent@baylibre.com>
Date: Wed, 26 Aug 2020 19:16:53 +0200
Subject: [PATCH 5/5] use display_{width,height} for cropping instead of
width,height
Use display_width and display_height to do the cropping if there are
part of the caps. Also always set the cropping.
Signed-off-by: Fabien Parent <fparent@baylibre.com>
---
sys/v4l2/gstv4l2object.c | 14 +++++++++-----
sys/v4l2/gstv4l2object.h | 2 +-
sys/v4l2/gstv4l2transform.c | 4 ++--
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index 886372789536..0fefbfb38686 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -4640,10 +4640,11 @@ gst_v4l2_object_poll (GstV4l2Object * v4l2object, gint timeout)
}
gboolean
-gst_v4l2_object_set_crop (GstV4l2Object * obj)
+gst_v4l2_object_set_crop (GstV4l2Object * obj, GstCaps * caps)
{
struct v4l2_selection sel = { 0 };
struct v4l2_crop crop = { 0 };
+ GstStructure *st;
sel.type = obj->type;
sel.target = V4L2_SEL_TGT_CROP;
@@ -4656,10 +4657,13 @@ gst_v4l2_object_set_crop (GstV4l2Object * obj)
crop.type = obj->type;
crop.c = sel.r;
- if (obj->align.padding_left + obj->align.padding_top +
- obj->align.padding_right + obj->align.padding_bottom == 0) {
- GST_DEBUG_OBJECT (obj->dbg_obj, "no cropping needed");
- return TRUE;
+ st = gst_caps_get_structure (caps, 0);
+ if (gst_structure_has_field (st, "display_width")) {
+ gst_structure_get_int(st, "display_width", &crop.c.width);
+ }
+
+ if (gst_structure_has_field (st, "display_height")) {
+ gst_structure_get_int(st, "display_height", &crop.c.height);
}
GST_DEBUG_OBJECT (obj->dbg_obj,
diff --git a/sys/v4l2/gstv4l2object.h b/sys/v4l2/gstv4l2object.h
index 92f22a74cac0..4462fdeba644 100644
--- a/sys/v4l2/gstv4l2object.h
+++ b/sys/v4l2/gstv4l2object.h
@@ -303,7 +303,7 @@ GstCaps * gst_v4l2_object_get_caps (GstV4l2Object * v4l2object, GstCaps *
gboolean gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info);
-gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj);
+gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj, GstCaps * caps);
gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object, GstQuery * query);
diff --git a/sys/v4l2/gstv4l2transform.c b/sys/v4l2/gstv4l2transform.c
index a9294e233b5b..b8990632a60d 100644
--- a/sys/v4l2/gstv4l2transform.c
+++ b/sys/v4l2/gstv4l2transform.c
@@ -220,10 +220,10 @@ gst_v4l2_transform_set_caps (GstBaseTransform * trans, GstCaps * incaps,
goto outcaps_failed;
/* FIXME implement fallback if crop not supported */
- if (!gst_v4l2_object_set_crop (self->v4l2output))
+ if (!gst_v4l2_object_set_crop (self->v4l2output, outcaps))
goto failed;
- if (!gst_v4l2_object_set_crop (self->v4l2capture))
+ if (!gst_v4l2_object_set_crop (self->v4l2capture, incaps))
goto failed;
return TRUE;
--
2.28.0