wp: remove WpSession and WpEndpointLink
We have ended up not using them, so let's not carry them in the ABI of 0.4 We can always revert that, but let's first decide how these objects should be used
This commit is contained in:
@@ -1,607 +0,0 @@
|
||||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2020 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION: endpoint-link
|
||||
* @title: PipeWire Endpoint Link
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "wp-endpoint-link"
|
||||
|
||||
#include "endpoint-link.h"
|
||||
#include "session.h"
|
||||
#include "log.h"
|
||||
#include "error.h"
|
||||
#include "wpenums.h"
|
||||
#include "private/pipewire-object-mixin.h"
|
||||
|
||||
#include <pipewire/extensions/session-manager.h>
|
||||
#include <pipewire/extensions/session-manager/introspect-funcs.h>
|
||||
|
||||
enum {
|
||||
SIGNAL_STATE_CHANGED,
|
||||
N_SIGNALS,
|
||||
};
|
||||
|
||||
static guint32 signals[N_SIGNALS] = {0};
|
||||
|
||||
static void wp_endpoint_link_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface);
|
||||
|
||||
/**
|
||||
* WpEndpointLink:
|
||||
*
|
||||
* The #WpEndpointLink class allows accessing the properties and methods of a
|
||||
* PipeWire endpoint link object (`struct pw_endpoint_link` from the
|
||||
* session-manager extension).
|
||||
*
|
||||
* A #WpEndpointLink is constructed internally when a new endpoint link appears
|
||||
* on the PipeWire registry and it is made available through the
|
||||
* #WpObjectManager API.
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_CODE (WpEndpointLink, wp_endpoint_link, WP_TYPE_GLOBAL_PROXY,
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_OBJECT,
|
||||
wp_pw_object_mixin_object_interface_init)
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
|
||||
wp_endpoint_link_pw_object_mixin_priv_interface_init));
|
||||
|
||||
static void
|
||||
wp_endpoint_link_init (WpEndpointLink * self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_activate_execute_step (WpObject * object,
|
||||
WpFeatureActivationTransition * transition, guint step,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
switch (step) {
|
||||
case WP_PW_OBJECT_MIXIN_STEP_BIND:
|
||||
case WP_TRANSITION_STEP_ERROR:
|
||||
/* base class can handle BIND and ERROR */
|
||||
WP_OBJECT_CLASS (wp_endpoint_link_parent_class)->
|
||||
activate_execute_step (object, transition, step, missing);
|
||||
break;
|
||||
case WP_PW_OBJECT_MIXIN_STEP_WAIT_INFO:
|
||||
/* just wait, info will be emitted anyway after binding */
|
||||
break;
|
||||
case WP_PW_OBJECT_MIXIN_STEP_CACHE_PARAMS:
|
||||
wp_pw_object_mixin_cache_params (object, missing);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_deactivate (WpObject * object, WpObjectFeatures features)
|
||||
{
|
||||
wp_pw_object_mixin_deactivate (object, features);
|
||||
WP_OBJECT_CLASS (wp_endpoint_link_parent_class)->deactivate (object, features);
|
||||
}
|
||||
|
||||
static const struct pw_endpoint_link_events endpoint_link_events = {
|
||||
PW_VERSION_ENDPOINT_LINK_EVENTS,
|
||||
.info = (HandleEventInfoFunc(endpoint_link)) wp_pw_object_mixin_handle_event_info,
|
||||
.param = wp_pw_object_mixin_handle_event_param,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_endpoint_link_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
||||
{
|
||||
wp_pw_object_mixin_handle_pw_proxy_created (proxy, pw_proxy,
|
||||
endpoint_link, &endpoint_link_events);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_pw_proxy_destroyed (WpProxy * proxy)
|
||||
{
|
||||
wp_pw_object_mixin_handle_pw_proxy_destroyed (proxy);
|
||||
|
||||
WP_PROXY_CLASS (wp_endpoint_link_parent_class)->pw_proxy_destroyed (proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_class_init (WpEndpointLinkClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
object_class->get_property = wp_pw_object_mixin_get_property;
|
||||
|
||||
wpobject_class->get_supported_features =
|
||||
wp_pw_object_mixin_get_supported_features;
|
||||
wpobject_class->activate_get_next_step =
|
||||
wp_pw_object_mixin_activate_get_next_step;
|
||||
wpobject_class->activate_execute_step =
|
||||
wp_endpoint_link_activate_execute_step;
|
||||
wpobject_class->deactivate = wp_endpoint_link_deactivate;
|
||||
|
||||
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_EndpointLink;
|
||||
proxy_class->pw_iface_version = PW_VERSION_ENDPOINT_LINK;
|
||||
proxy_class->pw_proxy_created = wp_endpoint_link_pw_proxy_created;
|
||||
proxy_class->pw_proxy_destroyed = wp_endpoint_link_pw_proxy_destroyed;
|
||||
|
||||
wp_pw_object_mixin_class_override_properties (object_class);
|
||||
|
||||
/**
|
||||
* WpEndpointLink::state-changed:
|
||||
* @self: the endpoint link
|
||||
* @old_state: the old state of the link
|
||||
* @new_state: the new state of the link
|
||||
* @error: (nullable): the error string if the new state is
|
||||
* %WP_ENDPOINT_LINK_STATE_ERROR
|
||||
*
|
||||
* Emitted when an endpoint link changes state
|
||||
*/
|
||||
signals[SIGNAL_STATE_CHANGED] = g_signal_new (
|
||||
"state-changed", G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 3,
|
||||
WP_TYPE_ENDPOINT_LINK_STATE, WP_TYPE_ENDPOINT_LINK_STATE, G_TYPE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_process_info (gpointer instance, gpointer old_info, gpointer i)
|
||||
{
|
||||
const struct pw_endpoint_link_info *info = i;
|
||||
|
||||
if (info->change_mask & PW_ENDPOINT_LINK_CHANGE_MASK_STATE) {
|
||||
WpEndpointLinkState old_state = old_info ?
|
||||
(WpEndpointLinkState) ((struct pw_endpoint_link_info *) old_info)->state
|
||||
: WP_ENDPOINT_LINK_STATE_ERROR;
|
||||
g_signal_emit (instance, signals[SIGNAL_STATE_CHANGED], 0,
|
||||
old_state, info->state, info->error);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
wp_endpoint_link_enum_params (gpointer instance, guint32 id,
|
||||
guint32 start, guint32 num, WpSpaPod *filter)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance);
|
||||
return pw_endpoint_link_enum_params (d->iface, 0, id, start, num,
|
||||
filter ? wp_spa_pod_get_spa_pod (filter) : NULL);
|
||||
}
|
||||
|
||||
static gint
|
||||
wp_endpoint_link_set_param (gpointer instance, guint32 id, guint32 flags,
|
||||
WpSpaPod * param)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance);
|
||||
return pw_endpoint_link_set_param (d->iface, id, flags,
|
||||
wp_spa_pod_get_spa_pod (param));
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface)
|
||||
{
|
||||
wp_pw_object_mixin_priv_interface_info_init (iface,
|
||||
endpoint_link, ENDPOINT_LINK);
|
||||
iface->process_info = wp_endpoint_link_process_info;
|
||||
iface->enum_params = wp_endpoint_link_enum_params;
|
||||
iface->set_param = wp_endpoint_link_set_param;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_endpoint_link_get_linked_object_ids:
|
||||
* @self: the endpoint link
|
||||
* @output_endpoint: (out) (optional): the bound id of the output (source)
|
||||
* endpoint
|
||||
* @input_endpoint: (out) (optional): the bound id of the input (sink)
|
||||
* endpoint
|
||||
*
|
||||
* Retrieves the ids of the objects that are linked by this endpoint link
|
||||
*
|
||||
* Note: Using this method requires %WP_PIPEWIRE_OBJECT_FEATURE_INFO
|
||||
*/
|
||||
void
|
||||
wp_endpoint_link_get_linked_object_ids (WpEndpointLink * self,
|
||||
guint32 * output_endpoint, guint32 * input_endpoint)
|
||||
{
|
||||
g_return_if_fail (WP_IS_ENDPOINT_LINK (self));
|
||||
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
struct pw_endpoint_link_info *info = d->info;
|
||||
g_return_if_fail (info);
|
||||
|
||||
if (output_endpoint)
|
||||
*output_endpoint = info->output_endpoint_id;
|
||||
if (input_endpoint)
|
||||
*input_endpoint = info->input_endpoint_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_endpoint_link_get_state:
|
||||
* @self: the endpoint link
|
||||
* @error: (out) (optional) (transfer none): the error string if the state is
|
||||
* %WP_ENDPOINT_LINK_STATE_ERROR
|
||||
*
|
||||
* Retrieves the current state of the link
|
||||
*
|
||||
* Note: Using this method requires %WP_PIPEWIRE_OBJECT_FEATURE_INFO
|
||||
* Returns: the current state of the link
|
||||
*/
|
||||
WpEndpointLinkState
|
||||
wp_endpoint_link_get_state (WpEndpointLink * self, const gchar ** error)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_ENDPOINT_LINK (self), WP_ENDPOINT_LINK_STATE_ERROR);
|
||||
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
struct pw_endpoint_link_info *info = d->info;
|
||||
g_return_val_if_fail (info, WP_ENDPOINT_LINK_STATE_ERROR);
|
||||
|
||||
if (error)
|
||||
*error = info->error;
|
||||
return (WpEndpointLinkState) info->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_endpoint_link_request_state:
|
||||
* @self: the endpoint link
|
||||
* @target: the desired target state of the link
|
||||
*
|
||||
* Requests a state change on the link
|
||||
*
|
||||
* Note: Using this method requires %WP_PROXY_FEATURE_BOUND
|
||||
*/
|
||||
void
|
||||
wp_endpoint_link_request_state (WpEndpointLink * self,
|
||||
WpEndpointLinkState target)
|
||||
{
|
||||
g_return_if_fail (WP_IS_ENDPOINT_LINK (self));
|
||||
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
g_return_if_fail (d->iface);
|
||||
|
||||
pw_endpoint_link_request_state (d->iface,
|
||||
(enum pw_endpoint_link_state) target);
|
||||
}
|
||||
|
||||
/* WpImplEndpointLink */
|
||||
|
||||
enum {
|
||||
IMPL_PROP_0,
|
||||
IMPL_PROP_ITEM,
|
||||
};
|
||||
|
||||
struct _WpImplEndpointLink
|
||||
{
|
||||
WpEndpointLink parent;
|
||||
|
||||
struct spa_interface iface;
|
||||
struct pw_endpoint_link_info info;
|
||||
WpProperties *immutable_props;
|
||||
|
||||
WpSiLink *item;
|
||||
};
|
||||
|
||||
static void wp_endpoint_link_impl_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (WpImplEndpointLink, wp_impl_endpoint_link, WP_TYPE_ENDPOINT_LINK,
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
|
||||
wp_endpoint_link_impl_pw_object_mixin_priv_interface_init))
|
||||
|
||||
static void
|
||||
on_item_activated (WpSessionItem * item, GAsyncResult * res, gpointer data)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (data);
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
if (!wp_object_activate_finish (WP_OBJECT (item), res, &error)) {
|
||||
wp_message_object (self, "failed to activate link: %s", error->message);
|
||||
self->info.error = g_strdup (error->message);
|
||||
/* on_si_link_flags_changed() will be called right after we return,
|
||||
taking care of the rest... */
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
impl_request_state (void *object, enum pw_endpoint_link_state state)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
int ret = 0;
|
||||
|
||||
if (state == self->info.state)
|
||||
return ret;
|
||||
|
||||
switch (state) {
|
||||
case PW_ENDPOINT_LINK_STATE_ACTIVE:
|
||||
wp_object_activate (WP_OBJECT (self->item),
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE, NULL,
|
||||
(GAsyncReadyCallback) on_item_activated, self);
|
||||
break;
|
||||
case PW_ENDPOINT_LINK_STATE_INACTIVE:
|
||||
wp_object_deactivate (WP_OBJECT (self->item),
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct pw_endpoint_link_methods impl_endpoint_link = {
|
||||
PW_VERSION_ENDPOINT_LINK_METHODS,
|
||||
.add_listener =
|
||||
(ImplAddListenerFunc(endpoint_link)) wp_pw_object_mixin_impl_add_listener,
|
||||
.subscribe_params = wp_pw_object_mixin_impl_subscribe_params,
|
||||
.enum_params = wp_pw_object_mixin_impl_enum_params,
|
||||
.set_param = wp_pw_object_mixin_impl_set_param,
|
||||
.request_state = impl_request_state,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_init (WpImplEndpointLink * self)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
|
||||
self->iface = SPA_INTERFACE_INIT (
|
||||
PW_TYPE_INTERFACE_EndpointLink,
|
||||
PW_VERSION_ENDPOINT_LINK,
|
||||
&impl_endpoint_link, self);
|
||||
|
||||
d->info = &self->info;
|
||||
d->iface = &self->iface;
|
||||
}
|
||||
|
||||
static void
|
||||
populate_properties (WpImplEndpointLink * self)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
|
||||
g_clear_pointer (&d->properties, wp_properties_unref);
|
||||
d->properties = wp_si_link_get_properties (self->item);
|
||||
if (!d->properties)
|
||||
d->properties = wp_properties_new_empty ();
|
||||
d->properties = wp_properties_ensure_unique_owner (d->properties);
|
||||
wp_properties_update (d->properties, self->immutable_props);
|
||||
|
||||
self->info.props = (struct spa_dict *) wp_properties_peek_dict (d->properties);
|
||||
}
|
||||
|
||||
static void
|
||||
on_si_link_properties_changed (WpSiLink * item, WpImplEndpointLink * self)
|
||||
{
|
||||
populate_properties (self);
|
||||
wp_pw_object_mixin_notify_info (self, PW_ENDPOINT_LINK_CHANGE_MASK_PROPS);
|
||||
}
|
||||
|
||||
static void
|
||||
on_si_link_features_changed (WpSiLink * item, GParamSpec * param,
|
||||
WpImplEndpointLink * self)
|
||||
{
|
||||
enum pw_endpoint_link_state old_state = self->info.state;
|
||||
guint features = wp_object_get_active_features (WP_OBJECT (item));
|
||||
|
||||
if (features & WP_SESSION_ITEM_FEATURE_ACTIVE)
|
||||
self->info.state = PW_ENDPOINT_LINK_STATE_ACTIVE;
|
||||
else
|
||||
self->info.state = PW_ENDPOINT_LINK_STATE_INACTIVE;
|
||||
|
||||
if (old_state != self->info.state) {
|
||||
wp_pw_object_mixin_notify_info (self, PW_ENDPOINT_LINK_CHANGE_MASK_STATE);
|
||||
g_signal_emit (self, signals[SIGNAL_STATE_CHANGED], 0,
|
||||
old_state, self->info.state, self->info.error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_constructed (GObject * object)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
g_autoptr (GVariant) info = NULL;
|
||||
g_autoptr (GVariantIter) immutable_props = NULL;
|
||||
const gchar *key, *value;
|
||||
g_autoptr (WpSiLinkable) si_out = NULL;
|
||||
g_autoptr (WpSiLinkable) si_in = NULL;
|
||||
|
||||
self->info.version = PW_VERSION_ENDPOINT_LINK_INFO;
|
||||
self->info.error = NULL;
|
||||
self->info.params = NULL;
|
||||
self->info.n_params = 0;
|
||||
|
||||
/* get info from the interface */
|
||||
info = wp_si_link_get_registration_info (self->item);
|
||||
g_variant_get (info, "a{ss}", &immutable_props);
|
||||
|
||||
/* get the current state */
|
||||
self->info.state =
|
||||
(wp_object_get_active_features (WP_OBJECT (self->item))
|
||||
& WP_SESSION_ITEM_FEATURE_ACTIVE)
|
||||
? PW_ENDPOINT_LINK_STATE_ACTIVE
|
||||
: PW_ENDPOINT_LINK_STATE_INACTIVE;
|
||||
|
||||
/* associate with the session and the endpoints */
|
||||
self->info.session_id = wp_session_item_get_associated_proxy_id (
|
||||
WP_SESSION_ITEM (self->item), WP_TYPE_SESSION);
|
||||
|
||||
si_out = wp_si_link_get_out_item (self->item);
|
||||
self->info.output_endpoint_id = wp_session_item_get_associated_proxy_id (
|
||||
WP_SESSION_ITEM (si_out), WP_TYPE_ENDPOINT);
|
||||
|
||||
si_in = wp_si_link_get_in_item (self->item);
|
||||
self->info.input_endpoint_id = wp_session_item_get_associated_proxy_id (
|
||||
WP_SESSION_ITEM (si_in), WP_TYPE_ENDPOINT);
|
||||
|
||||
/* construct export properties (these will come back through
|
||||
the registry and appear in wp_proxy_get_global_properties) */
|
||||
self->immutable_props = wp_properties_new_empty ();
|
||||
wp_properties_setf (self->immutable_props,
|
||||
PW_KEY_SESSION_ID, "%d", self->info.session_id);
|
||||
wp_properties_setf (self->immutable_props,
|
||||
PW_KEY_ENDPOINT_LINK_OUTPUT_ENDPOINT, "%d", self->info.output_endpoint_id);
|
||||
wp_properties_setf (self->immutable_props,
|
||||
PW_KEY_ENDPOINT_LINK_INPUT_ENDPOINT, "%d", self->info.input_endpoint_id);
|
||||
|
||||
/* populate immutable (global) properties */
|
||||
while (g_variant_iter_next (immutable_props, "{&s&s}", &key, &value))
|
||||
wp_properties_set (self->immutable_props, key, value);
|
||||
|
||||
/* populate standard properties */
|
||||
populate_properties (self);
|
||||
|
||||
/* subscribe to changes */
|
||||
g_signal_connect_object (self->item, "link-properties-changed",
|
||||
G_CALLBACK (on_si_link_properties_changed), self, 0);
|
||||
g_signal_connect_object (self->item, "notify::active-features",
|
||||
G_CALLBACK (on_si_link_features_changed), self, 0);
|
||||
|
||||
wp_object_update_features (WP_OBJECT (self),
|
||||
WP_PIPEWIRE_OBJECT_FEATURE_INFO, 0);
|
||||
|
||||
G_OBJECT_CLASS (wp_impl_endpoint_link_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_dispose (GObject * object)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
|
||||
g_clear_pointer (&self->immutable_props, wp_properties_unref);
|
||||
g_clear_pointer (&self->info.error, g_free);
|
||||
|
||||
wp_object_update_features (WP_OBJECT (self), 0,
|
||||
WP_PIPEWIRE_OBJECT_FEATURE_INFO);
|
||||
|
||||
G_OBJECT_CLASS (wp_impl_endpoint_link_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
|
||||
switch (property_id) {
|
||||
case IMPL_PROP_ITEM:
|
||||
self->item = g_value_get_object (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
|
||||
switch (property_id) {
|
||||
case IMPL_PROP_ITEM:
|
||||
g_value_set_object (value, self->item);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_activate_execute_step (WpObject * object,
|
||||
WpFeatureActivationTransition * transition, guint step,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
WpImplEndpointLink *self = WP_IMPL_ENDPOINT_LINK (object);
|
||||
|
||||
switch (step) {
|
||||
case WP_PW_OBJECT_MIXIN_STEP_BIND: {
|
||||
g_autoptr (WpCore) core = wp_object_get_core (object);
|
||||
struct pw_core *pw_core = wp_core_get_pw_core (core);
|
||||
|
||||
/* no pw_core -> we are not connected */
|
||||
if (!pw_core) {
|
||||
wp_transition_return_error (WP_TRANSITION (transition), g_error_new (
|
||||
WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
|
||||
"The WirePlumber core is not connected; "
|
||||
"object cannot be exported to PipeWire"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* bind */
|
||||
wp_proxy_watch_bind_error (WP_PROXY (self), WP_TRANSITION (transition));
|
||||
wp_proxy_set_pw_proxy (WP_PROXY (self), pw_core_export (pw_core,
|
||||
PW_TYPE_INTERFACE_EndpointLink,
|
||||
wp_properties_peek_dict (self->immutable_props),
|
||||
&self->iface, 0));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WP_OBJECT_CLASS (wp_impl_endpoint_link_parent_class)->
|
||||
activate_execute_step (object, transition, step, missing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_class_init (WpImplEndpointLinkClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
object_class->constructed = wp_impl_endpoint_link_constructed;
|
||||
object_class->dispose = wp_impl_endpoint_link_dispose;
|
||||
object_class->set_property = wp_impl_endpoint_link_set_property;
|
||||
object_class->get_property = wp_impl_endpoint_link_get_property;
|
||||
|
||||
wpobject_class->activate_execute_step =
|
||||
wp_impl_endpoint_link_activate_execute_step;
|
||||
|
||||
proxy_class->pw_proxy_created = NULL;
|
||||
proxy_class->pw_proxy_destroyed = NULL;
|
||||
|
||||
g_object_class_install_property (object_class, IMPL_PROP_ITEM,
|
||||
g_param_spec_object ("item", "item", "item", WP_TYPE_SI_LINK,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
#define pw_endpoint_link_emit(hooks,method,version,...) \
|
||||
spa_hook_list_call_simple(hooks, struct pw_endpoint_link_events, \
|
||||
method, version, ##__VA_ARGS__)
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_emit_info (struct spa_hook_list * hooks, gconstpointer info)
|
||||
{
|
||||
pw_endpoint_link_emit (hooks, info, 0, info);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_endpoint_link_emit_param (struct spa_hook_list * hooks, int seq,
|
||||
guint32 id, guint32 index, guint32 next, const struct spa_pod *param)
|
||||
{
|
||||
pw_endpoint_link_emit (hooks, param, 0, seq, id, index, next, param);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_impl_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface)
|
||||
{
|
||||
iface->flags |= WP_PW_OBJECT_MIXIN_PRIV_NO_PARAM_CACHE;
|
||||
iface->enum_params = NULL;
|
||||
iface->set_param = NULL;
|
||||
iface->emit_info = wp_impl_endpoint_link_emit_info;
|
||||
iface->emit_param = wp_impl_endpoint_link_emit_param;
|
||||
}
|
||||
|
||||
WpImplEndpointLink *
|
||||
wp_impl_endpoint_link_new (WpCore * core, WpSiLink * item)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
return g_object_new (WP_TYPE_IMPL_ENDPOINT_LINK,
|
||||
"core", core,
|
||||
"item", item,
|
||||
NULL);
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2020 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_ENDPOINT_LINK_H__
|
||||
#define __WIREPLUMBER_ENDPOINT_LINK_H__
|
||||
|
||||
#include "global-proxy.h"
|
||||
#include "si-interfaces.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* WpEndpointLinkState:
|
||||
* @WP_ENDPOINT_LINK_STATE_ERROR:
|
||||
* @WP_ENDPOINT_LINK_STATE_PREPARING:
|
||||
* @WP_ENDPOINT_LINK_STATE_INACTIVE:
|
||||
* @WP_ENDPOINT_LINK_STATE_ACTIVE:
|
||||
*/
|
||||
typedef enum {
|
||||
WP_ENDPOINT_LINK_STATE_ERROR = -1,
|
||||
WP_ENDPOINT_LINK_STATE_PREPARING,
|
||||
WP_ENDPOINT_LINK_STATE_INACTIVE,
|
||||
WP_ENDPOINT_LINK_STATE_ACTIVE,
|
||||
} WpEndpointLinkState;
|
||||
|
||||
/**
|
||||
* WP_TYPE_ENDPOINT_LINK:
|
||||
*
|
||||
* The #WpEndpointLink #GType
|
||||
*/
|
||||
#define WP_TYPE_ENDPOINT_LINK (wp_endpoint_link_get_type ())
|
||||
WP_API
|
||||
G_DECLARE_DERIVABLE_TYPE (WpEndpointLink, wp_endpoint_link,
|
||||
WP, ENDPOINT_LINK, WpGlobalProxy)
|
||||
|
||||
struct _WpEndpointLinkClass
|
||||
{
|
||||
WpGlobalProxyClass parent_class;
|
||||
};
|
||||
|
||||
WP_API
|
||||
void wp_endpoint_link_get_linked_object_ids (WpEndpointLink * self,
|
||||
guint32 * output_endpoint, guint32 * input_endpoint);
|
||||
|
||||
WP_API
|
||||
WpEndpointLinkState wp_endpoint_link_get_state (WpEndpointLink * self,
|
||||
const gchar ** error);
|
||||
|
||||
WP_API
|
||||
void wp_endpoint_link_request_state (WpEndpointLink * self,
|
||||
WpEndpointLinkState target);
|
||||
|
||||
/**
|
||||
* WP_TYPE_IMPL_ENDPOINT_LINK:
|
||||
*
|
||||
* The #WpImplEndpointLink #GType
|
||||
*/
|
||||
#define WP_TYPE_IMPL_ENDPOINT_LINK (wp_impl_endpoint_link_get_type ())
|
||||
WP_API
|
||||
G_DECLARE_FINAL_TYPE (WpImplEndpointLink, wp_impl_endpoint_link,
|
||||
WP, IMPL_ENDPOINT_LINK, WpEndpointLink)
|
||||
|
||||
WP_API
|
||||
WpImplEndpointLink * wp_impl_endpoint_link_new (WpCore * core, WpSiLink * item);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@@ -11,12 +11,10 @@
|
||||
* @title: PIpeWire Endpoint
|
||||
*/
|
||||
|
||||
#include "spa/param/param.h"
|
||||
#define G_LOG_DOMAIN "wp-endpoint"
|
||||
|
||||
#include "endpoint.h"
|
||||
#include "node.h"
|
||||
#include "session.h"
|
||||
#include "object-manager.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
@@ -342,117 +340,12 @@ static struct spa_param_info impl_param_info[] = {
|
||||
SPA_PARAM_INFO (SPA_PARAM_PropInfo, SPA_PARAM_INFO_READ)
|
||||
};
|
||||
|
||||
static void
|
||||
on_si_link_exported (WpSessionItem * link, GAsyncResult * res, gpointer data)
|
||||
{
|
||||
WpImplEndpoint *self = WP_IMPL_ENDPOINT (data);
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
if (!wp_object_activate_finish (WP_OBJECT (link), res, &error)) {
|
||||
wp_warning_object (self, "failed to export link: %s", error->message);
|
||||
g_object_unref (link);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
impl_create_link (void *object, const struct spa_dict *props)
|
||||
{
|
||||
WpImplEndpoint *self = WP_IMPL_ENDPOINT (object);
|
||||
const gchar *self_ep, *peer_ep;
|
||||
guint32 peer_ep_id;
|
||||
g_autoptr (WpSiEndpoint) peer_si_endpoint = NULL;
|
||||
g_autoptr (WpSession) session = NULL;
|
||||
g_autoptr (WpEndpoint) peer_ep_proxy = NULL;
|
||||
|
||||
/* find the session */
|
||||
session = wp_session_item_get_associated_proxy (
|
||||
WP_SESSION_ITEM (self->item), WP_TYPE_SESSION);
|
||||
g_return_val_if_fail (session, -ENAVAIL);
|
||||
|
||||
if (self->info.direction == PW_DIRECTION_OUTPUT) {
|
||||
self_ep = spa_dict_lookup (props, PW_KEY_ENDPOINT_LINK_OUTPUT_ENDPOINT);
|
||||
peer_ep = spa_dict_lookup (props, PW_KEY_ENDPOINT_LINK_INPUT_ENDPOINT);
|
||||
} else {
|
||||
self_ep = spa_dict_lookup (props, PW_KEY_ENDPOINT_LINK_INPUT_ENDPOINT);
|
||||
peer_ep = spa_dict_lookup (props, PW_KEY_ENDPOINT_LINK_OUTPUT_ENDPOINT);
|
||||
}
|
||||
|
||||
wp_debug_object (self, "requested link between %s [self] & %s [peer]",
|
||||
self_ep, peer_ep);
|
||||
|
||||
/* verify arguments */
|
||||
if (!peer_ep) {
|
||||
wp_warning_object (self,
|
||||
"a peer endpoint must be specified at the very least");
|
||||
/* not implemented */
|
||||
return -EINVAL;
|
||||
}
|
||||
if (self_ep && ((guint32) atoi (self_ep))
|
||||
!= wp_proxy_get_bound_id (WP_PROXY (self))) {
|
||||
wp_warning_object (self,
|
||||
"creating links for other endpoints is now allowed");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
/* convert to int */
|
||||
peer_ep_id = (guint32) atoi (peer_ep);
|
||||
|
||||
/* find the peer endpoint */
|
||||
peer_ep_proxy = wp_session_lookup_endpoint (session,
|
||||
WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=u", peer_ep_id, NULL);
|
||||
if (!peer_ep_proxy) {
|
||||
wp_warning_object (self, "endpoint %d not found in session", peer_ep_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
g_object_get (peer_ep_proxy, "item", &peer_si_endpoint, NULL);
|
||||
|
||||
wp_info_object (self, "creating endpoint link between "
|
||||
"%s " WP_OBJECT_FORMAT ", %s " WP_OBJECT_FORMAT,
|
||||
wp_endpoint_get_name (WP_ENDPOINT (self)),
|
||||
WP_OBJECT_ARGS (self->item),
|
||||
wp_endpoint_get_name (peer_ep_proxy),
|
||||
WP_OBJECT_ARGS (peer_si_endpoint));
|
||||
|
||||
/* create the link */
|
||||
{
|
||||
g_autoptr (WpSessionItem) link = NULL;
|
||||
g_autoptr (WpCore) core = NULL;
|
||||
WpProperties *props = NULL;
|
||||
WpSiEndpoint *out_endpoint, *in_endpoint;
|
||||
|
||||
core = wp_object_get_core (WP_OBJECT (self));
|
||||
link = wp_session_item_make (core, "si-standard-link");
|
||||
if (!link) {
|
||||
wp_warning_object (self, "si-standard-link factory is not available");
|
||||
return -ENAVAIL;
|
||||
}
|
||||
|
||||
if (self->info.direction == PW_DIRECTION_OUTPUT) {
|
||||
out_endpoint = self->item;
|
||||
in_endpoint = peer_si_endpoint;
|
||||
} else {
|
||||
out_endpoint = peer_si_endpoint;
|
||||
in_endpoint = self->item;
|
||||
}
|
||||
|
||||
props = wp_properties_new_empty ();
|
||||
wp_properties_setf (props, "out.item", "%p", out_endpoint);
|
||||
wp_properties_setf (props, "in.item", "%p", in_endpoint);
|
||||
wp_properties_setf (props, "session", "%p", session);
|
||||
wp_properties_setf (props, "manage.lifetime", "%u", TRUE);
|
||||
|
||||
if (G_UNLIKELY (!wp_session_item_configure (link, props))) {
|
||||
g_critical ("si-standard-link configuration failed");
|
||||
return -ENAVAIL;
|
||||
}
|
||||
|
||||
wp_object_activate (WP_OBJECT (link), WP_SESSION_ITEM_FEATURE_EXPORTED,
|
||||
NULL, (GAsyncReadyCallback) on_si_link_exported, self);
|
||||
link = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pw_endpoint_methods impl_endpoint = {
|
||||
PW_VERSION_ENDPOINT_METHODS,
|
||||
@@ -525,9 +418,8 @@ wp_impl_endpoint_constructed (GObject * object)
|
||||
|
||||
self->info.direction = (enum pw_direction) direction;
|
||||
|
||||
/* associate with the session */
|
||||
self->info.session_id = wp_session_item_get_associated_proxy_id (
|
||||
WP_SESSION_ITEM (self->item), WP_TYPE_SESSION);
|
||||
/* associate with the session (no session anymore, use -1) */
|
||||
self->info.session_id = SPA_ID_INVALID;
|
||||
|
||||
/* construct export properties (these will come back through
|
||||
the registry and appear in wp_proxy_get_global_properties) */
|
||||
|
@@ -5,7 +5,6 @@ wp_lib_sources = files(
|
||||
'core.c',
|
||||
'device.c',
|
||||
'endpoint.c',
|
||||
'endpoint-link.c',
|
||||
'error.c',
|
||||
'global-proxy.c',
|
||||
'iterator.c',
|
||||
@@ -21,7 +20,6 @@ wp_lib_sources = files(
|
||||
'properties.c',
|
||||
'proxy.c',
|
||||
'proxy-interfaces.c',
|
||||
'session.c',
|
||||
'session-item.c',
|
||||
'si-factory.c',
|
||||
'si-interfaces.c',
|
||||
@@ -39,7 +37,6 @@ wp_lib_headers = files(
|
||||
'defs.h',
|
||||
'device.h',
|
||||
'endpoint.h',
|
||||
'endpoint-link.h',
|
||||
'error.h',
|
||||
'global-proxy.h',
|
||||
'iterator.h',
|
||||
@@ -55,7 +52,6 @@ wp_lib_headers = files(
|
||||
'properties.h',
|
||||
'proxy.h',
|
||||
'proxy-interfaces.h',
|
||||
'session.h',
|
||||
'session-item.h',
|
||||
'si-factory.h',
|
||||
'si-interfaces.h',
|
||||
|
821
lib/wp/session.c
821
lib/wp/session.c
@@ -1,821 +0,0 @@
|
||||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019-2020 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION: session
|
||||
* @title: PipeWire Session
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "wp-session"
|
||||
|
||||
#include "session.h"
|
||||
#include "object-manager.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "wpenums.h"
|
||||
#include "private/pipewire-object-mixin.h"
|
||||
|
||||
#include <pipewire/extensions/session-manager.h>
|
||||
#include <pipewire/extensions/session-manager/introspect-funcs.h>
|
||||
|
||||
enum {
|
||||
SIGNAL_ENDPOINTS_CHANGED,
|
||||
SIGNAL_LINKS_CHANGED,
|
||||
N_SIGNALS,
|
||||
};
|
||||
|
||||
static guint32 signals[N_SIGNALS] = {0};
|
||||
|
||||
typedef struct _WpSessionPrivate WpSessionPrivate;
|
||||
struct _WpSessionPrivate
|
||||
{
|
||||
WpObjectManager *endpoints_om;
|
||||
WpObjectManager *links_om;
|
||||
};
|
||||
|
||||
static void wp_session_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface);
|
||||
|
||||
/**
|
||||
* WpSession:
|
||||
*
|
||||
* The #WpSession class allows accessing the properties and methods of a
|
||||
* PipeWire session object (`struct pw_session` from the session-manager
|
||||
* extension).
|
||||
*
|
||||
* A #WpSession is constructed internally when a new session appears on the
|
||||
* PipeWire registry and it is made available through the #WpObjectManager API.
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_CODE (WpSession, wp_session, WP_TYPE_GLOBAL_PROXY,
|
||||
G_ADD_PRIVATE (WpSession)
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_OBJECT,
|
||||
wp_pw_object_mixin_object_interface_init)
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
|
||||
wp_session_pw_object_mixin_priv_interface_init))
|
||||
|
||||
static void
|
||||
wp_session_init (WpSession * self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_on_endpoints_om_installed (WpObjectManager *endpoints_om,
|
||||
WpSession * self)
|
||||
{
|
||||
wp_object_update_features (WP_OBJECT (self), WP_SESSION_FEATURE_ENDPOINTS, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_emit_endpoints_changed (WpObjectManager *endpoints_om,
|
||||
WpSession * self)
|
||||
{
|
||||
g_signal_emit (self, signals[SIGNAL_ENDPOINTS_CHANGED], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_on_links_om_installed (WpObjectManager *links_om, WpSession * self)
|
||||
{
|
||||
wp_object_update_features (WP_OBJECT (self), WP_SESSION_FEATURE_LINKS, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_emit_links_changed (WpObjectManager *links_om, WpSession * self)
|
||||
{
|
||||
g_signal_emit (self, signals[SIGNAL_LINKS_CHANGED], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_enable_features_endpoints_links (WpSession * self,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
|
||||
guint32 bound_id = wp_proxy_get_bound_id (WP_PROXY (self));
|
||||
|
||||
if (missing & WP_SESSION_FEATURE_ENDPOINTS) {
|
||||
wp_debug_object (self, "enabling WP_SESSION_FEATURE_ENDPOINTS, bound_id:%u",
|
||||
bound_id);
|
||||
|
||||
priv->endpoints_om = wp_object_manager_new ();
|
||||
/* proxy endpoint -> check for session.id in global properties */
|
||||
wp_object_manager_add_interest (priv->endpoints_om,
|
||||
WP_TYPE_ENDPOINT,
|
||||
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, PW_KEY_SESSION_ID, "=u", bound_id,
|
||||
NULL);
|
||||
/* impl endpoint -> check for session.id in standard properties */
|
||||
wp_object_manager_add_interest (priv->endpoints_om,
|
||||
WP_TYPE_IMPL_ENDPOINT,
|
||||
WP_CONSTRAINT_TYPE_PW_PROPERTY, PW_KEY_SESSION_ID, "=u", bound_id,
|
||||
NULL);
|
||||
|
||||
wp_object_manager_request_object_features (priv->endpoints_om,
|
||||
WP_TYPE_ENDPOINT, WP_OBJECT_FEATURES_ALL);
|
||||
|
||||
g_signal_connect_object (priv->endpoints_om, "installed",
|
||||
G_CALLBACK (wp_session_on_endpoints_om_installed), self, 0);
|
||||
g_signal_connect_object (priv->endpoints_om, "objects-changed",
|
||||
G_CALLBACK (wp_session_emit_endpoints_changed), self, 0);
|
||||
|
||||
wp_core_install_object_manager (core, priv->endpoints_om);
|
||||
}
|
||||
|
||||
if (missing & WP_SESSION_FEATURE_LINKS) {
|
||||
wp_debug_object (self, "enabling WP_SESSION_FEATURE_LINKS, bound_id:%u",
|
||||
bound_id);
|
||||
|
||||
priv->links_om = wp_object_manager_new ();
|
||||
/* proxy link -> check for session.id in global properties */
|
||||
wp_object_manager_add_interest (priv->links_om,
|
||||
WP_TYPE_ENDPOINT_LINK,
|
||||
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, PW_KEY_SESSION_ID, "=u", bound_id,
|
||||
NULL);
|
||||
/* impl link -> check for session.id in standard properties */
|
||||
wp_object_manager_add_interest (priv->links_om,
|
||||
WP_TYPE_IMPL_ENDPOINT_LINK,
|
||||
WP_CONSTRAINT_TYPE_PW_PROPERTY, PW_KEY_SESSION_ID, "=u", bound_id,
|
||||
NULL);
|
||||
|
||||
wp_object_manager_request_object_features (priv->links_om,
|
||||
WP_TYPE_ENDPOINT_LINK, WP_OBJECT_FEATURES_ALL);
|
||||
|
||||
g_signal_connect_object (priv->links_om, "installed",
|
||||
G_CALLBACK (wp_session_on_links_om_installed), self, 0);
|
||||
g_signal_connect_object (priv->links_om, "objects-changed",
|
||||
G_CALLBACK (wp_session_emit_links_changed), self, 0);
|
||||
|
||||
wp_core_install_object_manager (core, priv->links_om);
|
||||
}
|
||||
}
|
||||
|
||||
static WpObjectFeatures
|
||||
wp_session_get_supported_features (WpObject * object)
|
||||
{
|
||||
return wp_pw_object_mixin_get_supported_features(object)
|
||||
| WP_SESSION_FEATURE_ENDPOINTS
|
||||
| WP_SESSION_FEATURE_LINKS;
|
||||
}
|
||||
|
||||
enum {
|
||||
STEP_CHILDREN = WP_PW_OBJECT_MIXIN_STEP_CUSTOM_START,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_session_activate_execute_step (WpObject * object,
|
||||
WpFeatureActivationTransition * transition, guint step,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
switch (step) {
|
||||
case WP_PW_OBJECT_MIXIN_STEP_BIND:
|
||||
case WP_TRANSITION_STEP_ERROR:
|
||||
/* base class can handle BIND and ERROR */
|
||||
WP_OBJECT_CLASS (wp_session_parent_class)->
|
||||
activate_execute_step (object, transition, step, missing);
|
||||
break;
|
||||
case WP_PW_OBJECT_MIXIN_STEP_WAIT_INFO:
|
||||
/* just wait, info will be emitted anyway after binding */
|
||||
break;
|
||||
case WP_PW_OBJECT_MIXIN_STEP_CACHE_PARAMS:
|
||||
wp_pw_object_mixin_cache_params (object, missing);
|
||||
break;
|
||||
case STEP_CHILDREN:
|
||||
wp_session_enable_features_endpoints_links (WP_SESSION (object),
|
||||
missing);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_deactivate (WpObject * object, WpObjectFeatures features)
|
||||
{
|
||||
WpSession *self = WP_SESSION (object);
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
|
||||
wp_pw_object_mixin_deactivate (object, features);
|
||||
|
||||
if (features & WP_SESSION_FEATURE_ENDPOINTS) {
|
||||
g_clear_object (&priv->endpoints_om);
|
||||
wp_object_update_features (object, 0, WP_SESSION_FEATURE_ENDPOINTS);
|
||||
}
|
||||
if (features & WP_SESSION_FEATURE_LINKS) {
|
||||
g_clear_object (&priv->links_om);
|
||||
wp_object_update_features (object, 0, WP_SESSION_FEATURE_LINKS);
|
||||
}
|
||||
|
||||
WP_OBJECT_CLASS (wp_session_parent_class)->deactivate (object, features);
|
||||
}
|
||||
|
||||
static const struct pw_session_events session_events = {
|
||||
PW_VERSION_SESSION_EVENTS,
|
||||
.info = (HandleEventInfoFunc(session)) wp_pw_object_mixin_handle_event_info,
|
||||
.param = wp_pw_object_mixin_handle_event_param,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_session_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
|
||||
{
|
||||
wp_pw_object_mixin_handle_pw_proxy_created (proxy, pw_proxy,
|
||||
session, &session_events);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_pw_proxy_destroyed (WpProxy * proxy)
|
||||
{
|
||||
WpSession *self = WP_SESSION (proxy);
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
|
||||
wp_pw_object_mixin_handle_pw_proxy_destroyed (proxy);
|
||||
|
||||
g_clear_object (&priv->endpoints_om);
|
||||
g_clear_object (&priv->links_om);
|
||||
wp_object_update_features (WP_OBJECT (self), 0,
|
||||
WP_SESSION_FEATURE_ENDPOINTS |
|
||||
WP_SESSION_FEATURE_LINKS);
|
||||
|
||||
WP_PROXY_CLASS (wp_session_parent_class)->pw_proxy_destroyed (proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_class_init (WpSessionClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
object_class->get_property = wp_pw_object_mixin_get_property;
|
||||
|
||||
wpobject_class->get_supported_features = wp_session_get_supported_features;
|
||||
wpobject_class->activate_get_next_step =
|
||||
wp_pw_object_mixin_activate_get_next_step;
|
||||
wpobject_class->activate_execute_step = wp_session_activate_execute_step;
|
||||
wpobject_class->deactivate = wp_session_deactivate;
|
||||
|
||||
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Session;
|
||||
proxy_class->pw_iface_version = PW_VERSION_SESSION;
|
||||
proxy_class->pw_proxy_created = wp_session_pw_proxy_created;
|
||||
proxy_class->pw_proxy_destroyed = wp_session_pw_proxy_destroyed;
|
||||
|
||||
wp_pw_object_mixin_class_override_properties (object_class);
|
||||
|
||||
/**
|
||||
* WpSession::endpoints-changed:
|
||||
* @self: the session
|
||||
*
|
||||
* Emitted when the sessions's endpoints change. This is only emitted
|
||||
* when %WP_SESSION_FEATURE_ENDPOINTS is enabled.
|
||||
*/
|
||||
signals[SIGNAL_ENDPOINTS_CHANGED] = g_signal_new (
|
||||
"endpoints-changed", G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
|
||||
|
||||
/**
|
||||
* WpSession::links-changed:
|
||||
* @self: the session
|
||||
*
|
||||
* Emitted when the session's links change. This is only emitted
|
||||
* when %WP_SESSION_FEATURE_LINKS is enabled.
|
||||
*/
|
||||
signals[SIGNAL_LINKS_CHANGED] = g_signal_new (
|
||||
"links-changed", G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static gint
|
||||
wp_session_enum_params (gpointer instance, guint32 id,
|
||||
guint32 start, guint32 num, WpSpaPod *filter)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance);
|
||||
return pw_session_enum_params (d->iface, 0, id, start, num,
|
||||
filter ? wp_spa_pod_get_spa_pod (filter) : NULL);
|
||||
}
|
||||
|
||||
static gint
|
||||
wp_session_set_param (gpointer instance, guint32 id, guint32 flags,
|
||||
WpSpaPod * param)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance);
|
||||
return pw_session_set_param (d->iface, id, flags,
|
||||
wp_spa_pod_get_spa_pod (param));
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface)
|
||||
{
|
||||
wp_pw_object_mixin_priv_interface_info_init (iface, session, SESSION);
|
||||
iface->enum_params = wp_session_enum_params;
|
||||
iface->set_param = wp_session_set_param;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_get_name:
|
||||
* @self: the session
|
||||
*
|
||||
* Requires %WP_PIPEWIRE_OBJECT_FEATURE_INFO
|
||||
*
|
||||
* Returns: (transfer none): the (unique) name of the session
|
||||
*/
|
||||
const gchar *
|
||||
wp_session_get_name (WpSession * self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_PIPEWIRE_OBJECT_FEATURE_INFO, NULL);
|
||||
|
||||
return wp_pipewire_object_get_property (WP_PIPEWIRE_OBJECT (self),
|
||||
"session.name");
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_get_n_endpoints:
|
||||
* @self: the session
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* Returns: the number of endpoints of this session
|
||||
*/
|
||||
guint
|
||||
wp_session_get_n_endpoints (WpSession * self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), 0);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_ENDPOINTS, 0);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_get_n_objects (priv->endpoints_om);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_endpoints_iterator:
|
||||
* @self: the session
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the endpoints that belong to this session
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_endpoints_iterator (WpSession * self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_ENDPOINTS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_new_iterator (priv->endpoints_om);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_endpoints_filtered_iterator:
|
||||
* @self: the session
|
||||
* @...: a list of constraints, terminated by %NULL
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* The constraints specified in the variable arguments must follow the rules
|
||||
* documented in wp_object_interest_new().
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the endpoints that belong to this session and match the constraints
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_endpoints_filtered_iterator (WpSession * self, ...)
|
||||
{
|
||||
WpObjectInterest *interest;
|
||||
va_list args;
|
||||
va_start (args, self);
|
||||
interest = wp_object_interest_new_valist (WP_TYPE_ENDPOINT, &args);
|
||||
va_end (args);
|
||||
return wp_session_new_endpoints_filtered_iterator_full (self, interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_endpoints_filtered_iterator_full: (rename-to wp_session_new_endpoints_filtered_iterator)
|
||||
* @self: the session
|
||||
* @interest: (transfer full): the interest
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the endpoints that belong to this session and match the @interest
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_endpoints_filtered_iterator_full (WpSession * self,
|
||||
WpObjectInterest * interest)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_ENDPOINTS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_new_filtered_iterator_full (priv->endpoints_om,
|
||||
interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_lookup_endpoint:
|
||||
* @self: the session
|
||||
* @...: a list of constraints, terminated by %NULL
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* The constraints specified in the variable arguments must follow the rules
|
||||
* documented in wp_object_interest_new().
|
||||
*
|
||||
* Returns: (transfer full) (nullable): the first endpoint that matches the
|
||||
* constraints, or %NULL if there is no such endpoint
|
||||
*/
|
||||
WpEndpoint *
|
||||
wp_session_lookup_endpoint (WpSession * self, ...)
|
||||
{
|
||||
WpObjectInterest *interest;
|
||||
va_list args;
|
||||
va_start (args, self);
|
||||
interest = wp_object_interest_new_valist (WP_TYPE_ENDPOINT, &args);
|
||||
va_end (args);
|
||||
return wp_session_lookup_endpoint_full (self, interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_lookup_endpoint_full: (rename-to wp_session_lookup_endpoint)
|
||||
* @self: the session
|
||||
* @interest: (transfer full): the interest
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_ENDPOINTS
|
||||
*
|
||||
* Returns: (transfer full) (nullable): the first endpoint that matches the
|
||||
* @interest, or %NULL if there is no such endpoint
|
||||
*/
|
||||
WpEndpoint *
|
||||
wp_session_lookup_endpoint_full (WpSession * self, WpObjectInterest * interest)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_ENDPOINTS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return (WpEndpoint *)
|
||||
wp_object_manager_lookup_full (priv->endpoints_om, interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_get_n_links:
|
||||
* @self: the session
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* Returns: the number of endpoint links of this session
|
||||
*/
|
||||
guint
|
||||
wp_session_get_n_links (WpSession * self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), 0);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_LINKS, 0);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_get_n_objects (priv->links_om);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_links_iterator:
|
||||
* @self: the session
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the endpoint links that belong to this session
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_links_iterator (WpSession * self)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_LINKS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_new_iterator (priv->links_om);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_links_filtered_iterator:
|
||||
* @self: the session
|
||||
* @...: a list of constraints, terminated by %NULL
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* The constraints specified in the variable arguments must follow the rules
|
||||
* documented in wp_object_interest_new().
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the links that belong to this session and match the constraints
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_links_filtered_iterator (WpSession * self, ...)
|
||||
{
|
||||
WpObjectInterest *interest;
|
||||
va_list args;
|
||||
va_start (args, self);
|
||||
interest = wp_object_interest_new_valist (WP_TYPE_ENDPOINT_LINK, &args);
|
||||
va_end (args);
|
||||
return wp_session_new_links_filtered_iterator_full (self, interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_new_links_filtered_iterator_full: (rename-to wp_session_new_links_filtered_iterator)
|
||||
* @self: the session
|
||||
* @interest: (transfer full): the interest
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* Returns: (transfer full): a #WpIterator that iterates over all
|
||||
* the links that belong to this session and match the @interest
|
||||
*/
|
||||
WpIterator *
|
||||
wp_session_new_links_filtered_iterator_full (WpSession * self,
|
||||
WpObjectInterest * interest)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_LINKS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return wp_object_manager_new_filtered_iterator_full (priv->links_om,
|
||||
interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_lookup_link:
|
||||
* @self: the session
|
||||
* @...: a list of constraints, terminated by %NULL
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* The constraints specified in the variable arguments must follow the rules
|
||||
* documented in wp_object_interest_new().
|
||||
*
|
||||
* Returns: (transfer full) (nullable): the first link that matches the
|
||||
* constraints, or %NULL if there is no such link
|
||||
*/
|
||||
WpEndpointLink *
|
||||
wp_session_lookup_link (WpSession * self, ...)
|
||||
{
|
||||
WpObjectInterest *interest;
|
||||
va_list args;
|
||||
va_start (args, self);
|
||||
interest = wp_object_interest_new_valist (WP_TYPE_ENDPOINT_LINK, &args);
|
||||
va_end (args);
|
||||
return wp_session_lookup_link_full (self, interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_session_lookup_link_full: (rename-to wp_session_lookup_link)
|
||||
* @self: the session
|
||||
* @interest: (transfer full): the interest
|
||||
*
|
||||
* Requires %WP_SESSION_FEATURE_LINKS
|
||||
*
|
||||
* Returns: (transfer full) (nullable): the first link that matches the
|
||||
* @interest, or %NULL if there is no such link
|
||||
*/
|
||||
WpEndpointLink *
|
||||
wp_session_lookup_link_full (WpSession * self, WpObjectInterest * interest)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
|
||||
g_return_val_if_fail (wp_object_get_active_features (WP_OBJECT (self)) &
|
||||
WP_SESSION_FEATURE_LINKS, NULL);
|
||||
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (self);
|
||||
return (WpEndpointLink *)
|
||||
wp_object_manager_lookup_full (priv->links_om, interest);
|
||||
}
|
||||
|
||||
/* WpImplSession */
|
||||
|
||||
typedef struct _WpImplSession WpImplSession;
|
||||
struct _WpImplSession
|
||||
{
|
||||
WpSession parent;
|
||||
|
||||
struct spa_interface iface;
|
||||
struct pw_session_info info;
|
||||
};
|
||||
|
||||
|
||||
static void wp_session_impl_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface);
|
||||
|
||||
/**
|
||||
* WpImplSession:
|
||||
*
|
||||
* A #WpImplSession allows implementing a session and exporting it to PipeWire.
|
||||
* To export a #WpImplSession, activate %WP_PROXY_FEATURE_BOUND.
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_CODE (WpImplSession, wp_impl_session, WP_TYPE_SESSION,
|
||||
G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
|
||||
wp_session_impl_pw_object_mixin_priv_interface_init))
|
||||
|
||||
static const struct pw_session_methods impl_session = {
|
||||
PW_VERSION_SESSION_METHODS,
|
||||
.add_listener =
|
||||
(ImplAddListenerFunc(session)) wp_pw_object_mixin_impl_add_listener,
|
||||
.subscribe_params = wp_pw_object_mixin_impl_subscribe_params,
|
||||
.enum_params = wp_pw_object_mixin_impl_enum_params,
|
||||
.set_param = wp_pw_object_mixin_impl_set_param,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_impl_session_init (WpImplSession * self)
|
||||
{
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
|
||||
self->iface = SPA_INTERFACE_INIT (
|
||||
PW_TYPE_INTERFACE_Session,
|
||||
PW_VERSION_SESSION,
|
||||
&impl_session, self);
|
||||
|
||||
d->info = &self->info;
|
||||
d->iface = &self->iface;
|
||||
|
||||
/* prepare INFO */
|
||||
d->properties = wp_properties_new_empty ();
|
||||
self->info.version = PW_VERSION_SESSION_INFO;
|
||||
self->info.props = (struct spa_dict *) wp_properties_peek_dict (d->properties);
|
||||
self->info.params = NULL;
|
||||
self->info.n_params = 0;
|
||||
|
||||
wp_object_update_features (WP_OBJECT (self),
|
||||
WP_PIPEWIRE_OBJECT_FEATURE_INFO, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_session_dispose (GObject * object)
|
||||
{
|
||||
wp_object_update_features (WP_OBJECT (object), 0,
|
||||
WP_PIPEWIRE_OBJECT_FEATURE_INFO);
|
||||
|
||||
G_OBJECT_CLASS (wp_impl_session_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_session_activate_execute_step (WpObject * object,
|
||||
WpFeatureActivationTransition * transition, guint step,
|
||||
WpObjectFeatures missing)
|
||||
{
|
||||
WpImplSession *self = WP_IMPL_SESSION (object);
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
|
||||
switch (step) {
|
||||
case WP_PW_OBJECT_MIXIN_STEP_BIND: {
|
||||
g_autoptr (WpCore) core = wp_object_get_core (object);
|
||||
struct pw_core *pw_core = wp_core_get_pw_core (core);
|
||||
|
||||
/* no pw_core -> we are not connected */
|
||||
if (!pw_core) {
|
||||
wp_transition_return_error (WP_TRANSITION (transition), g_error_new (
|
||||
WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
|
||||
"The WirePlumber core is not connected; "
|
||||
"object cannot be exported to PipeWire"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* make sure these props are not present; they are added by the server */
|
||||
wp_properties_set (d->properties, PW_KEY_OBJECT_ID, NULL);
|
||||
wp_properties_set (d->properties, PW_KEY_CLIENT_ID, NULL);
|
||||
wp_properties_set (d->properties, PW_KEY_FACTORY_ID, NULL);
|
||||
|
||||
wp_proxy_watch_bind_error (WP_PROXY (self), WP_TRANSITION (transition));
|
||||
wp_proxy_set_pw_proxy (WP_PROXY (self), pw_core_export (pw_core,
|
||||
PW_TYPE_INTERFACE_Session,
|
||||
wp_properties_peek_dict (d->properties),
|
||||
&self->iface, 0));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WP_OBJECT_CLASS (wp_impl_session_parent_class)->
|
||||
activate_execute_step (object, transition, step, missing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_session_pw_proxy_destroyed (WpProxy * proxy)
|
||||
{
|
||||
WpImplSession *self = WP_IMPL_SESSION (proxy);
|
||||
WpSessionPrivate *priv = wp_session_get_instance_private (WP_SESSION (self));
|
||||
|
||||
g_clear_object (&priv->endpoints_om);
|
||||
g_clear_object (&priv->links_om);
|
||||
wp_object_update_features (WP_OBJECT (self), 0,
|
||||
WP_SESSION_FEATURE_ENDPOINTS |
|
||||
WP_SESSION_FEATURE_LINKS);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_session_class_init (WpImplSessionClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpObjectClass *wpobject_class = (WpObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
object_class->dispose = wp_impl_session_dispose;
|
||||
|
||||
wpobject_class->activate_execute_step = wp_impl_session_activate_execute_step;
|
||||
|
||||
proxy_class->pw_proxy_created = NULL;
|
||||
proxy_class->pw_proxy_destroyed = wp_impl_session_pw_proxy_destroyed;
|
||||
}
|
||||
|
||||
#define pw_session_emit(hooks,method,version,...) \
|
||||
spa_hook_list_call_simple(hooks, struct pw_session_events, \
|
||||
method, version, ##__VA_ARGS__)
|
||||
|
||||
static void
|
||||
wp_impl_session_emit_info (struct spa_hook_list * hooks, gconstpointer info)
|
||||
{
|
||||
pw_session_emit (hooks, info, 0, info);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_impl_session_emit_param (struct spa_hook_list * hooks, int seq,
|
||||
guint32 id, guint32 index, guint32 next, const struct spa_pod *param)
|
||||
{
|
||||
pw_session_emit (hooks, param, 0, seq, id, index, next, param);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_session_impl_pw_object_mixin_priv_interface_init (
|
||||
WpPwObjectMixinPrivInterface * iface)
|
||||
{
|
||||
iface->flags |= WP_PW_OBJECT_MIXIN_PRIV_NO_PARAM_CACHE;
|
||||
iface->emit_info = wp_impl_session_emit_info;
|
||||
iface->emit_param = wp_impl_session_emit_param;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_impl_session_new:
|
||||
* @core: the #WpCore
|
||||
*
|
||||
* Returns: (transfer full): the newly constructed session implementation
|
||||
*/
|
||||
WpImplSession *
|
||||
wp_impl_session_new (WpCore * core)
|
||||
{
|
||||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
return g_object_new (WP_TYPE_IMPL_SESSION,
|
||||
"core", core,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_impl_session_set_property:
|
||||
* @self: the session implementation
|
||||
* @key: a property key
|
||||
* @value: a property value
|
||||
*
|
||||
* Sets the specified property on the PipeWire properties of the session.
|
||||
*
|
||||
* If this property is set before exporting the session, then it is also used
|
||||
* in the construction process of the session object and appears as a global
|
||||
* property.
|
||||
*/
|
||||
void
|
||||
wp_impl_session_set_property (WpImplSession * self,
|
||||
const gchar * key, const gchar * value)
|
||||
{
|
||||
g_return_if_fail (WP_IS_IMPL_SESSION (self));
|
||||
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
wp_properties_set (d->properties, key, value);
|
||||
wp_pw_object_mixin_notify_info (self, PW_SESSION_CHANGE_MASK_PROPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_impl_session_update_properties:
|
||||
* @self: the session implementation
|
||||
* @updates: a set of properties to add or update in the session's properties
|
||||
*
|
||||
* Adds or updates the values of the PipeWire properties of the session
|
||||
* using the properties in @updates as a source.
|
||||
*
|
||||
* If the properties are set before exporting the session, then they are also
|
||||
* used in the construction process of the session object and appear as
|
||||
* global properties.
|
||||
*/
|
||||
void
|
||||
wp_impl_session_update_properties (WpImplSession * self,
|
||||
WpProperties * updates)
|
||||
{
|
||||
g_return_if_fail (WP_IS_IMPL_SESSION (self));
|
||||
|
||||
WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
|
||||
wp_properties_update (d->properties, updates);
|
||||
wp_pw_object_mixin_notify_info (self, PW_SESSION_CHANGE_MASK_PROPS);
|
||||
}
|
121
lib/wp/session.h
121
lib/wp/session.h
@@ -1,121 +0,0 @@
|
||||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_SESSION_H__
|
||||
#define __WIREPLUMBER_SESSION_H__
|
||||
|
||||
#include "global-proxy.h"
|
||||
#include "endpoint.h"
|
||||
#include "endpoint-link.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* WpSessionFeatures:
|
||||
* @WP_SESSION_FEATURE_ENDPOINTS: caches information about endpoints, enabling
|
||||
* the use of wp_session_get_n_endpoints(), wp_session_lookup_endpoint(),
|
||||
* wp_session_new_endpoints_iterator() and related methods
|
||||
* @WP_SESSION_FEATURE_LINKS: caches information about endpoint links, enabling
|
||||
* the use of wp_session_get_n_links(), wp_session_lookup_link(),
|
||||
* wp_session_new_links_iterator() and related methods
|
||||
*
|
||||
* An extension of #WpProxyFeatures
|
||||
*/
|
||||
typedef enum { /*< flags >*/
|
||||
WP_SESSION_FEATURE_ENDPOINTS = (WP_PROXY_FEATURE_CUSTOM_START << 0),
|
||||
WP_SESSION_FEATURE_LINKS = (WP_PROXY_FEATURE_CUSTOM_START << 1),
|
||||
} WpSessionFeatures;
|
||||
|
||||
/**
|
||||
* WP_TYPE_SESSION:
|
||||
*
|
||||
* The #WpSession #GType
|
||||
*/
|
||||
#define WP_TYPE_SESSION (wp_session_get_type ())
|
||||
WP_API
|
||||
G_DECLARE_DERIVABLE_TYPE (WpSession, wp_session, WP, SESSION, WpGlobalProxy)
|
||||
|
||||
struct _WpSessionClass
|
||||
{
|
||||
WpGlobalProxyClass parent_class;
|
||||
};
|
||||
|
||||
WP_API
|
||||
const gchar * wp_session_get_name (WpSession * self);
|
||||
|
||||
/* endpoints */
|
||||
|
||||
WP_API
|
||||
guint wp_session_get_n_endpoints (WpSession * self);
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_endpoints_iterator (WpSession * self);
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_endpoints_filtered_iterator (WpSession * self, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_endpoints_filtered_iterator_full (WpSession * self,
|
||||
WpObjectInterest * interest);
|
||||
|
||||
WP_API
|
||||
WpEndpoint * wp_session_lookup_endpoint (WpSession * self, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpEndpoint * wp_session_lookup_endpoint_full (WpSession * self,
|
||||
WpObjectInterest * interest);
|
||||
|
||||
/* links */
|
||||
|
||||
WP_API
|
||||
guint wp_session_get_n_links (WpSession * self);
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_links_iterator (WpSession * self);
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_links_filtered_iterator (WpSession * self, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpIterator * wp_session_new_links_filtered_iterator_full (WpSession * self,
|
||||
WpObjectInterest * interest);
|
||||
|
||||
WP_API
|
||||
WpEndpointLink * wp_session_lookup_link (WpSession * self, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpEndpointLink * wp_session_lookup_link_full (WpSession * self,
|
||||
WpObjectInterest * interest);
|
||||
|
||||
/**
|
||||
* WP_TYPE_IMPL_SESSION:
|
||||
*
|
||||
* The #WpImplSession #GType
|
||||
*/
|
||||
#define WP_TYPE_IMPL_SESSION (wp_impl_session_get_type ())
|
||||
WP_API
|
||||
G_DECLARE_FINAL_TYPE (WpImplSession, wp_impl_session, WP, IMPL_SESSION, WpSession)
|
||||
|
||||
WP_API
|
||||
WpImplSession * wp_impl_session_new (WpCore * core);
|
||||
|
||||
WP_API
|
||||
void wp_impl_session_set_property (WpImplSession * self,
|
||||
const gchar * key, const gchar * value);
|
||||
|
||||
WP_API
|
||||
void wp_impl_session_update_properties (WpImplSession * self,
|
||||
WpProperties * updates);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@@ -72,12 +72,10 @@ wp_init (WpInitFlags flags)
|
||||
g_type_ensure (WP_TYPE_CLIENT);
|
||||
g_type_ensure (WP_TYPE_DEVICE);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT_LINK);
|
||||
g_type_ensure (WP_TYPE_LINK);
|
||||
g_type_ensure (WP_TYPE_METADATA);
|
||||
g_type_ensure (WP_TYPE_NODE);
|
||||
g_type_ensure (WP_TYPE_PORT);
|
||||
g_type_ensure (WP_TYPE_SESSION);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#include "core.h"
|
||||
#include "device.h"
|
||||
#include "endpoint.h"
|
||||
#include "endpoint-link.h"
|
||||
#include "error.h"
|
||||
#include "global-proxy.h"
|
||||
#include "iterator.h"
|
||||
@@ -30,7 +29,6 @@
|
||||
#include "properties.h"
|
||||
#include "proxy.h"
|
||||
#include "proxy-interfaces.h"
|
||||
#include "session.h"
|
||||
#include "session-item.h"
|
||||
#include "si-factory.h"
|
||||
#include "si-interfaces.h"
|
||||
|
@@ -752,95 +752,6 @@ static const luaL_Reg metadata_methods[] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* WpSession */
|
||||
|
||||
static int
|
||||
session_iterate_endpoints (lua_State *L)
|
||||
{
|
||||
WpSession *session = wplua_checkobject (L, 1, WP_TYPE_SESSION);
|
||||
WpObjectInterest *oi = get_optional_object_interest (L, 2, WP_TYPE_ENDPOINT);
|
||||
WpIterator *it = oi ?
|
||||
wp_session_new_endpoints_filtered_iterator_full (session,
|
||||
wp_object_interest_ref (oi)) :
|
||||
wp_session_new_endpoints_iterator (session);
|
||||
return push_wpiterator (L, it);
|
||||
}
|
||||
|
||||
static int
|
||||
session_lookup_endpoint (lua_State *L)
|
||||
{
|
||||
WpSession *session = wplua_checkobject (L, 1, WP_TYPE_SESSION);
|
||||
WpObjectInterest *oi = get_optional_object_interest (L, 2, WP_TYPE_ENDPOINT);
|
||||
WpEndpoint *ep = oi ?
|
||||
wp_session_lookup_endpoint_full (session, wp_object_interest_ref (oi)) :
|
||||
wp_session_lookup_endpoint (session, NULL);
|
||||
if (ep) {
|
||||
wplua_pushobject (L, ep);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
session_iterate_links (lua_State *L)
|
||||
{
|
||||
WpSession *session = wplua_checkobject (L, 1, WP_TYPE_SESSION);
|
||||
WpObjectInterest *oi = get_optional_object_interest (L, 2, WP_TYPE_ENDPOINT_LINK);
|
||||
WpIterator *it = oi ?
|
||||
wp_session_new_links_filtered_iterator_full (session,
|
||||
wp_object_interest_ref (oi)) :
|
||||
wp_session_new_links_iterator (session);
|
||||
return push_wpiterator (L, it);
|
||||
}
|
||||
|
||||
static int
|
||||
session_lookup_link (lua_State *L)
|
||||
{
|
||||
WpSession *session = wplua_checkobject (L, 1, WP_TYPE_SESSION);
|
||||
WpObjectInterest *oi = get_optional_object_interest (L, 2, WP_TYPE_ENDPOINT_LINK);
|
||||
WpEndpointLink *l = oi ?
|
||||
wp_session_lookup_link_full (session, wp_object_interest_ref (oi)) :
|
||||
wp_session_lookup_link (session, NULL);
|
||||
if (l) {
|
||||
wplua_pushobject (L, l);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg session_methods[] = {
|
||||
{ "iterate_endpoints", session_iterate_endpoints },
|
||||
{ "lookup_endpoint", session_lookup_endpoint },
|
||||
{ "iterate_links", session_iterate_links },
|
||||
{ "lookup_link", session_lookup_link },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* WpImplSession */
|
||||
|
||||
static int
|
||||
impl_session_new (lua_State *L)
|
||||
{
|
||||
WpImplSession *session = wp_impl_session_new (get_wp_core (L));
|
||||
wplua_pushobject (L, session);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_session_update_properties (lua_State *L)
|
||||
{
|
||||
WpImplSession *session = wplua_checkobject (L, 1, WP_TYPE_IMPL_SESSION);
|
||||
luaL_checktype (L, 2, LUA_TTABLE);
|
||||
WpProperties *props = wplua_table_to_properties (L, 2);
|
||||
wp_impl_session_update_properties (session, props);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg impl_session_methods[] = {
|
||||
{ "update_properties", impl_session_update_properties },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* WpEndpoint */
|
||||
|
||||
static int
|
||||
@@ -858,52 +769,6 @@ static const luaL_Reg endpoint_methods[] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* WpEndpointLink */
|
||||
|
||||
static int
|
||||
endpoint_link_get_state (lua_State *L)
|
||||
{
|
||||
WpEndpointLink *eplink = wplua_checkobject (L, 1, WP_TYPE_ENDPOINT_LINK);
|
||||
const gchar *error = NULL;
|
||||
WpEndpointLinkState state = wp_endpoint_link_get_state (eplink, &error);
|
||||
g_autoptr (GEnumClass) state_class =
|
||||
g_type_class_ref (WP_TYPE_ENDPOINT_LINK_STATE);
|
||||
lua_pushstring (L, g_enum_get_value (state_class, state)->value_nick);
|
||||
if (error)
|
||||
lua_pushstring (L, error);
|
||||
return error ? 2 : 1;
|
||||
}
|
||||
|
||||
static int
|
||||
endpoint_link_request_state (lua_State *L)
|
||||
{
|
||||
WpEndpointLink *eplink = wplua_checkobject (L, 1, WP_TYPE_ENDPOINT_LINK);
|
||||
const gchar *states[] = { "inactive", "active" };
|
||||
int state = luaL_checkoption (L, 2, NULL, states);
|
||||
wp_endpoint_link_request_state (eplink, (WpEndpointLinkState) (state+1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
endpoint_link_get_linked_object_ids (lua_State *L)
|
||||
{
|
||||
WpEndpointLink *eplink = wplua_checkobject (L, 1, WP_TYPE_ENDPOINT_LINK);
|
||||
guint32 output_endpoint;
|
||||
guint32 input_endpoint;
|
||||
wp_endpoint_link_get_linked_object_ids (eplink, &output_endpoint,
|
||||
&input_endpoint);
|
||||
lua_pushinteger (L, output_endpoint);
|
||||
lua_pushinteger (L, input_endpoint);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static const luaL_Reg endpoint_link_methods[] = {
|
||||
{ "get_state", endpoint_link_get_state },
|
||||
{ "request_state", endpoint_link_request_state },
|
||||
{ "get_linked_object_ids", endpoint_link_get_linked_object_ids },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* Device */
|
||||
|
||||
static int
|
||||
@@ -1277,14 +1142,8 @@ wp_lua_scripting_api_init (lua_State *L)
|
||||
object_manager_new, object_manager_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_METADATA,
|
||||
NULL, metadata_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_SESSION,
|
||||
NULL, session_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_IMPL_SESSION,
|
||||
impl_session_new, impl_session_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_ENDPOINT,
|
||||
NULL, endpoint_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_ENDPOINT_LINK,
|
||||
NULL, endpoint_link_methods);
|
||||
wplua_register_type_methods (L, WP_TYPE_DEVICE,
|
||||
device_new, NULL);
|
||||
wplua_register_type_methods (L, WP_TYPE_SPA_DEVICE,
|
||||
|
@@ -154,6 +154,5 @@ SANDBOX_EXPORT = {
|
||||
Node = WpNode_new,
|
||||
LocalNode = WpImplNode_new,
|
||||
Link = WpLink_new,
|
||||
ImplSession = WpImplSession_new,
|
||||
Pod = WpSpaPod,
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ struct _WpSiAudioEndpoint
|
||||
WpDirection direction;
|
||||
gchar role[32];
|
||||
guint priority;
|
||||
WpSession *session;
|
||||
WpSpaPod *format;
|
||||
gchar mode[32];
|
||||
GTask *format_task;
|
||||
@@ -68,7 +67,6 @@ si_audio_endpoint_reset (WpSessionItem * item)
|
||||
self->direction = WP_DIRECTION_INPUT;
|
||||
self->role[0] = '\0';
|
||||
self->priority = 0;
|
||||
g_clear_object (&self->session);
|
||||
if (self->format_task) {
|
||||
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
|
||||
g_task_return_new_error (t, WP_DOMAIN_LIBRARY,
|
||||
@@ -86,7 +84,6 @@ si_audio_endpoint_configure (WpSessionItem * item, WpProperties *p)
|
||||
{
|
||||
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
|
||||
g_autoptr (WpProperties) si_props = wp_properties_ensure_unique_owner (p);
|
||||
WpSession *session = NULL;
|
||||
const gchar *str;
|
||||
|
||||
/* reset previous config */
|
||||
@@ -121,16 +118,6 @@ si_audio_endpoint_configure (WpSessionItem * item, WpProperties *p)
|
||||
if (!str)
|
||||
wp_properties_setf (si_props, "priority", "%u", self->priority);
|
||||
|
||||
/* session is optional (only needed if we want to export) */
|
||||
str = wp_properties_get (si_props, "session");
|
||||
if (str && (sscanf(str, "%p", &session) != 1 || !WP_IS_SESSION (session)))
|
||||
return FALSE;
|
||||
if (!str)
|
||||
wp_properties_setf (si_props, "session", "%p", session);
|
||||
|
||||
if (session)
|
||||
self->session = g_object_ref (session);
|
||||
|
||||
wp_properties_set (si_props, "si.factory.name", SI_FACTORY_NAME);
|
||||
wp_properties_setf (si_props, "is.device", "%u", FALSE);
|
||||
wp_session_item_set_properties (WP_SESSION_ITEM (self),
|
||||
@@ -145,8 +132,6 @@ si_audio_endpoint_get_associated_proxy (WpSessionItem * item, GType proxy_type)
|
||||
|
||||
if (proxy_type == WP_TYPE_NODE)
|
||||
return self->node ? g_object_ref (self->node) : NULL;
|
||||
if (proxy_type == WP_TYPE_SESSION)
|
||||
return self->session ? g_object_ref (self->session) : NULL;
|
||||
else if (proxy_type == WP_TYPE_ENDPOINT)
|
||||
return self->impl_endpoint ? g_object_ref (self->impl_endpoint) : NULL;
|
||||
|
||||
|
@@ -22,16 +22,12 @@ struct _WpSiStandardLink
|
||||
GWeakRef in_item;
|
||||
const gchar *out_item_port_context;
|
||||
const gchar *in_item_port_context;
|
||||
WpSession *session;
|
||||
gboolean manage_lifetime;
|
||||
gboolean passive;
|
||||
|
||||
/* activate */
|
||||
GPtrArray *node_links;
|
||||
guint n_async_ops_wait;
|
||||
|
||||
/* export */
|
||||
WpImplEndpointLink *impl_endpoint_link;
|
||||
};
|
||||
|
||||
static void si_standard_link_link_init (WpSiLinkInterface * iface);
|
||||
@@ -106,7 +102,6 @@ si_standard_link_reset (WpSessionItem * item)
|
||||
g_weak_ref_set (&self->in_item, NULL);
|
||||
self->out_item_port_context = NULL;
|
||||
self->in_item_port_context = NULL;
|
||||
g_clear_object (&self->session);
|
||||
self->manage_lifetime = FALSE;
|
||||
self->passive = FALSE;
|
||||
|
||||
@@ -134,7 +129,6 @@ si_standard_link_configure (WpSessionItem * item, WpProperties * p)
|
||||
WpSiStandardLink *self = WP_SI_STANDARD_LINK (item);
|
||||
g_autoptr (WpProperties) si_props = wp_properties_ensure_unique_owner (p);
|
||||
WpSessionItem *out_item, *in_item;
|
||||
WpSession *session = NULL;
|
||||
const gchar *str;
|
||||
|
||||
/* reset previous config */
|
||||
@@ -172,13 +166,6 @@ si_standard_link_configure (WpSessionItem * item, WpProperties * p)
|
||||
wp_properties_setf (si_props, "passive", "%u",
|
||||
self->passive);
|
||||
|
||||
/* session is optional (only needed if we want to export) */
|
||||
str = wp_properties_get (si_props, "session");
|
||||
if (str && (sscanf(str, "%p", &session) != 1 || !WP_IS_SESSION (session)))
|
||||
return FALSE;
|
||||
if (!str)
|
||||
wp_properties_setf (si_props, "session", "%p", session);
|
||||
|
||||
if (self->manage_lifetime) {
|
||||
g_signal_connect_object (out_item, "notify::active-features",
|
||||
G_CALLBACK (on_item_features_changed), self, 0);
|
||||
@@ -190,8 +177,6 @@ si_standard_link_configure (WpSessionItem * item, WpProperties * p)
|
||||
|
||||
g_weak_ref_set(&self->out_item, out_item);
|
||||
g_weak_ref_set(&self->in_item, in_item);
|
||||
if (session)
|
||||
self->session = g_object_ref (session);
|
||||
|
||||
wp_properties_set (si_props, "si.factory.name", SI_FACTORY_NAME);
|
||||
wp_session_item_set_properties (WP_SESSION_ITEM (self),
|
||||
@@ -202,14 +187,6 @@ si_standard_link_configure (WpSessionItem * item, WpProperties * p)
|
||||
static gpointer
|
||||
si_standard_link_get_associated_proxy (WpSessionItem * item, GType proxy_type)
|
||||
{
|
||||
WpSiStandardLink *self = WP_SI_STANDARD_LINK (item);
|
||||
|
||||
if (proxy_type == WP_TYPE_SESSION)
|
||||
return self->session ? g_object_ref (self->session) : NULL;
|
||||
else if (proxy_type == WP_TYPE_ENDPOINT_LINK)
|
||||
return self->impl_endpoint_link ?
|
||||
g_object_ref (self->impl_endpoint_link) : NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -242,16 +219,6 @@ si_standard_link_disable_active (WpSessionItem *si)
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE);
|
||||
}
|
||||
|
||||
static void
|
||||
si_standard_link_disable_exported (WpSessionItem *si)
|
||||
{
|
||||
WpSiStandardLink *self = WP_SI_STANDARD_LINK (si);
|
||||
|
||||
g_clear_object (&self->impl_endpoint_link);
|
||||
wp_object_update_features (WP_OBJECT (self), 0,
|
||||
WP_SESSION_ITEM_FEATURE_EXPORTED);
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_activated (WpObject * proxy, GAsyncResult * res,
|
||||
WpTransition * transition)
|
||||
@@ -283,7 +250,6 @@ create_links (WpSiStandardLink * self, WpTransition * transition,
|
||||
guint32 out_channel, in_channel;
|
||||
gboolean link_all = FALSE;
|
||||
guint i;
|
||||
guint32 eplink_id;
|
||||
|
||||
/* tuple format:
|
||||
uint32 node_id;
|
||||
@@ -298,9 +264,6 @@ create_links (WpSiStandardLink * self, WpTransition * transition,
|
||||
core = wp_object_get_core (WP_OBJECT (self));
|
||||
g_return_val_if_fail (core, FALSE);
|
||||
|
||||
eplink_id = wp_session_item_get_associated_proxy_id (WP_SESSION_ITEM (self),
|
||||
WP_TYPE_ENDPOINT_LINK);
|
||||
|
||||
self->n_async_ops_wait = 0;
|
||||
self->node_links = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
|
||||
@@ -348,8 +311,6 @@ create_links (WpSiStandardLink * self, WpTransition * transition,
|
||||
wp_properties_setf (props, PW_KEY_LINK_OUTPUT_PORT, "%u", out_port_id);
|
||||
wp_properties_setf (props, PW_KEY_LINK_INPUT_NODE, "%u", in_node_id);
|
||||
wp_properties_setf (props, PW_KEY_LINK_INPUT_PORT, "%u", in_port_id);
|
||||
if (eplink_id != SPA_ID_INVALID)
|
||||
wp_properties_setf (props, "endpoint-link.id", "%u", eplink_id);
|
||||
if (self->passive)
|
||||
wp_properties_set (props, PW_KEY_LINK_PASSIVE, "true");
|
||||
|
||||
@@ -633,39 +594,6 @@ si_standard_link_enable_active (WpSessionItem *si, WpTransition *transition)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_impl_endpoint_link_activated (WpObject * object, GAsyncResult * res,
|
||||
WpTransition * transition)
|
||||
{
|
||||
WpSiStandardLink *self = wp_transition_get_source_object (transition);
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
if (!wp_object_activate_finish (object, res, &error)) {
|
||||
wp_transition_return_error (transition, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
|
||||
wp_object_update_features (WP_OBJECT (self),
|
||||
WP_SESSION_ITEM_FEATURE_EXPORTED, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
si_standard_link_enable_exported (WpSessionItem *si, WpTransition *transition)
|
||||
{
|
||||
WpSiStandardLink *self = WP_SI_STANDARD_LINK (si);
|
||||
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
|
||||
|
||||
self->impl_endpoint_link = wp_impl_endpoint_link_new (core,
|
||||
WP_SI_LINK (self));
|
||||
|
||||
g_signal_connect_object (self->impl_endpoint_link, "pw-proxy-destroyed",
|
||||
G_CALLBACK (wp_session_item_handle_proxy_destroyed), self, 0);
|
||||
|
||||
wp_object_activate (WP_OBJECT (self->impl_endpoint_link),
|
||||
WP_OBJECT_FEATURES_ALL, NULL,
|
||||
(GAsyncReadyCallback) on_impl_endpoint_link_activated, transition);
|
||||
}
|
||||
|
||||
static void
|
||||
si_standard_link_finalize (GObject * object)
|
||||
{
|
||||
@@ -689,9 +617,7 @@ si_standard_link_class_init (WpSiStandardLinkClass * klass)
|
||||
si_class->configure = si_standard_link_configure;
|
||||
si_class->get_associated_proxy = si_standard_link_get_associated_proxy;
|
||||
si_class->disable_active = si_standard_link_disable_active;
|
||||
si_class->disable_exported = si_standard_link_disable_exported;
|
||||
si_class->enable_active = si_standard_link_enable_active;
|
||||
si_class->enable_exported = si_standard_link_enable_exported;
|
||||
}
|
||||
|
||||
static GVariant *
|
||||
|
@@ -73,7 +73,6 @@ async_quit (WpCore *core, GAsyncResult *res, WpCtl * self)
|
||||
static gboolean
|
||||
status_prepare (WpCtl * self, GError ** error)
|
||||
{
|
||||
wp_object_manager_add_interest (self->om, WP_TYPE_SESSION, NULL);
|
||||
wp_object_manager_add_interest (self->om, WP_TYPE_CLIENT, NULL);
|
||||
wp_object_manager_add_interest (self->om, WP_TYPE_DEVICE, NULL);
|
||||
wp_object_manager_add_interest (self->om, WP_TYPE_ENDPOINT, NULL);
|
||||
@@ -215,28 +214,6 @@ print_stream_node (const GValue *item, gpointer data)
|
||||
}
|
||||
}
|
||||
|
||||
// static void
|
||||
// print_endpoint_link (const GValue *item, gpointer data)
|
||||
// {
|
||||
// WpEndpointLink *link = g_value_get_object (item);
|
||||
// WpSession *session = data;
|
||||
// guint32 id = wp_proxy_get_bound_id (WP_PROXY (link));
|
||||
// guint32 out_ep_id, in_ep_id;
|
||||
// g_autoptr (WpEndpoint) out_ep = NULL;
|
||||
// g_autoptr (WpEndpoint) in_ep = NULL;
|
||||
|
||||
// wp_endpoint_link_get_linked_object_ids (link, &out_ep_id, &in_ep_id);
|
||||
|
||||
// out_ep = wp_session_lookup_endpoint (session,
|
||||
// WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=u", out_ep_id, NULL);
|
||||
// in_ep = wp_session_lookup_endpoint (session,
|
||||
// WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=u", in_ep_id, NULL);
|
||||
|
||||
// printf (TREE_INDENT_EMPTY " %4u. [%u. %s] ➞ [%u. %s]\n", id,
|
||||
// out_ep_id, get_endpoint_friendly_name (out_ep),
|
||||
// in_ep_id, get_endpoint_friendly_name (in_ep));
|
||||
// }
|
||||
|
||||
static void
|
||||
status_run (WpCtl * self)
|
||||
{
|
||||
@@ -275,16 +252,13 @@ status_run (WpCtl * self)
|
||||
printf ("\n");
|
||||
|
||||
/* sessions */
|
||||
it = wp_object_manager_new_filtered_iterator (self->om, WP_TYPE_SESSION,
|
||||
NULL);
|
||||
for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
|
||||
WpSession *session = g_value_get_object (&val);
|
||||
const guint session_id = wp_proxy_get_bound_id (WP_PROXY (session));
|
||||
const gchar *media_type = wp_pipewire_object_get_property (
|
||||
WP_PIPEWIRE_OBJECT (session), PW_KEY_MEDIA_TYPE);
|
||||
const gchar *MEDIA_TYPES[] = { "Audio", "Video" };
|
||||
|
||||
for (guint i = 0; i < G_N_ELEMENTS (MEDIA_TYPES); i++) {
|
||||
const gchar *media_type = MEDIA_TYPES[i];
|
||||
g_autoptr (WpIterator) child_it = NULL;
|
||||
|
||||
printf ("Session %u (%s)\n", session_id, wp_session_get_name (session));
|
||||
printf ("%s\n", media_type);
|
||||
|
||||
if (media_type && *media_type != '\0') {
|
||||
gchar media_type_glob[16];
|
||||
@@ -366,11 +340,6 @@ status_run (WpCtl * self)
|
||||
g_clear_pointer (&child_it, wp_iterator_unref);
|
||||
}
|
||||
|
||||
// printf (TREE_INDENT_END "Endpoint links:\n");
|
||||
// child_it = wp_session_new_links_iterator (session);
|
||||
// wp_iterator_foreach (child_it, print_endpoint_link, session);
|
||||
// g_clear_pointer (&child_it, wp_iterator_unref);
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
# disabled temporarily
|
||||
if false
|
||||
executable('audiotestsrc-play',
|
||||
'audiotestsrc-play.c',
|
||||
c_args : [
|
||||
@@ -8,6 +10,7 @@ executable('audiotestsrc-play',
|
||||
install: false,
|
||||
dependencies : [giounix_dep, wp_dep, pipewire_dep],
|
||||
)
|
||||
endif
|
||||
|
||||
if wpipc_dep.found()
|
||||
executable('wpipc-client',
|
||||
|
@@ -48,9 +48,12 @@ test(
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
# disabled temporarily
|
||||
if false
|
||||
test(
|
||||
'test-si-standard-link',
|
||||
executable('test-si-standard-link', 'si-standard-link.c',
|
||||
dependencies: common_deps, c_args: common_args),
|
||||
env: common_env,
|
||||
)
|
||||
endif
|
||||
|
@@ -99,7 +99,6 @@ static void
|
||||
test_si_audio_endpoint_export (TestFixture * f, gconstpointer user_data)
|
||||
{
|
||||
g_autoptr (WpSessionItem) endpoint = NULL;
|
||||
g_autoptr (WpSession) session = NULL;
|
||||
g_autoptr (WpObjectManager) clients_om = NULL;
|
||||
g_autoptr (WpClient) self_client = NULL;
|
||||
|
||||
@@ -116,15 +115,6 @@ test_si_audio_endpoint_export (TestFixture * f, gconstpointer user_data)
|
||||
g_assert_nonnull (self_client =
|
||||
wp_object_manager_lookup (clients_om, WP_TYPE_CLIENT, NULL));
|
||||
|
||||
/* create session */
|
||||
|
||||
session = WP_SESSION (wp_impl_session_new (f->base.core));
|
||||
g_assert_nonnull (session);
|
||||
|
||||
wp_object_activate (WP_OBJECT (session), WP_OBJECT_FEATURES_ALL, NULL,
|
||||
(GAsyncReadyCallback) test_object_activate_finish_cb, f);
|
||||
g_main_loop_run (f->base.loop);
|
||||
|
||||
/* create endpoint */
|
||||
|
||||
endpoint = wp_session_item_make (f->base.core, "si-audio-endpoint");
|
||||
@@ -135,7 +125,6 @@ test_si_audio_endpoint_export (TestFixture * f, gconstpointer user_data)
|
||||
WpProperties *props = wp_properties_new_empty ();
|
||||
wp_properties_set (props, "name", "endpoint");
|
||||
wp_properties_set (props, "media.class", "Audio/Source");
|
||||
wp_properties_setf (props, "session", "%p", session);
|
||||
g_assert_true (wp_session_item_configure (endpoint, props));
|
||||
g_assert_true (wp_session_item_is_configured (endpoint));
|
||||
}
|
||||
@@ -154,7 +143,6 @@ test_si_audio_endpoint_export (TestFixture * f, gconstpointer user_data)
|
||||
{
|
||||
g_autoptr (WpEndpoint) ep = NULL;
|
||||
g_autoptr (WpProperties) props = NULL;
|
||||
gchar *tmp;
|
||||
|
||||
g_assert_nonnull (
|
||||
ep = wp_session_item_get_associated_proxy (endpoint, WP_TYPE_ENDPOINT));
|
||||
@@ -169,10 +157,6 @@ test_si_audio_endpoint_export (TestFixture * f, gconstpointer user_data)
|
||||
"endpoint");
|
||||
g_assert_cmpstr (wp_properties_get (props, "media.class"), ==,
|
||||
"Audio/Source");
|
||||
|
||||
tmp = g_strdup_printf ("%d", wp_proxy_get_bound_id (WP_PROXY (session)));
|
||||
g_assert_cmpstr (wp_properties_get (props, "session.id"), ==, tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
/* reset */
|
||||
|
@@ -11,7 +11,6 @@
|
||||
typedef struct {
|
||||
WpBaseTestFixture base;
|
||||
|
||||
WpSession *session;
|
||||
WpSessionItem *src_item;
|
||||
WpSessionItem *sink_item;
|
||||
gint activation_state;
|
||||
@@ -34,7 +33,6 @@ load_endpoint (TestFixture * f, const gchar * factory, const gchar * media_class
|
||||
WpProperties *props = wp_properties_new_empty ();
|
||||
wp_properties_set (props, "name", factory);
|
||||
wp_properties_set (props, "media.class", media_class);
|
||||
wp_properties_setf (props, "session", "%p", f->session);
|
||||
g_assert_true (wp_session_item_configure (endpoint, props));
|
||||
g_assert_true (wp_session_item_is_configured (endpoint));
|
||||
}
|
||||
@@ -81,14 +79,6 @@ test_si_standard_link_setup (TestFixture * f, gconstpointer user_data)
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
g_assert_nonnull (
|
||||
f->session = WP_SESSION (wp_impl_session_new (f->base.core)));
|
||||
wp_impl_session_set_property (WP_IMPL_SESSION (f->session),
|
||||
"session.name", "audio");
|
||||
wp_object_activate (WP_OBJECT (f->session), WP_OBJECT_FEATURES_ALL, NULL,
|
||||
(GAsyncReadyCallback) test_object_activate_finish_cb, f);
|
||||
g_main_loop_run (f->base.loop);
|
||||
|
||||
f->src_item = load_endpoint (f, "audiotestsrc", "Audio/Source");
|
||||
f->sink_item = load_endpoint (f, "fakesink", "Audio/Sink");
|
||||
}
|
||||
@@ -110,7 +100,6 @@ test_si_standard_link_teardown (TestFixture * f, gconstpointer user_data)
|
||||
g_main_loop_run (f->base.loop);
|
||||
g_clear_object (&f->sink_item);
|
||||
g_clear_object (&f->src_item);
|
||||
g_clear_object (&f->session);
|
||||
wp_base_test_fixture_teardown (&f->base);
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,6 @@ struct _TestSiEndpoint
|
||||
WpNode *node;
|
||||
WpDirection direction;
|
||||
gboolean changed_properties;
|
||||
WpSession *session;
|
||||
WpProxy *impl_endpoint;
|
||||
};
|
||||
|
||||
@@ -71,8 +70,6 @@ si_endpoint_get_associated_proxy (WpSessionItem * item, GType proxy_type)
|
||||
|
||||
if (proxy_type == WP_TYPE_NODE)
|
||||
return self->node ? g_object_ref (self->node) : NULL;
|
||||
else if (proxy_type == WP_TYPE_SESSION)
|
||||
return self->session ? g_object_ref (self->session) : NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -86,7 +83,6 @@ si_endpoint_reset (WpSessionItem * item)
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE | WP_SESSION_ITEM_FEATURE_EXPORTED);
|
||||
|
||||
g_clear_object (&self->node);
|
||||
g_clear_object (&self->session);
|
||||
|
||||
WP_SESSION_ITEM_CLASS (test_si_endpoint_parent_class)->reset (item);
|
||||
}
|
||||
@@ -274,22 +270,6 @@ test_endpoint_activate_done (WpObject * object, GAsyncResult * res,
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_endpoint_session_bound (WpObject * session, GAsyncResult * res,
|
||||
TestEndpointFixture *fixture)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
g_debug ("session export done");
|
||||
|
||||
g_assert_true (wp_object_activate_finish (session, res, &error));
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_true (WP_IS_IMPL_SESSION (session));
|
||||
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_endpoint_params_changed (WpPipewireObject * proxy,
|
||||
guint32 id, TestEndpointFixture *fixture)
|
||||
@@ -318,7 +298,6 @@ static void
|
||||
test_endpoint_no_props (TestEndpointFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (TestSiEndpoint) endpoint = NULL;
|
||||
g_autoptr (WpImplSession) session = NULL;
|
||||
|
||||
/* set up the export side */
|
||||
g_signal_connect (fixture->export_om, "object-added",
|
||||
@@ -340,24 +319,12 @@ test_endpoint_no_props (TestEndpointFixture *fixture, gconstpointer data)
|
||||
WP_TYPE_ENDPOINT, WP_OBJECT_FEATURES_ALL);
|
||||
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om);
|
||||
|
||||
/* create session */
|
||||
session = wp_impl_session_new (fixture->base.core);
|
||||
wp_object_activate (WP_OBJECT (session), WP_PROXY_FEATURE_BOUND, NULL,
|
||||
(GAsyncReadyCallback) test_endpoint_session_bound, fixture);
|
||||
|
||||
/* run until session is bound */
|
||||
g_main_loop_run (fixture->base.loop);
|
||||
g_assert_cmpint (wp_object_get_active_features (WP_OBJECT (session)), &,
|
||||
WP_PROXY_FEATURE_BOUND);
|
||||
g_assert_cmpint (wp_proxy_get_bound_id (WP_PROXY (session)), >, 0);
|
||||
|
||||
/* create endpoint */
|
||||
endpoint = g_object_new (test_si_endpoint_get_type (),
|
||||
"core", fixture->base.core, NULL);
|
||||
endpoint->name = "test-endpoint";
|
||||
endpoint->media_class = "Audio/Source";
|
||||
endpoint->direction = WP_DIRECTION_OUTPUT;
|
||||
endpoint->session = WP_SESSION (g_object_ref (session));
|
||||
wp_object_activate (WP_OBJECT (endpoint),
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE | WP_SESSION_ITEM_FEATURE_EXPORTED,
|
||||
NULL, (GAsyncReadyCallback) test_endpoint_activate_done, fixture);
|
||||
@@ -386,15 +353,11 @@ test_endpoint_no_props (TestEndpointFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpProperties) props = wp_global_proxy_get_global_properties (
|
||||
WP_GLOBAL_PROXY (fixture->proxy_endpoint));
|
||||
g_autofree gchar * session_id = g_strdup_printf ("%u",
|
||||
wp_proxy_get_bound_id (WP_PROXY (session)));
|
||||
|
||||
g_assert_cmpstr (wp_properties_get (props, PW_KEY_ENDPOINT_NAME), ==,
|
||||
"test-endpoint");
|
||||
g_assert_cmpstr (wp_properties_get (props, PW_KEY_MEDIA_CLASS), ==,
|
||||
"Audio/Source");
|
||||
g_assert_cmpstr (wp_properties_get (props, PW_KEY_SESSION_ID), ==,
|
||||
session_id);
|
||||
}
|
||||
|
||||
g_assert_cmpstr ("test-endpoint", ==,
|
||||
@@ -448,7 +411,6 @@ static void
|
||||
test_endpoint_with_props (TestEndpointFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (TestSiEndpoint) endpoint = NULL;
|
||||
g_autoptr (WpImplSession) session = NULL;
|
||||
|
||||
/* load modules */
|
||||
{
|
||||
@@ -481,24 +443,12 @@ test_endpoint_with_props (TestEndpointFixture *fixture, gconstpointer data)
|
||||
WP_TYPE_ENDPOINT, WP_OBJECT_FEATURES_ALL);
|
||||
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om);
|
||||
|
||||
/* create session */
|
||||
session = wp_impl_session_new (fixture->base.core);
|
||||
wp_object_activate (WP_OBJECT (session), WP_PROXY_FEATURE_BOUND, NULL,
|
||||
(GAsyncReadyCallback) test_endpoint_session_bound, fixture);
|
||||
|
||||
/* run until session is bound */
|
||||
g_main_loop_run (fixture->base.loop);
|
||||
g_assert_cmpint (wp_object_get_active_features (WP_OBJECT (session)), &,
|
||||
WP_PROXY_FEATURE_BOUND);
|
||||
g_assert_cmpint (wp_proxy_get_bound_id (WP_PROXY (session)), >, 0);
|
||||
|
||||
/* create endpoint */
|
||||
endpoint = g_object_new (test_si_endpoint_get_type (),
|
||||
"core", fixture->base.core, NULL);
|
||||
endpoint->name = "test-endpoint";
|
||||
endpoint->media_class = "Audio/Source";
|
||||
endpoint->direction = WP_DIRECTION_OUTPUT;
|
||||
endpoint->session = WP_SESSION (g_object_ref (session));
|
||||
|
||||
/* associate a node that has props */
|
||||
endpoint->node = wp_node_new_from_factory (fixture->base.core,
|
||||
|
@@ -51,13 +51,6 @@ test(
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-session',
|
||||
executable('test-session', 'session.c',
|
||||
dependencies: common_deps, c_args: common_args),
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-session-item',
|
||||
executable('test-session-item', 'session-item.c',
|
||||
|
@@ -39,7 +39,6 @@ struct _TestSiDummy
|
||||
WpSessionItem parent;
|
||||
const gchar *name;
|
||||
gboolean fail;
|
||||
WpSession *session;
|
||||
gboolean activate_done;
|
||||
gboolean export_done;
|
||||
};
|
||||
@@ -63,7 +62,6 @@ si_dummy_reset (WpSessionItem * item)
|
||||
|
||||
/* reset */
|
||||
self->fail = FALSE;
|
||||
g_clear_object (&self->session);
|
||||
|
||||
WP_SESSION_ITEM_CLASS (si_dummy_parent_class)->reset (item);
|
||||
}
|
||||
@@ -72,7 +70,6 @@ static gboolean
|
||||
si_dummy_configure (WpSessionItem * item, WpProperties * props)
|
||||
{
|
||||
TestSiDummy *self = TEST_SI_DUMMY (item);
|
||||
WpSession *session = NULL;
|
||||
const gchar *str = NULL;
|
||||
|
||||
/* reset previous config */
|
||||
@@ -82,14 +79,6 @@ si_dummy_configure (WpSessionItem * item, WpProperties * props)
|
||||
if (!str || sscanf(str, "%u", &self->fail) != 1)
|
||||
return FALSE;
|
||||
|
||||
/* session is optional (only needed if we want to export) */
|
||||
str = wp_properties_get (props, "session");
|
||||
if (str && (sscanf(str, "%p", &session) != 1 || !WP_IS_SESSION (session)))
|
||||
return FALSE;
|
||||
|
||||
if (session)
|
||||
self->session = g_object_ref (session);
|
||||
|
||||
wp_session_item_set_properties (WP_SESSION_ITEM (self), props);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -97,11 +86,6 @@ si_dummy_configure (WpSessionItem * item, WpProperties * props)
|
||||
static gpointer
|
||||
si_dummy_get_associated_proxy (WpSessionItem * item, GType proxy_type)
|
||||
{
|
||||
TestSiDummy *self = TEST_SI_DUMMY (item);
|
||||
|
||||
if (proxy_type == WP_TYPE_SESSION)
|
||||
return self->session ? g_object_ref (self->session) : NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -311,18 +295,14 @@ static void
|
||||
test_export (TestSessionItemFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpSessionItem) item = NULL;
|
||||
g_autoptr (WpSession) session = NULL;
|
||||
g_autoptr (WpSession) assoc_session = NULL;
|
||||
TestSiDummy *dummy;
|
||||
|
||||
session = (WpSession *) wp_impl_session_new (fixture->base.core);
|
||||
item = g_object_new (si_dummy_get_type (), "core", fixture->base.core, NULL);
|
||||
dummy = TEST_SI_DUMMY (item);
|
||||
|
||||
{
|
||||
g_autoptr (WpProperties) p = wp_properties_new_empty ();
|
||||
wp_properties_setf (p, "fail", "%u", FALSE);
|
||||
wp_properties_setf (p, "session", "%p", session);
|
||||
g_assert_true (wp_session_item_configure (item, g_steal_pointer (&p)));
|
||||
g_assert_true (wp_session_item_is_configured (item));
|
||||
}
|
||||
@@ -336,10 +316,6 @@ test_export (TestSessionItemFixture *fixture, gconstpointer data)
|
||||
g_assert_true (dummy->activate_done);
|
||||
g_assert_true (dummy->export_done);
|
||||
|
||||
assoc_session = wp_session_item_get_associated_proxy (item, WP_TYPE_SESSION);
|
||||
g_assert_nonnull (assoc_session);
|
||||
g_assert_true (assoc_session == session);
|
||||
|
||||
wp_object_deactivate (WP_OBJECT (item), WP_SESSION_ITEM_FEATURE_EXPORTED);
|
||||
g_assert_cmpint (wp_object_get_active_features (WP_OBJECT (item)), ==,
|
||||
WP_SESSION_ITEM_FEATURE_ACTIVE);
|
||||
@@ -355,17 +331,14 @@ static void
|
||||
test_export_error (TestSessionItemFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpSessionItem) item = NULL;
|
||||
g_autoptr (WpSession) session = NULL;
|
||||
TestSiDummy *dummy;
|
||||
|
||||
session = (WpSession *) wp_impl_session_new (fixture->base.core);
|
||||
item = g_object_new (si_dummy_get_type (), "core", fixture->base.core, NULL);
|
||||
dummy = TEST_SI_DUMMY (item);
|
||||
|
||||
{
|
||||
g_autoptr (WpProperties) p = wp_properties_new_empty ();
|
||||
wp_properties_setf (p, "fail", "%u", TRUE);
|
||||
wp_properties_setf (p, "session", "%p", session);
|
||||
g_assert_true (wp_session_item_configure (item, g_steal_pointer (&p)));
|
||||
g_assert_true (wp_session_item_is_configured (item));
|
||||
}
|
||||
|
@@ -1,245 +0,0 @@
|
||||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "../common/base-test-fixture.h"
|
||||
#include <pipewire/extensions/session-manager/keys.h>
|
||||
|
||||
typedef struct {
|
||||
WpBaseTestFixture base;
|
||||
|
||||
WpObjectManager *export_om;
|
||||
WpObjectManager *proxy_om;
|
||||
|
||||
WpImplSession *impl_session;
|
||||
WpProxy *proxy_session;
|
||||
|
||||
gint n_events;
|
||||
|
||||
} TestSessionFixture;
|
||||
|
||||
static void
|
||||
test_session_setup (TestSessionFixture *self, gconstpointer user_data)
|
||||
{
|
||||
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE);
|
||||
self->export_om = wp_object_manager_new ();
|
||||
self->proxy_om = wp_object_manager_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_teardown (TestSessionFixture *self, gconstpointer user_data)
|
||||
{
|
||||
g_clear_object (&self->proxy_om);
|
||||
g_clear_object (&self->export_om);
|
||||
wp_base_test_fixture_teardown (&self->base);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_exported_object_added (WpObjectManager *om,
|
||||
WpSession *session, TestSessionFixture *fixture)
|
||||
{
|
||||
g_debug ("exported object added");
|
||||
|
||||
g_assert_true (WP_IS_IMPL_SESSION (session));
|
||||
|
||||
g_assert_null (fixture->impl_session);
|
||||
fixture->impl_session = WP_IMPL_SESSION (session);
|
||||
|
||||
if (++fixture->n_events == 3)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_exported_object_removed (WpObjectManager *om,
|
||||
WpSession *session, TestSessionFixture *fixture)
|
||||
{
|
||||
g_debug ("exported object removed");
|
||||
|
||||
g_assert_true (WP_IS_IMPL_SESSION (session));
|
||||
|
||||
g_assert_nonnull (fixture->impl_session);
|
||||
fixture->impl_session = NULL;
|
||||
|
||||
if (++fixture->n_events == 2)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_proxy_object_added (WpObjectManager *om,
|
||||
WpSession *session, TestSessionFixture *fixture)
|
||||
{
|
||||
g_debug ("proxy object added");
|
||||
|
||||
g_assert_true (WP_IS_SESSION (session));
|
||||
|
||||
g_assert_null (fixture->proxy_session);
|
||||
fixture->proxy_session = WP_PROXY (session);
|
||||
|
||||
if (++fixture->n_events == 3)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_proxy_object_removed (WpObjectManager *om,
|
||||
WpSession *session, TestSessionFixture *fixture)
|
||||
{
|
||||
g_debug ("proxy object removed");
|
||||
|
||||
g_assert_true (WP_IS_SESSION (session));
|
||||
|
||||
g_assert_nonnull (fixture->proxy_session);
|
||||
fixture->proxy_session = NULL;
|
||||
|
||||
if (++fixture->n_events == 2)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_export_done (WpObject * session, GAsyncResult * res,
|
||||
TestSessionFixture *fixture)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
g_debug ("export done");
|
||||
|
||||
g_assert_true (wp_object_activate_finish (session, res, &error));
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_true (WP_IS_IMPL_SESSION (session));
|
||||
|
||||
if (++fixture->n_events == 3)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic_notify_properties (WpSession * session, GParamSpec * param,
|
||||
TestSessionFixture *fixture)
|
||||
{
|
||||
g_debug ("properties changed: %s", G_OBJECT_TYPE_NAME (session));
|
||||
|
||||
g_assert_true (WP_IS_SESSION (session));
|
||||
|
||||
if (++fixture->n_events == 2)
|
||||
g_main_loop_quit (fixture->base.loop);
|
||||
}
|
||||
|
||||
static void
|
||||
test_session_basic (TestSessionFixture *fixture, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpImplSession) session = NULL;
|
||||
|
||||
/* set up the export side */
|
||||
g_signal_connect (fixture->export_om, "object-added",
|
||||
(GCallback) test_session_basic_exported_object_added, fixture);
|
||||
g_signal_connect (fixture->export_om, "object-removed",
|
||||
(GCallback) test_session_basic_exported_object_removed, fixture);
|
||||
wp_object_manager_add_interest (fixture->export_om,
|
||||
WP_TYPE_IMPL_SESSION, NULL);
|
||||
wp_object_manager_request_object_features (fixture->export_om,
|
||||
WP_TYPE_IMPL_SESSION, WP_OBJECT_FEATURES_ALL);
|
||||
wp_core_install_object_manager (fixture->base.core, fixture->export_om);
|
||||
|
||||
/* set up the proxy side */
|
||||
g_signal_connect (fixture->proxy_om, "object-added",
|
||||
(GCallback) test_session_basic_proxy_object_added, fixture);
|
||||
g_signal_connect (fixture->proxy_om, "object-removed",
|
||||
(GCallback) test_session_basic_proxy_object_removed, fixture);
|
||||
wp_object_manager_add_interest (fixture->proxy_om, WP_TYPE_SESSION, NULL);
|
||||
wp_object_manager_request_object_features (fixture->proxy_om,
|
||||
WP_TYPE_SESSION, WP_OBJECT_FEATURES_ALL);
|
||||
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om);
|
||||
|
||||
/* create session */
|
||||
session = wp_impl_session_new (fixture->base.core);
|
||||
wp_impl_session_set_property (session, "test.property", "test-value");
|
||||
|
||||
/* verify properties are set before export */
|
||||
{
|
||||
g_autoptr (WpProperties) props =
|
||||
wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (session));
|
||||
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
||||
"test-value");
|
||||
}
|
||||
|
||||
/* do export */
|
||||
wp_object_activate (WP_OBJECT (session), WP_OBJECT_FEATURES_ALL, NULL,
|
||||
(GAsyncReadyCallback) test_session_basic_export_done, fixture);
|
||||
|
||||
/* run until objects are created and features are cached */
|
||||
fixture->n_events = 0;
|
||||
g_main_loop_run (fixture->base.loop);
|
||||
g_assert_cmpint (fixture->n_events, ==, 3);
|
||||
g_assert_nonnull (fixture->impl_session);
|
||||
g_assert_nonnull (fixture->proxy_session);
|
||||
g_assert_true (fixture->impl_session == session);
|
||||
|
||||
/* test round 1: verify the values on the proxy */
|
||||
|
||||
g_assert_cmphex (
|
||||
wp_object_get_active_features (WP_OBJECT (fixture->proxy_session)), ==,
|
||||
wp_object_get_supported_features (WP_OBJECT (fixture->proxy_session)));
|
||||
|
||||
g_assert_cmpuint (wp_proxy_get_bound_id (fixture->proxy_session), ==,
|
||||
wp_proxy_get_bound_id (WP_PROXY (session)));
|
||||
|
||||
{
|
||||
g_autoptr (WpProperties) props = wp_pipewire_object_get_properties (
|
||||
WP_PIPEWIRE_OBJECT (fixture->proxy_session));
|
||||
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
||||
"test-value");
|
||||
}
|
||||
|
||||
/* setup change signals */
|
||||
g_signal_connect (fixture->proxy_session, "notify::properties",
|
||||
(GCallback) test_session_basic_notify_properties, fixture);
|
||||
g_signal_connect (session, "notify::properties",
|
||||
(GCallback) test_session_basic_notify_properties, fixture);
|
||||
|
||||
/* change a property on the exported */
|
||||
fixture->n_events = 0;
|
||||
wp_impl_session_set_property (session, "test.property", "changed-value");
|
||||
|
||||
/* run until the change is on both sides */
|
||||
g_main_loop_run (fixture->base.loop);
|
||||
g_assert_cmpint (fixture->n_events, ==, 2);
|
||||
|
||||
/* verify the property change on both sides */
|
||||
{
|
||||
g_autoptr (WpProperties) props =
|
||||
wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (session));
|
||||
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
||||
"changed-value");
|
||||
}
|
||||
{
|
||||
g_autoptr (WpProperties) props = wp_pipewire_object_get_properties (
|
||||
WP_PIPEWIRE_OBJECT (fixture->proxy_session));
|
||||
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
||||
"changed-value");
|
||||
}
|
||||
|
||||
/* destroy impl session */
|
||||
fixture->n_events = 0;
|
||||
g_clear_object (&session);
|
||||
|
||||
/* run until objects are destroyed */
|
||||
g_main_loop_run (fixture->base.loop);
|
||||
g_assert_cmpint (fixture->n_events, ==, 2);
|
||||
g_assert_null (fixture->impl_session);
|
||||
g_assert_null (fixture->proxy_session);
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/session/basic", TestSessionFixture, NULL,
|
||||
test_session_setup, test_session_basic, test_session_teardown);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Reference in New Issue
Block a user