summaryrefslogtreecommitdiff
path: root/ext/gl
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2015-08-12 00:20:10 +0200
committerMatthew Waters <matthew@centricular.com>2015-08-12 00:25:35 +0200
commitb38f107bd3a83a2e6922decdb1f5f1f65abab5f8 (patch)
tree41fadbdb26abfc504580b0c50215c0e335ab423c /ext/gl
parentc867c8505bba9d7be6a2c9990877003df98da92e (diff)
downloadgstreamer-plugins-bad-b38f107bd3a83a2e6922decdb1f5f1f65abab5f8.tar.gz
glimagesink: take into account non 1/1 par for navigation
The current code was ignoring the par/dar aspect when transforming from window coordinates to stream coordinates resulting in incorrect coordinates being sent upstream in the navigation events.
Diffstat (limited to 'ext/gl')
-rw-r--r--ext/gl/gstglimagesink.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c
index 0528ed5c4..5f0e3ade7 100644
--- a/ext/gl/gstglimagesink.c
+++ b/ext/gl/gstglimagesink.c
@@ -360,6 +360,43 @@ enum
static guint gst_glimage_sink_signals[LAST_SIGNAL] = { 0 };
static void
+_display_size_to_stream_size (GstGLImageSink * gl_sink, gdouble x,
+ gdouble y, gdouble * stream_x, gdouble * stream_y)
+{
+ gdouble stream_width, stream_height;
+
+ stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&gl_sink->out_info);
+ stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info);
+
+ /* from display coordinates to stream coordinates */
+ if (gl_sink->display_rect.w > 0)
+ *stream_x =
+ (x - gl_sink->display_rect.x) / gl_sink->display_rect.w * stream_width;
+ else
+ *stream_x = 0.;
+
+ /* clip to stream size */
+ if (*stream_x < 0.)
+ *stream_x = 0.;
+ if (*stream_x > GST_VIDEO_INFO_WIDTH (&gl_sink->out_info))
+ *stream_x = GST_VIDEO_INFO_WIDTH (&gl_sink->out_info);
+
+ /* same for y-axis */
+ if (gl_sink->display_rect.h > 0)
+ *stream_y =
+ (y - gl_sink->display_rect.y) / gl_sink->display_rect.h * stream_height;
+ else
+ *stream_y = 0.;
+
+ if (*stream_y < 0.)
+ *stream_y = 0.;
+ if (*stream_y > GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info))
+ *stream_y = GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info);
+
+ GST_TRACE ("transform %fx%f into %fx%f", x, y, *stream_x, *stream_y);
+}
+
+static void
gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
* structure)
{
@@ -368,7 +405,7 @@ gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
GstPad *pad = NULL;
GstGLWindow *window;
guint width, height;
- gdouble x, y, xscale, yscale;
+ gdouble x, y;
if (!sink->context)
return;
@@ -384,19 +421,15 @@ gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));
/* Converting pointer coordinates to the non scaled geometry */
- if (width != GST_VIDEO_SINK_WIDTH (sink) &&
- width != 0 && gst_structure_get_double (structure, "pointer_x", &x)) {
- xscale = (gdouble) GST_VIDEO_SINK_WIDTH (sink) / width;
+ if (width != 0 && gst_structure_get_double (structure, "pointer_x", &x)
+ && height != 0 && gst_structure_get_double (structure, "pointer_y", &y)) {
+ gdouble stream_x, stream_y;
+
+ _display_size_to_stream_size (sink, x, y, &stream_x, &stream_y);
+
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
- (gdouble) x * xscale, NULL);
+ stream_x, "pointer_y", G_TYPE_DOUBLE, stream_y, NULL);
}
- if (height != GST_VIDEO_SINK_HEIGHT (sink) &&
- height != 0 && gst_structure_get_double (structure, "pointer_y", &y)) {
- yscale = (gdouble) GST_VIDEO_SINK_HEIGHT (sink) / height;
- gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
- (gdouble) y * yscale, NULL);
- }
-
if (GST_IS_PAD (pad) && GST_IS_EVENT (event))
gst_pad_send_event (pad, event);