2019-06-10 15:07:54 -04:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2019 Collabora Ltd.
|
|
|
|
|
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-17 15:39:19 +02:00
|
|
|
/**
|
|
|
|
|
* SECTION: WpPort
|
|
|
|
|
*
|
|
|
|
|
* The #WpPort class allows accessing the properties and methods of a
|
|
|
|
|
* PipeWire port object (`struct pw_port`).
|
|
|
|
|
*
|
|
|
|
|
* A #WpPort is constructed internally when a new port appears on the
|
|
|
|
|
* PipeWire registry and it is made available through the #WpObjectManager API.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-14 18:31:17 +03:00
|
|
|
#define G_LOG_DOMAIN "wp-port"
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
#include "port.h"
|
2019-11-07 20:44:55 +02:00
|
|
|
#include "private.h"
|
2019-08-22 20:04:39 +03:00
|
|
|
|
2019-06-10 15:07:54 -04:00
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
2020-02-17 15:39:19 +02:00
|
|
|
/**
|
|
|
|
|
* WpPort:
|
|
|
|
|
*/
|
2020-01-22 18:54:45 +02:00
|
|
|
struct _WpPort
|
2019-06-10 15:07:54 -04:00
|
|
|
{
|
|
|
|
|
WpProxy parent;
|
2019-08-27 17:33:25 +03:00
|
|
|
struct pw_port_info *info;
|
2019-07-09 09:02:09 -04:00
|
|
|
|
2019-06-10 15:07:54 -04:00
|
|
|
/* The port proxy listener */
|
|
|
|
|
struct spa_hook listener;
|
2019-08-27 17:33:25 +03:00
|
|
|
};
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
G_DEFINE_TYPE (WpPort, wp_port, WP_TYPE_PROXY)
|
2019-06-10 15:07:54 -04:00
|
|
|
|
2019-08-27 17:33:25 +03:00
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_init (WpPort * self)
|
2019-08-27 17:33:25 +03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_finalize (GObject * object)
|
2019-08-27 17:33:25 +03:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpPort *self = WP_PORT (object);
|
2019-08-27 17:33:25 +03:00
|
|
|
|
|
|
|
|
g_clear_pointer (&self->info, pw_port_info_free);
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
G_OBJECT_CLASS (wp_port_parent_class)->finalize (object);
|
2019-08-27 17:33:25 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-22 10:34:56 +02:00
|
|
|
static gconstpointer
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_get_info (WpProxy * self)
|
2019-08-27 17:33:25 +03:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
return WP_PORT (self)->info;
|
2020-01-22 10:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WpProperties *
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_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_PORT (self)->info->props);
|
2020-01-22 10:34:56 +02:00
|
|
|
}
|
2019-08-27 17:33:25 +03:00
|
|
|
|
2020-05-25 15:33:47 +03:00
|
|
|
static struct spa_param_info *
|
|
|
|
|
wp_port_get_param_info (WpProxy * proxy, guint * n_params)
|
|
|
|
|
{
|
|
|
|
|
WpPort *self = WP_PORT (proxy);
|
|
|
|
|
*n_params = self->info->n_params;
|
|
|
|
|
return self->info->params;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 10:34:56 +02:00
|
|
|
static gint
|
2020-06-04 09:31:01 -04:00
|
|
|
wp_port_enum_params (WpProxy * self, guint32 id, guint32 start, guint32 num,
|
|
|
|
|
WpSpaPod * filter)
|
2020-01-22 10:34:56 +02:00
|
|
|
{
|
2020-05-25 15:33:47 +03:00
|
|
|
struct pw_port *pwp = (struct pw_port *) wp_proxy_get_pw_proxy (self);
|
|
|
|
|
return pw_port_enum_params (pwp, 0, id, start, num,
|
|
|
|
|
filter ? wp_spa_pod_get_spa_pod (filter) : NULL);
|
2020-01-22 10:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
2020-05-25 15:33:47 +03:00
|
|
|
wp_port_subscribe_params (WpProxy * self, guint32 *ids, guint32 n_ids)
|
2020-01-22 10:34:56 +02:00
|
|
|
{
|
2020-05-25 15:33:47 +03:00
|
|
|
struct pw_port *pwp = (struct pw_port *) wp_proxy_get_pw_proxy (self);
|
|
|
|
|
return pw_port_subscribe_params (pwp, ids, n_ids);
|
2019-08-27 17:33:25 +03:00
|
|
|
}
|
|
|
|
|
|
2019-06-10 15:07:54 -04:00
|
|
|
static void
|
|
|
|
|
port_event_info(void *data, const struct pw_port_info *info)
|
|
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpPort *self = WP_PORT (data);
|
2019-08-27 17:33:25 +03:00
|
|
|
|
|
|
|
|
self->info = pw_port_info_update (self->info, info);
|
2020-01-30 17:41:25 +02:00
|
|
|
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
|
|
|
|
|
|
2019-08-27 17:33:25 +03:00
|
|
|
g_object_notify (G_OBJECT (self), "info");
|
|
|
|
|
|
|
|
|
|
if (info->change_mask & PW_PORT_CHANGE_MASK_PROPS)
|
|
|
|
|
g_object_notify (G_OBJECT (self), "properties");
|
2020-05-25 15:33:47 +03:00
|
|
|
|
|
|
|
|
if (info->change_mask & PW_PORT_CHANGE_MASK_PARAMS)
|
|
|
|
|
g_object_notify (G_OBJECT (self), "param-info");
|
2019-06-10 15:07:54 -04:00
|
|
|
}
|
|
|
|
|
|
2020-01-09 12:39:45 -05:00
|
|
|
static const struct pw_port_events port_events = {
|
|
|
|
|
PW_VERSION_PORT_EVENTS,
|
2019-06-10 15:07:54 -04:00
|
|
|
.info = port_event_info,
|
2020-01-22 10:34:56 +02:00
|
|
|
.param = wp_proxy_handle_event_param,
|
2019-06-10 15:07:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
2019-07-11 12:06:04 -04:00
|
|
|
{
|
2020-01-22 18:54:45 +02:00
|
|
|
WpPort *self = WP_PORT (proxy);
|
2020-01-09 12:39:45 -05:00
|
|
|
pw_port_add_listener ((struct pw_port *) pw_proxy,
|
2019-08-27 17:33:25 +03:00
|
|
|
&self->listener, &port_events, self);
|
2019-07-11 12:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-10 15:07:54 -04:00
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
wp_port_class_init (WpPortClass * klass)
|
2019-06-10 15:07:54 -04:00
|
|
|
{
|
2019-08-27 17:33:25 +03:00
|
|
|
GObjectClass *object_class = (GObjectClass *) klass;
|
|
|
|
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
2019-06-10 15:07:54 -04:00
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
object_class->finalize = wp_port_finalize;
|
2019-08-27 17:33:25 +03:00
|
|
|
|
2020-01-30 17:41:25 +02:00
|
|
|
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Port;
|
|
|
|
|
proxy_class->pw_iface_version = PW_VERSION_PORT;
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
proxy_class->get_info = wp_port_get_info;
|
|
|
|
|
proxy_class->get_properties = wp_port_get_properties;
|
2020-05-25 15:33:47 +03:00
|
|
|
proxy_class->get_param_info = wp_port_get_param_info;
|
2020-01-22 18:54:45 +02:00
|
|
|
proxy_class->enum_params = wp_port_enum_params;
|
|
|
|
|
proxy_class->subscribe_params = wp_port_subscribe_params;
|
2019-08-27 17:33:25 +03:00
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
proxy_class->pw_proxy_created = wp_port_pw_proxy_created;
|
2019-06-10 15:07:54 -04:00
|
|
|
}
|
2020-04-21 17:08:10 +03:00
|
|
|
|
|
|
|
|
WpDirection
|
|
|
|
|
wp_port_get_direction (WpPort * self)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (WP_IS_PORT (self), 0);
|
|
|
|
|
g_return_val_if_fail (wp_proxy_get_features (WP_PROXY (self)) &
|
|
|
|
|
WP_PROXY_FEATURE_INFO, 0);
|
|
|
|
|
|
|
|
|
|
return (WpDirection) self->info->direction;
|
|
|
|
|
}
|