all: Use new navigation interface and API

Use and implement the new navigation interface in all relevant sink elements,
and use API functions everywhere instead of directy accessing the event structure.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1633>
This commit is contained in:
Vivienne Watermeier 2022-02-14 16:08:23 +01:00 committed by GStreamer Marge Bot
parent f402b2e180
commit 6c2f6c3bd4
34 changed files with 477 additions and 519 deletions

View file

@ -605,8 +605,8 @@ gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
default:
GST_DEBUG_OBJECT (dfbvideosink, "key press event %c !",
event.input.key_symbol);
gst_navigation_send_key_event (GST_NAVIGATION (dfbvideosink),
"key-press", "prout");
gst_dfbvideosink_navigation_send_event
(gst_navigation_event_new_key_press ("prout"));
}
} else if (event.input.type == DIET_BUTTONPRESS) {
gint x, y;
@ -616,8 +616,9 @@ gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
GST_DEBUG_OBJECT (dfbvideosink, "button %d pressed at %dx%d",
event.input.button, x, y);
gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
"mouse-button-press", event.input.button, x, y);
gst_dfbvideosink_navigation_send_event
(gst_navigation_event_new_mouse_button_press (event.input.button,
x, y));
} else if (event.input.type == DIET_BUTTONRELEASE) {
gint x, y;
@ -626,14 +627,15 @@ gst_dfbvideosink_event_thread (GstDfbVideoSink * dfbvideosink)
GST_DEBUG_OBJECT (dfbvideosink, "button %d released at %dx%d",
event.input.button, x, y);
gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
"mouse-button-release", event.input.button, x, y);
gst_dfbvideosink_navigation_send_event
(gst_navigation_event_new_mouse_button_release
(event.input.button, x, y));
} else if (event.input.type == DIET_AXISMOTION) {
gint x, y;
dfbvideosink->layer->GetCursorPosition (dfbvideosink->layer, &x, &y);
gst_navigation_send_mouse_event (GST_NAVIGATION (dfbvideosink),
"mouse-move", 0, x, y);
gst_dfbvideosink_navigation_send_event
(gst_navigation_event_new_mouse_move (x, y));
} else {
GST_WARNING_OBJECT (dfbvideosink, "unhandled event type %d",
event.input.type);
@ -1983,10 +1985,9 @@ beach:
static void
gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstDfbVideoSink *dfbvideosink = GST_DFBVIDEOSINK (navigation);
GstEvent *event;
GstVideoRectangle dst = { 0, };
GstVideoRectangle src = { 0, };
GstVideoRectangle result;
@ -1999,13 +2000,15 @@ gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
dst.h = dfbvideosink->out_height;
gst_video_sink_center_rect (src, dst, &result, dfbvideosink->hw_scaling);
event = gst_event_new_navigation (structure);
event = gst_event_make_writable (event);
/* Our coordinates can be wrong here if we centered the video */
/* Converting pointer coordinates to the non scaled geometry */
if (gst_structure_get_double (structure, "pointer_x", &old_x)) {
if gst_navigation_event_get_coordinates
(event, &old_x, &old_y) {
x = old_x;
y = old_y;
if (x >= result.x && x <= (result.x + result.w)) {
x -= result.x;
@ -2014,13 +2017,6 @@ gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
} else {
x = 0;
}
GST_DEBUG_OBJECT (dfbvideosink, "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)) {
y = old_y;
if (y >= result.y && y <= (result.y + result.h)) {
y -= result.y;
y *= dfbvideosink->video_height;
@ -2028,14 +2024,17 @@ gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
} else {
y = 0;
}
GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event x "
"coordinate from %f to %f", old_x, x);
GST_DEBUG_OBJECT (dfbvideosink, "translated navigation event y "
"coordinate from %fd to %fd", old_y, y);
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
}
gst_navigation_event_set_coordinates (event, x, y);
}
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
if (GST_IS_PAD (pad)) {
if (!gst_pad_send_event (pad, gst_event_ref (event))) {
/* If upstream didn't handle the event we'll post a message with it
* for the application in case it wants to do something with it */
@ -2051,7 +2050,7 @@ gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
static void
gst_dfbvideosink_navigation_init (GstNavigationInterface * iface)
{
iface->send_event = gst_dfbvideosink_navigation_send_event;
iface->send_event_simple = gst_dfbvideosink_navigation_send_event;
}
static void

View file

@ -122,7 +122,7 @@ static CascadeClassifier *gst_handdetect_load_profile (GstHanddetect * filter,
static void gst_handdetect_navigation_interface_init (GstNavigationInterface *
iface);
static void gst_handdetect_navigation_send_event (GstNavigation * navigation,
GstStructure * structure);
GstEvent * event);
G_DEFINE_TYPE_WITH_CODE (GstHanddetect, gst_handdetect,
GST_TYPE_OPENCV_VIDEO_FILTER,
@ -136,7 +136,7 @@ GST_ELEMENT_REGISTER_DEFINE (handdetect, "handdetect", GST_RANK_NONE,
static void
gst_handdetect_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_handdetect_navigation_send_event;
iface->send_event_simple = gst_handdetect_navigation_send_event;
}
/* FIXME: this function used to parse the region of interests coordinates
@ -146,14 +146,12 @@ gst_handdetect_navigation_interface_init (GstNavigationInterface * iface)
*/
static void
gst_handdetect_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstHanddetect *filter = GST_HANDDETECT (navigation);
GstPad *peer;
if ((peer = gst_pad_get_peer (GST_BASE_TRANSFORM_CAST (filter)->sinkpad))) {
GstEvent *event;
event = gst_event_new_navigation (structure);
gst_pad_send_event (peer, event);
gst_object_unref (peer);
}
@ -481,11 +479,10 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform,
* !!! this will CHANGE in the future !!!
* !!! by adding gst_navigation_send_hand_detect_event() in navigation.c !!!
*/
gst_navigation_send_mouse_event (GST_NAVIGATION (filter),
"mouse-move",
0,
(double) (filter->best_r->x + filter->best_r->width * 0.5),
(double) (filter->best_r->y + filter->best_r->height * 0.5));
gst_handdetect_navigation_send_event (GST_NAVIGATION (filter),
gst_navigation_event_new_mouse_move (
(double) (filter->best_r->x + filter->best_r->width * 0.5),
(double) (filter->best_r->y + filter->best_r->height * 0.5)));
#endif
}
@ -571,11 +568,10 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform,
* !!! this will CHANGE in the future !!!
* !!! by adding gst_navigation_send_hand_detect_event() in navigation.c !!!
*/
gst_navigation_send_mouse_event (GST_NAVIGATION (filter),
"mouse-move",
0,
(double) (filter->best_r->x + filter->best_r->width * 0.5),
(double) (filter->best_r->y + filter->best_r->height * 0.5));
gst_handdetect_navigation_send_event (GST_NAVIGATION (filter),
gst_navigation_event_new_mouse_move (
(double) (filter->best_r->x + filter->best_r->width * 0.5),
(double) (filter->best_r->y + filter->best_r->height * 0.5)));
/* or use another way to send upstream navigation event for debug
*

View file

@ -632,69 +632,79 @@ _display_size_to_stream_size (GstVulkanSink * vk_sink,
static void
gst_vulkan_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstVulkanSink *vk_sink = GST_VULKAN_SINK (navigation);
GstVideoRectangle display_rect;
GstEvent *event = NULL;
gboolean handled;
gdouble x, y;
if (!vk_sink->swapper || !vk_sink->swapper->window) {
gst_structure_free (structure);
gst_event_unref (event);
return;
}
event = gst_event_make_writable (event);
gst_vulkan_swapper_get_surface_rectangles (vk_sink->swapper, NULL, NULL,
&display_rect);
/* Converting pointer coordinates to the non scaled geometry */
if (display_rect.w != 0 && display_rect.h != 0
&& gst_structure_get_double (structure, "pointer_x", &x)
&& gst_structure_get_double (structure, "pointer_y", &y)) {
&& gst_navigation_event_get_coordinates (event, &x, &y)) {
gdouble stream_x, stream_y;
_display_size_to_stream_size (vk_sink, &display_rect, x, y, &stream_x,
&stream_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
stream_x, "pointer_y", G_TYPE_DOUBLE, stream_y, NULL);
gst_navigation_event_set_coordinates (event, stream_x, stream_y);
}
event = gst_event_new_navigation (structure);
if (event) {
gboolean handled;
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (vk_sink), event);
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (vk_sink), event);
if (!handled)
gst_element_post_message ((GstElement *) vk_sink,
gst_navigation_message_new_event ((GstObject *) vk_sink, event));
if (!handled)
gst_element_post_message ((GstElement *) vk_sink,
gst_navigation_message_new_event ((GstObject *) vk_sink, event));
gst_event_unref (event);
}
gst_event_unref (event);
}
static void
gst_vulkan_sink_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_vulkan_sink_navigation_send_event;
iface->send_event_simple = gst_vulkan_sink_navigation_send_event;
}
static void
gst_vulkan_sink_key_event_cb (GstVulkanWindow * window, char *event_name, char
*key_string, GstVulkanSink * vk_sink)
{
GstEvent *event = NULL;
GST_DEBUG_OBJECT (vk_sink, "event %s key %s pressed", event_name, key_string);
gst_navigation_send_key_event (GST_NAVIGATION (vk_sink),
event_name, key_string);
if (0 == g_strcmp0 ("key-press", event_name))
event = gst_navigation_event_new_key_press (key_string);
else if (0 == g_strcmp0 ("key-release", event_name))
event = gst_navigation_event_new_key_release (key_string);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (vk_sink), event);
}
static void
gst_vulkan_sink_mouse_event_cb (GstVulkanWindow * window, char *event_name,
int button, double posx, double posy, GstVulkanSink * vk_sink)
{
GstEvent *event = NULL;
GST_DEBUG_OBJECT (vk_sink, "event %s at %g, %g", event_name, posx, posy);
gst_navigation_send_mouse_event (GST_NAVIGATION (vk_sink),
event_name, button, posx, posy);
if (0 == g_strcmp0 ("mouse-button-press", event_name))
event = gst_navigation_event_new_mouse_button_press (button, posx, posy);
else if (0 == g_strcmp0 ("mouse-button-release", event_name))
event = gst_navigation_event_new_mouse_button_release (button, posx, posy);
else if (0 == g_strcmp0 ("mouse-move", event_name))
event = gst_navigation_event_new_mouse_move (posx, posy);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (vk_sink), event);
}

