Skip to content
Snippets Groups Projects
Commit 1972bc01 authored by Apertis CI robot's avatar Apertis CI robot
Browse files

Merge updates from debian/bookworm

parents 6ff76160 d9542828
No related branches found
No related tags found
2 merge requests!14Backport update from debian/bookworm to v2022pre,!13Update from debian/bookworm for apertis/v2023dev0
Showing
with 315 additions and 586 deletions
......@@ -24,12 +24,13 @@ include:
.fedora:
variables:
# Update this tag when you want to trigger a rebuild
FDO_DISTRIBUTION_TAG: '2021-05-25.1'
FDO_DISTRIBUTION_TAG: '2021-10-26.0'
FDO_DISTRIBUTION_VERSION: '34'
# findutils: used by the .build script below
# dbus-devel: required by pipewire
# dbus-daemon: required by GDBus unit tests
# pip, doxygen: required for documentation
# ShellCheck: required by the CI
FDO_DISTRIBUTION_PACKAGES: >-
findutils
gcc
......@@ -42,6 +43,7 @@ include:
dbus-daemon
python3-pip
doxygen
ShellCheck
# install Sphinx and Breathe to generate documentation
# also install glib2-doc (required to make documentation links to GLib work)
# manually, to remove the 'tsflags=nodocs' flag that is enabled by default
......@@ -224,6 +226,15 @@ build_with_coverity:
- build-*/meson-logs
- cov-int/build-log.txt
shellcheck:
extends:
- .fedora
- .not_coverity
- .fdo.distribution-image@fedora
stage: analysis
script:
- shellcheck $(git grep -l "#\!/.*bin/.*sh")
pages:
extends:
- .not_coverity
......
WirePlumber 0.4.4
WirePlumber 0.4.5
~~~~~~~~~~~~~~~~~
Fixes:
- Fixed a crash that could happen after a node linking error (#76)
- Fixed a bug that would cause capture streams to link to monitor ports
of loopback nodes instead of linking to their capture ports
- Fixed a needless wait that would happen on applications using the pipewire
ALSA plugin (#92)
- Fixed an issue that would cause endless rescan loops in policy-node and
could potentially also cause other strange behaviors in case pavucontrol
or another monitoring utility was open while the policy was rescanning (#77)
- Fixed the endpoints-based policy that broke in recent versions and improved
its codebase to share more code and be more in-line with policy-node
- The semicolon character is now escaped properly in state files (#82)
- When a player requests encoded audio passthrough, the policy now prefers
linking to a device that supports that instead of trying to link to the
default device and potentially failing (#75)
- Miscellaneous robustness fixes in policy-node
API:
- Added WpFactory, a binding for pw_factory proxies. This allows object
managers to query factories that are loaded in the pipewire daemon
- The file-monitor-api plugin can now watch files for changes in addition
to directories
Past releases
~~~~~~~~~~~~~
WirePlumber 0.4.4
.................
Highlights:
- Implemented linking nodes in passthrough mode, which enables encoded
......@@ -26,7 +65,7 @@ API:
as well as the properties table properly
- Added ``WpClient.send_error()``, ``WpSpaPod.fixate()`` and
``WpSpaPod.filter()`` (both in C and Lua)
``WpSpaPod.filter()`` (both in C and Lua)
Misc:
......@@ -51,9 +90,6 @@ Misc:
- Fixed a re-entrancy issue in the wplua runtime (#73)
Past releases
~~~~~~~~~~~~~
WirePlumber 0.4.3
.................
......
wireplumber (0.4.5-1) unstable; urgency=medium
* Team upload.
* New upstream version 0.4.5
* Update symbols file
-- Dylan Aïssi <daissi@debian.org> Wed, 17 Nov 2021 20:34:51 +0100
wireplumber (0.4.4-1+apertis1) apertis; urgency=medium
* Sync updates from Debian bookworm
......
......@@ -40,6 +40,7 @@ libwireplumber-0.4.so.0 libwireplumber-0.4-0 #MINVER#
wp_endpoint_get_media_class@Base 0.3.95
wp_endpoint_get_name@Base 0.3.95
wp_endpoint_get_type@Base 0.3.95
wp_factory_get_type@Base 0.4.5
wp_feature_activation_transition_get_requested_features@Base 0.3.95
wp_feature_activation_transition_get_type@Base 0.3.95
wp_find_file@Base 0.4.2
......
/* WirePlumber
*
* Copyright © 2021 Collabora Ltd.
* @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#define G_LOG_DOMAIN "wp-factory"
#include "factory.h"
#include "private/pipewire-object-mixin.h"
#include "log.h"
/*! \defgroup wpfactory WpFactory */
/*!
* \struct WpFactory
*
* The WpFactory class allows accessing the properties and methods of
* PipeWire Factory objects (`struct pw_factory`).
*
* A WpFactory is constructed internally by wireplumber, when the pipewire
* constructed factory objects are reported in by PipeWire registry
* and it is made available for wireplumber clients through the
* WpObjectManager API.
*/
struct _WpFactory
{
WpGlobalProxy parent;
};
static void wp_factory_pw_object_mixin_priv_interface_init (
WpPwObjectMixinPrivInterface * iface);
G_DEFINE_TYPE_WITH_CODE (WpFactory, wp_factory, 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_factory_pw_object_mixin_priv_interface_init))
static void wp_factory_init (WpFactory * self)
{
}
static void
wp_factory_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_factory_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;
default:
g_assert_not_reached ();
}
}
static const struct pw_factory_events factory_events = {
PW_VERSION_FACTORY_EVENTS,
.info = (HandleEventInfoFunc(factory)) wp_pw_object_mixin_handle_event_info,
};
static void
wp_factory_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
wp_pw_object_mixin_handle_pw_proxy_created (proxy, pw_proxy,
factory, &factory_events);
}
static void
wp_factory_pw_proxy_destroyed (WpProxy * proxy)
{
wp_pw_object_mixin_handle_pw_proxy_destroyed (proxy);
WP_PROXY_CLASS (wp_factory_parent_class)->pw_proxy_destroyed (proxy);
}
static void
wp_factory_class_init (WpFactoryClass * 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_factory_activate_execute_step;
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Factory;
proxy_class->pw_iface_version = PW_VERSION_FACTORY;
proxy_class->pw_proxy_created = wp_factory_pw_proxy_created;
proxy_class->pw_proxy_destroyed = wp_factory_pw_proxy_destroyed;
wp_pw_object_mixin_class_override_properties (object_class);
}
static void
wp_factory_pw_object_mixin_priv_interface_init (
WpPwObjectMixinPrivInterface * iface)
{
wp_pw_object_mixin_priv_interface_info_init_no_params (iface, factory, FACTORY);
}
/* WirePlumber
*
* Copyright © 2021 Collabora Ltd.
* @author Ashok Sidipotu <ashok.sidipotuc@ollabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_FACTORY_H__
#define __WIREPLUMBER_FACTORY_H__
#include "global-proxy.h"
G_BEGIN_DECLS
struct pw_factory;
/*!
* \brief The WpFactory GType
* \ingroup wpfactory
*/
#define WP_TYPE_FACTORY (wp_factory_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpFactory, wp_factory, WP, FACTORY, WpGlobalProxy)
G_END_DECLS
#endif
......@@ -5,6 +5,7 @@ wp_lib_sources = files(
'device.c',
'endpoint.c',
'error.c',
'factory.c',
'global-proxy.c',
'iterator.c',
'link.c',
......@@ -65,6 +66,7 @@ wp_lib_headers = files(
'state.h',
'transition.h',
'wp.h',
'factory.h',
)
install_headers(wp_lib_headers,
......
......@@ -1064,7 +1064,7 @@ expose_tmp_globals (WpCore *core, GAsyncResult *res, WpRegistry *self)
WpGlobal *g = g_ptr_array_index (tmp_globals, i);
/* if global was already removed, drop it */
if (g->flags == 0)
if (g->flags == 0 || g->id == SPA_ID_INVALID)
continue;
/* if old global is owned by proxy, remove it */
......@@ -1307,6 +1307,7 @@ void
wp_global_rm_flag (WpGlobal *global, guint rm_flag)
{
WpRegistry *reg = global->registry;
guint32 id = global->id;
/* no flag to remove */
if (!(global->flags & rm_flag))
......@@ -1314,7 +1315,7 @@ wp_global_rm_flag (WpGlobal *global, guint rm_flag)
wp_trace_boxed (WP_TYPE_GLOBAL, global,
"remove global %u flag 0x%x [flags:0x%x, reg:%p]",
global->id, rm_flag, global->flags, reg);
id, rm_flag, global->flags, reg);
/* global was owned by the proxy; by removing the flag, we clear out
also the proxy pointer, which is presumably no longer valid and we
......@@ -1350,11 +1351,19 @@ wp_global_rm_flag (WpGlobal *global, guint rm_flag)
if (global->flags == 0)
g_object_unref (proxy);
}
/* It's possible to receive consecutive {add, remove, add} events for the
* same id. Since the WpGlobal might not be destroyed immediately below,
* (e.g. it's in tmp_globals list), we must invalidate the id now, so that
* this WpGlobal is not used in reference to objects added later.
*/
global->id = SPA_ID_INVALID;
wp_properties_setf (global->properties, PW_KEY_OBJECT_ID, NULL);
}
/* drop the registry's ref on global when it does not appear on the registry anymore */
if (!(global->flags & WP_GLOBAL_FLAG_APPEARS_ON_REGISTRY) && reg) {
g_clear_pointer (&g_ptr_array_index (reg->globals, global->id), wp_global_unref);
g_clear_pointer (&g_ptr_array_index (reg->globals, id), wp_global_unref);
}
}
......
......@@ -60,6 +60,7 @@ wp_init (WpInitFlags flags)
g_type_ensure (WP_TYPE_METADATA);
g_type_ensure (WP_TYPE_NODE);
g_type_ensure (WP_TYPE_PORT);
g_type_ensure (WP_TYPE_FACTORY);
}
/*!
......
......@@ -39,6 +39,7 @@
#include "transition.h"
#include "wpenums.h"
#include "wpversion.h"
#include "factory.h"
G_BEGIN_DECLS
......
project('wireplumber', ['c'],
version : '0.4.4',
version : '0.4.5',
license : 'MIT',
meson_version : '>= 0.56.0',
default_options : [
......
......@@ -104,7 +104,6 @@ shared_library(
'wireplumber-module-si-audio-adapter',
[
'module-si-audio-adapter.c',
'module-si-audio-adapter/audio-utils.c',
],
c_args : [common_c_args, '-DG_LOG_DOMAIN="m-si-audio-adapter"'],
install : true,
......
......@@ -111,14 +111,14 @@ wp_file_monitor_api_add_watch (WpFileMonitorApi * self, const gchar *path,
g_autoptr (GFile) f = NULL;
GFileMonitorFlags flags = G_FILE_MONITOR_NONE;
/* don't do anything if the directory is already being watched */
/* don't do anything if the path is already being watched */
if (g_hash_table_contains (self->monitors, path))
return TRUE;
/* get directory */
/* get path */
f = g_file_new_for_path (path);
if (!f) {
wp_warning_object (self, "Invalid directory '%s'", path);
wp_warning_object (self, "Invalid path '%s'", path);
return FALSE;
}
......@@ -134,10 +134,10 @@ wp_file_monitor_api_add_watch (WpFileMonitorApi * self, const gchar *path,
}
}
/* create the file monitor for that directory */
fm = g_file_monitor_directory (f, flags, NULL, &e);
/* create the file monitor for that path */
fm = g_file_monitor (f, flags, NULL, &e);
if (e) {
wp_warning_object (self, "Failed to add watch for directory '%s': %s", path,
wp_warning_object (self, "Failed to add watch for path '%s': %s", path,
e->message);
return FALSE;
}
......
......@@ -24,6 +24,7 @@ struct _WpSiAudioAdapter
/* configuration */
WpNode *node;
WpPort *port; /* only used for passthrough or convert mode */
gboolean no_format;
gboolean control_port;
gboolean monitor;
gboolean disable_dsp;
......@@ -69,6 +70,7 @@ si_audio_adapter_reset (WpSessionItem * item)
/* reset */
g_clear_object (&self->node);
g_clear_object (&self->port);
self->no_format = FALSE;
self->control_port = FALSE;
self->monitor = FALSE;
self->disable_dsp = FALSE;
......@@ -126,6 +128,8 @@ si_audio_adapter_find_format (WpSiAudioAdapter * self, WpNode * node)
formats = wp_pipewire_object_enum_params_sync (WP_PIPEWIRE_OBJECT (node),
"EnumFormat", NULL);
if (!formats)
return FALSE;
for (; wp_iterator_next (formats, &value); g_value_unset (&value)) {
WpSpaPod *pod = g_value_get_boxed (&value);
......@@ -224,7 +228,9 @@ si_audio_adapter_configure (WpSessionItem * item, WpProperties *p)
self->portconfig_direction = WP_DIRECTION_OUTPUT;
}
if (!si_audio_adapter_find_format (self, node)) {
str = wp_properties_get (si_props, "item.features.no-format");
self->no_format = str && pw_properties_parse_bool (str);
if (!self->no_format && !si_audio_adapter_find_format (self, node)) {
wp_message_object (item, "no usable format found for node %d",
wp_proxy_get_bound_id (WP_PROXY (node)));
return FALSE;
......@@ -525,8 +531,8 @@ si_audio_adapter_enable_active (WpSessionItem *si, WpTransition *transition)
"ports-changed", (GCallback) on_node_ports_changed, self, 0);
/* If device node, enum available formats and set one of them */
if (self->is_device || self->dont_remix || !self->is_autoconnect ||
self->disable_dsp || self->is_unpositioned)
if (!self->no_format && (self->is_device || self->dont_remix ||
!self->is_autoconnect || self->disable_dsp || self->is_unpositioned))
si_audio_adapter_configure_node (self, transition);
/* Otherwise just finish activating */
......
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include <wp/wp.h>
#include <pipewire/pipewire.h>
#include <spa/param/format-utils.h>
#include <spa/param/audio/format.h>
#include "audio-utils.h"
static enum spa_audio_format
select_format (WpSpaPod *value)
{
enum spa_audio_format ret = SPA_AUDIO_FORMAT_UNKNOWN;
static enum spa_audio_format fmt_order[] = {
/* float 32 is the best because it needs
no conversion from our internal pipeline format */
SPA_AUDIO_FORMAT_F32,
/* signed 16-bit is known to work very well;
unsigned should also be fine */
SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_U16,
/* then go for the formats that are aligned to sizeof(int),
from the best quality to the worst */
SPA_AUDIO_FORMAT_S32,
SPA_AUDIO_FORMAT_U32,
SPA_AUDIO_FORMAT_S24_32,
SPA_AUDIO_FORMAT_U24_32,
/* then float 64, which should need little conversion from float 32 */
SPA_AUDIO_FORMAT_F64,
/* and then try the reverse endianess too */
SPA_AUDIO_FORMAT_F32_OE,
SPA_AUDIO_FORMAT_S16_OE,
SPA_AUDIO_FORMAT_U16_OE,
SPA_AUDIO_FORMAT_S32_OE,
SPA_AUDIO_FORMAT_U32_OE,
SPA_AUDIO_FORMAT_S24_32_OE,
SPA_AUDIO_FORMAT_U24_32_OE,
SPA_AUDIO_FORMAT_F64_OE,
/* then go for unaligned strange formats */
SPA_AUDIO_FORMAT_S24,
SPA_AUDIO_FORMAT_U24,
SPA_AUDIO_FORMAT_S20,
SPA_AUDIO_FORMAT_U20,
SPA_AUDIO_FORMAT_S18,
SPA_AUDIO_FORMAT_U18,
SPA_AUDIO_FORMAT_S24_OE,
SPA_AUDIO_FORMAT_U24_OE,
SPA_AUDIO_FORMAT_S20_OE,
SPA_AUDIO_FORMAT_U20_OE,
SPA_AUDIO_FORMAT_S18_OE,
SPA_AUDIO_FORMAT_U18_OE,
/* leave 8-bit last, that's bad quality */
SPA_AUDIO_FORMAT_S8,
SPA_AUDIO_FORMAT_U8,
/* plannar formats are problematic currently, discourage their use */
SPA_AUDIO_FORMAT_F32P,
SPA_AUDIO_FORMAT_S16P,
SPA_AUDIO_FORMAT_S32P,
SPA_AUDIO_FORMAT_S24_32P,
SPA_AUDIO_FORMAT_S24P,
SPA_AUDIO_FORMAT_F64P,
SPA_AUDIO_FORMAT_U8P,
};
guint32 best = SPA_N_ELEMENTS(fmt_order);
/* Just return the value if it is not a choice value */
if (!wp_spa_pod_is_choice (value)) {
wp_spa_pod_get_id (value, &ret);
return ret;
}
guint32 choice_type =
wp_spa_id_value_number (wp_spa_pod_get_choice_type (value));
/* None */
if (choice_type == SPA_CHOICE_None) {
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (value);
wp_spa_pod_get_id (child, &ret);
}
/* Enum */
else if (choice_type == SPA_CHOICE_Enum) {
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (value);
GValue next = G_VALUE_INIT;
while (wp_iterator_next (it, &next)) {
enum spa_audio_format *format_id = (enum spa_audio_format *)
g_value_get_pointer (&next);
for (guint j = 0; j < SPA_N_ELEMENTS(fmt_order); j++) {
if (*format_id == fmt_order[j] && best > j) {
best = j;
break;
}
}
g_value_unset (&next);
}
if (best < SPA_N_ELEMENTS(fmt_order))
ret = fmt_order[best];
}
return ret;
}
static gint
select_rate (WpSpaPod *value)
{
gint ret = 0;
/* Just return the value if it is not a choice value */
if (!wp_spa_pod_is_choice (value)) {
wp_spa_pod_get_int (value, &ret);
return ret;
}
guint32 choice_type =
wp_spa_id_value_number (wp_spa_pod_get_choice_type (value));
/* None */
if (choice_type == SPA_CHOICE_None) {
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (value);
wp_spa_pod_get_int (child, &ret);
}
/* Enum */
else if (choice_type == SPA_CHOICE_Enum) {
/* pick the one closest to 48Khz */
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (value);
GValue next = G_VALUE_INIT;
while (wp_iterator_next (it, &next)) {
gint *rate = (gint *) g_value_get_pointer (&next);
if (abs (*rate - 48000) < abs (ret - 48000))
ret = *rate;
g_value_unset (&next);
}
}
/* Range */
else if (choice_type == SPA_CHOICE_Range) {
/* a range is typically 3 items: default, min, max;
however, sometimes ALSA drivers give bad min & max values
and pipewire picks a bad default... try to fix that here;
the default should be the one closest to 48K */
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (value);
GValue next = G_VALUE_INIT;
gint vals[3];
gint i = 0, min, max;
while (wp_iterator_next (it, &next) && i < 3) {
vals[i] = *(gint *) g_value_get_pointer (&next);
g_value_unset (&next);
i++;
}
min = SPA_MIN (vals[1], vals[2]);
max = SPA_MAX (vals[1], vals[2]);
ret = SPA_CLAMP (48000, min, max);
}
return ret;
}
static gint
select_channels (WpSpaPod *value, gint preference)
{
gint ret = 0;
/* Just return the value if it is not a choice value */
if (!wp_spa_pod_is_choice (value)) {
wp_spa_pod_get_int (value, &ret);
return ret;
}
guint32 choice_type =
wp_spa_id_value_number (wp_spa_pod_get_choice_type (value));
/* None */
if (choice_type == SPA_CHOICE_None) {
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (value);
wp_spa_pod_get_int (child, &ret);
}
/* Enum */
else if (choice_type == SPA_CHOICE_Enum) {
/* choose the most channels */
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (value);
GValue next = G_VALUE_INIT;
gint diff = SPA_AUDIO_MAX_CHANNELS;
while (wp_iterator_next (it, &next)) {
gint *channel = (gint *) g_value_get_pointer (&next);
if (abs (*channel - preference) < diff) {
diff = abs (*channel - preference);
ret = *channel;
}
g_value_unset (&next);
}
}
/* Range */
else if (choice_type == SPA_CHOICE_Range) {
/* a range is typically 3 items: default, min, max;
we want the most channels, but let's not trust max
to really be the max... ALSA drivers can be broken */
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (value);
GValue next = G_VALUE_INIT;
gint vals[3];
gint i = 0;
while (wp_iterator_next (it, &next) && i < 3) {
vals[i] = *(gint *) g_value_get_pointer (&next);
g_value_unset (&next);
i++;
}
ret = SPA_MAX (vals[1], preference);
ret = SPA_MIN (ret, vals[2]);
}
return ret;
}
gboolean
choose_sensible_raw_audio_format (WpIterator *formats,
gint channels_preference, struct spa_audio_info_raw *result)
{
guint most_channels = 0;
struct spa_audio_info_raw raw;
g_auto (GValue) item = G_VALUE_INIT;
for (; wp_iterator_next (formats, &item); g_value_unset (&item)) {
WpSpaPod *pod = g_value_get_boxed (&item);
uint32_t mtype, mstype;
/* initialize all fields to zero (SPA_AUDIO_FORMAT_UNKNOWN etc) and set
the unpositioned flag, which means there is no channel position array */
spa_memzero (&raw, sizeof(struct spa_audio_info_raw));
SPA_FLAG_SET(raw.flags, SPA_AUDIO_FLAG_UNPOSITIONED);
if (!wp_spa_pod_is_object (pod)) {
g_warning ("non-object POD appeared on formats list; this node is buggy");
continue;
}
if (!wp_spa_pod_get_object (pod, NULL,
"mediaType", "I", &mtype,
"mediaSubtype", "I", &mstype,
NULL)) {
g_warning ("format does not have media type / subtype");
continue;
}
if (!(mtype == SPA_MEDIA_TYPE_audio && mstype == SPA_MEDIA_SUBTYPE_raw))
continue;
/* go through the fields and populate raw */
g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (pod);
GValue next = G_VALUE_INIT;
while (wp_iterator_next (it, &next)) {
WpSpaPod *p = g_value_get_boxed (&next);
const gchar *key = NULL;
g_autoptr (WpSpaPod) value = NULL;
wp_spa_pod_get_property (p, &key, &value);
/* format */
if (g_strcmp0 (key, "format") == 0) {
raw.format = select_format (value);
}
/* rate */
else if (g_strcmp0 (key, "rate") == 0) {
raw.rate = select_rate (value);
}
/* channels */
else if (g_strcmp0 (key, "channels") == 0) {
raw.channels = select_channels (value, channels_preference);
}
/* position */
else if (g_strcmp0 (key, "position") == 0) {
/* just copy the array, there is no choice here */
g_return_val_if_fail (wp_spa_pod_is_array (value), FALSE);
SPA_FLAG_CLEAR (raw.flags, SPA_AUDIO_FLAG_UNPOSITIONED);
g_autoptr (WpIterator) array_it = wp_spa_pod_new_iterator (value);
GValue array_next = G_VALUE_INIT;
guint j = 0;
while (wp_iterator_next (array_it, &array_next)) {
guint32 *pos_id = (guint32 *)g_value_get_pointer (&array_next);
raw.position[j] = *pos_id;
g_value_unset (&array_next);
j++;
}
}
g_value_unset (&next);
}
/* figure out if this one is the best so far */
if (raw.format != SPA_AUDIO_FORMAT_UNKNOWN &&
raw.channels > most_channels ) {
most_channels = raw.channels;
*result = raw;
}
}
/* if we picked a format, most_channels must be > 0 */
return (most_channels > 0);
}
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
struct spa_audio_info_raw;
gboolean choose_sensible_raw_audio_format (WpIterator *formats,
gint channels_preference, struct spa_audio_info_raw *result);
......@@ -24,13 +24,11 @@ struct _WpSiAudioEndpoint
WpDirection direction;
gchar role[32];
guint priority;
WpSpaPod *format;
gchar mode[32];
GTask *format_task;
gboolean disable_dsp;
/* activation */
WpNode *node;
WpPort *port; /* only used for passthrough or convert mode */
WpSiAdapter *adapter;
/* export */
WpImplEndpoint *impl_endpoint;
......@@ -65,17 +63,11 @@ si_audio_endpoint_reset (WpSessionItem * item)
/* reset */
self->name[0] = '\0';
self->media_class[0] = '\0';
self->direction = WP_DIRECTION_INPUT;
self->role[0] = '\0';
self->priority = 0;
if (self->format_task) {
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
g_task_return_new_error (t, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_OPERATION_FAILED,
"item deactivated before format set");
}
g_clear_pointer (&self->format, wp_spa_pod_unref);
self->mode[0] = '\0';
self->disable_dsp = FALSE;
WP_SESSION_ITEM_CLASS (si_audio_endpoint_parent_class)->reset (item);
}
......@@ -119,6 +111,9 @@ si_audio_endpoint_configure (WpSessionItem * item, WpProperties *p)
if (!str)
wp_properties_setf (si_props, "priority", "%u", self->priority);
str = wp_properties_get (si_props, "item.features.no-dsp");
self->disable_dsp = str && pw_properties_parse_bool (str);
wp_properties_set (si_props, "item.factory.name", SI_FACTORY_NAME);
wp_session_item_set_properties (WP_SESSION_ITEM (self),
g_steal_pointer (&si_props));
......@@ -130,12 +125,11 @@ si_audio_endpoint_get_associated_proxy (WpSessionItem * item, GType proxy_type)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
if (proxy_type == WP_TYPE_NODE)
return self->node ? g_object_ref (self->node) : NULL;
else if (proxy_type == WP_TYPE_ENDPOINT)
if (proxy_type == WP_TYPE_ENDPOINT)
return self->impl_endpoint ? g_object_ref (self->impl_endpoint) : NULL;
return NULL;
return wp_session_item_get_associated_proxy (
WP_SESSION_ITEM (self->adapter), proxy_type);
}
static void
......@@ -143,8 +137,8 @@ si_audio_endpoint_disable_active (WpSessionItem *si)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (si);
g_clear_object (&self->adapter);
g_clear_object (&self->node);
g_clear_object (&self->port);
wp_object_update_features (WP_OBJECT (self), 0,
WP_SESSION_ITEM_FEATURE_ACTIVE);
}
......@@ -160,44 +154,19 @@ si_audio_endpoint_disable_exported (WpSessionItem *si)
}
static void
on_port_param_info (WpPipewireObject * port, GParamSpec * param,
WpSiAudioEndpoint *self)
on_adapter_activate_done (WpObject * adapter, GAsyncResult * res,
WpTransition * transition)
{
/* finish the task started by _set_ports_format() */
if (self->format_task) {
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
g_task_return_boolean (t, TRUE);
}
}
WpSiAudioEndpoint *self = wp_transition_get_source_object (transition);
g_autoptr (GError) error = NULL;
static void
on_node_ports_changed (WpObject * node, WpSiAudioEndpoint *self)
{
/* clear port and handler */
if (self->port) {
g_signal_handlers_disconnect_by_func (self->port, on_port_param_info, self);
g_clear_object (&self->port);
if (!wp_object_activate_finish (adapter, res, &error)) {
wp_transition_return_error (transition, g_steal_pointer (&error));
return;
}
if (wp_node_get_n_ports (self->node) > 0) {
/* if non DSP mode, listen for param-info on the single port in order to
* be notified of format changed events */
if (g_strcmp0 (self->mode, "dsp") != 0) {
self->port = wp_node_lookup_port (self->node,
WP_CONSTRAINT_TYPE_PW_PROPERTY, "port.direction", "=s",
self->direction == WP_DIRECTION_INPUT ? "in" : "out",
NULL);
if (self->port)
g_signal_connect_object (self->port, "notify::param-info",
G_CALLBACK (on_port_param_info), self, 0);
}
/* finish the task started by _set_ports_format() */
if (self->format_task) {
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
g_task_return_boolean (t, TRUE);
}
}
wp_object_update_features (WP_OBJECT (self),
WP_SESSION_ITEM_FEATURE_ACTIVE, 0);
}
static void
......@@ -206,17 +175,43 @@ on_node_activate_done (WpObject * node, GAsyncResult * res,
{
WpSiAudioEndpoint *self = wp_transition_get_source_object (transition);
g_autoptr (GError) error = NULL;
g_autoptr (WpCore) core = NULL;
g_autoptr (WpProperties) props = NULL;
if (!wp_object_activate_finish (node, res, &error)) {
wp_transition_return_error (transition, g_steal_pointer (&error));
return;
}
g_signal_connect_object (node, "ports-changed",
(GCallback) on_node_ports_changed, self, 0);
/* create adapter */
core = wp_object_get_core (WP_OBJECT (self));
self->adapter = WP_SI_ADAPTER (wp_session_item_make (core,
"si-audio-adapter"));
if (!self->adapter) {
wp_transition_return_error (transition,
g_error_new (WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVARIANT,
"si-audio-endpoint: could not create si-audio-adapter"));
}
wp_object_update_features (WP_OBJECT (self),
WP_SESSION_ITEM_FEATURE_ACTIVE, 0);
/* configure adapter */
props = wp_properties_new_empty ();
wp_properties_setf (props, "item.node", "%p", node);
wp_properties_set (props, "name", self->name);
wp_properties_set (props, "media.class", "Audio/Sink");
wp_properties_set (props, "item.features.no-format", "true");
wp_properties_set (props, "item.features.monitor", "true");
if (self->disable_dsp)
wp_properties_set (props, "item.features.no-dsp", "true");
if (!wp_session_item_configure (WP_SESSION_ITEM (self->adapter),
g_steal_pointer (&props))) {
wp_transition_return_error (transition,
g_error_new (WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVARIANT,
"si-audio-endpoint: could not configure si-audio-adapter"));
}
/* activate adapter */
wp_object_activate (WP_OBJECT (self->adapter), WP_SESSION_ITEM_FEATURE_ACTIVE,
NULL, (GAsyncReadyCallback) on_adapter_activate_done, transition);
}
static void
......@@ -227,7 +222,7 @@ si_audio_endpoint_enable_active (WpSessionItem *si, WpTransition *transition)
g_autofree gchar *name = g_strdup_printf ("control.%s", self->name);
g_autofree gchar *desc = g_strdup_printf ("%s %s Endpoint", self->role,
(self->direction == WP_DIRECTION_OUTPUT) ? "Capture" : "Playback");
g_autofree gchar *media = g_strdup_printf ("Audio/%s/Virtual",
g_autofree gchar *media = g_strdup_printf ("Audio/%s",
(self->direction == WP_DIRECTION_OUTPUT) ? "Source" : "Sink");
if (!wp_session_item_is_configured (si)) {
......@@ -325,6 +320,8 @@ static WpProperties *
si_audio_endpoint_get_properties (WpSiEndpoint * item)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
g_autoptr (WpNode) node = wp_session_item_get_associated_proxy (
WP_SESSION_ITEM (self->adapter), WP_TYPE_NODE);
WpProperties *result = wp_properties_new_empty ();
wp_properties_set (result, "endpoint.name", self->name);
......@@ -335,8 +332,9 @@ si_audio_endpoint_get_properties (WpSiEndpoint * item)
wp_properties_set (result, "media.role", self->role);
/* associate with the node */
g_return_val_if_fail (node, NULL);
wp_properties_setf (result, PW_KEY_NODE_ID, "%d",
wp_proxy_get_bound_id (WP_PROXY (self->node)));
wp_proxy_get_bound_id (WP_PROXY (node)));
return result;
}
......@@ -352,55 +350,7 @@ static GVariant *
si_audio_endpoint_get_ports (WpSiLinkable * item, const gchar * context)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
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;
guint32 node_id;
if (!g_strcmp0 (context, "output")) {
direction = WP_DIRECTION_OUTPUT;
}
else if (!g_strcmp0 (context, "input")) {
direction = WP_DIRECTION_INPUT;
}
else {
/* 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));
for (it = wp_node_new_ports_iterator (self->node);
wp_iterator_next (it, &val);
g_value_unset (&val))
{
WpPort *port = g_value_get_object (&val);
g_autoptr (WpProperties) props = NULL;
const gchar *channel;
guint32 port_id, channel_id = 0;
if (wp_port_get_direction (port) != direction)
continue;
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 */
props = wp_pipewire_object_get_properties (WP_PIPEWIRE_OBJECT (port));
channel = wp_properties_get (props, PW_KEY_AUDIO_CHANNEL);
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);
}
g_variant_builder_add (&b, "(uuu)", node_id, port_id, channel_id);
}
return g_variant_builder_end (&b);
return wp_si_linkable_get_ports (WP_SI_LINKABLE (self->adapter), context);
}
static void
......@@ -413,79 +363,7 @@ static WpSpaPod *
si_audio_endpoint_get_ports_format (WpSiAdapter * item, const gchar **mode)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
if (mode)
*mode = self->mode;
return self->format ? wp_spa_pod_ref (self->format) : NULL;
}
static WpSpaPod *
build_endpoint_format (WpSiAudioEndpoint * self, guint32 format, gint channels,
WpSpaPod *pos)
{
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
g_autoptr (WpSpaPod) position = pos;
g_autoptr (WpProperties) props = NULL;
g_autoptr (WpSpaPodBuilder) b = NULL;
const gchar *rate_str = NULL;
g_return_val_if_fail (channels > 0, NULL);
/* get the default clock rate */
g_return_val_if_fail (core, NULL);
props = wp_core_get_remote_properties (core);
g_return_val_if_fail (props, NULL);
rate_str = wp_properties_get (props, "default.clock.rate");
/* build the position array if not given */
if (!position) {
switch (channels) {
case 1: {
g_autoptr (WpSpaPodBuilder) pos_b = wp_spa_pod_builder_new_array ();
wp_spa_pod_builder_add_id (pos_b, SPA_AUDIO_CHANNEL_MONO);
position = wp_spa_pod_builder_end (pos_b);
break;
}
case 2: {
g_autoptr (WpSpaPodBuilder) pos_b = wp_spa_pod_builder_new_array ();
wp_spa_pod_builder_add_id (pos_b, SPA_AUDIO_CHANNEL_FL);
wp_spa_pod_builder_add_id (pos_b, SPA_AUDIO_CHANNEL_FR);
position = wp_spa_pod_builder_end (pos_b);
break;
}
default:
break;
}
}
/* build the format */
b = wp_spa_pod_builder_new_object ("Spa:Pod:Object:Param:Format", "Format");
wp_spa_pod_builder_add_property (b, "mediaType");
wp_spa_pod_builder_add_id (b, SPA_MEDIA_TYPE_audio);
wp_spa_pod_builder_add_property (b, "mediaSubtype");
wp_spa_pod_builder_add_id (b, SPA_MEDIA_SUBTYPE_raw);
wp_spa_pod_builder_add_property (b, "format");
wp_spa_pod_builder_add_id (b, format);
wp_spa_pod_builder_add_property (b, "rate");
wp_spa_pod_builder_add_int (b, rate_str ? atoi (rate_str) : 48000);
wp_spa_pod_builder_add_property (b, "channels");
wp_spa_pod_builder_add_int (b, channels);
if (position) {
wp_spa_pod_builder_add_property (b, "position");
wp_spa_pod_builder_add_pod (b, position);
}
return wp_spa_pod_builder_end (b);
}
static WpSpaPod *
build_endpoint_default_format (WpSiAudioEndpoint * self, const gchar *mode)
{
guint32 format = SPA_AUDIO_FORMAT_F32;
/* if dsp, use plannar format */
if (!mode || g_strcmp0 (mode, "dsp") == 0)
format = SPA_AUDIO_FORMAT_F32P;
return build_endpoint_format (self, format, 2, NULL);
return wp_si_adapter_get_ports_format (self->adapter, mode);
}
static void
......@@ -493,61 +371,15 @@ si_audio_endpoint_set_ports_format (WpSiAdapter * item, WpSpaPod *f,
const gchar *mode, GAsyncReadyCallback callback, gpointer data)
{
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
g_autoptr (WpSpaPod) format = f;
guint32 active = 0;
g_return_if_fail (core);
/* cancel previous task if any */
if (self->format_task) {
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
g_task_return_new_error (t, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVARIANT,
"setting new format before previous done");
}
/* build default format if NULL was given */
if (!format) {
format = build_endpoint_default_format (self, mode);
g_return_if_fail (format);
}
/* create the new task */
g_return_if_fail (!self->format_task);
self->format_task = g_task_new (self, NULL, callback, data);
active = wp_object_get_active_features (WP_OBJECT (self->node));
if (G_UNLIKELY (!(active & WP_NODE_FEATURE_PORTS))) {
g_autoptr (GTask) t = g_steal_pointer (&self->format_task);
g_task_return_new_error (t, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_OPERATION_FAILED,
"node feature ports is not enabled, aborting set format operation");
return;
}
/* set format and mode */
g_clear_pointer (&self->format, wp_spa_pod_unref);
self->format = g_steal_pointer (&format);
strncpy (self->mode, mode ? mode : "dsp", sizeof (self->mode) - 1);
/* configure DSP with chosen format */
wp_pipewire_object_set_param (WP_PIPEWIRE_OBJECT (self->node),
"PortConfig", 0, wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
"direction", "I", WP_DIRECTION_INPUT,
"mode", "K", self->mode,
"monitor", "b", TRUE,
"format", "P", self->format,
NULL));
/* the task finishes with new ports being emitted -> on_node_ports_changed */
wp_si_adapter_set_ports_format (self->adapter, f, mode, callback, data);
}
static gboolean
si_audio_endpoint_set_ports_format_finish (WpSiAdapter * item,
GAsyncResult * res, GError ** error)
{
return g_task_propagate_boolean (G_TASK (res), error);
WpSiAudioEndpoint *self = WP_SI_AUDIO_ENDPOINT (item);
return wp_si_adapter_set_ports_format_finish (self->adapter, res, error);
}
static void
......
......@@ -310,9 +310,10 @@ create_links (WpSiStandardLink * self, WpTransition * transition,
/* activate to ensure it is created without errors */
self->n_async_ops_wait++;
wp_object_activate (WP_OBJECT (link),
wp_object_activate_closure (WP_OBJECT (link),
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL, NULL,
(GAsyncReadyCallback) on_link_activated, transition);
g_cclosure_new_object (
(GCallback) on_link_activated, G_OBJECT (transition)));
}
g_variant_iter_free (iter);
return self->node_links->len > 0;
......
......@@ -21,6 +21,7 @@ function configProperties(node)
["node.id"] = node["bound-id"],
["client.id"] = np["client.id"],
["object.path"] = np["object.path"],
["priority.session"] = np["priority.session"],
}
for k, v in pairs(np) do
......
......@@ -24,7 +24,7 @@ state_table = state and state:load() or {}
function serializeArray(a)
local str = ""
for _, v in ipairs(a) do
str = str .. tostring(v) .. ";"
str = str .. tostring(v):gsub(";", "\\;") .. ";"
end
return str
end
......@@ -32,16 +32,19 @@ end
-- simple deserializer "foo;bar;" -> {"foo", "bar"}
function parseArray(str, convert_value)
local array = {}
local pos = 1
while true do
local next = str:find(";", pos, true)
if next then
local val = str:sub(pos, next-1)
local val = ""
local escaped = false
for i = 1, #str do
local c = str:sub(i,i)
if c == '\\' then
escaped = true
elseif c == ';' and not escaped then
val = convert_value and convert_value(val) or val
table.insert(array, val)
pos = next + 1
val = ""
else
break
val = val .. tostring(c)
escaped = false
end
end
return array
......@@ -263,6 +266,7 @@ function findBestRoute(dev_info, device_id)
if ri.direction == "Output" and ri.available ~= ri.prev_available then
best_avail = ri
ri.save = true
break
elseif ri.available == "yes" then
if (best_avail == nil or ri.priority > best_avail.priority) then
best_avail = ri
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment