Skip to content

Commit

Permalink
device provider: add convenience macros to register
Browse files Browse the repository at this point in the history
This macros will help to register a device provider
apart from a given plugin such as in a static build
of gstreamer where libgstreamer-full is generated.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/661>
  • Loading branch information
Stéphane Cerveau committed Dec 10, 2020
1 parent 7828237 commit ff36ce0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
51 changes: 51 additions & 0 deletions gst/gstdeviceprovider.h
Expand Up @@ -26,6 +26,57 @@

#include <gst/gstelement.h>

/**
* GST_DEVICE_PROVIDER_REGISTER_DEFINE:
*
* @d_p: The device provider name in lower case, with words separated by '_'.
* Used to generate `gst_device_provider_register_*(GstPlugin* plugin)`.
* @d_p_n: The public name of the device provider
* @r: The #GstRank of the device provider (higher rank means more importance when autoplugging, see #GstRank)
* @t: The #GType of the device provider.
*
* A convenience macro to define the entry point of a
* device provider `gst_device_provider_register_*(GstPlugin* plugin)`.
*
* Since: 1.20
*/
#define GST_DEVICE_PROVIDER_REGISTER_DEFINE(d_p, d_p_n, r, t) \
G_BEGIN_DECLS \
gboolean G_PASTE (gst_device_provider_register_, d_p) (GstPlugin * plugin) \
{ \
return gst_device_provider_register (plugin, d_p_n, r, t); \
} \
G_END_DECLS

/**
* GST_DEVICE_PROVIDER_REGISTER_DECLARE:
* @d_p: The device provider name in lower case, with words separated by '_'.
*
* This macro can be used to declare a new device provider.
* It has to be used in combination with #GST_DEVICE_PROVIDER_REGISTER_DEFINE macro
* and must be placed outside any block to declare the device provider registration
* function.
*
* Since: 1.20
*/
#define GST_DEVICE_PROVIDER_REGISTER_DECLARE(d_p) \
G_BEGIN_DECLS \
gboolean G_PASTE(gst_device_provider_register_, d_p) (GstPlugin * plugin); \
G_END_DECLS

/**
* GST_DEVICE_PROVIDER_REGISTER:
* @d_p: The device provider name in lower case, with words separated by '_'.
* @plugin: The #GstPlugin where to register the device provider.
*
* This macro can be used to register a device provider into a #GstPlugin.
* This method will be usually called in the plugin init function
* but can also be called with a NULL plugin.
*
* Since: 1.20
*/
#define GST_DEVICE_PROVIDER_REGISTER(d_p, plugin) G_PASTE(gst_device_provider_register_, d_p) (plugin)

G_BEGIN_DECLS

typedef struct _GstDeviceProvider GstDeviceProvider;
Expand Down
10 changes: 7 additions & 3 deletions tests/check/gst/gstdevice.c
Expand Up @@ -174,8 +174,12 @@ gst_test_device_provider_init (GstTestDeviceProvider * self)
{
}

static void
register_test_device_provider (void)
GST_DEVICE_PROVIDER_REGISTER_DECLARE (testdeviceprovider);

GST_DEVICE_PROVIDER_REGISTER_DEFINE (testdeviceprovider, "testdeviceprovider",
1, gst_test_device_provider_get_type ())

static void register_test_device_provider (void)
{
gst_device_provider_register (NULL, "testdeviceprovider", 1,
gst_test_device_provider_get_type ());
Expand All @@ -187,7 +191,7 @@ GST_START_TEST (test_device_provider_factory)
GList *factories;
GstDeviceProviderFactory *f;

register_test_device_provider ();
GST_DEVICE_PROVIDER_REGISTER (testdeviceprovider, NULL);

factories = gst_device_provider_factory_list_get_device_providers (1);

Expand Down

0 comments on commit ff36ce0

Please sign in to comment.