videocrop, videobox: Simplify navigation event handling and support touch events
authorColin Kinloch <colin.kinloch@collabora.com>
Mon, 10 Oct 2022 18:58:12 +0000 (19:58 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 11 Nov 2022 06:45:49 +0000 (06:45 +0000)
Signed-off-by: Colin Kinloch <colin.kinloch@collabora.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3053>

subprojects/gst-plugins-bad/sys/va/gstvavpp.c
subprojects/gst-plugins-good/gst/videobox/gstvideobox.c
subprojects/gst-plugins-good/gst/videocrop/gstvideocrop.c

index 730bea3..6355216 100644 (file)
@@ -1939,11 +1939,11 @@ gst_va_vpp_src_event (GstBaseTransform * trans, GstEvent * event)
           || gst_va_filter_get_orientation (btrans->filter) !=
           GST_VIDEO_ORIENTATION_IDENTITY) {
 
-        event = gst_event_make_writable (event);
-
         if (!gst_navigation_event_get_coordinates (event, &x, &y))
           break;
 
+        event = gst_event_make_writable (event);
+
         /* video-direction compensation */
         switch (gst_va_filter_get_orientation (btrans->filter)) {
           case GST_VIDEO_ORIENTATION_90R:
index 302e714..5267c91 100644 (file)
@@ -3189,29 +3189,25 @@ static gboolean
 gst_video_box_src_event (GstBaseTransform * trans, GstEvent * event)
 {
   GstVideoBox *video_box = GST_VIDEO_BOX (trans);
-  GstNavigationEventType type;
-  gdouble pointer_x;
-  gdouble pointer_y;
+  gdouble x, y, new_x, new_y;
 
   GST_OBJECT_LOCK (video_box);
-  type = gst_navigation_event_get_type (event);
-  if (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION &&
-      (video_box->box_left != 0 || video_box->box_top != 0) &&
-      (type == GST_NAVIGATION_EVENT_MOUSE_MOVE
-          || type == GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS
-          || type == GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE)) {
-    if (gst_navigation_event_get_coordinates (event, &pointer_x, &pointer_y)) {
-      gdouble new_pointer_x, new_pointer_y;
-
-      event = gst_event_make_writable (event);
-      new_pointer_x = pointer_x + video_box->box_left;
-      new_pointer_y = pointer_y + video_box->box_top;
-
-      gst_navigation_event_set_coordinates (event, new_pointer_x,
-          new_pointer_y);
-    } else {
-      GST_WARNING_OBJECT (video_box, "Failed to read navigation event");
-    }
+
+  switch (GST_EVENT_TYPE (event)) {
+    case GST_EVENT_NAVIGATION:
+      if ((video_box->box_left != 0 || video_box->box_top != 0)
+          && gst_navigation_event_get_coordinates (event, &x, &y)) {
+
+        event = gst_event_make_writable (event);
+        new_x = x + video_box->box_left;
+        new_y = y + video_box->box_top;
+
+        GST_TRACE_OBJECT (video_box, "from %fx%f to %fx%f", x, y, new_x, new_y);
+        gst_navigation_event_set_coordinates (event, new_x, new_y);
+      }
+      break;
+    default:
+      break;
   }
   GST_OBJECT_UNLOCK (video_box);
 
index 9ef4d1e..b87ee96 100644 (file)
@@ -123,26 +123,27 @@ static GstFlowReturn gst_video_crop_transform_ip (GstBaseTransform * trans,
 static gboolean
 gst_video_crop_src_event (GstBaseTransform * trans, GstEvent * event)
 {
-  GstNavigationEventType type;
-  double pointer_x;
-  double pointer_y;
+  double x, y, new_x, new_y;
 
   GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
   GST_OBJECT_LOCK (vcrop);
 
-  type = gst_navigation_event_get_type (event);
-  if (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION &&
-      (vcrop->crop_left != 0 || vcrop->crop_top != 0) &&
-      (type == GST_NAVIGATION_EVENT_MOUSE_MOVE
-          || type == GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS
-          || type == GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE)) {
-    if (gst_navigation_event_get_coordinates (event, &pointer_x, &pointer_y)) {
-      event = gst_event_make_writable (event);
-      gst_navigation_event_set_coordinates (event, pointer_x + vcrop->crop_left,
-          pointer_y + vcrop->crop_top);
-    } else {
-      GST_WARNING_OBJECT (vcrop, "Failed to read navigation event");
-    }
+  switch (GST_EVENT_TYPE (event)) {
+    case GST_EVENT_NAVIGATION:
+      if ((vcrop->crop_left != 0 || vcrop->crop_top != 0)
+          && gst_navigation_event_get_coordinates (event, &x, &y)) {
+
+        new_x = x + vcrop->crop_left;
+        new_y = y + vcrop->crop_top;
+
+        event = gst_event_make_writable (event);
+
+        GST_TRACE_OBJECT (vcrop, "from %fx%f to %fx%f", x, y, new_x, new_y);
+        gst_navigation_event_set_coordinates (event, new_x, new_y);
+      }
+      break;
+    default:
+      break;
   }
 
   GST_OBJECT_UNLOCK (vcrop);