View file

@ -551,11 +551,7 @@ gst_rfb_src_event (GstBaseSrc * bsrc, GstEvent * event)
GstRfbSrc *src = GST_RFB_SRC (bsrc);
gdouble x, y;
gint button;
const GstStructure *structure;
const gchar *event_type;
gboolean key_event, key_press;
key_event = FALSE;
GstNavigationEventType event_type;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:
@ -564,55 +560,62 @@ gst_rfb_src_event (GstBaseSrc * bsrc, GstEvent * event)
if (src->view_only)
break;
structure = gst_event_get_structure (event);
event_type = gst_structure_get_string (structure, "event");
if (strcmp (event_type, "key-press") == 0) {
key_event = key_press = TRUE;
} else if (strcmp (event_type, "key-release") == 0) {
key_event = TRUE;
key_press = FALSE;
}
if (key_event) {
event_type = gst_navigation_event_get_type (event);
switch (event_type) {
#ifdef HAVE_X11
const gchar *key;
KeySym key_sym;
case GST_NAVIGATION_EVENT_KEY_PRESS:
case GST_NAVIGATION_EVENT_KEY_RELEASE:{
const gchar *key;
KeySym key_sym;
key = gst_structure_get_string (structure, "key");
key_sym = XStringToKeysym (key);
gst_navigation_event_parse_key_event (event, &key);
key_sym = XStringToKeysym (key);
if (key_sym != NoSymbol)
rfb_decoder_send_key_event (src->decoder, key_sym, key_press);
if (key_sym != NoSymbol)
rfb_decoder_send_key_event (src->decoder, key_sym,
event_type == GST_NAVIGATION_EVENT_KEY_PRESS);
break;
}
#endif
break;
}
gst_structure_get_double (structure, "pointer_x", &x);
gst_structure_get_double (structure, "pointer_y", &y);
gst_structure_get_int (structure, "button", &button);
/* we need to take care of the offset's */
x += src->decoder->offset_x;
y += src->decoder->offset_y;
if (strcmp (event_type, "mouse-move") == 0) {
GST_LOG_OBJECT (src, "sending mouse-move event "
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
} else if (strcmp (event_type, "mouse-button-release") == 0) {
src->button_mask &= ~(1 << (button - 1));
GST_LOG_OBJECT (src, "sending mouse-button-release event "
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
} else if (strcmp (event_type, "mouse-button-press") == 0) {
src->button_mask |= (1 << (button - 1));
GST_LOG_OBJECT (src, "sending mouse-button-press event "
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:{
gst_navigation_event_parse_mouse_button_event (event,
&button, &x, &y);
x += src->decoder->offset_x;
y += src->decoder->offset_y;
src->button_mask |= (1 << (button - 1));
GST_LOG_OBJECT (src, "sending mouse-button-press event "
"button_mask=%d, x=%d, y=%d",
src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
break;
}
case GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE:{
gst_navigation_event_parse_mouse_button_event (event,
&button, &x, &y);
x += src->decoder->offset_x;
y += src->decoder->offset_y;
src->button_mask &= ~(1 << (button - 1));
GST_LOG_OBJECT (src, "sending mouse-button-release event "
"button_mask=%d, x=%d, y=%d",
src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
break;
}
case GST_NAVIGATION_EVENT_MOUSE_MOVE:{
gst_navigation_event_parse_mouse_move_event (event, &x, &y);
x += src->decoder->offset_x;
y += src->decoder->offset_y;
GST_LOG_OBJECT (src, "sending mouse-move event "
"button_mask=%d, x=%d, y=%d",
src->button_mask, (gint) x, (gint) y);
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
(gint) x, (gint) y);
break;
}
default:
break;
}
break;
default:

View file

@ -687,9 +687,17 @@ static void
gst_d3d11_video_sink_key_event (GstD3D11Window * window, const gchar * event,
const gchar * key, GstD3D11VideoSink * self)
{
GstEvent *key_event = NULL;
if (self->enable_navigation_events) {
GST_LOG_OBJECT (self, "send key event %s, key %s", event, key);
gst_navigation_send_key_event (GST_NAVIGATION (self), event, key);
if (0 == g_strcmp0 ("key-press", event))
key_event = gst_navigation_event_new_key_press (key);
else if (0 == g_strcmp0 ("key-release", event))
key_event = gst_navigation_event_new_key_release (key);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (self), key_event);
}
}
@ -697,11 +705,20 @@ static void
gst_d3d11_video_mouse_key_event (GstD3D11Window * window, const gchar * event,
gint button, gdouble x, gdouble y, GstD3D11VideoSink * self)
{
GstEvent *mouse_event = NULL;
if (self->enable_navigation_events) {
GST_LOG_OBJECT (self,
"send mouse event %s, button %d (%.1f, %.1f)", event, button, x, y);
gst_navigation_send_mouse_event (GST_NAVIGATION (self), event, button, x,
y);
if (0 == g_strcmp0 ("mouse-button-press", event))
mouse_event = gst_navigation_event_new_mouse_button_press (button, x, y);
else if (0 == g_strcmp0 ("mouse-button-release", event))
mouse_event = gst_navigation_event_new_mouse_button_release (button, x, y);
else if (0 == g_strcmp0 ("mouse-move", event))
mouse_event = gst_navigation_event_new_mouse_move (x, y);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (self), mouse_event);
}
}
@ -1330,10 +1347,9 @@ gst_d3d11_video_sink_video_overlay_init (GstVideoOverlayInterface * iface)
/* Navigation interface */
static void
gst_d3d11_video_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstD3D11VideoSink *self = GST_D3D11_VIDEO_SINK (navigation);
GstEvent *event = gst_event_new_navigation (structure);
/* TODO: add support for translating native coordinate and video coordinate
* when force-aspect-ratio is set */
@ -1354,7 +1370,7 @@ gst_d3d11_video_sink_navigation_send_event (GstNavigation * navigation,
static void
gst_d3d11_video_sink_navigation_init (GstNavigationInterface * iface)
{
iface->send_event = gst_d3d11_video_sink_navigation_send_event;
iface->send_event_simple = gst_d3d11_video_sink_navigation_send_event;
}
static gboolean

View file

@ -2140,11 +2140,11 @@ d3d_wnd_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
gchar *utfrep = g_utf16_to_utf8 (wcrep, 128, NULL, NULL, NULL);
if (utfrep) {
if (message == WM_KEYDOWN)
gst_navigation_send_key_event (GST_NAVIGATION (sink), "key-press",
utfrep);
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_key_press (utfrep));
else if (message == WM_KEYUP)
gst_navigation_send_key_event (GST_NAVIGATION (sink),
"key-release", utfrep);
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_key_release (utfrep));
g_free (utfrep);
}
}
@ -2161,45 +2161,38 @@ d3d_wnd_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (sink->enable_navigation_events
&& d3d_get_render_coordinates (sink, LOWORD (lParam), HIWORD (lParam),
&x, &y)) {
gint button;
const gchar *action = NULL;
switch (message) {
case WM_MOUSEMOVE:
button = 0;
action = "mouse-move";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_move (x, y));
break;
case WM_LBUTTONDOWN:
button = 1;
action = "mouse-button-press";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_press (1, x, y));
break;
case WM_LBUTTONUP:
button = 1;
action = "mouse-button-release";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_release (1, x, y));
break;
case WM_RBUTTONDOWN:
button = 2;
action = "mouse-button-press";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_press (2, x, y));
break;
case WM_RBUTTONUP:
button = 2;
action = "mouse-button-release";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_release (2, x, y));
break;
case WM_MBUTTONDOWN:
button = 3;
action = "mouse-button-press";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_press (3, x, y));
break;
case WM_MBUTTONUP:
button = 3;
action = "mouse-button-release";
gst_navigation_send_event_simple (GST_NAVIGATION (sink),
gst_navigation_event_new_mouse_button_release (3, x, y));
break;
default:
break;
}
if (action) {
/* GST_DEBUG_OBJECT(sink, "%s: %lfx%lf", action, x, y); */
gst_navigation_send_mouse_event (GST_NAVIGATION (sink), action,
button, x, y);
}
}
break;
}

