mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
deviceprovider: reorganize the code a little
This commit is contained in:
parent
3ddbea9874
commit
be762c326c
2 changed files with 324 additions and 347 deletions
|
|
@ -35,24 +35,158 @@
|
||||||
GST_DEBUG_CATEGORY_EXTERN (pinos_debug);
|
GST_DEBUG_CATEGORY_EXTERN (pinos_debug);
|
||||||
#define GST_CAT_DEFAULT pinos_debug
|
#define GST_CAT_DEFAULT pinos_debug
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GstPinosDevice, gst_pinos_device, GST_TYPE_DEVICE);
|
||||||
|
|
||||||
static GstDevice *gst_pinos_device_new (gpointer id, const gchar * device_name,
|
enum
|
||||||
GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type);
|
{
|
||||||
|
PROP_PATH = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static GstDevice *
|
||||||
|
gst_pinos_device_new (gpointer id, const gchar * device_name,
|
||||||
|
GstCaps * caps, const gchar * path, GstPinosDeviceType type)
|
||||||
|
{
|
||||||
|
GstPinosDevice *gstdev;
|
||||||
|
const gchar *element = NULL;
|
||||||
|
const gchar *klass = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (device_name, NULL);
|
||||||
|
g_return_val_if_fail (path, NULL);
|
||||||
|
g_return_val_if_fail (caps, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case GST_PINOS_DEVICE_TYPE_SOURCE:
|
||||||
|
element = "pinossrc";
|
||||||
|
klass = "Video/Source/Pinos";
|
||||||
|
break;
|
||||||
|
case GST_PINOS_DEVICE_TYPE_SINK:
|
||||||
|
element = "pinossink";
|
||||||
|
klass = "Video/Sink/Pinos";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gstdev = g_object_new (GST_TYPE_PINOS_DEVICE,
|
||||||
|
"display-name", device_name, "caps", caps, "device-class", klass,
|
||||||
|
"path", path, NULL);
|
||||||
|
|
||||||
|
gstdev->id = id;
|
||||||
|
gstdev->type = type;
|
||||||
|
gstdev->element = element;
|
||||||
|
|
||||||
|
return GST_DEVICE (gstdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstElement *
|
||||||
|
gst_pinos_device_create_element (GstDevice * device, const gchar * name)
|
||||||
|
{
|
||||||
|
GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device);
|
||||||
|
GstElement *elem;
|
||||||
|
|
||||||
|
elem = gst_element_factory_make (pinos_dev->element, name);
|
||||||
|
g_object_set (elem, "source", pinos_dev->path, NULL);
|
||||||
|
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element)
|
||||||
|
{
|
||||||
|
GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device);
|
||||||
|
|
||||||
|
if (!strcmp (pinos_dev->element, "pinossrc")) {
|
||||||
|
if (!GST_IS_PINOS_SRC (element))
|
||||||
|
return FALSE;
|
||||||
|
} else if (!strcmp (pinos_dev->element, "pinossink")) {
|
||||||
|
if (!GST_IS_PINOS_SINK (element))
|
||||||
|
return FALSE;
|
||||||
|
} else {
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_set (element, "source", pinos_dev->path, NULL);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstPinosDevice *device;
|
||||||
|
|
||||||
|
device = GST_PINOS_DEVICE_CAST (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_PATH:
|
||||||
|
g_value_set_string (value, device->path);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstPinosDevice *device;
|
||||||
|
|
||||||
|
device = GST_PINOS_DEVICE_CAST (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_PATH:
|
||||||
|
device->path = g_value_dup_string (value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_finalize (GObject * object)
|
||||||
|
{
|
||||||
|
GstPinosDevice *device = GST_PINOS_DEVICE (object);
|
||||||
|
|
||||||
|
g_free (device->path);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gst_pinos_device_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_class_init (GstPinosDeviceClass * klass)
|
||||||
|
{
|
||||||
|
GstDeviceClass *dev_class = GST_DEVICE_CLASS (klass);
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
dev_class->create_element = gst_pinos_device_create_element;
|
||||||
|
dev_class->reconfigure_element = gst_pinos_device_reconfigure_element;
|
||||||
|
|
||||||
|
object_class->get_property = gst_pinos_device_get_property;
|
||||||
|
object_class->set_property = gst_pinos_device_set_property;
|
||||||
|
object_class->finalize = gst_pinos_device_finalize;
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class, PROP_PATH,
|
||||||
|
g_param_spec_string ("path", "Path",
|
||||||
|
"The internal path of the Pinos device", "",
|
||||||
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_init (GstPinosDevice * device)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider,
|
G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider,
|
||||||
GST_TYPE_DEVICE_PROVIDER);
|
GST_TYPE_DEVICE_PROVIDER);
|
||||||
|
|
||||||
static void gst_pinos_device_provider_finalize (GObject * object);
|
|
||||||
static void gst_pinos_device_provider_set_property (GObject * object,
|
|
||||||
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
||||||
static void gst_pinos_device_provider_get_property (GObject * object,
|
|
||||||
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
||||||
|
|
||||||
|
|
||||||
static GList *gst_pinos_device_provider_probe (GstDeviceProvider * provider);
|
|
||||||
static gboolean gst_pinos_device_provider_start (GstDeviceProvider * provider);
|
|
||||||
static void gst_pinos_device_provider_stop (GstDeviceProvider * provider);
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
|
@ -71,92 +205,6 @@ pinos_client_name (void)
|
||||||
return g_strdup_printf ("GStreamer-pid-%lu", (gulong) getpid ());
|
return g_strdup_printf ("GStreamer-pid-%lu", (gulong) getpid ());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass)
|
|
||||||
{
|
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
||||||
GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass);
|
|
||||||
gchar *client_name;
|
|
||||||
|
|
||||||
gobject_class->set_property = gst_pinos_device_provider_set_property;
|
|
||||||
gobject_class->get_property = gst_pinos_device_provider_get_property;
|
|
||||||
gobject_class->finalize = gst_pinos_device_provider_finalize;
|
|
||||||
|
|
||||||
dm_class->probe = gst_pinos_device_provider_probe;
|
|
||||||
dm_class->start = gst_pinos_device_provider_start;
|
|
||||||
dm_class->stop = gst_pinos_device_provider_stop;
|
|
||||||
|
|
||||||
client_name = pinos_client_name ();
|
|
||||||
g_object_class_install_property (gobject_class,
|
|
||||||
PROP_CLIENT_NAME,
|
|
||||||
g_param_spec_string ("client-name", "Client Name",
|
|
||||||
"The Pinos client_name_to_use", client_name,
|
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
||||||
GST_PARAM_MUTABLE_READY));
|
|
||||||
g_free (client_name);
|
|
||||||
|
|
||||||
gst_device_provider_class_set_static_metadata (dm_class,
|
|
||||||
"Pinos Device Provider", "Sink/Source/Audio/Video",
|
|
||||||
"List and provide Pinos source and sink devices",
|
|
||||||
"Wim Taymans <wim.taymans@gmail.com>");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_provider_init (GstPinosDeviceProvider * self)
|
|
||||||
{
|
|
||||||
self->client_name = pinos_client_name ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_provider_finalize (GObject * object)
|
|
||||||
{
|
|
||||||
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
|
||||||
|
|
||||||
g_free (self->client_name);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_pinos_device_provider_parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_provider_set_property (GObject * object,
|
|
||||||
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
case PROP_CLIENT_NAME:
|
|
||||||
g_free (self->client_name);
|
|
||||||
if (!g_value_get_string (value)) {
|
|
||||||
GST_WARNING_OBJECT (self,
|
|
||||||
"Empty Pinos client name not allowed. "
|
|
||||||
"Resetting to default value");
|
|
||||||
self->client_name = pinos_client_name ();
|
|
||||||
} else
|
|
||||||
self->client_name = g_value_dup_string (value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_provider_get_property (GObject * object,
|
|
||||||
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
case PROP_CLIENT_NAME:
|
|
||||||
g_value_set_string (value, self->client_name);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstDevice *
|
static GstDevice *
|
||||||
new_source (const PinosSourceInfo *info)
|
new_source (const PinosSourceInfo *info)
|
||||||
{
|
{
|
||||||
|
|
@ -165,12 +213,86 @@ new_source (const PinosSourceInfo *info)
|
||||||
if (info->formats)
|
if (info->formats)
|
||||||
caps = gst_caps_from_string (g_bytes_get_data (info->formats, NULL));
|
caps = gst_caps_from_string (g_bytes_get_data (info->formats, NULL));
|
||||||
else
|
else
|
||||||
caps = gst_caps_new_empty_simple("video/x-raw");
|
caps = gst_caps_new_any();
|
||||||
|
|
||||||
return gst_pinos_device_new (info->id, info->name,
|
return gst_pinos_device_new (info->id, info->name,
|
||||||
caps, info->name, GST_PINOS_DEVICE_TYPE_SOURCE);
|
caps, info->name, GST_PINOS_DEVICE_TYPE_SOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
get_source_info_cb (PinosContext *context,
|
||||||
|
const PinosSourceInfo *info,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GstPinosDeviceProvider *self = user_data;
|
||||||
|
GstDevice *dev;
|
||||||
|
|
||||||
|
if (info == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
dev = new_source (info);
|
||||||
|
|
||||||
|
if (dev)
|
||||||
|
gst_device_provider_device_add (GST_DEVICE_PROVIDER (self), dev);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstPinosDevice *
|
||||||
|
find_device (GstDeviceProvider *provider, gpointer id)
|
||||||
|
{
|
||||||
|
GList *item;
|
||||||
|
GstPinosDevice *dev = NULL;
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (provider);
|
||||||
|
for (item = provider->devices; item; item = item->next) {
|
||||||
|
dev = item->data;
|
||||||
|
if (dev->id == id) {
|
||||||
|
gst_object_ref (dev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dev = NULL;
|
||||||
|
}
|
||||||
|
GST_OBJECT_UNLOCK (provider);
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
context_subscribe_cb (PinosContext *context,
|
||||||
|
PinosSubscriptionEvent type,
|
||||||
|
PinosSubscriptionFlags flags,
|
||||||
|
gpointer id,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GstPinosDeviceProvider *self = user_data;
|
||||||
|
GstDeviceProvider *provider = user_data;
|
||||||
|
GstPinosDevice *dev;
|
||||||
|
|
||||||
|
if (flags != PINOS_SUBSCRIPTION_FLAGS_SOURCE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dev = find_device (provider, id);
|
||||||
|
|
||||||
|
if (type == PINOS_SUBSCRIPTION_EVENT_NEW) {
|
||||||
|
if (flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE && dev == NULL)
|
||||||
|
pinos_context_get_source_info_by_id (context,
|
||||||
|
id,
|
||||||
|
PINOS_SOURCE_INFO_FLAGS_FORMATS,
|
||||||
|
get_source_info_cb,
|
||||||
|
NULL,
|
||||||
|
self);
|
||||||
|
} else if (type == PINOS_SUBSCRIPTION_EVENT_REMOVE) {
|
||||||
|
if (flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE && dev != NULL) {
|
||||||
|
gst_device_provider_device_remove (GST_DEVICE_PROVIDER (self),
|
||||||
|
GST_DEVICE (dev));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dev)
|
||||||
|
gst_object_unref (dev);
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gboolean end;
|
gboolean end;
|
||||||
GList **devices;
|
GList **devices;
|
||||||
|
|
@ -193,72 +315,6 @@ list_source_info_cb (PinosContext *c,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
get_source_info_cb (PinosContext *context,
|
|
||||||
const PinosSourceInfo *info,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
GstPinosDeviceProvider *self = user_data;
|
|
||||||
GstDevice *dev;
|
|
||||||
|
|
||||||
if (info == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
dev = new_source (info);
|
|
||||||
|
|
||||||
if (dev)
|
|
||||||
gst_device_provider_device_add (GST_DEVICE_PROVIDER (self), dev);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
context_subscribe_cb (PinosContext *context,
|
|
||||||
PinosSubscriptionEvent type,
|
|
||||||
PinosSubscriptionFlags flags,
|
|
||||||
gpointer id,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
GstPinosDeviceProvider *self = user_data;
|
|
||||||
GstDeviceProvider *provider = user_data;
|
|
||||||
|
|
||||||
if (flags != PINOS_SUBSCRIPTION_FLAGS_SOURCE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (type == PINOS_SUBSCRIPTION_EVENT_NEW) {
|
|
||||||
if (flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE)
|
|
||||||
pinos_context_get_source_info_by_id (context,
|
|
||||||
id,
|
|
||||||
PINOS_SOURCE_INFO_FLAGS_FORMATS,
|
|
||||||
get_source_info_cb,
|
|
||||||
NULL,
|
|
||||||
self);
|
|
||||||
} else if (type == PINOS_SUBSCRIPTION_EVENT_REMOVE) {
|
|
||||||
GstPinosDevice *dev = NULL;
|
|
||||||
GList *item;
|
|
||||||
|
|
||||||
GST_OBJECT_LOCK (self);
|
|
||||||
for (item = provider->devices; item; item = item->next) {
|
|
||||||
dev = item->data;
|
|
||||||
|
|
||||||
if (((flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE &&
|
|
||||||
dev->type == GST_PINOS_DEVICE_TYPE_SOURCE)) &&
|
|
||||||
dev->id == id) {
|
|
||||||
gst_object_ref (dev);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dev = NULL;
|
|
||||||
}
|
|
||||||
GST_OBJECT_UNLOCK (self);
|
|
||||||
|
|
||||||
if (dev) {
|
|
||||||
gst_device_provider_device_remove (GST_DEVICE_PROVIDER (self),
|
|
||||||
GST_DEVICE (dev));
|
|
||||||
gst_object_unref (dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
gst_pinos_device_provider_probe (GstDeviceProvider * provider)
|
gst_pinos_device_provider_probe (GstDeviceProvider * provider)
|
||||||
{
|
{
|
||||||
|
|
@ -365,20 +421,23 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
|
||||||
|
|
||||||
if (!(self->loop = pinos_main_loop_new (c, "pinos-device-monitor"))) {
|
if (!(self->loop = pinos_main_loop_new (c, "pinos-device-monitor"))) {
|
||||||
GST_ERROR_OBJECT (self, "Could not create pinos mainloop");
|
GST_ERROR_OBJECT (self, "Could not create pinos mainloop");
|
||||||
goto mainloop_failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pinos_main_loop_start (self->loop, &error)) {
|
if (!pinos_main_loop_start (self->loop, &error)) {
|
||||||
GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message);
|
GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message);
|
||||||
g_clear_object (&self->loop);
|
g_clear_object (&self->loop);
|
||||||
goto mainloop_failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
pinos_main_loop_lock (self->loop);
|
pinos_main_loop_lock (self->loop);
|
||||||
|
|
||||||
if (!(self->context = pinos_context_new (c, self->client_name, NULL))) {
|
if (!(self->context = pinos_context_new (c, self->client_name, NULL))) {
|
||||||
GST_ERROR_OBJECT (self, "Failed to create context");
|
GST_ERROR_OBJECT (self, "Failed to create context");
|
||||||
goto unlock_and_fail;
|
pinos_main_loop_unlock (self->loop);
|
||||||
|
pinos_main_loop_stop (self->loop);
|
||||||
|
g_clear_object (&self->loop);
|
||||||
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (self->context,
|
g_signal_connect (self->context,
|
||||||
|
|
@ -400,18 +459,11 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
mainloop_failed:
|
failed:
|
||||||
{
|
{
|
||||||
g_main_context_unref (c);
|
g_main_context_unref (c);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
unlock_and_fail:
|
|
||||||
{
|
|
||||||
pinos_main_loop_unlock (self->loop);
|
|
||||||
gst_pinos_device_provider_stop (provider);
|
|
||||||
g_main_context_unref (c);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -428,140 +480,22 @@ gst_pinos_device_provider_stop (GstDeviceProvider * provider)
|
||||||
g_clear_object (&self->loop);
|
g_clear_object (&self->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
PROP_INTERNAL_NAME = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstPinosDevice, gst_pinos_device, GST_TYPE_DEVICE);
|
|
||||||
|
|
||||||
static void gst_pinos_device_get_property (GObject * object, guint prop_id,
|
|
||||||
GValue * value, GParamSpec * pspec);
|
|
||||||
static void gst_pinos_device_set_property (GObject * object, guint prop_id,
|
|
||||||
const GValue * value, GParamSpec * pspec);
|
|
||||||
static void gst_pinos_device_finalize (GObject * object);
|
|
||||||
static GstElement *gst_pinos_device_create_element (GstDevice * device,
|
|
||||||
const gchar * name);
|
|
||||||
static gboolean gst_pinos_device_reconfigure_element (GstDevice * device,
|
|
||||||
GstElement * element);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_pinos_device_class_init (GstPinosDeviceClass * klass)
|
gst_pinos_device_provider_set_property (GObject * object,
|
||||||
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstDeviceClass *dev_class = GST_DEVICE_CLASS (klass);
|
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
|
|
||||||
dev_class->create_element = gst_pinos_device_create_element;
|
|
||||||
dev_class->reconfigure_element = gst_pinos_device_reconfigure_element;
|
|
||||||
|
|
||||||
object_class->get_property = gst_pinos_device_get_property;
|
|
||||||
object_class->set_property = gst_pinos_device_set_property;
|
|
||||||
object_class->finalize = gst_pinos_device_finalize;
|
|
||||||
|
|
||||||
g_object_class_install_property (object_class, PROP_INTERNAL_NAME,
|
|
||||||
g_param_spec_string ("internal-name", "Internal Pinos device name",
|
|
||||||
"The internal name of the Pinos device", "",
|
|
||||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_init (GstPinosDevice * device)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_finalize (GObject * object)
|
|
||||||
{
|
|
||||||
GstPinosDevice *device = GST_PINOS_DEVICE (object);
|
|
||||||
|
|
||||||
g_free (device->internal_name);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_pinos_device_parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstElement *
|
|
||||||
gst_pinos_device_create_element (GstDevice * device, const gchar * name)
|
|
||||||
{
|
|
||||||
GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device);
|
|
||||||
GstElement *elem;
|
|
||||||
|
|
||||||
elem = gst_element_factory_make (pinos_dev->element, name);
|
|
||||||
g_object_set (elem, "source", pinos_dev->internal_name, NULL);
|
|
||||||
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element)
|
|
||||||
{
|
|
||||||
GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device);
|
|
||||||
|
|
||||||
if (!strcmp (pinos_dev->element, "pinossrc")) {
|
|
||||||
if (!GST_IS_PINOS_SRC (element))
|
|
||||||
return FALSE;
|
|
||||||
} else if (!strcmp (pinos_dev->element, "pinossink")) {
|
|
||||||
if (!GST_IS_PINOS_SINK (element))
|
|
||||||
return FALSE;
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_set (element, "source", pinos_dev->internal_name, NULL);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstDevice *
|
|
||||||
gst_pinos_device_new (gpointer id, const gchar * device_name,
|
|
||||||
GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type)
|
|
||||||
{
|
|
||||||
GstPinosDevice *gstdev;
|
|
||||||
const gchar *element = NULL;
|
|
||||||
const gchar *klass = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (device_name, NULL);
|
|
||||||
g_return_val_if_fail (internal_name, NULL);
|
|
||||||
g_return_val_if_fail (caps, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case GST_PINOS_DEVICE_TYPE_SOURCE:
|
|
||||||
element = "pinossrc";
|
|
||||||
klass = "Video/Source";
|
|
||||||
break;
|
|
||||||
case GST_PINOS_DEVICE_TYPE_SINK:
|
|
||||||
element = "pinossink";
|
|
||||||
klass = "Video/Sink";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gstdev = g_object_new (GST_TYPE_PINOS_DEVICE,
|
|
||||||
"display-name", device_name, "caps", caps, "device-class", klass,
|
|
||||||
"internal-name", internal_name, NULL);
|
|
||||||
|
|
||||||
gstdev->id = id;
|
|
||||||
gstdev->type = type;
|
|
||||||
gstdev->element = element;
|
|
||||||
|
|
||||||
return GST_DEVICE (gstdev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pinos_device_get_property (GObject * object, guint prop_id,
|
|
||||||
GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstPinosDevice *device;
|
|
||||||
|
|
||||||
device = GST_PINOS_DEVICE_CAST (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_INTERNAL_NAME:
|
case PROP_CLIENT_NAME:
|
||||||
g_value_set_string (value, device->internal_name);
|
g_free (self->client_name);
|
||||||
|
if (!g_value_get_string (value)) {
|
||||||
|
GST_WARNING_OBJECT (self,
|
||||||
|
"Empty Pinos client name not allowed. "
|
||||||
|
"Resetting to default value");
|
||||||
|
self->client_name = pinos_client_name ();
|
||||||
|
} else
|
||||||
|
self->client_name = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
|
@ -569,21 +503,65 @@ gst_pinos_device_get_property (GObject * object, guint prop_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_pinos_device_set_property (GObject * object, guint prop_id,
|
gst_pinos_device_provider_get_property (GObject * object,
|
||||||
const GValue * value, GParamSpec * pspec)
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstPinosDevice *device;
|
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
||||||
|
|
||||||
device = GST_PINOS_DEVICE_CAST (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_INTERNAL_NAME:
|
case PROP_CLIENT_NAME:
|
||||||
device->internal_name = g_value_dup_string (value);
|
g_value_set_string (value, self->client_name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_provider_finalize (GObject * object)
|
||||||
|
{
|
||||||
|
GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object);
|
||||||
|
|
||||||
|
g_free (self->client_name);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gst_pinos_device_provider_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass);
|
||||||
|
gchar *client_name;
|
||||||
|
|
||||||
|
gobject_class->set_property = gst_pinos_device_provider_set_property;
|
||||||
|
gobject_class->get_property = gst_pinos_device_provider_get_property;
|
||||||
|
gobject_class->finalize = gst_pinos_device_provider_finalize;
|
||||||
|
|
||||||
|
dm_class->probe = gst_pinos_device_provider_probe;
|
||||||
|
dm_class->start = gst_pinos_device_provider_start;
|
||||||
|
dm_class->stop = gst_pinos_device_provider_stop;
|
||||||
|
|
||||||
|
client_name = pinos_client_name ();
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_CLIENT_NAME,
|
||||||
|
g_param_spec_string ("client-name", "Client Name",
|
||||||
|
"The Pinos client_name_to_use", client_name,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||||
|
GST_PARAM_MUTABLE_READY));
|
||||||
|
g_free (client_name);
|
||||||
|
|
||||||
|
gst_device_provider_class_set_static_metadata (dm_class,
|
||||||
|
"Pinos Device Provider", "Sink/Source/Audio/Video",
|
||||||
|
"List and provide Pinos source and sink devices",
|
||||||
|
"Wim Taymans <wim.taymans@gmail.com>");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pinos_device_provider_init (GstPinosDeviceProvider * self)
|
||||||
|
{
|
||||||
|
self->client_name = pinos_client_name ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,37 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
typedef struct _GstPinosDevice GstPinosDevice;
|
||||||
|
typedef struct _GstPinosDeviceClass GstPinosDeviceClass;
|
||||||
|
|
||||||
|
#define GST_TYPE_PINOS_DEVICE (gst_pinos_device_get_type())
|
||||||
|
#define GST_IS_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE))
|
||||||
|
#define GST_IS_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE))
|
||||||
|
#define GST_PINOS_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDeviceClass))
|
||||||
|
#define GST_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDevice))
|
||||||
|
#define GST_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstPinosDeviceClass))
|
||||||
|
#define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj))
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GST_PINOS_DEVICE_TYPE_SOURCE,
|
||||||
|
GST_PINOS_DEVICE_TYPE_SINK,
|
||||||
|
} GstPinosDeviceType;
|
||||||
|
|
||||||
|
struct _GstPinosDevice {
|
||||||
|
GstDevice parent;
|
||||||
|
|
||||||
|
GstPinosDeviceType type;
|
||||||
|
gpointer id;
|
||||||
|
gchar *path;
|
||||||
|
const gchar *element;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GstPinosDeviceClass {
|
||||||
|
GstDeviceClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType gst_pinos_device_get_type (void);
|
||||||
|
|
||||||
typedef struct _GstPinosDeviceProvider GstPinosDeviceProvider;
|
typedef struct _GstPinosDeviceProvider GstPinosDeviceProvider;
|
||||||
typedef struct _GstPinosDeviceProviderClass GstPinosDeviceProviderClass;
|
typedef struct _GstPinosDeviceProviderClass GstPinosDeviceProviderClass;
|
||||||
|
|
||||||
|
|
@ -56,44 +87,12 @@ struct _GstPinosDeviceProvider {
|
||||||
PinosContext *context;
|
PinosContext *context;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GST_PINOS_DEVICE_TYPE_SOURCE,
|
|
||||||
GST_PINOS_DEVICE_TYPE_SINK,
|
|
||||||
} GstPinosDeviceType;
|
|
||||||
|
|
||||||
struct _GstPinosDeviceProviderClass {
|
struct _GstPinosDeviceProviderClass {
|
||||||
GstDeviceProviderClass parent_class;
|
GstDeviceProviderClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_pinos_device_provider_get_type (void);
|
GType gst_pinos_device_provider_get_type (void);
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GstPinosDevice GstPinosDevice;
|
|
||||||
typedef struct _GstPinosDeviceClass GstPinosDeviceClass;
|
|
||||||
|
|
||||||
#define GST_TYPE_PINOS_DEVICE (gst_pinos_device_get_type())
|
|
||||||
#define GST_IS_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE))
|
|
||||||
#define GST_IS_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE))
|
|
||||||
#define GST_PINOS_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDeviceClass))
|
|
||||||
#define GST_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDevice))
|
|
||||||
#define GST_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstPinosDeviceClass))
|
|
||||||
#define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj))
|
|
||||||
|
|
||||||
struct _GstPinosDevice {
|
|
||||||
GstDevice parent;
|
|
||||||
|
|
||||||
GstPinosDeviceType type;
|
|
||||||
gpointer id;
|
|
||||||
gchar *internal_name;
|
|
||||||
const gchar *element;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GstPinosDeviceClass {
|
|
||||||
GstDeviceClass parent_class;
|
|
||||||
};
|
|
||||||
|
|
||||||
GType gst_pinos_device_get_type (void);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_PINOS_DEVICE_PROVIDER_H__ */
|
#endif /* __GST_PINOS_DEVICE_PROVIDER_H__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue