From 8648275601c077c33ec88ef3ae1438c4dafa3e2e Mon Sep 17 00:00:00 2001 From: Vivienne Watermeier Date: Mon, 14 Feb 2022 14:06:12 +0100 Subject: [PATCH] navigation: Improve interface to avoid exposing implementation details This deprecates the current send_event interface, and the wrapper functions based on it, replacing it with a send_event_simple interface and wrapper function. Together with the new event constructors, this avoids implementations having to directly access the underlying structure. Part-of: --- .../gst-docs/symbols/symbol_index.json | 2 + .../gst-libs/gst/video/navigation.c | 43 +++++++++++++++++ .../gst-libs/gst/video/navigation.h | 46 ++++++++++++++----- .../tests/check/libs/struct_aarch64.h | 2 +- .../tests/check/libs/struct_arm.h | 2 +- .../tests/check/libs/struct_i386.h | 2 +- .../tests/check/libs/struct_i386_osx.h | 2 +- .../tests/check/libs/struct_ppc32.h | 2 +- .../tests/check/libs/struct_ppc64.h | 2 +- .../tests/check/libs/struct_x86_64.h | 2 +- 10 files changed, 86 insertions(+), 19 deletions(-) diff --git a/subprojects/gst-docs/symbols/symbol_index.json b/subprojects/gst-docs/symbols/symbol_index.json index 7741aaec80..9230d00de2 100644 --- a/subprojects/gst-docs/symbols/symbol_index.json +++ b/subprojects/gst-docs/symbols/symbol_index.json @@ -12300,6 +12300,8 @@ "GstNavigationInterface.iface", "GstNavigationInterface.send_event", "GstNavigationInterface::send_event", + "GstNavigationInterface.send_event_simple", + "GstNavigationInterface::send_event_simple", "GstNavigationMessageType", "GstNavigationQueryType", "GstNavigationtest", diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c index c2300a4ba9..4cad1de393 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c @@ -64,11 +64,26 @@ G_DEFINE_INTERFACE (GstNavigation, gst_navigation, 0); +static void +gst_navigation_default_send_event_simple (GstNavigation * navigation, + GstEvent * event) +{ + GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation); + + if (iface->send_event) { + iface->send_event (navigation, + gst_structure_copy (gst_event_get_structure (event))); + } else { + gst_event_unref (event); + } +} + static void gst_navigation_default_init (GstNavigationInterface * iface) { /* default virtual functions */ iface->send_event = NULL; + iface->send_event_simple = gst_navigation_default_send_event_simple; } /* The interface implementer should make sure that the object can handle @@ -80,6 +95,8 @@ gst_navigation_send_event (GstNavigation * navigation, GstStructure * structure) if (iface->send_event) { iface->send_event (navigation, structure); + } else if (iface->send_event_simple) { + iface->send_event_simple (navigation, gst_event_new_navigation (structure)); } else { gst_structure_free (structure); } @@ -179,6 +196,32 @@ gst_navigation_send_command (GstNavigation * navigation, "command", "command-code", G_TYPE_UINT, (guint) command, NULL)); } +/** + * gst_navigation_send_event_simple: + * @navigation: The navigation interface instance + * @event: The event to send + * + * Sends an event to the navigation interface. + * Since: 1.22 + */ +void +gst_navigation_send_event_simple (GstNavigation * navigation, GstEvent * event) +{ + GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation); + + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION); + + if (iface->send_event_simple) { + iface->send_event_simple (navigation, event); + } else if (iface->send_event) { + iface->send_event (navigation, + gst_structure_copy (gst_event_get_structure (event))); + gst_event_unref (event); + } else { + gst_event_unref (event); + } +} + /* Navigation Queries */ #define GST_NAVIGATION_QUERY_HAS_TYPE(query,query_type) \ diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h index 79d3ea6e69..a7dd93ed0b 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h @@ -44,6 +44,7 @@ typedef struct _GstNavigationInterface GstNavigationInterface; * GstNavigationInterface: * @iface: the parent interface * @send_event: sending a navigation event + * @send_event_simple: sending a navigation event (Since: 1.22) * * Navigation interface. */ @@ -51,7 +52,24 @@ struct _GstNavigationInterface { GTypeInterface iface; /* virtual functions */ + + /** + * GstNavigationInterface::send_event: + * + * sending a navigation event. + * + * Deprecated: 1.22: Use #GstNavigationInterface.send_event_simple() instead. + */ void (*send_event) (GstNavigation *navigation, GstStructure *structure); + + /** + * GstNavigationInterface::send_event_simple: + * + * sending a navigation event. + * + * Since: 1.22 + */ + void (*send_event_simple) (GstNavigation *navigation, GstEvent *event); }; GST_VIDEO_API @@ -337,25 +355,29 @@ gboolean gst_navigation_event_parse_command (GstEvent *event, /* interface virtual function wrappers */ -GST_VIDEO_API -void gst_navigation_send_event (GstNavigation *navigation, - GstStructure *structure); +GST_VIDEO_DEPRECATED_FOR(gst_navigation_send_event_simple) +void gst_navigation_send_event (GstNavigation *navigation, + GstStructure *structure); -GST_VIDEO_API -void gst_navigation_send_key_event (GstNavigation *navigation, - const char *event, const char *key); +GST_VIDEO_DEPRECATED_FOR(gst_navigation_send_event_simple) +void gst_navigation_send_key_event (GstNavigation *navigation, + const char *event, const char *key); -GST_VIDEO_API -void gst_navigation_send_mouse_event (GstNavigation *navigation, - const char *event, int button, double x, double y); +GST_VIDEO_DEPRECATED_FOR(gst_navigation_send_event_simple) +void gst_navigation_send_mouse_event (GstNavigation *navigation, + const char *event, int button, double x, double y); -GST_VIDEO_API +GST_VIDEO_DEPRECATED_FOR(gst_navigation_send_event_simple) void gst_navigation_send_mouse_scroll_event (GstNavigation *navigation, double x, double y, double delta_x, double delta_y); +GST_VIDEO_DEPRECATED_FOR(gst_navigation_send_event_simple) +void gst_navigation_send_command (GstNavigation *navigation, + GstNavigationCommand command); + GST_VIDEO_API -void gst_navigation_send_command (GstNavigation *navigation, - GstNavigationCommand command); +void gst_navigation_send_event_simple (GstNavigation *navigation, + GstEvent *event); G_END_DECLS diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_aarch64.h b/subprojects/gst-plugins-base/tests/check/libs/struct_aarch64.h index 81828f6da9..f35e9878c4 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_aarch64.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_aarch64.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 24}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 32}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_arm.h b/subprojects/gst-plugins-base/tests/check/libs/struct_arm.h index 107137eeec..61b502dd3b 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_arm.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_arm.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 28}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 36}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_i386.h b/subprojects/gst-plugins-base/tests/check/libs/struct_i386.h index 7a9f7c5333..f0bdf78219 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_i386.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_i386.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 12}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 16}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_i386_osx.h b/subprojects/gst-plugins-base/tests/check/libs/struct_i386_osx.h index 83fcac9786..c81df23c9f 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_i386_osx.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_i386_osx.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 28}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 36}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_ppc32.h b/subprojects/gst-plugins-base/tests/check/libs/struct_ppc32.h index 0e4228249a..567d64e70d 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_ppc32.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_ppc32.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 12}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 16}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_ppc64.h b/subprojects/gst-plugins-base/tests/check/libs/struct_ppc64.h index 7732266566..3c6c09bb1b 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_ppc64.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_ppc64.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 24}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 32}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16}, diff --git a/subprojects/gst-plugins-base/tests/check/libs/struct_x86_64.h b/subprojects/gst-plugins-base/tests/check/libs/struct_x86_64.h index 81828f6da9..f35e9878c4 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/struct_x86_64.h +++ b/subprojects/gst-plugins-base/tests/check/libs/struct_x86_64.h @@ -36,7 +36,7 @@ GstCheckABIStruct list[] = { {"GstFFTF64Complex", sizeof (GstFFTF64Complex), 16}, {"GstFFTS16Complex", sizeof (GstFFTS16Complex), 4}, {"GstFFTS32Complex", sizeof (GstFFTS32Complex), 8}, - {"GstNavigationInterface", sizeof (GstNavigationInterface), 24}, + {"GstNavigationInterface", sizeof (GstNavigationInterface), 32}, {"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_index_entry", sizeof (gst_riff_index_entry), 16},