View file

@ -70,7 +70,7 @@ static void gst_d3dvideosink_expose (GstVideoOverlay * overlay);
static void gst_d3dvideosink_navigation_interface_init (GstNavigationInterface *
iface);
static void gst_d3dvideosink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure);
GstEvent * event);
/* GObject */
static void gst_d3dvideosink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@ -580,7 +580,7 @@ gst_d3dvideosink_video_overlay_interface_init (GstVideoOverlayInterface * iface)
static void
gst_d3dvideosink_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_d3dvideosink_navigation_send_event;
iface->send_event_simple = gst_d3dvideosink_navigation_send_event;
}
/* Video Render Code */
@ -622,23 +622,19 @@ gst_d3dvideosink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
static void
gst_d3dvideosink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstD3DVideoSink *sink = GST_D3DVIDEOSINK (navigation);
GstEvent *e;
if ((e = gst_event_new_navigation (structure))) {
GstPad *pad;
if ((pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink)))) {
if (!gst_pad_send_event (pad, gst_event_ref (e))) {
/* If upstream didn't handle the event we'll post a message with it
* for the application in case it wants to do something with it */
gst_element_post_message (GST_ELEMENT_CAST (sink),
gst_navigation_message_new_event (GST_OBJECT_CAST (sink), e));
}
gst_event_unref (e);
gst_object_unref (pad);
GstPad *pad;
if ((pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink)))) {
if (!gst_pad_send_event (pad, gst_event_ref (event))) {
/* If upstream didn't handle the event we'll post a message with it
* for the application in case it wants to do something with it */
gst_element_post_message (GST_ELEMENT_CAST (sink),
gst_navigation_message_new_event (GST_OBJECT_CAST (sink), event));
}
gst_object_unref (pad);
}
}

View file

@ -155,14 +155,11 @@ gst_dshowvideosink_videooverlay_init (GstVideoOverlayInterface * iface)
static void
gst_dshowvideosink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstDshowVideoSink *sink = GST_DSHOWVIDEOSINK (navigation);
GstEvent *event = NULL;
GstPad *pad = NULL;
event = gst_event_new_navigation (structure);
/* FXIME: handle aspect ratio. */
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));
@ -178,10 +175,9 @@ static void
gst_dshowvideosink_navigation_interface_init (GstNavigationInterface * iface)
{
/* FIXME: navigation interface partially implemented.
* Need to call gst_navigation_send_mouse_event and
* gst_navigation_send_key_event like in directdrawsink.
* Need to call gst_navigation_send_event_simple and like in directdrawsink.
*/
iface->send_event = gst_dshowvideosink_navigation_send_event;
iface->send_event_simple = gst_dshowvideosink_navigation_send_event;
}
static void

View file

@ -1885,7 +1885,6 @@ gst_va_vpp_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVaVpp *self = GST_VA_VPP (trans);
GstVaBaseTransform *btrans = GST_VA_BASE_TRANSFORM (trans);
GstStructure *structure;
const GstVideoInfo *in_info = &btrans->in_info, *out_info = &btrans->out_info;
gdouble new_x = 0, new_y = 0, x = 0, y = 0, w_factor = 1, h_factor = 1;
gboolean ret;
@ -1899,12 +1898,9 @@ gst_va_vpp_src_event (GstBaseTransform * trans, GstEvent * event)
|| gst_va_filter_get_orientation (btrans->filter) !=
GST_VIDEO_ORIENTATION_IDENTITY) {
event =
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
event = gst_event_make_writable (event);
structure = (GstStructure *) gst_event_get_structure (event);
if (!gst_structure_get_double (structure, "pointer_x", &x)
|| !gst_structure_get_double (structure, "pointer_y", &y))
if (!gst_navigation_event_get_coordinates (event, &x, &y))
break;
/* video-direction compensation */
@ -1952,8 +1948,7 @@ gst_va_vpp_src_event (GstBaseTransform * trans, GstEvent * event)
/* crop compensation is done by videocrop */
GST_TRACE_OBJECT (self, "from %fx%f to %fx%f", x, y, new_x, new_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
gst_navigation_event_set_coordinates (event, new_x, new_y);
}
break;
default:

View file

@ -35,6 +35,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <gst/check/gstcheck.h>
#include <gst/video/navigation.h>
#include <string.h>
#ifndef HAVE_PIPE2
@ -2988,32 +2989,29 @@ navigation_probe_source (GstPad * pad, GstPadProbeInfo * info,
{
test_data *td = user_data;
navigation_master_data *d = td->md;
const GstStructure *s;
const gchar *string, *key;
GstEvent *e;
const gchar *key;
double x, y;
if (GST_IS_EVENT (info->data)) {
if (GST_EVENT_TYPE (info->data) == GST_EVENT_NAVIGATION) {
s = gst_event_get_structure (info->data);
FAIL_UNLESS (s);
e = GST_EVENT (info->data);
/* mouse-move */
string = gst_structure_get_string (s, "event");
if (string && !strcmp (string, "mouse-move")) {
if (gst_structure_get_double (s, "pointer_x", &x) && x == 4.7) {
if (gst_structure_get_double (s, "pointer_y", &y) && y == 0.1) {
switch (gst_navigation_event_get_type (e)) {
case GST_NAVIGATION_EVENT_MOUSE_MOVE:
gst_navigation_event_parse_mouse_move_event (e, &x, &y);
if (x == 4.7 && y == 0.1)
d->navigation_received[TEST_NAV_MOUSE_MOVE] = TRUE;
}
}
}
break;
/* key-press */
string = gst_structure_get_string (s, "event");
if (string && !strcmp (string, "key-press")) {
key = gst_structure_get_string (s, "key");
if (key && !strcmp (key, "Left")) {
d->navigation_received[TEST_NAV_KEY_PRESS] = TRUE;
}
case GST_NAVIGATION_EVENT_KEY_PRESS:
gst_navigation_event_parse_key_event (e, &key);
if (!strcmp (key, "Left"))
d->navigation_received[TEST_NAV_KEY_PRESS] = TRUE;
break;
default:
break;
}
/* drop at this point to imply successful handling; the upstream filesrc
@ -3067,7 +3065,6 @@ send_navigation_event (const GValue * v, gpointer user_data)
navigation_slave_data *d = td->sd;
GstElement *sink;
GstPad *pad, *peer;
GstStructure *s;
GstEvent *e = NULL;
sink = g_value_get_object (v);
@ -3080,15 +3077,10 @@ send_navigation_event (const GValue * v, gpointer user_data)
switch (d->step) {
case TEST_NAV_MOUSE_MOVE:
s = gst_structure_new ("application/x-gst-navigation", "event",
G_TYPE_STRING, "mouse-move", "button", G_TYPE_INT, 0, "pointer_x",
G_TYPE_DOUBLE, 4.7, "pointer_y", G_TYPE_DOUBLE, 0.1, NULL);
e = gst_event_new_navigation (s);
e = gst_navigation_event_new_mouse_move (4.7, 0.1);
break;
case TEST_NAV_KEY_PRESS:
s = gst_structure_new ("application/x-gst-navigation", "event",
G_TYPE_STRING, "key-press", "key", G_TYPE_STRING, "Left", NULL);
e = gst_event_new_navigation (s);
e = gst_navigation_event_new_key_press ("Left");
break;
}

View file

@ -595,21 +595,22 @@ gst_glimage_sink_set_rotate_method (GstGLImageSink * gl_sink,
}
static void
gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
* structure)
gst_glimage_sink_navigation_send_event (GstNavigation * navigation,
GstEvent * event)
{
GstGLImageSink *sink = GST_GLIMAGE_SINK (navigation);
gboolean handled = FALSE;
GstEvent *event = NULL;
GstGLWindow *window;
guint width, height;
gdouble x, y;
if (!sink->context) {
gst_structure_free (structure);
gst_event_unref (event);
return;
}
event = gst_event_make_writable (event);
window = gst_gl_context_get_window (sink->context);
g_return_if_fail (GST_IS_GL_WINDOW (window));
@ -618,47 +619,43 @@ gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
gst_gl_window_get_surface_dimensions (window, &width, &height);
/* Converting pointer coordinates to the non scaled geometry */
if (width != 0 && gst_structure_get_double (structure, "pointer_x", &x)
&& height != 0 && gst_structure_get_double (structure, "pointer_y", &y)) {
if (width != 0 && height != 0 &&
gst_navigation_event_get_coordinates (event, &x, &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,
stream_x, "pointer_y", G_TYPE_DOUBLE, stream_y, NULL);
gst_navigation_event_set_coordinates (event, stream_x, stream_y);
}
/* Converting pointer scroll coordinates to the non scaled geometry */
if (width != 0 && gst_structure_get_double (structure, "delta_pointer_x", &x)
&& height != 0
&& gst_structure_get_double (structure, "delta_pointer_y", &y)) {
gdouble stream_x, stream_y;
if (width != 0 && height != 0 && gst_navigation_event_get_type (event)
== GST_NAVIGATION_EVENT_MOUSE_SCROLL) {
gdouble dx, dy, stream_dx, stream_dy;
_display_scroll_value_to_stream_scroll_value (sink, x, y, &stream_x,
&stream_y);
gst_navigation_event_parse_mouse_scroll_event (event, &x, &y, &dx, &dy);
_display_scroll_value_to_stream_scroll_value (sink, dx, dy, &stream_dx,
&stream_dy);
gst_structure_set (structure, "delta_pointer_x", G_TYPE_DOUBLE,
stream_x, "delta_pointer_y", G_TYPE_DOUBLE, stream_y, NULL);
gst_event_replace (&event,
gst_navigation_event_new_mouse_scroll (x, y, stream_dx, stream_dy));
}
event = gst_event_new_navigation (structure);
if (event) {
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (sink), event);
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (sink), event);
if (!handled)
gst_element_post_message ((GstElement *) sink,
gst_navigation_message_new_event ((GstObject *) sink, event));
if (!handled)
gst_element_post_message ((GstElement *) sink,
gst_navigation_message_new_event ((GstObject *) sink, event));
gst_event_unref (event);
}
gst_event_unref (event);
gst_object_unref (window);
}
static void
gst_glimage_sink_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_glimage_sink_navigation_send_event;
iface->send_event_simple = gst_glimage_sink_navigation_send_event;
}
#define gst_glimage_sink_parent_class parent_class
@ -946,18 +943,34 @@ static void
gst_glimage_sink_key_event_cb (GstGLWindow * window, char *event_name, char
*key_string, GstGLImageSink * gl_sink)
{
GstEvent *event = NULL;
GST_DEBUG_OBJECT (gl_sink, "event %s key %s pressed", event_name, key_string);
gst_navigation_send_key_event (GST_NAVIGATION (gl_sink),
event_name, key_string);
if (0 == g_strcmp0 ("key-press", event_name))
event = gst_navigation_event_new_key_press (key_string);
else if (0 == g_strcmp0 ("key-release", event_name))
event = gst_navigation_event_new_key_release (key_string);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (gl_sink), event);
}
static void
gst_glimage_sink_mouse_event_cb (GstGLWindow * window, char *event_name,
int button, double posx, double posy, GstGLImageSink * gl_sink)
{
GstEvent *event = NULL;
GST_DEBUG_OBJECT (gl_sink, "event %s at %g, %g", event_name, posx, posy);
gst_navigation_send_mouse_event (GST_NAVIGATION (gl_sink),
event_name, button, posx, posy);
if (0 == g_strcmp0 ("mouse-button-press", event_name))
event = gst_navigation_event_new_mouse_button_press (button, posx, posy);
else if (0 == g_strcmp0 ("mouse-button-release", event_name))
event = gst_navigation_event_new_mouse_button_release (button, posx, posy);
else if (0 == g_strcmp0 ("mouse-move", event_name))
event = gst_navigation_event_new_mouse_move (posx, posy);
if (event)
gst_navigation_send_event_simple (GST_NAVIGATION (gl_sink), event);
}
@ -967,8 +980,8 @@ gst_glimage_sink_mouse_scroll_event_cb (GstGLWindow * window,
GstGLImageSink * gl_sink)
{
GST_DEBUG_OBJECT (gl_sink, "event scroll at %g, %g", posx, posy);
gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (gl_sink),
posx, posy, delta_x, delta_y);
gst_navigation_send_event_simple (GST_NAVIGATION (gl_sink),
gst_navigation_event_new_mouse_scroll (posx, posy, delta_x, delta_y));
}
static void

View file

@ -447,20 +447,17 @@ gst_gl_sink_bin_change_state (GstElement * element, GstStateChange transition)
}
static void
gst_gl_sink_bin_navigation_send_event (GstNavigation * navigation, GstStructure
* structure)
gst_gl_sink_bin_navigation_send_event (GstNavigation * navigation,
GstEvent * event)
{
GstGLSinkBin *self = GST_GL_SINK_BIN (navigation);
GstElement *nav =
gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_NAVIGATION);
if (nav) {
gst_navigation_send_event (GST_NAVIGATION (nav), structure);
structure = NULL;
gst_navigation_send_event_simple (GST_NAVIGATION (nav), event);
gst_object_unref (nav);
} else {
GstEvent *event = gst_event_new_navigation (structure);
structure = NULL;
gst_element_send_event (GST_ELEMENT (self), event);
}
}
@ -470,7 +467,7 @@ gst_gl_sink_bin_navigation_interface_init (gpointer g_iface,
gpointer g_iface_data)
{
GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
iface->send_event = gst_gl_sink_bin_navigation_send_event;
iface->send_event_simple = gst_gl_sink_bin_navigation_send_event;
}
static void

