2015-07-08 17:40:37 +02:00
|
|
|
/* GStreamer
|
|
|
|
|
* Copyright (C) 2012 Olivier Crete <olivier.crete@collabora.com>
|
|
|
|
|
* (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
2017-05-23 19:15:33 +02:00
|
|
|
* pipewiredeviceprovider.c: PipeWire device probing and monitoring
|
2015-07-08 17:40:37 +02:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
#include "gstpipewireformat.h"
|
|
|
|
|
#include "gstpipewiredeviceprovider.h"
|
|
|
|
|
#include "gstpipewiresrc.h"
|
|
|
|
|
#include "gstpipewiresink.h"
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (pipewire_debug);
|
|
|
|
|
#define GST_CAT_DEFAULT pipewire_debug
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
G_DEFINE_TYPE (GstPipeWireDevice, gst_pipewire_device, GST_TYPE_DEVICE);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
PROP_ID = 1,
|
2015-07-08 17:40:37 +02:00
|
|
|
};
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
static GstDevice *
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_new (uint32_t id, const gchar * device_name,
|
2016-11-24 17:00:42 +01:00
|
|
|
GstCaps * caps, const gchar *klass,
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceType type, GstStructure *props)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *gstdev;
|
2015-07-09 17:34:01 +02:00
|
|
|
const gchar *element = NULL;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
g_return_val_if_fail (device_name, NULL);
|
|
|
|
|
g_return_val_if_fail (caps, NULL);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
switch (type) {
|
2017-05-23 19:15:33 +02:00
|
|
|
case GST_PIPEWIRE_DEVICE_TYPE_SOURCE:
|
|
|
|
|
element = "pipewiresrc";
|
2015-07-09 17:34:01 +02:00
|
|
|
break;
|
2017-05-23 19:15:33 +02:00
|
|
|
case GST_PIPEWIRE_DEVICE_TYPE_SINK:
|
|
|
|
|
element = "pipewiresink";
|
2015-07-09 17:34:01 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
gstdev = g_object_new (GST_TYPE_PIPEWIRE_DEVICE,
|
2015-07-09 17:34:01 +02:00
|
|
|
"display-name", device_name, "caps", caps, "device-class", klass,
|
2016-11-24 17:00:42 +01:00
|
|
|
"id", id, "properties", props, NULL);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
gstdev->id = id;
|
|
|
|
|
gstdev->type = type;
|
|
|
|
|
gstdev->element = element;
|
|
|
|
|
|
|
|
|
|
return GST_DEVICE (gstdev);
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
static GstElement *
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_create_element (GstDevice * device, const gchar * name)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *pipewire_dev = GST_PIPEWIRE_DEVICE (device);
|
2015-07-09 17:34:01 +02:00
|
|
|
GstElement *elem;
|
2017-01-20 15:53:03 +01:00
|
|
|
gchar *str;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
elem = gst_element_factory_make (pipewire_dev->element, name);
|
|
|
|
|
str = g_strdup_printf ("%u", pipewire_dev->id);
|
2017-01-20 15:53:03 +01:00
|
|
|
g_object_set (elem, "path", str, NULL);
|
|
|
|
|
g_free (str);
|
2015-07-09 17:34:01 +02:00
|
|
|
|
|
|
|
|
return elem;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
static gboolean
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_reconfigure_element (GstDevice * device, GstElement * element)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *pipewire_dev = GST_PIPEWIRE_DEVICE (device);
|
2017-01-20 15:53:03 +01:00
|
|
|
gchar *str;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (!strcmp (pipewire_dev->element, "pipewiresrc")) {
|
|
|
|
|
if (!GST_IS_PIPEWIRE_SRC (element))
|
2015-07-09 17:34:01 +02:00
|
|
|
return FALSE;
|
2017-05-23 19:15:33 +02:00
|
|
|
} else if (!strcmp (pipewire_dev->element, "pipewiresink")) {
|
|
|
|
|
if (!GST_IS_PIPEWIRE_SINK (element))
|
2015-07-09 17:34:01 +02:00
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
str = g_strdup_printf ("%u", pipewire_dev->id);
|
2017-01-20 15:53:03 +01:00
|
|
|
g_object_set (element, "path", str, NULL);
|
|
|
|
|
g_free (str);
|
2015-07-09 17:34:01 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_get_property (GObject * object, guint prop_id,
|
2015-07-09 17:34:01 +02:00
|
|
|
GValue * value, GParamSpec * pspec)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *device;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
device = GST_PIPEWIRE_DEVICE_CAST (object);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-11-24 17:00:42 +01:00
|
|
|
case PROP_ID:
|
|
|
|
|
g_value_set_uint (value, device->id);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_set_property (GObject * object, guint prop_id,
|
2015-07-09 17:34:01 +02:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *device;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
device = GST_PIPEWIRE_DEVICE_CAST (object);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-11-24 17:00:42 +01:00
|
|
|
case PROP_ID:
|
|
|
|
|
device->id = g_value_get_uint (value);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_finalize (GObject * object)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
G_OBJECT_CLASS (gst_pipewire_device_parent_class)->finalize (object);
|
2015-07-09 17:34:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_class_init (GstPipeWireDeviceClass * klass)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
|
|
|
|
GstDeviceClass *dev_class = GST_DEVICE_CLASS (klass);
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
dev_class->create_element = gst_pipewire_device_create_element;
|
|
|
|
|
dev_class->reconfigure_element = gst_pipewire_device_reconfigure_element;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
object_class->get_property = gst_pipewire_device_get_property;
|
|
|
|
|
object_class->set_property = gst_pipewire_device_set_property;
|
|
|
|
|
object_class->finalize = gst_pipewire_device_finalize;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
g_object_class_install_property (object_class, PROP_ID,
|
|
|
|
|
g_param_spec_uint ("id", "Id",
|
2017-05-23 19:15:33 +02:00
|
|
|
"The internal id of the PipeWire device", 0, G_MAXUINT32, SPA_ID_INVALID,
|
2015-07-09 17:34:01 +02:00
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_init (GstPipeWireDevice * device)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
G_DEFINE_TYPE (GstPipeWireDeviceProvider, gst_pipewire_device_provider,
|
2015-07-09 17:34:01 +02:00
|
|
|
GST_TYPE_DEVICE_PROVIDER);
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_CLIENT_NAME,
|
|
|
|
|
PROP_LAST
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-08 17:40:37 +02:00
|
|
|
static GstDevice *
|
2017-05-23 19:15:33 +02:00
|
|
|
new_node (const struct pw_node_info *info)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-02-01 08:58:21 +01:00
|
|
|
GstCaps *caps = NULL;
|
2015-07-17 17:01:46 +02:00
|
|
|
GstStructure *props;
|
2016-12-22 17:08:19 +01:00
|
|
|
const gchar *klass = NULL;
|
2016-12-02 13:38:43 +01:00
|
|
|
SpaDictItem *item;
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceType type;
|
2017-02-01 08:58:21 +01:00
|
|
|
int i;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-02-01 17:48:12 +01:00
|
|
|
caps = gst_caps_new_empty ();
|
2017-02-01 08:58:21 +01:00
|
|
|
if (info->max_inputs > 0 && info->max_outputs == 0) {
|
2017-05-23 19:15:33 +02:00
|
|
|
type = GST_PIPEWIRE_DEVICE_TYPE_SINK;
|
2017-02-01 08:58:21 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < info->n_input_formats; i++) {
|
2017-03-27 15:20:01 +02:00
|
|
|
GstCaps *c1 = gst_caps_from_format (info->input_formats[i]);
|
|
|
|
|
if (c1)
|
|
|
|
|
gst_caps_append (caps, c1);
|
2017-02-01 08:58:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (info->max_outputs > 0 && info->max_inputs == 0) {
|
2017-05-23 19:15:33 +02:00
|
|
|
type = GST_PIPEWIRE_DEVICE_TYPE_SOURCE;
|
2017-02-01 08:58:21 +01:00
|
|
|
for (i = 0; i < info->n_output_formats; i++) {
|
2017-03-27 15:20:01 +02:00
|
|
|
GstCaps *c1 = gst_caps_from_format (info->output_formats[i]);
|
|
|
|
|
if (c1)
|
|
|
|
|
gst_caps_append (caps, c1);
|
2017-02-01 08:58:21 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-05-23 19:15:33 +02:00
|
|
|
type = GST_PIPEWIRE_DEVICE_TYPE_UNKNOWN;
|
2017-02-01 08:58:21 +01:00
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
props = gst_structure_new_empty ("pipewire-proplist");
|
2016-12-22 17:08:19 +01:00
|
|
|
if (info->props) {
|
|
|
|
|
spa_dict_for_each (item, info->props)
|
|
|
|
|
gst_structure_set (props, item->key, G_TYPE_STRING, item->value, NULL);
|
2015-07-17 17:01:46 +02:00
|
|
|
|
2017-01-20 15:53:03 +01:00
|
|
|
klass = spa_dict_lookup (info->props, "media.class");
|
2016-12-22 17:08:19 +01:00
|
|
|
}
|
2015-07-17 17:01:46 +02:00
|
|
|
if (klass == NULL)
|
|
|
|
|
klass = "unknown/unknown";
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
return gst_pipewire_device_new (info->id,
|
2015-07-14 15:49:52 +02:00
|
|
|
info->name,
|
|
|
|
|
caps,
|
2015-07-17 17:01:46 +02:00
|
|
|
klass,
|
2017-02-01 08:58:21 +01:00
|
|
|
type,
|
2015-07-17 17:01:46 +02:00
|
|
|
props);
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
get_node_info_cb (struct pw_context *context,
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaResult res,
|
2017-05-23 19:15:33 +02:00
|
|
|
const struct pw_node_info *info,
|
2016-05-06 13:01:52 +02:00
|
|
|
gpointer user_data)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = user_data;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
if (info) {
|
|
|
|
|
GstDevice *dev;
|
|
|
|
|
dev = new_node (info);
|
|
|
|
|
if (dev)
|
|
|
|
|
gst_device_provider_device_add (GST_DEVICE_PROVIDER (self), dev);
|
|
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
static GstPipeWireDevice *
|
2016-11-24 17:00:42 +01:00
|
|
|
find_device (GstDeviceProvider *provider, uint32_t id)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
|
|
|
|
GList *item;
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *dev = NULL;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 17:40:37 +02:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_context_subscription (struct pw_listener *listener,
|
|
|
|
|
struct pw_context *context,
|
|
|
|
|
enum pw_subscription_event event,
|
|
|
|
|
uint32_t type,
|
|
|
|
|
uint32_t id)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPipeWireDeviceProvider, ctx_subscription);
|
2016-12-22 16:50:01 +01:00
|
|
|
GstDeviceProvider *provider = GST_DEVICE_PROVIDER (self);
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDevice *dev;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (type != context->type.node)
|
2015-07-08 17:40:37 +02:00
|
|
|
return;
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
dev = find_device (provider, id);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (event == PW_SUBSCRIPTION_EVENT_NEW) {
|
2016-12-02 13:38:43 +01:00
|
|
|
if (dev == NULL)
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_get_node_info_by_id (context,
|
|
|
|
|
id,
|
|
|
|
|
get_node_info_cb,
|
|
|
|
|
self);
|
|
|
|
|
} else if (event == PW_SUBSCRIPTION_EVENT_REMOVE) {
|
2016-12-02 13:38:43 +01:00
|
|
|
if (dev != NULL) {
|
2015-07-08 17:40:37 +02:00
|
|
|
gst_device_provider_device_remove (GST_DEVICE_PROVIDER (self),
|
2015-07-09 17:34:01 +02:00
|
|
|
GST_DEVICE (dev));
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-09 17:34:01 +02:00
|
|
|
if (dev)
|
|
|
|
|
gst_object_unref (dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
gboolean end;
|
|
|
|
|
GList **devices;
|
|
|
|
|
} InfoData;
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
list_node_info_cb (struct pw_context *c,
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaResult res,
|
2017-05-23 19:15:33 +02:00
|
|
|
const struct pw_node_info *info,
|
2016-11-24 17:00:42 +01:00
|
|
|
void *user_data)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
|
|
|
|
InfoData *data = user_data;
|
2016-11-24 17:00:42 +01:00
|
|
|
if (info) {
|
|
|
|
|
*data->devices = g_list_prepend (*data->devices, gst_object_ref_sink (new_node (info)));
|
|
|
|
|
} else {
|
|
|
|
|
data->end = TRUE;
|
2016-01-07 12:15:57 +01:00
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
get_core_info_cb (struct pw_context *c,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
const struct pw_core_info *info,
|
|
|
|
|
void *user_data)
|
2015-07-17 17:01:46 +02:00
|
|
|
{
|
2016-01-07 12:15:57 +01:00
|
|
|
GstDeviceProvider *provider = user_data;
|
2015-07-17 17:01:46 +02:00
|
|
|
const gchar *value;
|
|
|
|
|
|
2016-12-22 17:08:19 +01:00
|
|
|
if (info == NULL || info->props == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-01-20 15:53:03 +01:00
|
|
|
value = spa_dict_lookup (info->props, "monitors");
|
2015-07-17 17:01:46 +02:00
|
|
|
if (value) {
|
2017-01-20 15:53:03 +01:00
|
|
|
gchar **monitors = g_strsplit (value, ",", -1);
|
2015-07-17 17:01:46 +02:00
|
|
|
gint i;
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
GST_DEBUG_OBJECT (provider, "have hidden providers: %s", value);
|
2015-07-17 17:01:46 +02:00
|
|
|
|
2017-01-20 15:53:03 +01:00
|
|
|
for (i = 0; monitors[i]; i++) {
|
|
|
|
|
if (strcmp (monitors[i], "v4l2") == 0)
|
|
|
|
|
gst_device_provider_hide_provider (provider, "v4l2deviceprovider");
|
|
|
|
|
else if (strcmp (monitors[i], "alsa") == 0)
|
|
|
|
|
gst_device_provider_hide_provider (provider, "pulsedeviceprovider");
|
2015-07-17 17:01:46 +02:00
|
|
|
}
|
2017-01-20 15:53:03 +01:00
|
|
|
g_strfreev (monitors);
|
2015-07-17 17:01:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 17:40:37 +02:00
|
|
|
static GList *
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_probe (GstDeviceProvider * provider)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider);
|
|
|
|
|
struct pw_loop *l = NULL;
|
|
|
|
|
struct pw_context *c = NULL;
|
2015-07-08 17:40:37 +02:00
|
|
|
InfoData data;
|
|
|
|
|
|
2015-07-17 17:01:46 +02:00
|
|
|
GST_DEBUG_OBJECT (self, "starting probe");
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (!(l = pw_loop_new ()))
|
2015-07-08 17:40:37 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (!(c = pw_context_new (l, self->client_name, NULL)))
|
2015-07-08 17:40:37 +02:00
|
|
|
goto failed;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_connect (c, 0);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
for (;;) {
|
2017-05-23 19:15:33 +02:00
|
|
|
enum pw_context_state state;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
state = c->state;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
if (state <= 0) {
|
2016-11-24 17:00:42 +01:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to connect: %s", c->error);
|
2015-07-08 17:40:37 +02:00
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (state == PW_CONTEXT_STATE_CONNECTED)
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Wait until something happens */
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_loop_iterate (l, -1);
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
GST_DEBUG_OBJECT (self, "connected");
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_get_core_info (c,
|
|
|
|
|
get_core_info_cb,
|
|
|
|
|
self);
|
2015-07-17 17:01:46 +02:00
|
|
|
|
|
|
|
|
|
2015-07-08 17:40:37 +02:00
|
|
|
data.end = FALSE;
|
|
|
|
|
data.devices = NULL;
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_list_node_info (c,
|
|
|
|
|
list_node_info_cb,
|
|
|
|
|
&data);
|
2015-07-08 17:40:37 +02:00
|
|
|
for (;;) {
|
2016-11-24 17:00:42 +01:00
|
|
|
if (c->state <= 0)
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
if (data.end)
|
|
|
|
|
break;
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_loop_iterate (l, -1);
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_disconnect (c);
|
|
|
|
|
pw_context_destroy (c);
|
|
|
|
|
pw_loop_destroy (l);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
return *data.devices;
|
|
|
|
|
|
|
|
|
|
failed:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_loop_destroy (l);
|
2015-07-08 17:40:37 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_context_state_changed (struct pw_listener *listener,
|
|
|
|
|
struct pw_context *context)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = SPA_CONTAINER_OF (listener, GstPipeWireDeviceProvider, ctx_state_changed);
|
|
|
|
|
enum pw_context_state state;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
state= context->state;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
GST_DEBUG ("got context state %d", state);
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
2017-05-23 19:15:33 +02:00
|
|
|
case PW_CONTEXT_STATE_CONNECTING:
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
2017-05-23 19:15:33 +02:00
|
|
|
case PW_CONTEXT_STATE_UNCONNECTED:
|
|
|
|
|
case PW_CONTEXT_STATE_CONNECTED:
|
2015-07-09 11:35:18 +02:00
|
|
|
break;
|
2017-05-23 19:15:33 +02:00
|
|
|
case PW_CONTEXT_STATE_ERROR:
|
2016-11-24 17:00:42 +01:00
|
|
|
GST_ERROR_OBJECT (self, "context error: %s", context->error);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_signal (self->main_loop, FALSE);
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_start (GstDeviceProvider * provider)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2015-07-17 17:01:46 +02:00
|
|
|
GST_DEBUG_OBJECT (self, "starting provider");
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
self->loop = pw_loop_new ();
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (!(self->main_loop = pw_thread_main_loop_new (self->loop, "pipewire-device-monitor"))) {
|
|
|
|
|
GST_ERROR_OBJECT (self, "Could not create PipeWire mainloop");
|
2016-11-24 17:00:42 +01:00
|
|
|
goto failed_main_loop;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
2015-07-09 11:35:18 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (pw_thread_main_loop_start (self->main_loop) != SPA_RESULT_OK) {
|
|
|
|
|
GST_ERROR_OBJECT (self, "Could not start PipeWire mainloop");
|
2016-11-24 17:00:42 +01:00
|
|
|
goto failed_start;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_lock (self->main_loop);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (!(self->context = pw_context_new (self->loop, self->client_name, NULL))) {
|
2015-07-08 17:40:37 +02:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to create context");
|
2016-11-24 17:00:42 +01:00
|
|
|
goto failed_context;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&self->context->state_changed,
|
2016-12-22 16:50:01 +01:00
|
|
|
&self->ctx_state_changed,
|
|
|
|
|
on_context_state_changed);
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&self->context->subscription,
|
2016-12-22 16:50:01 +01:00
|
|
|
&self->ctx_subscription,
|
|
|
|
|
on_context_subscription);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_connect (self->context, 0);
|
2015-07-17 17:01:46 +02:00
|
|
|
for (;;) {
|
2017-05-23 19:15:33 +02:00
|
|
|
enum pw_context_state state;
|
2015-07-17 17:01:46 +02:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
state = self->context->state;
|
2015-07-17 17:01:46 +02:00
|
|
|
|
|
|
|
|
if (state <= 0) {
|
2016-11-24 17:00:42 +01:00
|
|
|
GST_WARNING_OBJECT (self, "Failed to connect: %s", self->context->error);
|
2015-07-17 17:01:46 +02:00
|
|
|
goto not_running;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (state == PW_CONTEXT_STATE_CONNECTED)
|
2015-07-17 17:01:46 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Wait until something happens */
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_wait (self->main_loop);
|
2015-07-17 17:01:46 +02:00
|
|
|
}
|
|
|
|
|
GST_DEBUG_OBJECT (self, "connected");
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_get_core_info (self->context,
|
|
|
|
|
get_core_info_cb,
|
|
|
|
|
self);
|
|
|
|
|
pw_thread_main_loop_unlock (self->main_loop);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2015-07-17 17:01:46 +02:00
|
|
|
not_running:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_destroy (self->context);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->context = NULL;
|
|
|
|
|
failed_context:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_unlock (self->main_loop);
|
2016-11-24 17:00:42 +01:00
|
|
|
failed_start:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_destroy (self->main_loop);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->main_loop = NULL;
|
|
|
|
|
failed_main_loop:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_loop_destroy (self->loop);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->loop = NULL;
|
2017-02-01 08:58:21 +01:00
|
|
|
return TRUE;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_stop (GstDeviceProvider * provider)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
if (self->context) {
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_context_disconnect (self->context);
|
|
|
|
|
pw_context_destroy (self->context);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->context = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (self->main_loop) {
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_thread_main_loop_destroy (self->main_loop);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->main_loop = NULL;
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
2015-07-17 17:01:46 +02:00
|
|
|
if (self->loop) {
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_loop_destroy (self->loop);
|
2016-11-24 17:00:42 +01:00
|
|
|
self->loop = NULL;
|
2015-07-17 17:01:46 +02:00
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_set_property (GObject * object,
|
2015-07-09 17:34:01 +02:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_CLIENT_NAME:
|
|
|
|
|
g_free (self->client_name);
|
|
|
|
|
if (!g_value_get_string (value)) {
|
|
|
|
|
GST_WARNING_OBJECT (self,
|
2017-05-23 19:15:33 +02:00
|
|
|
"Empty PipeWire client name not allowed. "
|
2015-07-09 17:34:01 +02:00
|
|
|
"Resetting to default value");
|
2017-05-23 19:15:33 +02:00
|
|
|
self->client_name = pw_client_name ();
|
2015-07-09 17:34:01 +02:00
|
|
|
} else
|
|
|
|
|
self->client_name = g_value_dup_string (value);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2015-07-09 17:34:01 +02:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_get_property (GObject * object,
|
2015-07-09 17:34:01 +02:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object);
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-07-09 17:34:01 +02:00
|
|
|
case PROP_CLIENT_NAME:
|
|
|
|
|
g_value_set_string (value, self->client_name);
|
2015-07-08 17:40:37 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 17:34:01 +02:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_finalize (GObject * object)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (object);
|
2015-07-09 17:34:01 +02:00
|
|
|
|
|
|
|
|
g_free (self->client_name);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
G_OBJECT_CLASS (gst_pipewire_device_provider_parent_class)->finalize (object);
|
2015-07-09 17:34:01 +02:00
|
|
|
}
|
2015-07-08 17:40:37 +02:00
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_class_init (GstPipeWireDeviceProviderClass * klass)
|
2015-07-08 17:40:37 +02:00
|
|
|
{
|
2015-07-09 17:34:01 +02:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass);
|
|
|
|
|
gchar *client_name;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
gobject_class->set_property = gst_pipewire_device_provider_set_property;
|
|
|
|
|
gobject_class->get_property = gst_pipewire_device_provider_get_property;
|
|
|
|
|
gobject_class->finalize = gst_pipewire_device_provider_finalize;
|
2015-07-08 17:40:37 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
dm_class->probe = gst_pipewire_device_provider_probe;
|
|
|
|
|
dm_class->start = gst_pipewire_device_provider_start;
|
|
|
|
|
dm_class->stop = gst_pipewire_device_provider_stop;
|
2015-07-09 17:34:01 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
client_name = pw_client_name ();
|
2015-07-09 17:34:01 +02:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_CLIENT_NAME,
|
|
|
|
|
g_param_spec_string ("client-name", "Client Name",
|
2017-05-23 19:15:33 +02:00
|
|
|
"The PipeWire client_name_to_use", client_name,
|
2015-07-09 17:34:01 +02:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
|
|
|
GST_PARAM_MUTABLE_READY));
|
|
|
|
|
g_free (client_name);
|
|
|
|
|
|
|
|
|
|
gst_device_provider_class_set_static_metadata (dm_class,
|
2017-05-23 19:15:33 +02:00
|
|
|
"PipeWire Device Provider", "Sink/Source/Audio/Video",
|
|
|
|
|
"List and provide PipeWire source and sink devices",
|
2015-07-09 17:34:01 +02:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
gst_pipewire_device_provider_init (GstPipeWireDeviceProvider * self)
|
2015-07-09 17:34:01 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
self->client_name = pw_client_name ();
|
2015-07-08 17:40:37 +02:00
|
|
|
}
|