2020-03-17 23:03:10 +02:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2020 Collabora Ltd.
|
|
|
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <wp/wp.h>
|
2020-05-04 11:23:50 +03:00
|
|
|
#include <pipewire/keys.h>
|
2020-05-19 11:17:52 -04:00
|
|
|
#include <pipewire/properties.h>
|
2020-05-04 11:23:50 +03:00
|
|
|
#include <pipewire/extensions/session-manager/keys.h>
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2020-05-04 11:23:50 +03:00
|
|
|
#include <spa/param/format.h>
|
2020-03-17 23:03:10 +02:00
|
|
|
#include <spa/param/audio/raw.h>
|
2020-05-04 11:23:50 +03:00
|
|
|
#include <spa/param/param.h>
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
#include "module-si-audio-adapter/audio-utils.h"
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
#define SI_FACTORY_NAME "si-audio-adapter"
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
struct _WpSiAudioAdapter
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
|
|
|
|
WpSessionItem parent;
|
|
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
|
WpNode *node;
|
2021-03-17 14:52:41 -04:00
|
|
|
WpSession *session;
|
2020-03-17 23:03:10 +02:00
|
|
|
gchar name[96];
|
|
|
|
|
gchar media_class[32];
|
|
|
|
|
gchar role[32];
|
|
|
|
|
guint priority;
|
2020-05-11 11:34:20 +03:00
|
|
|
guint preferred_n_channels;
|
2020-03-17 23:03:10 +02:00
|
|
|
gboolean control_port;
|
|
|
|
|
gboolean monitor;
|
|
|
|
|
WpDirection direction;
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
/* activate */
|
2020-03-17 23:03:10 +02:00
|
|
|
struct spa_audio_info_raw format;
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
/* export */
|
|
|
|
|
WpImplEndpoint *impl_endpoint;
|
2020-03-17 23:03:10 +02:00
|
|
|
};
|
|
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
static void si_audio_adapter_endpoint_init (WpSiEndpointInterface * iface);
|
|
|
|
|
static void si_audio_adapter_port_info_init (WpSiPortInfoInterface * iface);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
G_DECLARE_FINAL_TYPE(WpSiAudioAdapter, si_audio_adapter, WP, SI_AUDIO_ADAPTER,
|
|
|
|
|
WpSessionItem)
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (WpSiAudioAdapter, si_audio_adapter,
|
|
|
|
|
WP_TYPE_SESSION_ITEM,
|
|
|
|
|
G_IMPLEMENT_INTERFACE (WP_TYPE_SI_ENDPOINT, si_audio_adapter_endpoint_init)
|
|
|
|
|
G_IMPLEMENT_INTERFACE (WP_TYPE_SI_PORT_INFO, si_audio_adapter_port_info_init))
|
2020-03-17 23:03:10 +02:00
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_init (WpSiAudioAdapter * self)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_reset (WpSessionItem * item)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
/* deactivate first */
|
|
|
|
|
wp_object_deactivate (WP_OBJECT (self),
|
|
|
|
|
WP_SESSION_ITEM_FEATURE_ACTIVE | WP_SESSION_ITEM_FEATURE_EXPORTED);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
/* reset */
|
2020-04-09 19:24:42 +03:00
|
|
|
g_clear_object (&self->node);
|
2021-03-17 14:52:41 -04:00
|
|
|
g_clear_object (&self->session);
|
2020-03-17 23:03:10 +02:00
|
|
|
self->name[0] = '\0';
|
|
|
|
|
self->media_class[0] = '\0';
|
|
|
|
|
self->role[0] = '\0';
|
|
|
|
|
self->priority = 0;
|
|
|
|
|
self->control_port = FALSE;
|
|
|
|
|
self->monitor = FALSE;
|
|
|
|
|
self->direction = WP_DIRECTION_INPUT;
|
2020-05-11 11:34:20 +03:00
|
|
|
self->preferred_n_channels = 0;
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
WP_SESSION_ITEM_CLASS (si_audio_adapter_parent_class)->reset (item);
|
2021-03-17 14:52:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_configure (WpSessionItem * item, WpProperties *p)
|
2021-03-17 14:52:41 -04:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2021-03-17 14:52:41 -04:00
|
|
|
g_autoptr (WpProperties) si_props = wp_properties_ensure_unique_owner (p);
|
|
|
|
|
WpNode *node = NULL;
|
|
|
|
|
WpProperties *node_props = NULL;
|
|
|
|
|
WpSession *session = NULL;
|
|
|
|
|
const gchar *str;
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
/* reset previous config */
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_reset (item);
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
str = wp_properties_get (si_props, "node");
|
|
|
|
|
if (!str || sscanf(str, "%p", &node) != 1 || !WP_IS_NODE (node))
|
|
|
|
|
return FALSE;
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
node_props = wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (node));
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (si_props, "name");
|
|
|
|
|
if (str) {
|
|
|
|
|
strncpy (self->name, str, sizeof (self->name) - 1);
|
2020-03-17 23:03:10 +02:00
|
|
|
} else {
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (node_props, PW_KEY_NODE_NAME);
|
|
|
|
|
if (G_LIKELY (str))
|
|
|
|
|
strncpy (self->name, str, sizeof (self->name) - 1);
|
|
|
|
|
else
|
|
|
|
|
strncpy (self->name, "Unknown", sizeof (self->name) - 1);
|
|
|
|
|
wp_properties_set (si_props, "name", self->name);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (si_props, "media-class");
|
|
|
|
|
if (str) {
|
|
|
|
|
strncpy (self->media_class, str, sizeof (self->media_class) - 1);
|
2020-03-17 23:03:10 +02:00
|
|
|
} else {
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (node_props, PW_KEY_MEDIA_CLASS);
|
|
|
|
|
if (G_LIKELY (str))
|
|
|
|
|
strncpy (self->media_class, str, sizeof (self->media_class) - 1);
|
|
|
|
|
else
|
|
|
|
|
strncpy (self->media_class, "Unknown", sizeof (self->media_class) - 1);
|
|
|
|
|
wp_properties_set (si_props, "media-class", self->media_class);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (si_props, "role");
|
|
|
|
|
if (str) {
|
|
|
|
|
strncpy (self->role, str, sizeof (self->role) - 1);
|
2020-03-17 23:03:10 +02:00
|
|
|
} else {
|
2021-03-17 14:52:41 -04:00
|
|
|
str = wp_properties_get (node_props, PW_KEY_MEDIA_ROLE);
|
|
|
|
|
if (str)
|
|
|
|
|
strncpy (self->role, str, sizeof (self->role) - 1);
|
|
|
|
|
else
|
|
|
|
|
strncpy (self->role, "Unknown", sizeof (self->role) - 1);
|
|
|
|
|
wp_properties_set (si_props, "role", self->role);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strstr (self->media_class, "Source") ||
|
|
|
|
|
strstr (self->media_class, "Output"))
|
|
|
|
|
self->direction = WP_DIRECTION_OUTPUT;
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_properties_setf (si_props, "direction", "%u", self->direction);
|
|
|
|
|
|
|
|
|
|
str = wp_properties_get (si_props, "priority");
|
|
|
|
|
if (str && sscanf(str, "%u", &self->priority) != 1)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (!str)
|
|
|
|
|
wp_properties_setf (si_props, "priority", "%u", self->priority);
|
|
|
|
|
|
|
|
|
|
str = wp_properties_get (si_props, "preferred-n-channels");
|
|
|
|
|
if (str && sscanf(str, "%u", &self->preferred_n_channels) != 1)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (!str)
|
|
|
|
|
wp_properties_setf (si_props, "preferred-n-channels", "%u",
|
|
|
|
|
self->preferred_n_channels);
|
|
|
|
|
|
|
|
|
|
str = wp_properties_get (si_props, "enable-control-port");
|
|
|
|
|
if (str && sscanf(str, "%u", &self->control_port) != 1)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (!str)
|
|
|
|
|
wp_properties_setf (si_props, "enable-control-port", "%u",
|
|
|
|
|
self->control_port);
|
|
|
|
|
|
|
|
|
|
str = wp_properties_get (si_props, "enable-monitor");
|
|
|
|
|
if (str && sscanf(str, "%u", &self->monitor) != 1)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (!str)
|
|
|
|
|
wp_properties_setf (si_props, "enable-monitor", "%u", self->monitor);
|
|
|
|
|
|
|
|
|
|
/* 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);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
self->node = g_object_ref (node);
|
|
|
|
|
if (session)
|
|
|
|
|
self->session = g_object_ref (session);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_properties_set (si_props, "si-factory-name", SI_FACTORY_NAME);
|
|
|
|
|
wp_session_item_set_properties (WP_SESSION_ITEM (self),
|
|
|
|
|
g_steal_pointer (&si_props));
|
2020-03-17 23:03:10 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
static gpointer
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_get_associated_proxy (WpSessionItem * item, GType proxy_type)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
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;
|
|
|
|
|
else if (proxy_type == WP_TYPE_ENDPOINT)
|
|
|
|
|
return self->impl_endpoint ? g_object_ref (self->impl_endpoint) : NULL;
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
return NULL;
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_disable_active (WpSessionItem *si)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (si);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
self->format = (struct spa_audio_info_raw){ 0 };
|
|
|
|
|
wp_object_update_features (WP_OBJECT (self), 0,
|
|
|
|
|
WP_SESSION_ITEM_FEATURE_ACTIVE);
|
|
|
|
|
}
|
2020-05-11 11:34:20 +03:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_disable_exported (WpSessionItem *si)
|
2021-03-17 14:52:41 -04:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (si);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
g_clear_object (&self->impl_endpoint);
|
|
|
|
|
wp_object_update_features (WP_OBJECT (self), 0,
|
|
|
|
|
WP_SESSION_ITEM_FEATURE_EXPORTED);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-17 14:52:41 -04:00
|
|
|
on_feature_ports_ready (WpObject * node, GAsyncResult * res,
|
2020-03-17 23:03:10 +02:00
|
|
|
WpTransition * transition)
|
|
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = wp_transition_get_source_object (transition);
|
2020-03-17 23:03:10 +02:00
|
|
|
g_autoptr (GError) error = NULL;
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
if (!wp_object_activate_finish (node, res, &error)) {
|
2020-03-17 23:03:10 +02:00
|
|
|
wp_transition_return_error (transition, g_steal_pointer (&error));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_object_update_features (WP_OBJECT (self),
|
|
|
|
|
WP_SESSION_ITEM_FEATURE_ACTIVE, 0);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-17 14:52:41 -04:00
|
|
|
on_ports_configuration_done (WpCore * core, GAsyncResult * res,
|
2020-05-04 10:12:35 +03:00
|
|
|
WpTransition * transition)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = wp_transition_get_source_object (transition);
|
2020-05-04 10:12:35 +03:00
|
|
|
g_autoptr (GError) error = NULL;
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
if (!wp_core_sync_finish (core, res, &error)) {
|
2020-05-04 10:12:35 +03:00
|
|
|
wp_transition_return_error (transition, g_steal_pointer (&error));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_object_activate (WP_OBJECT (self->node), WP_NODE_FEATURE_PORTS, NULL,
|
|
|
|
|
(GAsyncReadyCallback) on_feature_ports_ready, transition);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:29:48 -04:00
|
|
|
static WpSpaPod *
|
|
|
|
|
format_audio_raw_build (const struct spa_audio_info_raw *info)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpSpaPodBuilder) builder = wp_spa_pod_builder_new_object (
|
2021-01-13 20:11:41 +02:00
|
|
|
"Spa:Pod:Object:Param:Format", "Format");
|
2020-04-16 13:29:48 -04:00
|
|
|
wp_spa_pod_builder_add (builder,
|
2021-01-14 10:50:43 +02:00
|
|
|
"mediaType", "K", "audio",
|
|
|
|
|
"mediaSubtype", "K", "raw",
|
2020-04-16 13:29:48 -04:00
|
|
|
"format", "I", info->format,
|
|
|
|
|
"rate", "i", info->rate,
|
|
|
|
|
"channels", "i", info->channels,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (!SPA_FLAG_IS_SET (info->flags, SPA_AUDIO_FLAG_UNPOSITIONED)) {
|
|
|
|
|
/* Build the position array spa pod */
|
|
|
|
|
g_autoptr (WpSpaPodBuilder) position_builder = wp_spa_pod_builder_new_array ();
|
|
|
|
|
for (guint i = 0; i < info->channels; i++)
|
|
|
|
|
wp_spa_pod_builder_add_id (position_builder, info->position[i]);
|
|
|
|
|
|
|
|
|
|
/* Add the position property */
|
|
|
|
|
wp_spa_pod_builder_add_property (builder, "position");
|
|
|
|
|
g_autoptr (WpSpaPod) position = wp_spa_pod_builder_end (position_builder);
|
|
|
|
|
wp_spa_pod_builder_add_pod (builder, position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wp_spa_pod_builder_end (builder);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 23:03:10 +02:00
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_configure_ports (WpSiAudioAdapter *self, WpTransition * transition)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-17 14:52:41 -04:00
|
|
|
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
|
|
|
|
|
g_autoptr (WpSpaPod) format = NULL, port_format = NULL;
|
|
|
|
|
g_autoptr (WpSpaPod) pod = NULL;
|
|
|
|
|
|
|
|
|
|
/* set the chosen device/client format on the node */
|
|
|
|
|
format = format_audio_raw_build (&self->format);
|
|
|
|
|
wp_pipewire_object_set_param (WP_PIPEWIRE_OBJECT (self->node),
|
|
|
|
|
"Format", 0, format);
|
|
|
|
|
|
|
|
|
|
/* now choose the DSP format: keep the chanels but use F32 plannar @ 48K */
|
|
|
|
|
self->format.format = SPA_AUDIO_FORMAT_F32P;
|
|
|
|
|
self->format.rate = ({
|
|
|
|
|
g_autoptr (WpProperties) props = wp_core_get_remote_properties (core);
|
|
|
|
|
const gchar *rate_str = wp_properties_get (props, "default.clock.rate");
|
|
|
|
|
rate_str ? atoi (rate_str) : 48000;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
wp_debug_object (self, "format: F32P %uch @ %u", self->format.channels,
|
|
|
|
|
self->format.rate);
|
|
|
|
|
|
|
|
|
|
port_format = format_audio_raw_build (&self->format);
|
|
|
|
|
pod = wp_spa_pod_new_object (
|
|
|
|
|
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
|
|
|
|
|
"direction", "I", self->direction,
|
|
|
|
|
"mode", "K", "dsp",
|
|
|
|
|
"monitor", "b", self->monitor,
|
|
|
|
|
"control", "b", self->control_port,
|
|
|
|
|
"format", "P", port_format,
|
|
|
|
|
NULL);
|
|
|
|
|
wp_pipewire_object_set_param (WP_PIPEWIRE_OBJECT (self->node),
|
|
|
|
|
"PortConfig", 0, pod);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_core_sync (core, NULL,
|
|
|
|
|
(GAsyncReadyCallback) on_ports_configuration_done, transition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_node_enum_format_done (WpPipewireObject * proxy, GAsyncResult * res,
|
|
|
|
|
WpTransition * transition)
|
|
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = wp_transition_get_source_object (transition);
|
2021-03-17 14:52:41 -04:00
|
|
|
g_autoptr (WpIterator) formats = NULL;
|
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
gint pref_chan;
|
|
|
|
|
|
|
|
|
|
formats = wp_pipewire_object_enum_params_finish (proxy, res, &error);
|
|
|
|
|
if (error) {
|
|
|
|
|
wp_transition_return_error (transition, g_steal_pointer (&error));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 34 is the max number of channels that SPA knows about
|
|
|
|
|
in the spa_audio_channel enum */
|
|
|
|
|
pref_chan = self->preferred_n_channels ? self->preferred_n_channels : 34;
|
|
|
|
|
|
|
|
|
|
if (!choose_sensible_raw_audio_format (formats, pref_chan, &self->format)) {
|
|
|
|
|
wp_warning_object (self, "failed to choose a sensible audio format");
|
|
|
|
|
wp_transition_return_error (transition,
|
|
|
|
|
g_error_new (WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
|
|
|
|
|
"failed to choose a sensible audio format"));
|
|
|
|
|
return;
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
2021-03-17 14:52:41 -04:00
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_configure_ports (self, transition);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 17:38:31 +03:00
|
|
|
static void
|
2021-03-17 14:52:41 -04:00
|
|
|
on_impl_endpoint_activated (WpObject * object, GAsyncResult * res,
|
|
|
|
|
WpTransition * transition)
|
2020-04-16 17:38:31 +03:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = wp_transition_get_source_object (transition);
|
2021-03-17 14:52:41 -04:00
|
|
|
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
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_enable_active (WpSessionItem *si, WpTransition *transition)
|
2021-03-17 14:52:41 -04:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (si);
|
2021-03-17 14:52:41 -04:00
|
|
|
|
|
|
|
|
if (!wp_session_item_is_configured (si)) {
|
|
|
|
|
wp_transition_return_error (transition,
|
|
|
|
|
g_error_new (WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVARIANT,
|
2021-03-18 14:47:22 -04:00
|
|
|
"si-audio-adapter: item is not configured"));
|
2021-03-17 14:52:41 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wp_pipewire_object_enum_params (WP_PIPEWIRE_OBJECT (self->node),
|
|
|
|
|
"EnumFormat", NULL, NULL,
|
|
|
|
|
(GAsyncReadyCallback) on_node_enum_format_done, transition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_enable_exported (WpSessionItem *si, WpTransition *transition)
|
2021-03-17 14:52:41 -04:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (si);
|
2021-03-17 14:52:41 -04:00
|
|
|
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
|
|
|
|
|
|
|
|
|
|
self->impl_endpoint = wp_impl_endpoint_new (core, WP_SI_ENDPOINT (self));
|
|
|
|
|
|
|
|
|
|
g_signal_connect_object (self->impl_endpoint, "pw-proxy-destroyed",
|
|
|
|
|
G_CALLBACK (wp_session_item_handle_proxy_destroyed), self, 0);
|
|
|
|
|
|
|
|
|
|
wp_object_activate (WP_OBJECT (self->impl_endpoint),
|
|
|
|
|
WP_OBJECT_FEATURES_ALL, NULL,
|
|
|
|
|
(GAsyncReadyCallback) on_impl_endpoint_activated, transition);
|
2020-04-16 17:38:31 +03:00
|
|
|
}
|
|
|
|
|
|
2020-03-17 23:03:10 +02:00
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_class_init (WpSiAudioAdapterClass * klass)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
|
|
|
|
WpSessionItemClass *si_class = (WpSessionItemClass *) klass;
|
|
|
|
|
|
2021-03-18 14:47:22 -04:00
|
|
|
si_class->reset = si_audio_adapter_reset;
|
|
|
|
|
si_class->configure = si_audio_adapter_configure;
|
|
|
|
|
si_class->get_associated_proxy = si_audio_adapter_get_associated_proxy;
|
|
|
|
|
si_class->disable_active = si_audio_adapter_disable_active;
|
|
|
|
|
si_class->disable_exported = si_audio_adapter_disable_exported;
|
|
|
|
|
si_class->enable_active = si_audio_adapter_enable_active;
|
|
|
|
|
si_class->enable_exported = si_audio_adapter_enable_exported;
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 14:45:17 +02:00
|
|
|
static GVariant *
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_get_registration_info (WpSiEndpoint * item)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2020-03-20 14:45:17 +02:00
|
|
|
GVariantBuilder b;
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2020-03-20 14:45:17 +02:00
|
|
|
g_variant_builder_init (&b, G_VARIANT_TYPE ("(ssya{ss})"));
|
|
|
|
|
g_variant_builder_add (&b, "s", self->name);
|
|
|
|
|
g_variant_builder_add (&b, "s", self->media_class);
|
|
|
|
|
g_variant_builder_add (&b, "y", (guchar) self->direction);
|
|
|
|
|
g_variant_builder_add (&b, "a{ss}", NULL);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
2020-03-20 14:45:17 +02:00
|
|
|
return g_variant_builder_end (&b);
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WpProperties *
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_get_properties (WpSiEndpoint * item)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2020-03-17 23:03:10 +02:00
|
|
|
g_autoptr (WpProperties) node_props = NULL;
|
|
|
|
|
WpProperties *result;
|
|
|
|
|
|
2020-03-20 14:45:17 +02:00
|
|
|
result = wp_properties_new (
|
|
|
|
|
PW_KEY_MEDIA_ROLE, self->role,
|
|
|
|
|
NULL);
|
2020-05-07 11:51:13 -04:00
|
|
|
wp_properties_setf (result, "endpoint.priority", "%u", self->priority);
|
2020-03-17 23:03:10 +02:00
|
|
|
|
|
|
|
|
/* copy useful properties from the node */
|
2020-11-13 19:54:00 +02:00
|
|
|
node_props =
|
|
|
|
|
wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (self->node));
|
2020-03-31 12:12:21 +03:00
|
|
|
wp_properties_update_keys (result, node_props,
|
2020-03-17 23:03:10 +02:00
|
|
|
PW_KEY_DEVICE_ID,
|
2020-05-20 13:19:45 -04:00
|
|
|
PW_KEY_NODE_TARGET,
|
2020-03-17 23:03:10 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* associate with the node */
|
|
|
|
|
wp_properties_setf (result, PW_KEY_NODE_ID, "%d",
|
|
|
|
|
wp_proxy_get_bound_id (WP_PROXY (self->node)));
|
|
|
|
|
|
2020-06-02 17:46:35 +03:00
|
|
|
wp_properties_set (result, "endpoint.description",
|
|
|
|
|
wp_properties_get (node_props, PW_KEY_NODE_DESCRIPTION));
|
2020-06-16 16:41:01 +03:00
|
|
|
wp_properties_set (result, PW_KEY_ENDPOINT_AUTOCONNECT,
|
|
|
|
|
wp_properties_get (node_props, PW_KEY_NODE_AUTOCONNECT));
|
2020-06-02 17:46:35 +03:00
|
|
|
|
2020-03-17 23:03:10 +02:00
|
|
|
/* propagate the device icon, if this is a device */
|
|
|
|
|
const gchar *icon = wp_properties_get (node_props, PW_KEY_DEVICE_ICON_NAME);
|
|
|
|
|
if (icon)
|
|
|
|
|
wp_properties_set (result, PW_KEY_ENDPOINT_ICON_NAME, icon);
|
|
|
|
|
|
|
|
|
|
/* endpoint.client.id: the id of the client that created the node
|
|
|
|
|
* Not to be confused with client.id, which will also be set on the endpoint
|
|
|
|
|
* to the id of the client object that creates the endpoint (wireplumber) */
|
|
|
|
|
wp_properties_set (result, PW_KEY_ENDPOINT_CLIENT_ID,
|
|
|
|
|
wp_properties_get (node_props, PW_KEY_CLIENT_ID));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_endpoint_init (WpSiEndpointInterface * iface)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
iface->get_registration_info = si_audio_adapter_get_registration_info;
|
|
|
|
|
iface->get_properties = si_audio_adapter_get_properties;
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 10:12:35 +03:00
|
|
|
static GVariant *
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_get_ports (WpSiPortInfo * item, const gchar * context)
|
2020-05-04 10:12:35 +03:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
WpSiAudioAdapter *self = WP_SI_AUDIO_ADAPTER (item);
|
2020-05-04 10:12:35 +03:00
|
|
|
g_auto (GVariantBuilder) b = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_ARRAY);
|
|
|
|
|
g_autoptr (WpIterator) it = NULL;
|
|
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
WpDirection direction = self->direction;
|
2020-05-19 11:17:52 -04:00
|
|
|
gboolean monitor_context = FALSE;
|
2020-05-04 10:12:35 +03:00
|
|
|
guint32 node_id;
|
|
|
|
|
|
2020-05-19 11:17:52 -04:00
|
|
|
/* context can only be NULL, "reverse" or "monitor" */
|
2020-05-04 10:12:35 +03:00
|
|
|
if (!g_strcmp0 (context, "reverse")) {
|
2020-05-19 11:05:36 -04:00
|
|
|
direction = (self->direction == WP_DIRECTION_INPUT) ?
|
2020-05-04 10:12:35 +03:00
|
|
|
WP_DIRECTION_OUTPUT : WP_DIRECTION_INPUT;
|
|
|
|
|
}
|
2020-05-19 11:17:52 -04:00
|
|
|
else if (!g_strcmp0 (context, "monitor")) {
|
|
|
|
|
direction = WP_DIRECTION_OUTPUT;
|
|
|
|
|
monitor_context = TRUE;
|
|
|
|
|
}
|
2020-05-04 10:12:35 +03:00
|
|
|
else if (context != NULL) {
|
|
|
|
|
/* on any other context, return an empty list of ports */
|
|
|
|
|
return g_variant_new_array (G_VARIANT_TYPE ("(uuu)"), NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&b, G_VARIANT_TYPE ("a(uuu)"));
|
|
|
|
|
node_id = wp_proxy_get_bound_id (WP_PROXY (self->node));
|
|
|
|
|
|
2021-02-05 10:20:33 -05:00
|
|
|
for (it = wp_node_new_ports_iterator (self->node);
|
2020-05-04 10:12:35 +03:00
|
|
|
wp_iterator_next (it, &val);
|
|
|
|
|
g_value_unset (&val))
|
|
|
|
|
{
|
|
|
|
|
WpPort *port = g_value_get_object (&val);
|
|
|
|
|
g_autoptr (WpProperties) props = NULL;
|
2020-05-19 11:17:52 -04:00
|
|
|
const gchar *str;
|
2020-05-04 10:12:35 +03:00
|
|
|
const gchar *channel;
|
|
|
|
|
guint32 port_id, channel_id = 0;
|
2020-05-19 11:17:52 -04:00
|
|
|
gboolean is_monitor = FALSE;
|
2020-05-04 10:12:35 +03:00
|
|
|
|
|
|
|
|
if (wp_port_get_direction (port) != direction)
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-05-19 11:17:52 -04:00
|
|
|
/* skip monitor ports if not monitor context, or skip non-monitor ports if
|
|
|
|
|
* monitor context */
|
2020-11-13 19:54:00 +02:00
|
|
|
props = wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (port));
|
2020-05-19 11:17:52 -04:00
|
|
|
str = wp_properties_get (props, PW_KEY_PORT_MONITOR);
|
|
|
|
|
is_monitor = str && pw_properties_parse_bool (str);
|
|
|
|
|
if (is_monitor != monitor_context)
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-05-04 10:12:35 +03:00
|
|
|
port_id = wp_proxy_get_bound_id (WP_PROXY (port));
|
|
|
|
|
|
|
|
|
|
/* try to find the audio channel; if channel is NULL, this will silently
|
|
|
|
|
leave the channel_id to its default value, 0 */
|
|
|
|
|
channel = wp_properties_get (props, PW_KEY_AUDIO_CHANNEL);
|
2021-01-13 20:11:41 +02:00
|
|
|
if (channel) {
|
|
|
|
|
WpSpaIdValue idval = wp_spa_id_value_from_short_name (
|
|
|
|
|
"Spa:Enum:AudioChannel", channel);
|
|
|
|
|
if (idval)
|
|
|
|
|
channel_id = wp_spa_id_value_number (idval);
|
|
|
|
|
}
|
2020-05-04 10:12:35 +03:00
|
|
|
|
|
|
|
|
g_variant_builder_add (&b, "(uuu)", node_id, port_id, channel_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_variant_builder_end (&b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_port_info_init (WpSiPortInfoInterface * iface)
|
2020-05-04 10:12:35 +03:00
|
|
|
{
|
2021-03-18 14:47:22 -04:00
|
|
|
iface->get_ports = si_audio_adapter_get_ports;
|
2020-05-04 10:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
2021-01-31 23:29:55 +02:00
|
|
|
WP_PLUGIN_EXPORT gboolean
|
|
|
|
|
wireplumber__module_init (WpCore * core, GVariant * args, GError ** error)
|
2020-03-17 23:03:10 +02:00
|
|
|
{
|
2021-03-17 14:52:41 -04:00
|
|
|
wp_si_factory_register (core, wp_si_factory_new_simple (SI_FACTORY_NAME,
|
2021-03-18 14:47:22 -04:00
|
|
|
si_audio_adapter_get_type ()));
|
2021-01-31 23:29:55 +02:00
|
|
|
return TRUE;
|
2020-03-17 23:03:10 +02:00
|
|
|
}
|