View file

@ -658,7 +658,6 @@ static gboolean
gst_gl_transformation_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstGLTransformation *transformation = GST_GL_TRANSFORMATION (trans);
GstStructure *structure;
gboolean ret;
GST_DEBUG_OBJECT (trans, "handling %s event", GST_EVENT_TYPE_NAME (event));
@ -666,12 +665,9 @@ gst_gl_transformation_src_event (GstBaseTransform * trans, GstEvent * event)
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:{
gdouble x, y;
event =
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
event = gst_event_make_writable (event);
structure = (GstStructure *) gst_event_get_structure (event);
if (gst_structure_get_double (structure, "pointer_x", &x) &&
gst_structure_get_double (structure, "pointer_y", &y)) {
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
gdouble new_x, new_y;
if (!_screen_coord_to_model_coord (transformation, x, y, &new_x,
@ -680,8 +676,7 @@ gst_gl_transformation_src_event (GstBaseTransform * trans, GstEvent * event)
return TRUE;
}
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
gst_navigation_event_set_coordinates (event, x, y);
}
break;
}

View file

@ -6041,11 +6041,11 @@ gst_play_bin_overlay_init (gpointer g_iface, gpointer g_iface_data)
static void
gst_play_bin_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstPlayBin *playbin = GST_PLAY_BIN (navigation);
gst_navigation_send_event (GST_NAVIGATION (playbin->playsink), structure);
gst_navigation_send_event_simple (GST_NAVIGATION (playbin->playsink), event);
}
static void
@ -6053,7 +6053,7 @@ gst_play_bin_navigation_init (gpointer g_iface, gpointer g_iface_data)
{
GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
iface->send_event = gst_play_bin_navigation_send_event;
iface->send_event_simple = gst_play_bin_navigation_send_event;
}
static const GList *

View file

@ -5149,11 +5149,11 @@ gst_play_bin3_overlay_init (gpointer g_iface, gpointer g_iface_data)
static void
gst_play_bin3_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstPlayBin3 *playbin = GST_PLAY_BIN3 (navigation);
gst_navigation_send_event (GST_NAVIGATION (playbin->playsink), structure);
gst_navigation_send_event_simple (GST_NAVIGATION (playbin->playsink), event);
}
static void
@ -5161,7 +5161,7 @@ gst_play_bin3_navigation_init (gpointer g_iface, gpointer g_iface_data)
{
GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
iface->send_event = gst_play_bin3_navigation_send_event;
iface->send_event_simple = gst_play_bin3_navigation_send_event;
}
static const GList *

View file

@ -5437,7 +5437,7 @@ gst_play_sink_overlay_init (gpointer g_iface, gpointer g_iface_data)
static void
gst_play_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstPlaySink *playsink = GST_PLAY_SINK (navigation);
GstBin *bin = NULL;
@ -5451,20 +5451,14 @@ gst_play_sink_navigation_send_event (GstNavigation * navigation,
GstElement *nav = gst_bin_get_by_interface (bin, GST_TYPE_NAVIGATION);
if (nav) {
gst_navigation_send_event (GST_NAVIGATION (nav), structure);
structure = NULL;
gst_navigation_send_event_simple (GST_NAVIGATION (nav), event);
gst_object_unref (nav);
} else {
GstEvent *event = gst_event_new_navigation (structure);
structure = NULL;
gst_element_send_event (GST_ELEMENT (bin), event);
}
gst_object_unref (bin);
}
if (structure)
gst_structure_free (structure);
}
static void
@ -5472,7 +5466,7 @@ gst_play_sink_navigation_init (gpointer g_iface, gpointer g_iface_data)
{
GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
iface->send_event = gst_play_sink_navigation_send_event;
iface->send_event_simple = gst_play_sink_navigation_send_event;
}
static const GList *

View file

