Add port order metadata to JACK sink / source ports

Adds JACK metadata property to ports created by *module-jack-sink*
and *module-jack-source* with key `JACK_METADATA_ORDER`, the port index
(1-based, in order of creation) as value and type
`http://www.w3.org/2001/XMLSchema#int`.

This allows JACK applications, which use JACK metadata, to list or display
these ports in correct order.

See also: https://jackaudio.org/api/group__Metadata.html

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/550>
This commit is contained in:
Christopher Arndt 2021-05-01 16:57:13 +02:00 committed by PulseAudio Marge Bot
parent 39125a0f2b
commit 2af43a8baf
2 changed files with 34 additions and 0 deletions

View file

@ -28,6 +28,8 @@
#include <unistd.h>
#include <jack/jack.h>
#include <jack/metadata.h>
#include <jack/uuid.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
@ -69,6 +71,8 @@ PA_MODULE_USAGE(
"connect=<connect ports?>");
#define DEFAULT_SINK_NAME "jack_out"
#define METADATA_TYPE_INT "http://www.w3.org/2001/XMLSchema#int"
#define METADATA_KEY_ORDER "http://jackaudio.org/metadata/order"
struct userdata {
pa_core *core;
@ -301,6 +305,8 @@ int pa__init(pa_module*m) {
const char **ports = NULL, **p;
pa_sink_new_data data;
jack_latency_range_t r;
jack_uuid_t port_uuid;
char port_order[4];
size_t n;
pa_assert(m);
@ -389,6 +395,17 @@ int pa__init(pa_module*m) {
pa_log("jack_port_register() failed.");
goto fail;
}
/* Set order of ports as JACK metadata, if possible. */
/* See: https://jackaudio.org/api/group__Metadata.html */
port_uuid = jack_port_uuid(u->port[i]);
if (!jack_uuid_empty(port_uuid)) {
if (snprintf(port_order, 4, "%d", i+1) >= 4)
pa_log("Port order metadata value > 999 truncated.");
if (jack_set_property(u->client, port_uuid, METADATA_KEY_ORDER, port_order, METADATA_TYPE_INT) != 0)
pa_log("jack_set_property() failed.");
}
}
pa_sink_new_data_init(&data);

View file

@ -28,6 +28,8 @@
#include <unistd.h>
#include <jack/jack.h>
#include <jack/metadata.h>
#include <jack/uuid.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
@ -59,6 +61,8 @@ PA_MODULE_USAGE(
"connect=<connect ports?>");
#define DEFAULT_SOURCE_NAME "jack_in"
#define METADATA_TYPE_INT "http://www.w3.org/2001/XMLSchema#int"
#define METADATA_KEY_ORDER "http://jackaudio.org/metadata/order"
struct userdata {
pa_core *core;
@ -249,6 +253,8 @@ int pa__init(pa_module*m) {
const char **ports = NULL, **p;
pa_source_new_data data;
jack_latency_range_t r;
jack_uuid_t port_uuid;
char port_order[4];
size_t n;
pa_assert(m);
@ -331,6 +337,17 @@ int pa__init(pa_module*m) {
pa_log("jack_port_register() failed.");
goto fail;
}
/* Set order of ports as JACK metadata, if possible. */
/* See: https://jackaudio.org/api/group__Metadata.html */
port_uuid = jack_port_uuid(u->port[i]);
if (!jack_uuid_empty(port_uuid)) {
if (snprintf(port_order, 4, "%d", i+1) >= 4)
pa_log("Port order metadata value > 999 truncated.");
if (jack_set_property(u->client, port_uuid, METADATA_KEY_ORDER, port_order, METADATA_TYPE_INT) != 0)
pa_log("jack_set_property() failed.");
}
}
pa_source_new_data_init(&data);