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>
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index 8863727..0fefbfb 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -4640,10 +4640,11 @@
 }
 
 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 @@
   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 92f22a7..4462fde 100644
--- a/sys/v4l2/gstv4l2object.h
+++ b/sys/v4l2/gstv4l2object.h
@@ -303,7 +303,7 @@
 
 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 a9294e2..b899063 100644
--- a/sys/v4l2/gstv4l2transform.c
+++ b/sys/v4l2/gstv4l2transform.c
@@ -220,10 +220,10 @@
     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;