@ -1193,8 +1193,7 @@ gst_video_scale_src_event (GstBaseTransform * trans, GstEvent * event)
GstVideoScale *videoscale = GST_VIDEO_SCALE_CAST (trans);
GstVideoFilter *filter = GST_VIDEO_FILTER_CAST (trans);
gboolean ret;
gdouble a;
GstStructure *structure;
gdouble x, y;
GST_DEBUG_OBJECT (videoscale, "handling %s event",
GST_EVENT_TYPE_NAME (event));
@ -1203,17 +1202,12 @@ gst_video_scale_src_event (GstBaseTransform * trans, GstEvent * event)
case GST_EVENT_NAVIGATION:
if (filter->in_info.width != filter->out_info.width ||
filter->in_info.height != filter->out_info.height) {
event =
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
event = gst_event_make_writable (event);
structure = (GstStructure *) gst_event_get_structure (event);
if (gst_structure_get_double (structure, "pointer_x", &a)) {
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
a * filter->in_info.width / filter->out_info.width, NULL);
}
if (gst_structure_get_double (structure, "pointer_y", &a)) {
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
a * filter->in_info.height / filter->out_info.height, NULL);
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
gst_navigation_event_set_coordinates (event,
x * filter->in_info.width / filter->out_info.width,
y * filter->in_info.height / filter->out_info.height);
}
}
break;

View file

@ -610,8 +610,8 @@ gst_x_image_sink_handle_xevents (GstXImageSink * ximagesink)
GST_DEBUG ("ximagesink pointer moved over window at %d,%d",
pointer_x, pointer_y);
gst_navigation_send_mouse_event (GST_NAVIGATION (ximagesink),
"mouse-move", 0, pointer_x, pointer_y);
gst_navigation_send_event_simple (GST_NAVIGATION (ximagesink),
gst_navigation_event_new_mouse_move (pointer_x, pointer_y));
g_mutex_lock (&ximagesink->flow_lock);
g_mutex_lock (&ximagesink->x_lock);
@ -635,14 +635,16 @@ gst_x_image_sink_handle_xevents (GstXImageSink * ximagesink)
events for interactivity/navigation */
GST_DEBUG ("ximagesink button %d pressed over window at %d,%d",
e.xbutton.button, e.xbutton.x, e.xbutton.x);
gst_navigation_send_mouse_event (GST_NAVIGATION (ximagesink),
"mouse-button-press", e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_event_simple (GST_NAVIGATION (ximagesink),
gst_navigation_event_new_mouse_button_press (e.xbutton.button,
e.xbutton.x, e.xbutton.y));
break;
case ButtonRelease:
GST_DEBUG ("ximagesink button %d release over window at %d,%d",
e.xbutton.button, e.xbutton.x, e.xbutton.x);
gst_navigation_send_mouse_event (GST_NAVIGATION (ximagesink),
"mouse-button-release", e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_event_simple (GST_NAVIGATION (ximagesink),
gst_navigation_event_new_mouse_button_release (e.xbutton.button,
e.xbutton.x, e.xbutton.y));
break;
case KeyPress:
case KeyRelease:
@ -665,8 +667,10 @@ gst_x_image_sink_handle_xevents (GstXImageSink * ximagesink)
GST_DEBUG_OBJECT (ximagesink,
"key %d pressed over window at %d,%d (%s)",
e.xkey.keycode, e.xkey.x, e.xkey.y, key_str);
gst_navigation_send_key_event (GST_NAVIGATION (ximagesink),
e.type == KeyPress ? "key-press" : "key-release", key_str);
gst_navigation_send_event_simple (GST_NAVIGATION (ximagesink),
(e.type == KeyPress) ?
gst_navigation_event_new_key_press (key_str) :
gst_navigation_event_new_key_release (key_str));
break;
default:
GST_DEBUG_OBJECT (ximagesink, "ximagesink unhandled X event (%d)",
@ -1550,10 +1554,9 @@ no_pool:
/* Interfaces stuff */
static void
gst_x_image_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstXImageSink *ximagesink = GST_X_IMAGE_SINK (navigation);
GstEvent *event = NULL;
gint x_offset, y_offset;
gdouble x, y;
gboolean handled = FALSE;
@ -1569,42 +1572,37 @@ gst_x_image_sink_navigation_send_event (GstNavigation * navigation,
if (!ximagesink->xwindow) {
g_mutex_unlock (&ximagesink->flow_lock);
gst_structure_free (structure);
gst_event_unref (event);
return;
}
event = gst_event_make_writable (event);
x_offset = ximagesink->xwindow->width - GST_VIDEO_SINK_WIDTH (ximagesink);
y_offset = ximagesink->xwindow->height - GST_VIDEO_SINK_HEIGHT (ximagesink);
g_mutex_unlock (&ximagesink->flow_lock);
if (x_offset > 0 && gst_structure_get_double (structure, "pointer_x", &x)) {
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
x -= x_offset / 2;
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
}
if (y_offset > 0 && gst_structure_get_double (structure, "pointer_y", &y)) {
y -= y_offset / 2;
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
gst_navigation_event_set_coordinates (event, x, y);
}
event = gst_event_new_navigation (structure);
if (event) {
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (ximagesink), event);
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (ximagesink), event);
if (!handled)
gst_element_post_message (GST_ELEMENT_CAST (ximagesink),
gst_navigation_message_new_event (GST_OBJECT_CAST (ximagesink),
event));
if (!handled)
gst_element_post_message (GST_ELEMENT_CAST (ximagesink),
gst_navigation_message_new_event (GST_OBJECT_CAST (ximagesink), event));
gst_event_unref (event);
}
gst_event_unref (event);
}
static void
gst_x_image_sink_navigation_init (GstNavigationInterface * iface)
{
iface->send_event = gst_x_image_sink_navigation_send_event;
iface->send_event_simple = gst_x_image_sink_navigation_send_event;
}
static void

View file

@ -453,8 +453,8 @@ gst_xv_image_sink_handle_xevents (GstXvImageSink * xvimagesink)
GST_DEBUG ("xvimagesink pointer moved over window at %d,%d",
pointer_x, pointer_y);
gst_navigation_send_mouse_event (GST_NAVIGATION (xvimagesink),
"mouse-move", 0, e.xbutton.x, e.xbutton.y);
gst_navigation_send_event_simple (GST_NAVIGATION (xvimagesink),
gst_navigation_event_new_mouse_move (e.xbutton.x, e.xbutton.y));
g_mutex_lock (&xvimagesink->flow_lock);
g_mutex_lock (&xvimagesink->context->lock);
@ -478,16 +478,18 @@ gst_xv_image_sink_handle_xevents (GstXvImageSink * xvimagesink)
events for interactivity/navigation */
GST_DEBUG ("xvimagesink button %d pressed over window at %d,%d",
e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_mouse_event (GST_NAVIGATION (xvimagesink),
"mouse-button-press", e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_event_simple (GST_NAVIGATION (xvimagesink),
gst_navigation_event_new_mouse_button_press (e.xbutton.button,
e.xbutton.x, e.xbutton.y));
break;
case ButtonRelease:
/* Mouse button released over our window. We send upstream
events for interactivity/navigation */
GST_DEBUG ("xvimagesink button %d released over window at %d,%d",
e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_mouse_event (GST_NAVIGATION (xvimagesink),
"mouse-button-release", e.xbutton.button, e.xbutton.x, e.xbutton.y);
gst_navigation_send_event_simple (GST_NAVIGATION (xvimagesink),
gst_navigation_event_new_mouse_button_release (e.xbutton.button,
e.xbutton.x, e.xbutton.y));
break;
case KeyPress:
case KeyRelease:
@ -510,8 +512,10 @@ gst_xv_image_sink_handle_xevents (GstXvImageSink * xvimagesink)
GST_DEBUG_OBJECT (xvimagesink,
"key %d pressed over window at %d,%d (%s)",
e.xkey.keycode, e.xkey.x, e.xkey.y, key_str);
gst_navigation_send_key_event (GST_NAVIGATION (xvimagesink),
e.type == KeyPress ? "key-press" : "key-release", key_str);
gst_navigation_send_event_simple (GST_NAVIGATION (xvimagesink),
(e.type == KeyPress) ?
gst_navigation_event_new_key_press (key_str) :
gst_navigation_event_new_key_release (key_str));
break;
default:
GST_DEBUG_OBJECT (xvimagesink, "xvimagesink unhandled X event (%d)",
@ -1147,11 +1151,10 @@ no_pool:
/* Interfaces stuff */
static void
gst_xv_image_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstXvImageSink *xvimagesink = GST_XV_IMAGE_SINK (navigation);
gboolean handled = FALSE;
GstEvent *event = NULL;
GstVideoRectangle src = { 0, };
GstVideoRectangle dst = { 0, };
@ -1164,7 +1167,7 @@ gst_xv_image_sink_navigation_send_event (GstNavigation * navigation,
if (!(xwindow = xvimagesink->xwindow)) {
g_mutex_unlock (&xvimagesink->flow_lock);
gst_structure_free (structure);
gst_event_unref (event);
return;
}
@ -1190,37 +1193,31 @@ gst_xv_image_sink_navigation_send_event (GstNavigation * navigation,
xscale = (gdouble) xvimagesink->video_width / result.w;
yscale = (gdouble) xvimagesink->video_height / result.h;
event = gst_event_make_writable (event);
/* Converting pointer coordinates to the non scaled geometry */
if (gst_structure_get_double (structure, "pointer_x", &x)) {
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
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);
gst_navigation_event_set_coordinates (event, x * xscale, y * yscale);
}
event = gst_event_new_navigation (structure);
if (event) {
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (xvimagesink), event);
gst_event_ref (event);
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (xvimagesink), event);
if (!handled)
gst_element_post_message ((GstElement *) xvimagesink,
gst_navigation_message_new_event ((GstObject *) xvimagesink, event));
if (!handled)
gst_element_post_message ((GstElement *) xvimagesink,
gst_navigation_message_new_event ((GstObject *) xvimagesink, event));
gst_event_unref (event);
}
gst_event_unref (event);
}
static void
gst_xv_image_sink_navigation_init (GstNavigationInterface * iface)
{
iface->send_event = gst_xv_image_sink_navigation_send_event;
iface->send_event_simple = gst_xv_image_sink_navigation_send_event;
}
static void

View file

@ -55,8 +55,7 @@ struct TestElementClass
GType test_element_get_type (void);
static void init_interface (GType type);
static void nav_send_event (GstNavigation * navigation,
GstStructure * structure);
static void nav_send_event (GstNavigation * navigation, GstEvent * event);
G_DEFINE_TYPE_WITH_CODE (TestElement, test_element, GST_TYPE_ELEMENT,
init_interface (g_define_type_id));
@ -64,7 +63,7 @@ G_DEFINE_TYPE_WITH_CODE (TestElement, test_element, GST_TYPE_ELEMENT,
static void
test_element_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = nav_send_event;
iface->send_event_simple = nav_send_event;
}
static void
@ -91,9 +90,8 @@ test_element_init (TestElement * this)
}
static void
nav_send_event (GstNavigation * navigation, GstStructure * structure)
nav_send_event (GstNavigation * navigation, GstEvent * event)
{
GstEvent *event = gst_event_new_navigation (structure);
GstNavigationEventType etype = gst_navigation_event_get_type (event);
TestElement *self = (TestElement *) (navigation);
@ -171,17 +169,23 @@ GST_START_TEST (test_events)
test_element->sent_key = "1";
gst_navigation_send_key_event (GST_NAVIGATION (test_element), "key-press",
"1");
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_key_press ("1"));
test_element->sent_type = GST_NAVIGATION_EVENT_KEY_RELEASE;
test_element->sent_key = "2";
gst_navigation_send_key_event (GST_NAVIGATION (test_element), "key-release",
"2");
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_key_release ("2"));
test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_MOVE;
test_element->sent_x = 50;
test_element->sent_y = 100;
gst_navigation_send_mouse_event (GST_NAVIGATION (test_element), "mouse-move",
0, 50, 100);
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_mouse_move (50, 100));
test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_SCROLL;
test_element->sent_x = 60;
@ -190,6 +194,8 @@ GST_START_TEST (test_events)
test_element->sent_delta_y = 3;
gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (test_element),
60, 120, 2, 3);
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_mouse_scroll (60, 120, 2, 3));
test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS;
test_element->sent_x = 10;
@ -197,11 +203,15 @@ GST_START_TEST (test_events)
test_element->sent_button = 1;
gst_navigation_send_mouse_event (GST_NAVIGATION (test_element),
"mouse-button-press", 1, 10, 20);
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_mouse_button_press (1, 10, 20));
for (i = 0; i < G_N_ELEMENTS (cmds); i++) {
test_element->sent_type = GST_NAVIGATION_EVENT_COMMAND;
test_element->sent_command = cmds[i];
gst_navigation_send_command (GST_NAVIGATION (test_element), cmds[i]);
gst_navigation_send_event_simple (GST_NAVIGATION (test_element),
gst_navigation_event_new_command (cmds[i]));
}
gst_object_unref (test_element);

