sys/xvimage/xvimagesink.c: Handle navigation events correcly with borders if applicable.
authorJulien Moutte <julien@moutte.net>
Tue, 22 Nov 2005 10:09:54 +0000 (10:09 +0000)
committerJulien Moutte <julien@moutte.net>
Tue, 22 Nov 2005 10:09:54 +0000 (10:09 +0000)
Original commit message from CVS:
2005-11-22  Julien MOUTTE  <julien@moutte.net>

* sys/xvimage/xvimagesink.c:
(gst_xvimagesink_navigation_send_event): Handle navigation
events correcly with borders if applicable.

ChangeLog
sys/xvimage/xvimagesink.c

index 5ed72c9..458b585 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-22  Julien MOUTTE  <julien@moutte.net>
+
+       * sys/xvimage/xvimagesink.c:
+       (gst_xvimagesink_navigation_send_event): Handle navigation
+       events correcly with borders if applicable.
+
 2005-11-22  Tim-Philipp Müller  <tim at centricular dot net>
 
        * gst/ffmpegcolorspace/gstffmpegcodecmap.c:
index 2a00441..8313bd7 100644 (file)
@@ -1751,22 +1751,47 @@ gst_xvimagesink_navigation_send_event (GstNavigation * navigation,
 
   if ((peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (xvimagesink)))) {
     GstEvent *event;
+    GstVideoRectangle src, dst, result;
     gdouble x, y, xscale = 1.0, yscale = 1.0;
 
-    event = gst_event_new_custom (GST_EVENT_NAVIGATION, structure);
+    event = gst_event_new_navigation (structure);
 
-    if (xvimagesink->xwindow) {
-      xscale = GST_VIDEO_SINK_WIDTH (xvimagesink) / xvimagesink->xwindow->width;
-      yscale =
-          GST_VIDEO_SINK_HEIGHT (xvimagesink) / xvimagesink->xwindow->height;
+    /* We take the flow_lock while we look at the window */
+    g_mutex_lock (xvimagesink->flow_lock);
+
+    if (!xvimagesink->xwindow) {
+      g_mutex_unlock (xvimagesink->flow_lock);
+      return;
+    }
+
+    src.w = GST_VIDEO_SINK_WIDTH (xvimagesink);
+    src.h = GST_VIDEO_SINK_HEIGHT (xvimagesink);
+    dst.w = xvimagesink->xwindow->width;
+    dst.h = xvimagesink->xwindow->height;
+
+    g_mutex_unlock (xvimagesink->flow_lock);
+
+    if (xvimagesink->keep_aspect) {
+      gst_video_sink_center_rect (src, dst, &result, TRUE);
+    } else {
+      result.x = result.y = 0;
+      result.w = dst.w;
+      result.h = dst.h;
     }
 
+    xscale = (gdouble) GST_VIDEO_SINK_WIDTH (xvimagesink) / result.w;
+    yscale = (gdouble) GST_VIDEO_SINK_HEIGHT (xvimagesink) / result.h;
+
     /* Converting pointer coordinates to the non scaled geometry */
     if (gst_structure_get_double (structure, "pointer_x", &x)) {
+      x = MIN (x, result.x + result.w);
+      x = MAX (x - result.x, 0);
       gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
           (gdouble) x * xscale, NULL);
     }
     if (gst_structure_get_double (structure, "pointer_y", &y)) {
+      y = MIN (y, result.y + result.h);
+      y = MAX (y - result.y, 0);
       gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
           (gdouble) y * yscale, NULL);
     }