2020-01-08 09:25:24 -05:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2019 Collabora Ltd.
|
|
|
|
|
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
#include "device.h"
|
2020-01-08 09:25:24 -05:00
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
struct _WpDevice
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
|
|
|
|
WpProxy parent;
|
|
|
|
|
struct pw_device_info *info;
|
|
|
|
|
|
|
|
|
|
/* The device proxy listener */
|
|
|
|
|
struct spa_hook listener;
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
G_DEFINE_TYPE (WpDevice, wp_device, WP_TYPE_PROXY)
|
2020-01-08 09:25:24 -05:00
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_init (WpDevice * self)
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_finalize (GObject * object)
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpDevice *self = WP_DEVICE (object);
|
2020-01-08 09:25:24 -05:00
|
|
|
|
|
|
|
|
g_clear_pointer (&self->info, pw_device_info_free);
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
G_OBJECT_CLASS (wp_device_parent_class)->finalize (object);
|
2020-01-08 09:25:24 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-22 10:34:56 +02:00
|
|
|
static gconstpointer
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_get_info (WpProxy * self)
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
return WP_DEVICE (self)->info;
|
2020-01-22 10:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WpProperties *
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_get_properties (WpProxy * self)
|
2020-01-22 10:34:56 +02:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
return wp_properties_new_wrap_dict (WP_DEVICE (self)->info->props);
|
2020-01-22 10:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_enum_params (WpProxy * self, guint32 id, guint32 start,
|
2020-01-22 10:34:56 +02:00
|
|
|
guint32 num, const struct spa_pod *filter)
|
|
|
|
|
{
|
|
|
|
|
struct pw_device *pwp;
|
|
|
|
|
int device_enum_params_result;
|
|
|
|
|
|
|
|
|
|
pwp = (struct pw_device *) wp_proxy_get_pw_proxy (self);
|
|
|
|
|
device_enum_params_result = pw_device_enum_params (pwp, 0, id, start, num,
|
|
|
|
|
filter);
|
|
|
|
|
g_warn_if_fail (device_enum_params_result >= 0);
|
2020-01-08 09:25:24 -05:00
|
|
|
|
2020-01-22 10:34:56 +02:00
|
|
|
return device_enum_params_result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_set_param (WpProxy * self, guint32 id, guint32 flags,
|
2020-01-22 10:34:56 +02:00
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct pw_device *pwp;
|
|
|
|
|
int device_set_param_result;
|
|
|
|
|
|
|
|
|
|
pwp = (struct pw_device *) wp_proxy_get_pw_proxy (self);
|
|
|
|
|
device_set_param_result = pw_device_set_param (pwp, id, flags, param);
|
|
|
|
|
g_warn_if_fail (device_set_param_result >= 0);
|
|
|
|
|
|
|
|
|
|
return device_set_param_result;
|
2020-01-08 09:25:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_event_info(void *data, const struct pw_device_info *info)
|
|
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpDevice *self = WP_DEVICE (data);
|
2020-01-08 09:25:24 -05:00
|
|
|
|
|
|
|
|
self->info = pw_device_info_update (self->info, info);
|
|
|
|
|
g_object_notify (G_OBJECT (self), "info");
|
|
|
|
|
|
|
|
|
|
if (info->change_mask & PW_DEVICE_CHANGE_MASK_PROPS)
|
|
|
|
|
g_object_notify (G_OBJECT (self), "properties");
|
|
|
|
|
|
|
|
|
|
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-09 12:39:45 -05:00
|
|
|
static const struct pw_device_events device_events = {
|
|
|
|
|
PW_VERSION_DEVICE_EVENTS,
|
2020-01-08 09:25:24 -05:00
|
|
|
.info = device_event_info,
|
2020-01-22 10:34:56 +02:00
|
|
|
.param = wp_proxy_handle_event_param,
|
2020-01-08 09:25:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpDevice *self = WP_DEVICE (proxy);
|
2020-01-09 12:39:45 -05:00
|
|
|
pw_device_add_listener ((struct pw_device *) pw_proxy,
|
2020-01-08 09:25:24 -05:00
|
|
|
&self->listener, &device_events, self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_device_class_init (WpDeviceClass * klass)
|
2020-01-08 09:25:24 -05:00
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = (GObjectClass *) klass;
|
|
|
|
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
object_class->finalize = wp_device_finalize;
|
2020-01-08 09:25:24 -05:00
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
proxy_class->get_info = wp_device_get_info;
|
|
|
|
|
proxy_class->get_properties = wp_device_get_properties;
|
|
|
|
|
proxy_class->enum_params = wp_device_enum_params;
|
|
|
|
|
proxy_class->set_param = wp_device_set_param;
|
2020-01-08 09:25:24 -05:00
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
proxy_class->pw_proxy_created = wp_device_pw_proxy_created;
|
2020-01-08 09:25:24 -05:00
|
|
|
}
|