View file

@ -2175,7 +2175,8 @@ navigation_cmd_cb (GtkButton * button, PlaybackApp * app)
}
if (cmd != GST_NAVIGATION_COMMAND_INVALID)
gst_navigation_send_command (GST_NAVIGATION (app->navigation_element), cmd);
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_command (cmd));
}
#if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
@ -2271,8 +2272,9 @@ button_press_cb (GtkWidget * widget, GdkEventButton * event, PlaybackApp * app)
gtk_widget_grab_focus (widget);
if (app->navigation_element)
gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
"mouse-button-press", event->button, event->x, event->y);
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_mouse_button_press (event->button, event->x,
event->y));
return FALSE;
}
@ -2282,8 +2284,9 @@ button_release_cb (GtkWidget * widget, GdkEventButton * event,
PlaybackApp * app)
{
if (app->navigation_element)
gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
"mouse-button-release", event->button, event->x, event->y);
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_mouse_button_release (event->button, event->x,
event->y));
return FALSE;
}
@ -2292,8 +2295,8 @@ static gboolean
key_press_cb (GtkWidget * widget, GdkEventKey * event, PlaybackApp * app)
{
if (app->navigation_element)
gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
"key-press", gdk_keyval_name (event->keyval));
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_key_press (gdk_keyval_name (event->keyval)));
return FALSE;
}
@ -2302,8 +2305,8 @@ static gboolean
key_release_cb (GtkWidget * widget, GdkEventKey * event, PlaybackApp * app)
{
if (app->navigation_element)
gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
"key-release", gdk_keyval_name (event->keyval));
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_key_release (gdk_keyval_name (event->keyval)));
return FALSE;
}
@ -2312,8 +2315,8 @@ static gboolean
motion_notify_cb (GtkWidget * widget, GdkEventMotion * event, PlaybackApp * app)
{
if (app->navigation_element)
gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
"mouse-move", 0, event->x, event->y);
gst_navigation_send_event_simple (GST_NAVIGATION (app->navigation_element),
gst_navigation_event_new_mouse_move (event->x, event->y));
return FALSE;
}

View file

@ -319,15 +319,15 @@ gst_gtk_base_sink_set_property (GObject * object, guint prop_id,
static void
gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstGtkBaseSink *sink = GST_GTK_BASE_SINK (navigation);
GstEvent *event;
GstPad *pad;
gdouble x, y;
if (gst_structure_get_double (structure, "pointer_x", &x) &&
gst_structure_get_double (structure, "pointer_y", &y)) {
event = gst_event_make_writable (event);
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
GtkGstBaseWidget *widget = gst_gtk_base_sink_get_widget (sink);
gdouble stream_x, stream_y;
@ -338,15 +338,13 @@ gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
gtk_gst_base_widget_display_size_to_stream_size (widget,
x, y, &stream_x, &stream_y);
gst_structure_set (structure,
"pointer_x", G_TYPE_DOUBLE, (gdouble) stream_x,
"pointer_y", G_TYPE_DOUBLE, (gdouble) stream_y, NULL);
gst_navigation_event_set_coordinates (event, stream_x, stream_y);
}
event = gst_event_new_navigation (structure);
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));
GST_TRACE_OBJECT (sink, "navigation event %" GST_PTR_FORMAT, structure);
GST_TRACE_OBJECT (sink, "navigation event %" GST_PTR_FORMAT,
gst_event_get_structure (event));
if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
if (!gst_pad_send_event (pad, gst_event_ref (event))) {
@ -363,7 +361,7 @@ gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
static void
gst_gtk_base_sink_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_gtk_base_sink_navigation_send_event;
iface->send_event_simple = gst_gtk_base_sink_navigation_send_event;
}
static gboolean

View file

@ -290,13 +290,14 @@ gtk_gst_base_widget_key_event (GtkWidget * widget, GdkEventKey * event)
if ((element = g_weak_ref_get (&base_widget->element))) {
if (GST_IS_NAVIGATION (element)) {
const gchar *str = _gdk_key_to_navigation_string (event->keyval);
const gchar *key_type =
event->type == GDK_KEY_PRESS ? "key-press" : "key-release";
if (!str)
str = event->string;
gst_navigation_send_key_event (GST_NAVIGATION (element), key_type, str);
gst_navigation_send_event_simple (GST_NAVIGATION (element),
(event->type == GDK_KEY_PRESS) ?
gst_navigation_event_new_key_press (str) :
gst_navigation_event_new_key_release (str));
}
g_object_unref (element);
}
@ -378,11 +379,12 @@ gtk_gst_base_widget_button_event (GtkWidget * widget, GdkEventButton * event)
if ((element = g_weak_ref_get (&base_widget->element))) {
if (GST_IS_NAVIGATION (element)) {
const gchar *key_type =
event->type ==
GDK_BUTTON_PRESS ? "mouse-button-press" : "mouse-button-release";
gst_navigation_send_mouse_event (GST_NAVIGATION (element), key_type,
event->button, event->x, event->y);
gst_navigation_send_event_simple (GST_NAVIGATION (element),
(event->type == GDK_BUTTON_PRESS) ?
gst_navigation_event_new_mouse_button_press (event->button,
event->x, event->y) :
gst_navigation_event_new_mouse_button_release (event->button,
event->x, event->y));
}
g_object_unref (element);
}
@ -398,8 +400,8 @@ gtk_gst_base_widget_motion_event (GtkWidget * widget, GdkEventMotion * event)
if ((element = g_weak_ref_get (&base_widget->element))) {
if (GST_IS_NAVIGATION (element)) {
gst_navigation_send_mouse_event (GST_NAVIGATION (element), "mouse-move",
0, event->x, event->y);
gst_navigation_send_event_simple (GST_NAVIGATION (element),
gst_navigation_event_new_mouse_move (event->x, event->y));
}
g_object_unref (element);
}
@ -443,8 +445,8 @@ gtk_gst_base_widget_scroll_event (GtkWidget * widget, GdkEventScroll * event)
break;
}
}
gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (element),
x, y, delta_x, delta_y);
gst_navigation_send_event_simple (GST_NAVIGATION (element),
gst_navigation_event_new_mouse_scroll (x, y, delta_x, delta_y));
}
g_object_unref (element);
}

