From 01e2a2152d8650ef676aa6ea016aa46552cb7023 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 2 Apr 2015 16:09:13 +0200 Subject: [PATCH] video: Add a new "event" navigation message type This will be useful for elements that wish to post unhandled navigation events on the bus to give the application a chance to do something with it https://bugzilla.gnome.org/show_bug.cgi?id=747245 --- gst-libs/gst/video/navigation.c | 53 +++++++++++++++++++++++++++++++++ gst-libs/gst/video/navigation.h | 9 +++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/video/navigation.c b/gst-libs/gst/video/navigation.c index c598875913..a034a07276 100644 --- a/gst-libs/gst/video/navigation.c +++ b/gst-libs/gst/video/navigation.c @@ -495,6 +495,8 @@ gst_navigation_message_get_type (GstMessage * message) return GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED; else if (g_str_equal (m_type, "angles-changed")) return GST_NAVIGATION_MESSAGE_ANGLES_CHANGED; + else if (g_str_equal (m_type, "event")) + return GST_NAVIGATION_MESSAGE_EVENT; return GST_NAVIGATION_MESSAGE_INVALID; } @@ -553,6 +555,57 @@ gst_navigation_message_parse_mouse_over (GstMessage * message, return TRUE; } +/** + * gst_navigation_message_new_event: + * @src: A #GstObject to set as source of the new message. + * @event: (transfer none): A navigation #GstEvent + * + * Creates a new #GstNavigation message with type + * #GST_NAVIGATION_MESSAGE_EVENT. + * + * Returns: The new #GstMessage. + */ +GstMessage * +gst_navigation_message_new_event (GstObject * src, GstEvent * event) +{ + GstStructure *s; + GstMessage *m; + + s = gst_structure_new (GST_NAVIGATION_MESSAGE_NAME, + "type", G_TYPE_STRING, "event", "event", GST_TYPE_EVENT, event, NULL); + + m = gst_message_new_custom (GST_MESSAGE_ELEMENT, src, s); + + return m; +} + +/** + * gst_navigation_message_parse_event: + * @message: A #GstMessage to inspect. + * @event: (transfer full): a pointer to a #GstEvent to receive the contained + * navigation event. + * + * Parse a #GstNavigation message of type #GST_NAVIGATION_MESSAGE_EVENT + * and extract contained #GstEvent. The caller must unref the @event when done + * with it. + * + * Returns: %TRUE if the message could be successfully parsed. %FALSE if not. + */ +gboolean +gst_navigation_message_parse_event (GstMessage * message, GstEvent ** event) +{ + if (!GST_NAVIGATION_MESSAGE_HAS_TYPE (message, EVENT)) + return FALSE; + + if (event) { + const GstStructure *s = gst_message_get_structure (message); + if (!gst_structure_get (s, "event", GST_TYPE_EVENT, event, NULL)) + return FALSE; + } + + return TRUE; +} + /** * gst_navigation_message_new_commands_changed: * @src: A #GstObject to set as source of the new message. diff --git a/gst-libs/gst/video/navigation.h b/gst-libs/gst/video/navigation.h index 3630dc3041..4b45bcb585 100644 --- a/gst-libs/gst/video/navigation.h +++ b/gst-libs/gst/video/navigation.h @@ -178,6 +178,8 @@ gboolean gst_navigation_query_parse_angles (GstQuery *query, guint * @GST_NAVIGATION_MESSAGE_ANGLES_CHANGED: Sent when display angles in a multi-angle * feature (such as a multiangle DVD) change - either angles have appeared or * disappeared. + * @GST_NAVIGATION_MESSAGE_EVENT: Sent when a navigation event was not handled + * by any element in the pipeline. * * A set of notifications that may be received on the bus when navigation * related status changes. @@ -186,7 +188,8 @@ typedef enum { GST_NAVIGATION_MESSAGE_INVALID, GST_NAVIGATION_MESSAGE_MOUSE_OVER, GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED, - GST_NAVIGATION_MESSAGE_ANGLES_CHANGED + GST_NAVIGATION_MESSAGE_ANGLES_CHANGED, + GST_NAVIGATION_MESSAGE_EVENT } GstNavigationMessageType; GstNavigationMessageType gst_navigation_message_get_type (GstMessage *message); @@ -205,6 +208,10 @@ gboolean gst_navigation_message_parse_angles_changed (GstMessage *message guint *cur_angle, guint *n_angles); +GstMessage * gst_navigation_message_new_event (GstObject *src, + GstEvent *event); +gboolean gst_navigation_message_parse_event (GstMessage *message, + GstEvent ** event); /* event parsing functions */ /** * GstNavigationEventType: