directdrawsink: respect PAR with coordinates

This commit is contained in:
Andoni Morales Alastruey 2013-04-05 17:26:57 +00:00 committed by Sebastian Dröge
parent 3eaa4128cc
commit f4f4a8a0f3

View file

@ -193,47 +193,48 @@ gst_directdraw_sink_navigation_send_event (GstNavigation * navigation,
GstDirectDrawSink *ddrawsink = GST_DIRECTDRAW_SINK (navigation); GstDirectDrawSink *ddrawsink = GST_DIRECTDRAW_SINK (navigation);
GstEvent *event; GstEvent *event;
GstVideoRectangle src, dst, result; GstVideoRectangle src, dst, result;
double x, y, old_x, old_y; gdouble x, y, old_x, old_y, xscale = 1.0, yscale=1.0;
GstPad *pad = NULL; GstPad *pad = NULL;
src.w = GST_VIDEO_SINK_WIDTH (ddrawsink); src.w = GST_VIDEO_SINK_WIDTH (ddrawsink);
src.h = GST_VIDEO_SINK_HEIGHT (ddrawsink); src.h = GST_VIDEO_SINK_HEIGHT (ddrawsink);
dst.w = ddrawsink->out_width; dst.w = ddrawsink->out_width;
dst.h = ddrawsink->out_height; dst.h = ddrawsink->out_height;
gst_video_sink_center_rect (src, dst, &result, FALSE);
event = gst_event_new_navigation (structure); event = gst_event_new_navigation (structure);
/* Our coordinates can be wrong here if we centered the video */ if (ddrawsink->keep_aspect_ratio) {
gst_video_sink_center_rect (src, dst, &result, TRUE);
} else {
result.x = 0;
result.y = 0;
result.w = dst.w;
result.h = dst.h;
}
/* We calculate scaling using the original video frames geometry to include
pixel aspect ratio scaling. */
xscale = (gdouble) ddrawsink->video_width / result.w;
yscale = (gdouble) ddrawsink->video_height / result.h;
/* Converting pointer coordinates to the non scaled geometry */ /* Converting pointer coordinates to the non scaled geometry */
if (gst_structure_get_double (structure, "pointer_x", &old_x)) { if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
x = old_x; x = old_x;
x = MIN (x, result.x + result.w);
if (x >= result.x && x <= (result.x + result.w)) { x = MAX (x - result.x, 0);
x -= result.x; gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
x *= ddrawsink->video_width; (gdouble) x * xscale, NULL);
x /= result.w; GST_DEBUG_OBJECT (ddrawsink,
} else { "translated navigation event x coordinate from %f to %f", old_x, x);
x = 0;
}
GST_DEBUG_OBJECT (ddrawsink, "translated navigation event x "
"coordinate from %f to %f", old_x, x);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
} }
if (gst_structure_get_double (structure, "pointer_y", &old_y)) { if (gst_structure_get_double (structure, "pointer_y", &old_y)) {
y = old_y; y = old_y;
y = MIN (y, result.y + result.h);
if (y >= result.y && y <= (result.y + result.h)) { y = MAX (y - result.y, 0);
y -= result.y; gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
y *= ddrawsink->video_height; (gdouble) y * yscale, NULL);
y /= result.h; GST_DEBUG_OBJECT (ddrawsink,
} else { "translated navigation event x coordinate from %f to %f", old_y, y);
y = 0;
}
GST_DEBUG_OBJECT (ddrawsink, "translated navigation event y "
"coordinate from %f to %f", old_y, y);
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
} }
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (ddrawsink)); pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (ddrawsink));