View file

@ -558,16 +558,15 @@ config_failed:
static void
gst_qt_sink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstQtSink *qt_sink = GST_QT_SINK (navigation);
GstEvent *event;
GstPad *pad;
event = gst_event_new_navigation (structure);
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (qt_sink));
GST_TRACE_OBJECT (qt_sink, "navigation event %" GST_PTR_FORMAT, structure);
GST_TRACE_OBJECT (qt_sink, "navigation event %" GST_PTR_FORMAT,
gst_event_get_structure(event));
if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
if (!gst_pad_send_event (pad, gst_event_ref (event))) {
@ -583,5 +582,5 @@ gst_qt_sink_navigation_send_event (GstNavigation * navigation,
static void gst_qt_sink_navigation_interface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_qt_sink_navigation_send_event;
iface->send_event_simple = gst_qt_sink_navigation_send_event;
}

View file

@ -437,8 +437,9 @@ QtGLVideoItem::wheelEvent(QWheelEvent * event)
#else
auto position = *event;
#endif
gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (element),
position.x(), position.y(), delta.x(), delta.y());
gst_navigation_send_event_simple (GST_NAVIGATION (element),
gst_navigation_event_new_mouse_scroll (position.x(), position.y(),
delta.x(), delta.y()));
g_object_unref (element);
}
g_mutex_unlock (&this->priv->lock);
@ -462,8 +463,6 @@ QtGLVideoItem::hoverMoveEvent(QHoverEvent * event)
if (!mouseHovering)
return;
quint32 button = !!mousePressedButton;
g_mutex_lock (&this->priv->lock);
/* can't do anything when we don't have input format */
@ -477,8 +476,8 @@ QtGLVideoItem::hoverMoveEvent(QHoverEvent * event)
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
if (element != NULL) {
gst_navigation_send_mouse_event (GST_NAVIGATION (element), "mouse-move",
button, pos.x(), pos.y());
gst_navigation_send_event_simple (GST_NAVIGATION (element),
gst_navigation_event_new_mouse_move (pos.x(), pos.y()));
g_object_unref (element);
}
}
@ -486,7 +485,7 @@ QtGLVideoItem::hoverMoveEvent(QHoverEvent * event)
}
void
QtGLVideoItem::sendMouseEvent(QMouseEvent * event, const gchar * type)
QtGLVideoItem::sendMouseEvent(QMouseEvent * event, gboolean is_press)
{
quint32 button = 0;
@ -512,16 +511,17 @@ QtGLVideoItem::sendMouseEvent(QMouseEvent * event, const gchar * type)
}
QPointF pos = mapPointToStreamSize(event->pos());
gchar* event_type = g_strconcat ("mouse-button-", type, NULL);
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
if (element != NULL) {
gst_navigation_send_mouse_event (GST_NAVIGATION (element), event_type,
button, pos.x(), pos.y());
gst_navigation_send_event_simple (GST_NAVIGATION (element),
(is_press) ? gst_navigation_event_new_mouse_button_press (button,
pos.x(), pos.y()) :
gst_navigation_event_new_mouse_button_release (button, pos.x(),
pos.y()));
g_object_unref (element);
}
g_free (event_type);
g_mutex_unlock (&this->priv->lock);
}
@ -529,13 +529,13 @@ void
QtGLVideoItem::mousePressEvent(QMouseEvent * event)
{
forceActiveFocus();
sendMouseEvent(event, "press");
sendMouseEvent(event, TRUE);
}
void
QtGLVideoItem::mouseReleaseEvent(QMouseEvent * event)
{
sendMouseEvent(event, "release");
sendMouseEvent(event, FALSE);
}
void

View file

@ -112,7 +112,7 @@ private:
void fitStreamToAllocatedSize(GstVideoRectangle * result);
QPointF mapPointToStreamSize(QPointF);
void sendMouseEvent(QMouseEvent * event, const gchar * type);
void sendMouseEvent(QMouseEvent * event, gboolean is_press);
quint32 mousePressedButton;
bool mouseHovering;

View file

