wireplumber/lib/wp/port.c

191 lines
5.3 KiB
C
Raw Normal View History

2019-06-10 15:07:54 -04:00
/* WirePlumber
*
* Copyright © 2019-2020 Collabora Ltd.
2019-06-10 15:07:54 -04:00
* @author Julian Bouzas <julian.bouzas@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
2020-02-17 15:39:19 +02:00
/**
* SECTION: port
* @title: PipeWire Port
2020-02-17 15:39:19 +02:00
*/
#define G_LOG_DOMAIN "wp-port"
#include "port.h"
#include "private/pipewire-object-mixin.h"
struct _WpPort
2019-06-10 15:07:54 -04:00
{
WpGlobalProxy parent;
struct pw_port_info *info;
2019-06-10 15:07:54 -04:00
struct spa_hook listener;
};
static void wp_port_pipewire_object_interface_init (WpPipewireObjectInterface * iface);
/**
* 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.
*/
G_DEFINE_TYPE_WITH_CODE (WpPort, wp_port, WP_TYPE_GLOBAL_PROXY,
G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_OBJECT, wp_port_pipewire_object_interface_init));
2019-06-10 15:07:54 -04:00
static void
wp_port_init (WpPort * self)
{
}
static WpObjectFeatures
wp_port_get_supported_features (WpObject * object)
{
WpPort *self = WP_PORT (object);
return WP_PROXY_FEATURE_BOUND | WP_PIPEWIRE_OBJECT_FEATURE_INFO |
wp_pipewire_object_mixin_param_info_to_features (
self->info ? self->info->params : NULL,
self->info ? self->info->n_params : 0);
}
static void
wp_port_activate_execute_step (WpObject * object,
WpFeatureActivationTransition * transition, guint step,
WpObjectFeatures missing)
{
switch (step) {
case WP_PIPEWIRE_OBJECT_MIXIN_STEP_CACHE_INFO:
wp_pipewire_object_mixin_cache_info (object, transition);
break;
default:
WP_OBJECT_CLASS (wp_port_parent_class)->
activate_execute_step (object, transition, step, missing);
break;
}
}
static void
wp_port_deactivate (WpObject * object, WpObjectFeatures features)
{
wp_pipewire_object_mixin_deactivate (object, features);
WP_OBJECT_CLASS (wp_port_parent_class)->deactivate (object, features);
}
2019-06-10 15:07:54 -04:00
static void
port_event_info(void *data, const struct pw_port_info *info)
{
WpPort *self = WP_PORT (data);
self->info = pw_port_info_update (self->info, info);
wp_object_update_features (WP_OBJECT (self),
WP_PIPEWIRE_OBJECT_FEATURE_INFO, 0);
wp_pipewire_object_mixin_handle_event_info (self, info,
PW_PORT_CHANGE_MASK_PROPS, PW_PORT_CHANGE_MASK_PARAMS);
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,
.param = wp_pipewire_object_mixin_handle_event_param,
2019-06-10 15:07:54 -04:00
};
static void
wp_port_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
WpPort *self = WP_PORT (proxy);
2020-01-09 12:39:45 -05:00
pw_port_add_listener ((struct pw_port *) pw_proxy,
&self->listener, &port_events, self);
}
static void
wp_port_pw_proxy_destroyed (WpProxy * proxy)
{
g_clear_pointer (&WP_PORT (proxy)->info, pw_port_info_free);
wp_object_update_features (WP_OBJECT (proxy), 0,
WP_PIPEWIRE_OBJECT_FEATURE_INFO);
wp_pipewire_object_mixin_deactivate (WP_OBJECT (proxy),
WP_OBJECT_FEATURES_ALL);
}
2019-06-10 15:07:54 -04:00
static void
wp_port_class_init (WpPortClass * klass)
2019-06-10 15:07:54 -04:00
{
GObjectClass *object_class = (GObjectClass *) klass;
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
WpProxyClass *proxy_class = (WpProxyClass *) klass;
2019-06-10 15:07:54 -04:00
object_class->get_property = wp_pipewire_object_mixin_get_property;
wpobject_class->get_supported_features = wp_port_get_supported_features;
wpobject_class->activate_get_next_step =
wp_pipewire_object_mixin_activate_get_next_step;
wpobject_class->activate_execute_step = wp_port_activate_execute_step;
wpobject_class->deactivate = wp_port_deactivate;
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Port;
proxy_class->pw_iface_version = PW_VERSION_PORT;
proxy_class->pw_proxy_created = wp_port_pw_proxy_created;
proxy_class->pw_proxy_destroyed = wp_port_pw_proxy_destroyed;
wp_pipewire_object_mixin_class_override_properties (object_class);
}
static gconstpointer
wp_port_get_native_info (WpPipewireObject * obj)
{
return WP_PORT (obj)->info;
}
static WpProperties *
wp_port_get_properties (WpPipewireObject * obj)
{
return wp_properties_new_wrap_dict (WP_PORT (obj)->info->props);
}
static GVariant *
wp_port_get_param_info (WpPipewireObject * obj)
{
WpPort *self = WP_PORT (obj);
return wp_pipewire_object_mixin_param_info_to_gvariant (self->info->params,
self->info->n_params);
}
static void
wp_port_enum_params (WpPipewireObject * obj, const gchar * id,
WpSpaPod *filter, GCancellable * cancellable,
GAsyncReadyCallback callback, gpointer user_data)
{
wp_pipewire_object_mixin_enum_params (pw_port, obj, id, filter, cancellable,
callback, user_data);
}
static void
wp_port_pipewire_object_interface_init (WpPipewireObjectInterface * iface)
{
iface->get_native_info = wp_port_get_native_info;
iface->get_properties = wp_port_get_properties;
iface->get_param_info = wp_port_get_param_info;
iface->enum_params = wp_port_enum_params;
iface->enum_params_finish = wp_pipewire_object_mixin_enum_params_finish;
iface->enum_cached_params = wp_pipewire_object_mixin_enum_cached_params;
iface->set_param = wp_pipewire_object_mixin_set_param_unimplemented;
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_object_get_active_features (WP_OBJECT (self)) &
WP_PIPEWIRE_OBJECT_FEATURE_INFO, 0);
2020-04-21 17:08:10 +03:00
return (WpDirection) self->info->direction;
}