@ -59,7 +59,7 @@ gst_navigationtest_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVideoInfo *info;
GstNavigationtest *navtest;
const gchar *type;
GstNavigationEventType type;
navtest = GST_NAVIGATIONTEST (trans);
@ -68,38 +68,44 @@ gst_navigationtest_src_event (GstBaseTransform * trans, GstEvent * event)
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:
{
const GstStructure *s = gst_event_get_structure (event);
gint fps_n, fps_d;
fps_n = GST_VIDEO_INFO_FPS_N (info);
fps_d = GST_VIDEO_INFO_FPS_D (info);
type = gst_structure_get_string (s, "event");
if (g_str_equal (type, "mouse-move")) {
gst_structure_get_double (s, "pointer_x", &navtest->x);
gst_structure_get_double (s, "pointer_y", &navtest->y);
} else if (g_str_equal (type, "mouse-button-press")) {
ButtonClick *click = g_new (ButtonClick, 1);
type = gst_navigation_event_get_type (event);
switch (type) {
case GST_NAVIGATION_EVENT_MOUSE_MOVE:{
gst_navigation_event_get_coordinates (event, &navtest->x,
&navtest->y);
break;
}
case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:{
ButtonClick *click = g_new (ButtonClick, 1);
gst_structure_get_double (s, "pointer_x", &click->x);
gst_structure_get_double (s, "pointer_y", &click->y);
click->images_left = (fps_n + fps_d - 1) / fps_d;
/* green */
click->cy = 150;
click->cu = 46;
click->cv = 21;
navtest->clicks = g_slist_prepend (navtest->clicks, click);
} else if (g_str_equal (type, "mouse-button-release")) {
ButtonClick *click = g_new (ButtonClick, 1);
gst_navigation_event_get_coordinates (event, &click->x, &click->y);
click->images_left = (fps_n + fps_d - 1) / fps_d;
/* green */
click->cy = 150;
click->cu = 46;
click->cv = 21;
navtest->clicks = g_slist_prepend (navtest->clicks, click);
break;
}
case GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE:{
ButtonClick *click = g_new (ButtonClick, 1);
gst_structure_get_double (s, "pointer_x", &click->x);
gst_structure_get_double (s, "pointer_y", &click->y);
click->images_left = (fps_n + fps_d - 1) / fps_d;
/* red */
click->cy = 76;
click->cu = 85;
click->cv = 255;
navtest->clicks = g_slist_prepend (navtest->clicks, click);
gst_navigation_event_get_coordinates (event, &click->x, &click->y);
click->images_left = (fps_n + fps_d - 1) / fps_d;
/* red */
click->cy = 76;
click->cu = 85;
click->cv = 255;
navtest->clicks = g_slist_prepend (navtest->clicks, click);
break;
}
default:
break;
}
break;
}

View file

@ -29,6 +29,7 @@
#include "gstdebugutilselements.h"
#include "gstnavseek.h"
#include <gst/video/navigation.h>
#include <string.h>
#include <math.h>
@ -252,19 +253,11 @@ gst_navseek_src_event (GstBaseTransform * trans, GstEvent * event)
case GST_EVENT_NAVIGATION:
{
/* Check for a keyup and convert left/right to a seek event */
const GstStructure *structure;
const gchar *event_type;
structure = gst_event_get_structure (event);
g_return_val_if_fail (structure != NULL, FALSE);
event_type = gst_structure_get_string (structure, "event");
g_return_val_if_fail (event_type != NULL, FALSE);
if (strcmp (event_type, "key-press") == 0) {
if (gst_navigation_event_get_type (event)
== GST_NAVIGATION_EVENT_KEY_PRESS) {
const gchar *key;
key = gst_structure_get_string (structure, "key");
gst_navigation_event_parse_key_event (event, &key);
g_return_val_if_fail (key != NULL, FALSE);
if (strcmp (key, "Left") == 0) {

View file

@ -3187,41 +3187,28 @@ static gboolean
gst_video_box_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVideoBox *video_box = GST_VIDEO_BOX (trans);
GstStructure *new_structure;
const GstStructure *structure;
const gchar *event_name;
GstNavigationEventType type;
gdouble pointer_x;
gdouble pointer_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)) {
structure = gst_event_get_structure (event);
event_name = gst_structure_get_string (structure, "event");
(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;
if (event_name &&
(strcmp (event_name, "mouse-move") == 0 ||
strcmp (event_name, "mouse-button-press") == 0 ||
strcmp (event_name, "mouse-button-release") == 0)) {
if (gst_structure_get_double (structure, "pointer_x", &pointer_x) &&
gst_structure_get_double (structure, "pointer_y", &pointer_y)) {
gdouble new_pointer_x, new_pointer_y;
GstEvent *new_event;
event = gst_event_make_writable (event);
new_pointer_x = pointer_x + video_box->box_left;
new_pointer_y = pointer_y + video_box->box_top;
new_pointer_x = pointer_x + video_box->box_left;
new_pointer_y = pointer_y + video_box->box_top;
new_structure = gst_structure_copy (structure);
gst_structure_set (new_structure,
"pointer_x", G_TYPE_DOUBLE, (gdouble) (new_pointer_x),
"pointer_y", G_TYPE_DOUBLE, (gdouble) (new_pointer_y), NULL);
new_event = gst_event_new_navigation (new_structure);
gst_event_unref (event);
event = new_event;
} else {
GST_WARNING_OBJECT (video_box, "Failed to read navigation event");
}
gst_navigation_event_set_coordinates (event, new_pointer_x,
new_pointer_y);
} else {
GST_WARNING_OBJECT (video_box, "Failed to read navigation event");
}
}
GST_OBJECT_UNLOCK (video_box);

View file

@ -123,48 +123,31 @@ static GstFlowReturn gst_video_crop_transform_ip (GstBaseTransform * trans,
static gboolean
gst_video_crop_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstEvent *new_event;
GstStructure *new_structure;
const GstStructure *structure;
const gchar *event_name;
GstNavigationEventType type;
double pointer_x;
double pointer_y;
GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
new_event = NULL;
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)) {
structure = gst_event_get_structure (event);
event_name = gst_structure_get_string (structure, "event");
if (event_name &&
(strcmp (event_name, "mouse-move") == 0 ||
strcmp (event_name, "mouse-button-press") == 0 ||
strcmp (event_name, "mouse-button-release") == 0)) {
if (gst_structure_get_double (structure, "pointer_x", &pointer_x) &&
gst_structure_get_double (structure, "pointer_y", &pointer_y)) {
new_structure = gst_structure_copy (structure);
gst_structure_set (new_structure,
"pointer_x", G_TYPE_DOUBLE, (double) (pointer_x + vcrop->crop_left),
"pointer_y", G_TYPE_DOUBLE, (double) (pointer_y + vcrop->crop_top),
NULL);
new_event = gst_event_new_navigation (new_structure);
gst_event_unref (event);
} else {
GST_WARNING_OBJECT (vcrop, "Failed to read navigation event");
}
(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");
}
}
GST_OBJECT_UNLOCK (vcrop);
return GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans,
(new_event ? new_event : event));
return GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);
}
static void

View file

@ -1223,7 +1223,6 @@ gst_video_flip_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVideoFlip *vf = GST_VIDEO_FLIP (trans);
gdouble new_x, new_y, x, y;
GstStructure *structure;
gboolean ret;
GstVideoInfo *out_info = &GST_VIDEO_FILTER (trans)->out_info;
@ -1231,12 +1230,9 @@ gst_video_flip_src_event (GstBaseTransform * trans, GstEvent * event)
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:
event =
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
event = gst_event_make_writable (event);
structure = (GstStructure *) gst_event_get_structure (event);
if (gst_structure_get_double (structure, "pointer_x", &x) &&
gst_structure_get_double (structure, "pointer_y", &y)) {
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
GST_DEBUG_OBJECT (vf, "converting %fx%f", x, y);
GST_OBJECT_LOCK (vf);
switch (vf->active_method) {
@ -1275,8 +1271,7 @@ gst_video_flip_src_event (GstBaseTransform * trans, GstEvent * event)
}
GST_OBJECT_UNLOCK (vf);
GST_DEBUG_OBJECT (vf, "to %fx%f", new_x, new_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
gst_navigation_event_set_coordinates (event, new_x, new_y);
}
break;
default:

View file

@ -1899,20 +1899,16 @@ gst_vaapipostproc_src_event (GstBaseTransform * trans, GstEvent * event)
{
GstVaapiPostproc *const postproc = GST_VAAPIPOSTPROC (trans);
gdouble new_x = 0, new_y = 0, x = 0, y = 0, w_factor = 1, h_factor = 1;
GstStructure *structure;
gboolean ret;
GST_TRACE_OBJECT (postproc, "handling %s event", GST_EVENT_TYPE_NAME (event));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:
event =
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
event = gst_event_make_writable (event);
structure = (GstStructure *) gst_event_get_structure (event);
if (postproc->has_vpp
&& gst_structure_get_double (structure, "pointer_x", &x)
&& gst_structure_get_double (structure, "pointer_y", &y)) {
if (postproc->has_vpp &&
gst_navigation_event_get_coordinates (event, &x, &y)) {
GST_DEBUG_OBJECT (postproc, "converting %fx%f", x, y);
/* video-direction compensation */
@ -1961,8 +1957,7 @@ gst_vaapipostproc_src_event (GstBaseTransform * trans, GstEvent * event)
new_y += postproc->crop_top;
GST_DEBUG_OBJECT (postproc, "to %fx%f", new_x, new_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
gst_navigation_event_set_coordinates (event, new_x, new_y);
}
break;
default:

View file

@ -896,40 +896,34 @@ gst_vaapisink_color_balance_iface_init (GstColorBalanceInterface * iface)
static void
gst_vaapisink_navigation_send_event (GstNavigation * navigation,
GstStructure * structure)
GstEvent * event)
{
GstVaapiSink *const sink = GST_VAAPISINK (navigation);
GstPad *peer;
if (!sink->window) {
gst_structure_free (structure);
gst_event_unref (event);
return;
}
if ((peer = gst_pad_get_peer (GST_VAAPI_PLUGIN_BASE_SINK_PAD (sink)))) {
GstEvent *event;
GstVaapiRectangle *disp_rect = &sink->display_rect;
gdouble x, y, xscale = 1.0, yscale = 1.0;
event = gst_event_new_navigation (structure);
/* We calculate scaling using the original video frames geometry to include
pixel aspect ratio scaling. */
xscale = (gdouble) sink->video_width / disp_rect->width;
yscale = (gdouble) sink->video_height / disp_rect->height;
event = gst_event_make_writable (event);
/* Converting pointer coordinates to the non scaled geometry */
if (gst_structure_get_double (structure, "pointer_x", &x)) {
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
x = MIN (x, disp_rect->x + disp_rect->width);
x = MAX (x - disp_rect->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, disp_rect->y + disp_rect->height);
y = MAX (y - disp_rect->y, 0);
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
(gdouble) y * yscale, NULL);
gst_navigation_event_set_coordinates (event, x * xscale, y * yscale);
}
if (!gst_pad_send_event (peer, gst_event_ref (event))) {
@ -946,7 +940,7 @@ gst_vaapisink_navigation_send_event (GstNavigation * navigation,
static void
gst_vaapisink_navigation_iface_init (GstNavigationInterface * iface)
{
iface->send_event = gst_vaapisink_navigation_send_event;
iface->send_event_simple = gst_vaapisink_navigation_send_event;
}
/* ------------------------------------------------------------------------ */

View file

@ -155,8 +155,7 @@ static void
vpp_test_mouse_events (VppTestContext * ctx,
const VppTestCoordinateParams * const params, const size_t nparams)
{
GstStructure *structure;
GstEvent *event;
GstEvent *event = NULL;
VppTestCoordinate probed = { 0, };
guint i, j;
@ -180,13 +179,23 @@ vpp_test_mouse_events (VppTestContext * ctx,
for (j = 0; j < G_N_ELEMENTS (mouse_events); ++j) {
probed.x = probed.y = -1;
switch (j) {
case 0:
event = gst_navigation_event_new_mouse_move (params[i].send.x,
params[i].send.y);
break;
case 1:
event = gst_navigation_event_new_mouse_button_press (0,
params[i].send.x, params[i].send.y);
break;
case 2:
event = gst_navigation_event_new_mouse_button_release (0,
params[i].send.x, params[i].send.y);
break;
}
GST_LOG ("sending %s event %fx%f", mouse_events[j], params[i].send.x,
params[i].send.y);
structure = gst_structure_new ("application/x-gst-navigation", "event",
G_TYPE_STRING, mouse_events[j],
"pointer_x", G_TYPE_DOUBLE, params[i].send.x,
"pointer_y", G_TYPE_DOUBLE, params[i].send.y, NULL);
event = gst_event_new_navigation (structure);
gst_element_send_event (ctx->pipeline, event);
GST_LOG ("probed %s event %fx%f", mouse_events[j], probed.x, probed.y);